Java Code Examples for com.intellij.openapi.fileTypes.ExtensionFileNameMatcher

The following examples show how to use com.intellij.openapi.fileTypes.ExtensionFileNameMatcher. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: consulo   Source File: RemovedMappingTracker.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
static List<RemovedMapping> readRemovedMappings(@Nonnull Element e) {
  List<Element> children = e.getChildren(ELEMENT_REMOVED_MAPPING);
  if (children.isEmpty()) {
    return Collections.emptyList();
  }

  List<RemovedMapping> result = new ArrayList<>();
  for (Element mapping : children) {
    String ext = mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_EXT);
    FileNameMatcher matcher = ext == null ? FileTypeManager.parseFromString(mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_PATTERN)) : new ExtensionFileNameMatcher(ext);
    boolean approved = Boolean.parseBoolean(mapping.getAttributeValue(ATTRIBUTE_APPROVED));
    String fileTypeName = mapping.getAttributeValue(ATTRIBUTE_TYPE);
    if (fileTypeName == null) continue;

    RemovedMapping removedMapping = new RemovedMapping(matcher, fileTypeName, approved);
    result.add(removedMapping);
  }
  return result;
}
 
Example 2
Source Project: consulo   Source File: RemovedMappingTracker.java    License: Apache License 2.0 6 votes vote down vote up
private static Element writeRemovedMapping(@Nonnull String fileTypeName, @Nonnull FileNameMatcher matcher, boolean specifyTypeName, boolean approved) {
  Element mapping = new Element(ELEMENT_REMOVED_MAPPING);
  if (matcher instanceof ExtensionFileNameMatcher) {
    mapping.setAttribute(AbstractFileType.ATTRIBUTE_EXT, ((ExtensionFileNameMatcher)matcher).getExtension());
  }
  else if (AbstractFileType.writePattern(matcher, mapping)) {
    return null;
  }
  if (approved) {
    mapping.setAttribute(ATTRIBUTE_APPROVED, "true");
  }
  if (specifyTypeName) {
    mapping.setAttribute(ATTRIBUTE_TYPE, fileTypeName);
  }

  return mapping;
}
 
Example 3
Source Project: consulo   Source File: FileTypeAssocTable.java    License: Apache License 2.0 6 votes vote down vote up
boolean removeAssociation(@Nonnull FileNameMatcher matcher, @Nonnull T type) {
  if (matcher instanceof ExtensionFileNameMatcher) {
    String extension = ((ExtensionFileNameMatcher)matcher).getExtension();
    if (myExtensionMappings.get(extension) == type) {
      myExtensionMappings.remove(extension);
      return true;
    }
    return false;
  }

  if (matcher instanceof ExactFileNameMatcher) {
    final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher;
    String fileName = exactFileNameMatcher.getFileName();

    final Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings;
    if (mapToUse.get(fileName) == type) {
      mapToUse.remove(fileName);
      return true;
    }
    return false;
  }

  return myMatchingMappings.removeIf(assoc -> matcher.equals(assoc.getFirst()));
}
 
Example 4
Source Project: consulo   Source File: FileTypeAssocTable.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
T findAssociatedFileType(@Nonnull FileNameMatcher matcher) {
  if (matcher instanceof ExtensionFileNameMatcher) {
    return findByExtension(((ExtensionFileNameMatcher)matcher).getExtension());
  }

  if (matcher instanceof ExactFileNameMatcher) {
    final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher;

    Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings;
    return mapToUse.get(exactFileNameMatcher.getFileName());
  }

  for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) {
    if (matcher.equals(mapping.getFirst())) return mapping.getSecond();
  }

  return null;
}
 
Example 5
@NotNull
private List<FileNameMatcher> parse(@Nullable String semicolonDelimited) {
    if (semicolonDelimited == null) {
        return Collections.emptyList();
    }

    StringTokenizer tokenizer = new StringTokenizer(semicolonDelimited, FileTypeConsumer.EXTENSION_DELIMITER, false);
    ArrayList<FileNameMatcher> list = new ArrayList<>();
    while (tokenizer.hasMoreTokens()) {
        list.add(new ExtensionFileNameMatcher(tokenizer.nextToken().trim()));
    }
    return list;
}
 
