Java 类com.intellij.openapi.fileTypes.ExtensionFileNameMatcher 实例源码

项目:intellij-ce-playground    文件:FileTypeAssocTable.java   
@Nullable
public T findAssociatedFileType(@NotNull FileNameMatcher matcher) {
  if (matcher instanceof ExtensionFileNameMatcher) {
    return myExtensionMappings.get(((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;
}
项目:intellij-ce-playground    文件:ResolveImportUtil.java   
@Nullable
private static PsiFile findPyFileInDir(PsiDirectory dir, String referencedName) {
  PsiFile file = dir.findFile(referencedName + PyNames.DOT_PY);
  if (file == null) {
    final List<FileNameMatcher> associations = FileTypeManager.getInstance().getAssociations(PythonFileType.INSTANCE);
    for (FileNameMatcher association : associations) {
      if (association instanceof ExtensionFileNameMatcher) {
        file = dir.findFile(referencedName + "." + ((ExtensionFileNameMatcher)association).getExtension());
        if (file != null) break;
      }
    }
  }
  if (file != null && FileUtil.getNameWithoutExtension(file.getName()).equals(referencedName)) {
    return file;
  }
  return null;
}
项目:tools-idea    文件:FileTypeAssocTable.java   
public void addAssociation(FileNameMatcher matcher, T type) {
  if (matcher instanceof ExtensionFileNameMatcher) {
    myExtensionMappings.put(((ExtensionFileNameMatcher)matcher).getExtension(), type);
  }
  else if (matcher instanceof ExactFileNameMatcher) {
    final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher;

    if (exactFileNameMatcher.isIgnoreCase()) {
      myExactFileNameAnyCaseMappings.put(exactFileNameMatcher.getFileName(), type);
    } else {
      myExactFileNameMappings.put(exactFileNameMatcher.getFileName(), type);
    }
  } else {
    myMatchingMappings.add(new Pair<FileNameMatcher, T>(matcher, type));
  }
}
项目:tools-idea    文件:FileTypeAssocTable.java   
@Nullable
public T findAssociatedFileType(final FileNameMatcher matcher) {
  if (matcher instanceof ExtensionFileNameMatcher) {
    return myExtensionMappings.get(((ExtensionFileNameMatcher)matcher).getExtension());
  }

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

    if (exactFileNameMatcher.isIgnoreCase()) {
      return myExactFileNameAnyCaseMappings.get(exactFileNameMatcher.getFileName());
    } else {
      return myExactFileNameMappings.get(exactFileNameMatcher.getFileName());
    }
  }

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

  return null;
}
项目:consulo-lua    文件:LuaFileUtil.java   
@Override
public boolean accept(VirtualFile file)
{
    if(file.isDirectory())
    {
        return true;
    }

    for(ExtensionFileNameMatcher matcher : LuaFileType.EXTENSION_FILE_NAME_MATCHERS)
    {
        if(matcher.accept(file.getName()))
        {
            return true;
        }
    }

    return false;
}
项目:consulo    文件:FileTypeAssocTable.java   
public void addAssociation(FileNameMatcher matcher, T type) {
  if (matcher instanceof ExtensionFileNameMatcher) {
    myExtensionMappings.put(((ExtensionFileNameMatcher)matcher).getExtension(), type);
  }
  else if (matcher instanceof ExactFileNameMatcher) {
    final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher;

    if (exactFileNameMatcher.isIgnoreCase()) {
      myExactFileNameAnyCaseMappings.put(exactFileNameMatcher.getFileName(), type);
    } else {
      myExactFileNameMappings.put(exactFileNameMatcher.getFileName(), type);
    }
  } else {
    myMatchingMappings.add(new Pair<FileNameMatcher, T>(matcher, type));
  }
}
项目:consulo    文件:FileTypeAssocTable.java   
@Nullable
public T findAssociatedFileType(final FileNameMatcher matcher) {
  if (matcher instanceof ExtensionFileNameMatcher) {
    return myExtensionMappings.get(((ExtensionFileNameMatcher)matcher).getExtension());
  }

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

    if (exactFileNameMatcher.isIgnoreCase()) {
      return myExactFileNameAnyCaseMappings.get(exactFileNameMatcher.getFileName());
    } else {
      return myExactFileNameMappings.get(exactFileNameMatcher.getFileName());
    }
  }

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

  return null;
}
项目:protobuf-jetbrains-plugin    文件:ProtostuffPluginController.java   
@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;
}
项目:intellij-ce-playground    文件:FileNameMatcherFactoryImpl.java   
@NotNull
public FileNameMatcher createMatcher(@NotNull String pattern) {
  if (pattern.startsWith("*.") &&
      pattern.indexOf('*', 2) < 0 &&
      pattern.indexOf('.', 2) < 0 &&
      pattern.indexOf('?', 2) < 0) {
    return new ExtensionFileNameMatcher(pattern.substring(2).toLowerCase());
  }

  if (pattern.contains("*") || pattern.contains("?")) {
    return new WildcardFileNameMatcher(pattern);
  }

  return new ExactFileNameMatcher(pattern);
}
项目:intellij-ce-playground    文件:FileTypeAssocTable.java   
public boolean isAssociatedWith(@NotNull T type, @NotNull 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;
}
项目:intellij-ce-playground    文件:FileTypeAssocTable.java   
public void addAssociation(FileNameMatcher matcher, 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));
  }
}
项目:intellij-ce-playground    文件:FileTypeAssocTable.java   
boolean removeAssociation(@NotNull FileNameMatcher matcher, @NotNull 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;
  }

  List<Pair<FileNameMatcher, T>> copy = new ArrayList<Pair<FileNameMatcher, T>>(myMatchingMappings);
  for (Pair<FileNameMatcher, T> assoc : copy) {
    if (matcher.equals(assoc.getFirst())) {
      myMatchingMappings.remove(assoc);
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:AndroidRenderscriptFileType.java   
public static FileNameMatcher[] fileNameMatchers() {
  return new FileNameMatcher[] {
    new ExtensionFileNameMatcher(CODE_EXTENSION),
    new ExtensionFileNameMatcher(FS_CODE_EXTENSION),
    new ExtensionFileNameMatcher(HEADER_EXTENSION),
  };
}
项目:intellij    文件:ProjectViewFileTypeFactory.java   
@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);
}
项目:spoofax-intellij    文件:MetaborgFileTypeConsumer.java   
/**
 * Consumes the file type with only the specified extensions.
 *
 * @param fileType   The file type.
 * @param extensions The file extensions, without a leading '.'.
 */
