com.intellij.openapi.fileTypes.ExactFileNameMatcher Java Examples

The following examples show how to use com.intellij.openapi.fileTypes.ExactFileNameMatcher. 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 File: FileTypeAssocTable.java    From consulo with 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 File: FileTypeAssocTable.java    From consulo with 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 File: BuildSystemProvider.java    From intellij with 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 File: BashFileTypeLoader.java    From BashSupport with 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 File: IgnoreManager.java    From idea-gitignore with 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 File: BcfgFileTypeFactory.java    From buck with 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 File: BuckFileTypeFactory.java    From buck with 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 File: FileTypeAssocTable.java    From consulo with 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 File: FileTypeAssocTable.java    From consulo with 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 File: ESLintConfigFileTypeFactory.java    From eslint-plugin with 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 File: IgnoreFileTypeFactory.java    From idea-gitignore with 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());
}