Java 类com.intellij.psi.util.PsiFilter 实例源码

项目:asciidoctor-intellij-plugin    文件:AsciiDocFileUtil.java   
public static List<AsciiDocSection> findProperties(Project project, String key) {
  List<AsciiDocSection> result = null;
  Collection<VirtualFile> virtualFiles =
    FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, AsciiDocFileType.INSTANCE,
      GlobalSearchScope.allScope(project));
  for (VirtualFile virtualFile : virtualFiles) {
    AsciiDocFile asciiDocFile = (AsciiDocFile)PsiManager.getInstance(project).findFile(virtualFile);
    if (asciiDocFile != null) {
      ArrayList<AsciiDocSection> properties = new ArrayList<>();
      new PsiFilter(AsciiDocSection.class).createVisitor(properties).visitFile(asciiDocFile);
      for (AsciiDocSection property : properties) {
        if (key.equals(property.getTitle())) {
          if (result == null) {
            result = new ArrayList<>();
          }
          result.add(property);
        }
      }
    }
  }
  return result != null ? result : Collections.emptyList();
}
项目:intellij-ce-playground    文件:PsiChangeTracker.java   
public static <T extends PsiElement> Map<T, FileStatus> getElementsChanged(PsiElement file,
                                                                           PsiElement oldFile,
                                                                           final PsiFilter<T> filter) {
  final HashMap<T, FileStatus> result = new HashMap<T, FileStatus>();
  final List<T> oldElements = new ArrayList<T>();
  final List<T> elements = new ArrayList<T>();

  if (file == null) {
    oldFile.accept(filter.createVisitor(oldElements));
    calculateStatuses(elements, oldElements, result, filter);
    return result;
  }

  final Project project = file.getProject();

  file.accept(filter.createVisitor(elements));
  final VirtualFile vf = file.getContainingFile().getVirtualFile();
  FileStatus status = vf == null ? null : FileStatusManager.getInstance(project).getStatus(vf);
  if (status == null && oldFile == null) {
    status = FileStatus.ADDED;
  }
  if (status == FileStatus.ADDED ||
      status == FileStatus.DELETED ||
      status == FileStatus.DELETED_FROM_FS ||
      status == FileStatus.UNKNOWN) {
    for (T element : elements) {
      result.put(element, status);
    }
    return result;
  }

  if (oldFile == null) return result;
  oldFile.accept(filter.createVisitor(oldElements));
  calculateStatuses(elements, oldElements, result, filter);

  return result;
}
项目:tools-idea    文件:PsiChangeTracker.java   
public static <T extends PsiElement> Map<T, FileStatus> getElementsChanged(PsiFile file, final PsiFilter<T> filter) {
  final Project project = file.getProject();
  final VirtualFile vf = file.getVirtualFile();

  if (vf == null) return Collections.emptyMap();

  final String oldText = getUnmodifiedDocument(vf, project);
  //TODO: make loop for different languages
  //TODO: for ( PsiFile f : file.getViewProvider().getAllFiles() )
  //TODO: for some languages (eg XML) isEquivalentTo works ugly. Think about pluggable matchers for different languages/elements
  final PsiFile oldFile = oldText == null
                          ? null : PsiFileFactory.getInstance(project).createFileFromText(oldText, file);
  return getElementsChanged(file, oldFile, filter);
}
项目:tools-idea    文件:PsiChangeTracker.java   
public static <T extends PsiElement> Map<T, FileStatus> getElementsChanged(PsiElement file,
                                                                           PsiElement oldFile,
                                                                           final PsiFilter<T> filter) {
  final HashMap<T, FileStatus> result = new HashMap<T, FileStatus>();
  final List<T> oldElements = new ArrayList<T>();
  final List<T> elements = new ArrayList<T>();

  if (file == null) {
    oldFile.accept(filter.createVisitor(oldElements));
    calculateStatuses(elements, oldElements, result, filter);
    return result;
  }

  final Project project = file.getProject();

  file.accept(filter.createVisitor(elements));
  final VirtualFile vf = file.getContainingFile().getVirtualFile();
  FileStatus status = vf == null ? null : FileStatusManager.getInstance(project).getStatus(vf);
  if (status == null && oldFile == null) {
    status = FileStatus.ADDED;
  }
  if (status == FileStatus.ADDED ||
      status == FileStatus.DELETED ||
      status == FileStatus.DELETED_FROM_FS ||
      status == FileStatus.UNKNOWN) {
    for (T element : elements) {
      result.put(element, status);
    }
    return result;
  }

  if (oldFile == null) return result;
  oldFile.accept(filter.createVisitor(oldElements));
  calculateStatuses(elements, oldElements, result, filter);

  return result;
}
项目:asciidoctor-intellij-plugin    文件:AsciiDocFileUtil.java   
public static List<AsciiDocSection> findProperties(Project project) {
  List<AsciiDocSection> result = new ArrayList<>();
  Collection<VirtualFile> virtualFiles =
    FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, AsciiDocFileType.INSTANCE,
      GlobalSearchScope.allScope(project));
  for (VirtualFile virtualFile : virtualFiles) {
    AsciiDocFile simpleFile = (AsciiDocFile)PsiManager.getInstance(project).findFile(virtualFile);
    if (simpleFile != null) {
      new PsiFilter(AsciiDocSection.class).createVisitor(result).visitFile(simpleFile);
    }
  }
  return result;
}
项目:intellij-ce-playground    文件:PsiChangeTrackerTest.java   
public void testMethods() throws Exception {
  doTest(new PsiFilter<PsiMethod>(PsiMethod.class));
}
项目:intellij-ce-playground    文件:PsiChangeTrackerTest.java   
public void testFields() throws Exception {
  doTest(new PsiFilter<PsiField>(PsiField.class));
}
项目:intellij-ce-playground    文件:PsiChangeTrackerTest.java   
private <T extends PsiElement> void doTest(PsiFilter<T> filter) throws IOException {
  final Map<T,FileStatus> map = PsiChangeTracker.getElementsChanged(myChangedFile, myOriginalFile, filter);
  final Map<String, String> changes = convert(map);
  final Map<String, String> expected = getExpectedResults();
  assert expected.equals(changes) : "Changes are not equal \n Expected:\n" + expected + "\nFound:\n" + changes;
}
项目:tools-idea    文件:PsiChangeTrackerTest.java   
public void testMethods() throws Exception {
  doTest(new PsiFilter<PsiMethod>(PsiMethod.class));
}
项目:tools-idea    文件:PsiChangeTrackerTest.java   
public void testFields() throws Exception {
  doTest(new PsiFilter<PsiField>(PsiField.class));
}
项目:tools-idea    文件:PsiChangeTrackerTest.java   
private <T extends PsiElement> void doTest(PsiFilter<T> filter) throws IOException {
  final Map<T,FileStatus> map = PsiChangeTracker.getElementsChanged(myChangedFile, myOriginalFile, filter);
  final Map<String, String> changes = convert(map);
  final Map<String, String> expected = getExpectedResults();
  assert expected.equals(changes) : "Changes are not equal \n Expected:\n" + expected + "\nFound:\n" + changes;
}