public void consume(final FileType fileType, @NonNls final String... extensions) {
    Preconditions.checkNotNull(fileType);
    Preconditions.checkNotNull(extensions);

    final FileNameMatcher[] matchers = new FileNameMatcher[extensions.length];
    for (int i = 0; i < extensions.length; i++) {
        matchers[i] = new ExtensionFileNameMatcher(extensions[i]);
    }
    consume(fileType, matchers);
}
项目:spoofax-intellij    文件:FileTypeUtils.java   
/**
 * Registers the given file type with IntelliJ IDEA.
 *
 * @param fileType The file type to register.
 */
public static void register(final IMetaborgFileType fileType) {
    FileTypeManagerEx.getInstanceEx().registerFileType(fileType);

    // Associate the file type with its file extensions.
    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    for (final String ext : fileType.getExtensions()) {
        final FileNameMatcher matcher = new ExtensionFileNameMatcher(ext);
        fileTypeManager.associate(fileType, matcher);
    }
}
项目:tools-idea    文件:FileNameMatcherFactoryImpl.java   
@NotNull
public FileNameMatcher createMatcher(@NotNull String pattern) {
  if (pattern.startsWith("*.") &&
      pattern.indexOf('*', 2) < 0 &&
      pattern.indexOf('.', 2) < 0 &&
      pattern.indexOf('?', 2) < 0) {
    return new ExtensionFileNameMatcher(pattern.substring(2).toLowerCase());
  }

  if (pattern.contains("*") || pattern.contains("?")) {
    return new WildcardFileNameMatcher(pattern);
  }

  return new ExactFileNameMatcher(pattern);
}
项目:tools-idea    文件:FileTypeAssocTable.java   
public boolean isAssociatedWith(T type, 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;
}
项目:tools-idea    文件:FileTypeAssocTable.java   
public boolean removeAssociation(FileNameMatcher matcher, 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;
    final Map<String, T> mapToUse;
    String fileName = exactFileNameMatcher.getFileName();

    if (exactFileNameMatcher.isIgnoreCase()) {
      mapToUse = myExactFileNameAnyCaseMappings;
    } else {
      mapToUse = myExactFileNameMappings;
    }
    if(mapToUse.get(fileName) == type) {
      mapToUse.remove(fileName);
      return true;
    }
    return false;
  }

  List<Pair<FileNameMatcher, T>> copy = new ArrayList<Pair<FileNameMatcher, T>>(myMatchingMappings);
  for (Pair<FileNameMatcher, T> assoc : copy) {
    if (matcher.equals(assoc.getFirst())) {
      myMatchingMappings.remove(assoc);
      return true;
    }
  }

  return false;
}
项目:consulo    文件:FileTypeAssocTable.java   
public boolean isAssociatedWith(T type, 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;
}
项目:consulo    文件:FileTypeAssocTable.java   
public boolean removeAssociation(FileNameMatcher matcher, 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;
    final Map<CharSequence, T> mapToUse;
    String fileName = exactFileNameMatcher.getFileName();

    if (exactFileNameMatcher.isIgnoreCase()) {
      mapToUse = myExactFileNameAnyCaseMappings;
    } else {
      mapToUse = myExactFileNameMappings;
    }
    if(mapToUse.get(fileName) == type) {
      mapToUse.remove(fileName);
      return true;
    }
    return false;
  }

  List<Pair<FileNameMatcher, T>> copy = new ArrayList<Pair<FileNameMatcher, T>>(myMatchingMappings);
  for (Pair<FileNameMatcher, T> assoc : copy) {
    if (matcher.equals(assoc.getFirst())) {
      myMatchingMappings.remove(assoc);
      return true;
    }
  }

  return false;
}
项目:intellij    文件:BazelBuildSystemProvider.java   
@Override
public ImmutableList<FileNameMatcher> buildLanguageFileTypeMatchers() {
  return ImmutableList.of(
      new ExactFileNameMatcher("BUILD"), new ExactFileNameMatcher("BUILD.bazel"),
      new ExtensionFileNameMatcher("bzl"), new ExactFileNameMatcher("WORKSPACE"));
}
项目:defrac-plugin-intellij    文件:DefracSettingsFileType.java   
@NotNull
public static FileNameMatcher[] fileNameMatchers() {
  return new FileNameMatcher[] {
      new ExtensionFileNameMatcher(EXTENSION)
  };
}
项目:intellij-haxe    文件:HaxeFileTypeLoader.java   
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
  consumer.consume(
    HaxeFileType.HAXE_FILE_TYPE,
    new ExtensionFileNameMatcher(HaxeFileType.DEFAULT_EXTENSION));
}
项目:intellij-haxe    文件:HXMLFileTypeFactory.java   
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
  consumer.consume(
    HXMLFileType.INSTANCE,
    new ExtensionFileNameMatcher(HXMLFileType.DEFAULT_EXTENSION));
}
项目:DeftIDEA    文件:LIDFileTypeFactory.java   
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
  consumer.consume(
          LIDFileType.INSTANCE,
          new ExtensionFileNameMatcher(LIDFileType.DEFAULT_EXTENSION),
          new ExtensionFileNameMatcher(LIDFileType.ALTERNATE_EXTENSION));
}
项目:DeftIDEA    文件:DylanFileTypeFactory.java   
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
  consumer.consume(
    DylanFileType.INSTANCE,
    new ExtensionFileNameMatcher(DylanFileType.DEFAULT_EXTENSION));
}
项目:DeftIDEA    文件:MelangeInterfaceFileTypeFactory.java   
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
  consumer.consume(
    MelangeInterfaceFileType.INSTANCE,
    new ExtensionFileNameMatcher(MelangeInterfaceFileType.DEFAULT_EXTENSION));
}