Example 6
Source Project: intellij   Source File: BuildSystemProvider.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns the list of file types recognized as build system files. */
default ImmutableList<FileNameMatcher> buildLanguageFileTypeMatchers() {
  ImmutableList.Builder<FileNameMatcher> list = ImmutableList.builder();
  possibleBuildFileNames().forEach(s -> list.add(new ExactFileNameMatcher(s)));
  possibleWorkspaceFileNames().forEach(s -> list.add(new ExactFileNameMatcher(s)));
  list.add(new ExtensionFileNameMatcher("bzl"));
  return list.build();
}
 
Example 7
Source Project: intellij   Source File: ProjectViewFileTypeFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void createFileTypes(@NotNull final FileTypeConsumer consumer) {
  FileNameMatcher[] matchers =
      ProjectViewStorageManager.VALID_EXTENSIONS
          .stream()
          .map(ExtensionFileNameMatcher::new)
          .toArray(ExtensionFileNameMatcher[]::new);
  consumer.consume(ProjectViewFileType.INSTANCE, matchers);
}
 
Example 8
Source Project: buck   Source File: BcfgFileTypeFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) {
  fileTypeConsumer.consume(
      BcfgFileType.INSTANCE,
      new ExtensionFileNameMatcher(BcfgFileType.DEFAULT_EXTENSION),
      new ExactFileNameMatcher(".buckconfig.local"),
      new ExtensionFileNameMatcher("bcfg"));
}
 
Example 9
Source Project: buck   Source File: BuckFileTypeFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) {
  fileTypeConsumer.consume(
      BuckFileType.INSTANCE,
      new ExactFileNameMatcher(BuckFileType.DEFAULT_FILENAME),
      new ExtensionFileNameMatcher(BuckFileType.DEFAULT_FILENAME),
      new ExtensionFileNameMatcher(BuckFileType.DEFAULT_EXTENSION));
}
 
Example 10
Source Project: consulo   Source File: FileTypeAssocTable.java    License: Apache License 2.0 5 votes vote down vote up
boolean isAssociatedWith(@Nonnull T type, @Nonnull FileNameMatcher matcher) {
  if (matcher instanceof ExtensionFileNameMatcher || matcher instanceof ExactFileNameMatcher) {
    return findAssociatedFileType(matcher) == type;
  }

  for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) {
    if (matcher.equals(mapping.getFirst()) && type == mapping.getSecond()) return true;
  }

  return false;
}
 
Example 11
Source Project: consulo   Source File: FileTypeAssocTable.java    License: Apache License 2.0 5 votes vote down vote up
public void addAssociation(@Nonnull FileNameMatcher matcher, @Nonnull T type) {
  if (matcher instanceof ExtensionFileNameMatcher) {
    myExtensionMappings.put(((ExtensionFileNameMatcher)matcher).getExtension(), type);
  }
  else if (matcher instanceof ExactFileNameMatcher) {
    final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher;

    Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings;
    mapToUse.put(exactFileNameMatcher.getFileName(), type);
  }
  else {
    myMatchingMappings.add(Pair.create(matcher, type));
  }
}
 
Example 12
Source Project: intellij-haxe   Source File: HaxeFileTypeLoader.java    License: Apache License 2.0 4 votes vote down vote up
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
  consumer.consume(
    HaxeFileType.HAXE_FILE_TYPE,
    new ExtensionFileNameMatcher(HaxeFileType.DEFAULT_EXTENSION));
}
 
Example 13
Source Project: intellij-haxe   Source File: HXMLFileTypeFactory.java    License: Apache License 2.0 4 votes vote down vote up
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
  consumer.consume(
    HXMLFileType.INSTANCE,
    new ExtensionFileNameMatcher(HXMLFileType.DEFAULT_EXTENSION));
}