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

The following examples show how to use com.intellij.openapi.fileTypes.ExactFileNameMatcher. 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: 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 2
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 3
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 4
Source Project: BashSupport   Source File: BashFileTypeLoader.java    License: Apache License 2.0 5 votes vote down vote up
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
    consumer.consume(BashFileType.BASH_FILE_TYPE, BashFileType.SH_EXTENSION);
    consumer.consume(BashFileType.BASH_FILE_TYPE, BashFileType.BASH_EXTENSION);

    consumer.consume(BashFileType.BASH_FILE_TYPE,
            new ExactFileNameMatcher(BashFileType.BASHRC_FILENAME),
            new ExactFileNameMatcher(BashFileType.PROFILE_FILENAME),
            new ExactFileNameMatcher(BashFileType.BASH_LOGOUT_FILENAME),
            new ExactFileNameMatcher(BashFileType.BASH_PROFILE_FILENAME),
            new ExactFileNameMatcher(BashFileType.BASH_ALIASES_FILENAME));
}
 
Example 5
Source Project: idea-gitignore   Source File: IgnoreManager.java    License: MIT License 5 votes vote down vote up
/**
 * Associates given file with proper {@link IgnoreFileType}.
 *
 * @param fileName to associate
 * @param fileType file type to bind with pattern
 */
public static void associateFileType(@NotNull final String fileName, @NotNull final IgnoreFileType fileType) {
    final Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
        application.invokeLater(() -> application.runWriteAction(() -> {
            fileTypeManager.associate(fileType, new ExactFileNameMatcher(fileName));
            FILE_TYPES_ASSOCIATION_QUEUE.remove(fileName);
        }), ModalityState.NON_MODAL);
    } else if (!FILE_TYPES_ASSOCIATION_QUEUE.containsKey(fileName)) {
        FILE_TYPES_ASSOCIATION_QUEUE.put(fileName, fileType);
    }
}
 
Example 6
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 7
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 8
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 9
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 10
Source Project: eslint-plugin   Source File: ESLintConfigFileTypeFactory.java    License: MIT License 4 votes vote down vote up
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
        consumer.consume(ESLintConfigFileType.INSTANCE, new ExactFileNameMatcher(ESLintConfigFileType.ESLINTRC));
//                new ExtensionFileNameMatcher(ESLintConfigFileType.ESLINTRC), new ExactFileNameMatcher("eslint.json"));
    }
 
Example 11
Source Project: idea-gitignore   Source File: IgnoreFileTypeFactory.java    License: MIT License 2 votes vote down vote up
/**
 * Shorthand for consuming ignore file types.
 *
 * @param consumer file types consumer
 * @param fileType file type to consume
 */
private void consume(@NotNull FileTypeConsumer consumer, @NotNull IgnoreFileType fileType) {
    consumer.consume(fileType, new ExactFileNameMatcher(fileType.getIgnoreLanguage().getFilename()));
    consumer.consume(fileType, fileType.getIgnoreLanguage().getExtension());
}