Java 类com.intellij.psi.search.PsiElementProcessor 实例源码

项目:intellij-ce-playground    文件:ClassImplementationsSearch.java   
public static boolean processImplementations(final PsiClass psiClass, final Processor<PsiElement> processor, SearchScope scope) {
  if (!FunctionalExpressionSearch.search(psiClass, scope).forEach(new Processor<PsiFunctionalExpression>() {
    @Override
    public boolean process(PsiFunctionalExpression expression) {
      return processor.process(expression);
    }
  })) {
    return false;
  }

  final boolean showInterfaces = Registry.is("ide.goto.implementation.show.interfaces");
  return ClassInheritorsSearch.search(psiClass, scope, true).forEach(new PsiElementProcessorAdapter<PsiClass>(new PsiElementProcessor<PsiClass>() {
    public boolean execute(@NotNull PsiClass element) {
      if (!showInterfaces && element.isInterface()) {
        return true;
      }
      return processor.process(element);
    }
  }));
}
项目:intellij-ce-playground    文件:GuessManagerImpl.java   
private void addExprTypesByDerivedClasses(LinkedHashSet<PsiType> set, PsiExpression expr) {
  PsiType type = expr.getType();
  if (!(type instanceof PsiClassType)) return;
  PsiClass refClass = PsiUtil.resolveClassInType(type);
  if (refClass == null) return;

  PsiManager manager = PsiManager.getInstance(myProject);
  PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5);
  ClassInheritorsSearch.search(refClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));
  if (processor.isOverflow()) return;

  for (PsiClass derivedClass : processor.getCollection()) {
    if (derivedClass instanceof PsiAnonymousClass) continue;
    PsiType derivedType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(derivedClass);
    set.add(derivedType);
  }
}
项目:intellij-ce-playground    文件:AbstractPatternBasedConfigurationProducer.java   
public PsiElement checkPatterns(ConfigurationContext context, LinkedHashSet<String> classes) {
  PsiElement[] result;
  final DataContext dataContext = context.getDataContext();
  if (TestsUIUtil.isMultipleSelectionImpossible(dataContext)) {
    return null;
  }
  final PsiElement[] locationElements = collectLocationElements(classes, dataContext);
  PsiElementProcessor.CollectElements<PsiElement> processor = new PsiElementProcessor.CollectElements<PsiElement>();
  if (locationElements != null) {
    collectTestMembers(locationElements, false, true, processor);
    result = processor.toArray();
  }
  else if (collectContextElements(dataContext, true, true, classes, processor)) {
    result = processor.toArray();
  }
  else {
    return null;
  }
  if (result.length <= 1) {
    return null;
  }
  return result[0];
}
项目:intellij-ce-playground    文件:AbstractAddToTestsPatternAction.java   
@Override
public void update(AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  presentation.setVisible(false);
  final DataContext dataContext = e.getDataContext();
  final PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
  if (psiElements != null) {
    PsiElementProcessor.CollectElementsWithLimit<PsiElement> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiElement>(2);
    getPatternBasedProducer().collectTestMembers(psiElements, false, false, processor);
    Collection<PsiElement> collection = processor.getCollection();
    if (collection.isEmpty()) return;
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project != null) {
      final List<T> foundConfigurations = collectPatternConfigurations(collection, project);
      if (!foundConfigurations.isEmpty()) {
        presentation.setVisible(true);
        if (foundConfigurations.size() == 1) {
          presentation.setText("Add to temp suite: " + foundConfigurations.get(0).getName());
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:MarkerType.java   
private static String getOverriddenMethodTooltip(@NotNull PsiMethod method) {
  PsiElementProcessor.CollectElementsWithLimit<PsiMethod> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiMethod>(5);
  OverridingMethodsSearch.search(method, true).forEach(new PsiElementProcessorAdapter<PsiMethod>(processor));

  boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);

  if (processor.isOverflow()){
    return isAbstract ? DaemonBundle.message("method.is.implemented.too.many") : DaemonBundle.message("method.is.overridden.too.many");
  }

  PsiMethod[] overridings = processor.toArray(PsiMethod.EMPTY_ARRAY);
  if (overridings.length == 0) {
    final PsiClass aClass = method.getContainingClass();
    if (aClass != null && FunctionalExpressionSearch.search(aClass).findFirst() != null) {
      return "Has functional implementations";
    }
    return null;
  }

  Comparator<PsiMethod> comparator = new MethodCellRenderer(false).getComparator();
  Arrays.sort(overridings, comparator);

  String start = isAbstract ? DaemonBundle.message("method.is.implemented.header") : DaemonBundle.message("method.is.overriden.header");
  @NonNls String pattern = "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#javaClass/{1}\">{1}</a>";
  return composeText(overridings, start, pattern, IdeActions.ACTION_GOTO_IMPLEMENTATION);
}
项目:intellij-ce-playground    文件:StatementMover.java   
@Nullable
private static <T extends PsiElement> T findChildOfType(@Nullable final PsiElement element,
                                                        @NotNull final Class<T> aClass,
                                                        @Nullable final Class<? extends PsiElement> stopAt) {
  final PsiElementProcessor.FindElement<PsiElement> processor = new PsiElementProcessor.FindElement<PsiElement>() {
    @Override
    public boolean execute(@NotNull PsiElement each) {
      if (each == element) return true; // strict
      if (aClass.isInstance(each)) {
        return setFound(each);
      }
      return stopAt == null || !stopAt.isInstance(each);
    }
  };

  PsiTreeUtil.processElements(element, processor);
  //noinspection unchecked
  return (T)processor.getFoundElement();
}
项目:intellij-ce-playground    文件:RefactoringHierarchyUtil.java   
private static void _findImplementingClasses(PsiClass anInterface, final Set<PsiClass> visited, final Collection<PsiClass> result) {
  LOG.assertTrue(anInterface.isInterface());
  visited.add(anInterface);
  ClassInheritorsSearch.search(anInterface, false).forEach(new PsiElementProcessorAdapter<PsiClass>(new PsiElementProcessor<PsiClass>() {
    public boolean execute(@NotNull PsiClass aClass) {
      if (!aClass.isInterface()) {
        result.add(aClass);
      }
      else if (!visited.contains(aClass)){
        _findImplementingClasses(aClass, visited, result);
      }
      return true;
    }

  }));
}
项目:intellij-ce-playground    文件:PsiTreeUtil.java   
/**
 * Recursive (depth first) search for first element of any of given {@code classes}.
 *
 * @param element a PSI element to start search from.
 * @param strict  if false the {@code element} is also included in the search.
 * @param classes element types to search for.
 * @param <T>     type to cast found element to.
 * @return first found element, or null if nothing found.
 */
@Nullable
@Contract("null, _, _ -> null")
public static <T extends PsiElement> T findChildOfAnyType(@Nullable final PsiElement element,
                                                          final boolean strict,
                                                          @NotNull final Class<? extends T>... classes) {
  PsiElementProcessor.FindElement<PsiElement> processor = new PsiElementProcessor.FindElement<PsiElement>() {
    @Override
    public boolean execute(@NotNull PsiElement each) {
      if (strict && each == element) return true;
      if (instanceOf(each, classes)) {
        return setFound(each);
      }
      return true;
    }
  };

  processElements(element, processor);
  //noinspection unchecked
  return (T)processor.getFoundElement();
}
项目:intellij-ce-playground    文件:PsiTreeUtil.java   
@NotNull
public static <T extends PsiElement> Collection<T> findChildrenOfAnyType(@Nullable final PsiElement element,
                                                                         @NotNull final Class<? extends T>... classes) {
  if (element == null) {
    return ContainerUtil.emptyList();
  }

  PsiElementProcessor.CollectElements<T> processor = new PsiElementProcessor.CollectElements<T>() {
    @Override
    public boolean execute(@NotNull T each) {
      if (each == element) return true;
      if (instanceOf(each, classes)) {
        return super.execute(each);
      }
      return true;
    }
  };
  processElements(element, processor);
  return processor.getCollection();
}
项目:intellij-ce-playground    文件:PsiDirectoryImpl.java   
@Override
public boolean processChildren(PsiElementProcessor<PsiFileSystemItem> processor) {
  checkValid();
  ProgressIndicatorProvider.checkCanceled();

  for (VirtualFile vFile : myFile.getChildren()) {
    boolean isDir = vFile.isDirectory();
    if (processor instanceof PsiFileSystemItemProcessor && !((PsiFileSystemItemProcessor)processor).acceptItem(vFile.getName(), isDir)) {
      continue;
    }

    PsiFileSystemItem item = isDir ? myManager.findDirectory(vFile) : myManager.findFile(vFile);
    if (item != null && !processor.execute(item)) {
      return false;
    }
  }

  return true;
}
项目:intellij-ce-playground    文件:PsiDirectoryImpl.java   
@Override
@NotNull
public PsiElement[] getChildren() {
  checkValid();

  VirtualFile[] files = myFile.getChildren();
  final ArrayList<PsiElement> children = new ArrayList<PsiElement>(files.length);
  processChildren(new PsiElementProcessor<PsiFileSystemItem>() {
    @Override
    public boolean execute(@NotNull final PsiFileSystemItem element) {
      children.add(element);
      return true;
    }
  });

  return PsiUtilCore.toPsiElementArray(children);
}
项目:intellij-ce-playground    文件:FindUsagesAction.java   
static void chooseAmbiguousTargetAndPerform(@NotNull final Project project,
                                            final Editor editor,
                                            @NotNull PsiElementProcessor<PsiElement> processor) {
  if (editor == null) {
    Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"), CommonBundle.getErrorTitle(),
                               Messages.getErrorIcon());
  }
  else {
    int offset = editor.getCaretModel().getOffset();
    boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor, FindBundle.message("find.usages.ambiguous.title"), null);
    if (!chosen) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
          HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
        }
      }, project.getDisposed());
    }
  }
}
项目:intellij-ce-playground    文件:ScratchProjectViewPane.java   
@Nullable
@Override
protected Collection<AbstractTreeNode> getChildrenImpl() {
  if (isAlwaysLeaf()) return Collections.emptyList();
  return ApplicationManager.getApplication().runReadAction(new Computable<Collection<AbstractTreeNode>>() {
    @Override
    public Collection<AbstractTreeNode> compute() {
      final PsiFileSystemItem value = getValue();
      if (value == null || !value.isValid()) return Collections.emptyList();
      final List<AbstractTreeNode> list = ContainerUtil.newArrayList();
      value.processChildren(new PsiElementProcessor<PsiFileSystemItem>() {
        @Override
        public boolean execute(@NotNull PsiFileSystemItem element) {
          if (!myRootType.isIgnored(value.getProject(), element.getVirtualFile())) {
            list.add(new MyPsiNode(value.getProject(), myRootType, element));
          }
          return true;
        }
      });
      return list;
    }
  });
}
项目:intellij-ce-playground    文件:PySectionBasedDocStringTest.java   
@Nullable
private String findFirstDocString() {
  final PsiElementProcessor.FindElement<PsiElement> processor = new PsiElementProcessor.FindElement<PsiElement>() {
    @Override
    public boolean execute(@NotNull PsiElement element) {
      if (element instanceof PyStringLiteralExpression && element.getFirstChild().getNode().getElementType() == PyTokenTypes.DOCSTRING) {
        return setFound(element);
      }
      return true;
    }
  };
  PsiTreeUtil.processElements(myFixture.getFile(), processor);
  if (!processor.isFound()) {
    return null;
  }
  final PsiElement foundElement = processor.getFoundElement();
  assertNotNull(foundElement);
  return ((PyStringLiteralExpression)foundElement).getStringValue();
}
项目:intellij-ce-playground    文件:RegExpBackrefImpl.java   
public RegExpGroup resolve() {
    final int index = getIndex();

    final PsiElementProcessor.FindFilteredElement<RegExpElement> processor = new PsiElementProcessor.FindFilteredElement<RegExpElement>(new PsiElementFilter() {
        int groupCount;

        public boolean isAccepted(PsiElement element) {
            if (element instanceof RegExpGroup) {
                if (((RegExpGroup)element).isCapturing() && ++groupCount == index) {
                    return true;
                }
            }
            return element == RegExpBackrefImpl.this;
        }
    });

    PsiTreeUtil.processElements(getContainingFile(), processor);
    if (processor.getFoundElement() instanceof RegExpGroup) {
        return (RegExpGroup)processor.getFoundElement();
    }
    return null;
}
项目:intellij-ce-playground    文件:RegExpNamedGroupRefImpl.java   
@Nullable
public RegExpGroup resolve() {
  final PsiElementProcessor.FindFilteredElement<RegExpGroup> processor = new PsiElementProcessor.FindFilteredElement<RegExpGroup>(
    new PsiElementFilter() {
      public boolean isAccepted(PsiElement element) {
        if (!(element instanceof RegExpGroup)) {
          return false;
        }
        final RegExpGroup regExpGroup = (RegExpGroup)element;
        return (regExpGroup.isPythonNamedGroup() || regExpGroup.isRubyNamedGroup()) &&
               Comparing.equal(getGroupName(), regExpGroup.getGroupName());
      }
    }
  );
  PsiTreeUtil.processElements(getContainingFile(), processor);
  return processor.getFoundElement();
}
项目:intellij-ce-playground    文件:IdRefReference.java   
@Override
@Nullable
public PsiElement resolve() {
  final PsiElement[] result = new PsiElement[1];
  process(new PsiElementProcessor<PsiElement>() {
    final String canonicalText = getCanonicalText();

    @Override
    public boolean execute(@NotNull final PsiElement element) {
      final String idValue = getIdValue(element);
      if (idValue != null && idValue.equals(canonicalText)) {
        result[0] = getIdValueElement(element);
        return false;
      }
      return true;
    }
  });

  return result[0];
}
项目:intellij-ce-playground    文件:IdRefReference.java   
@Override
@NotNull
public Object[] getVariants() {
  final List<String> result = new LinkedList<String>();

  process(new PsiElementProcessor<PsiElement>() {
    @Override
    public boolean execute(@NotNull final PsiElement element) {
      String value = getIdValue(element);
      if (value != null) {
        result.add(value);
      }
      return true;
    }
  });

  return ArrayUtil.toObjectArray(result);
}
项目:intellij-ce-playground    文件:ObjectEqualityInspection.java   
private boolean implementersHaveOnlyPrivateConstructors(final PsiClass aClass) {
  final GlobalSearchScope scope = GlobalSearchScope.allScope(aClass.getProject());
  final PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit(6);
  final ProgressManager progressManager = ProgressManager.getInstance();
  progressManager.runProcess(new Runnable() {
    @Override
    public void run() {
      ClassInheritorsSearch.search(aClass, scope, true, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));
    }
  }, null);
  if (processor.isOverflow()) {
    return false;
  }
  final Collection<PsiClass> implementers = processor.getCollection();
  for (PsiClass implementer : implementers) {
    if (!implementer.isInterface() && !implementer.hasModifierProperty(PsiModifier.ABSTRACT)) {
      if (!hasOnlyPrivateConstructors(implementer)) {
        return false;
      }
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:XmlNSDescriptorImpl.java   
@Override
public void validate(@NotNull XmlDocument document, @NotNull ValidationHost host) {
  if (document.getLanguage() == DTDLanguage.INSTANCE) {
    final List<XmlElementDecl> decls = new ArrayList<XmlElementDecl>(3);

    XmlUtil.processXmlElements(document, new PsiElementProcessor() {
      @Override
      public boolean execute(@NotNull final PsiElement element) {
        if (element instanceof XmlElementDecl) decls.add((XmlElementDecl)element);
        return true;
      }
    }, false);
    XmlUtil.doDuplicationCheckForElements(
      decls.toArray(new XmlElementDecl[decls.size()]),
      new HashMap<String, XmlElementDecl>(decls.size()),
      XML_ELEMENT_DECL_PROVIDER,
      host
    );
    return;
  }
  ExternalDocumentValidator.doValidation(document,host);
}
项目:intellij-ce-playground    文件:XsltCodeInsightUtil.java   
@Nullable
public static PsiElement findFirstRealTagChild(@NotNull XmlTag xmlTag) {
    final PsiElement[] child = new PsiElement[1];
    xmlTag.processElements(new PsiElementProcessor() {
        public boolean execute(@NotNull PsiElement element) {
            if (element instanceof XmlToken) {
                if (((XmlToken)element).getTokenType() == XmlTokenType.XML_TAG_END) {
                    child[0] = element.getNextSibling();
                    return false;
                }
            }
            return true;
        }
    }, xmlTag);
    return child[0];
}
项目:intellij-ce-playground    文件:XmlElementImpl.java   
@Nullable
protected static String getNameFromEntityRef(final CompositeElement compositeElement, final IElementType xmlEntityDeclStart) {
  final ASTNode node = compositeElement.findChildByType(xmlEntityDeclStart);
  if (node == null) return null;
  ASTNode name = node.getTreeNext();

  if (name != null && name.getElementType() == TokenType.WHITE_SPACE) {
    name = name.getTreeNext();
  }

  if (name != null && name.getElementType() == XmlElementType.XML_ENTITY_REF) {
    final StringBuilder builder = new StringBuilder();

    ((XmlElement)name.getPsi()).processElements(new PsiElementProcessor() {
      @Override
      public boolean execute(@NotNull final PsiElement element) {
        builder.append(element.getText());
        return true;
      }
    }, name.getPsi());
    if (builder.length() > 0) return builder.toString();
  }
  return null;
}
项目:intellij-ce-playground    文件:RngNsDescriptor.java   
@Override
public Object[] getDependences() {
  if (myPattern != null) {
    if (DumbService.isDumb(myElement.getProject())) {
      return new Object[] { ModificationTracker.EVER_CHANGED, ExternalResourceManager.getInstance()};
    }
    final Object[] a = { myElement, ExternalResourceManager.getInstance() };
    final PsiElementProcessor.CollectElements<XmlFile> processor = new PsiElementProcessor.CollectElements<XmlFile>();
    RelaxIncludeIndex.processForwardDependencies(myFile, processor);
    if (processor.getCollection().size() > 0) {
      return ArrayUtil.mergeArrays(a, processor.toArray());
    } else {
      return a;
    }
  }
  return new Object[]{ ModificationTracker.EVER_CHANGED };
}
项目:intellij-ce-playground    文件:GroovyMarkerTypes.java   
@Nullable
@Override
public String fun(PsiElement element) {
  PsiElement parent = element.getParent();
  if (!(parent instanceof GrField)) return null;
  final List<GrAccessorMethod> accessors = GroovyPropertyUtils.getFieldAccessors((GrField)parent);

  PsiElementProcessor.CollectElementsWithLimit<PsiMethod> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiMethod>(5);

  for (GrAccessorMethod method : accessors) {
    OverridingMethodsSearch.search(method, true).forEach(new PsiElementProcessorAdapter<PsiMethod>(processor));
  }
  if (processor.isOverflow()) {
    return DaemonBundle.message("method.is.overridden.too.many");
  }

  PsiMethod[] overridings = processor.toArray(new PsiMethod[processor.getCollection().size()]);
  if (overridings.length == 0) return null;

  Comparator<PsiMethod> comparator = new MethodCellRenderer(false).getComparator();
  Arrays.sort(overridings, comparator);

  String start = DaemonBundle.message("method.is.overriden.header");
  @NonNls String pattern = "&nbsp;&nbsp;&nbsp;&nbsp;{1}";
  return GutterIconTooltipHelper.composeText(overridings, start, pattern);
}
项目:intellij-ce-playground    文件:DtdCompletionData.java   
@Override
public Object[] get(final PsiElement context, CompletionContext completionContext) {
  final List<String> results = new LinkedList<String>();

  final PsiElementProcessor processor = new PsiElementProcessor() {
    @Override
    public boolean execute(@NotNull final PsiElement element) {
      if (element instanceof XmlEntityDecl) {
        final XmlEntityDecl xmlEntityDecl = (XmlEntityDecl)element;
        if (xmlEntityDecl.isInternalReference()) {
          results.add(xmlEntityDecl.getName());
        }
      }
      return true;
    }
  };

  XmlUtil.processXmlElements((XmlFile)context.getContainingFile().getOriginalFile(), processor, true);
  return ArrayUtil.toObjectArray(results);
}
项目:intellij-ce-playground    文件:UnusedDefineInspection.java   
@Override
public void visitDefine(RncDefine pattern) {
  final RncGrammar grammar = PsiTreeUtil.getParentOfType(pattern, RncGrammar.class);
  final PsiFile file = pattern.getContainingFile();
  if (grammar != null) {
    if (processRncUsages(pattern, new LocalSearchScope(grammar))) return;
  } else {
    if (processRncUsages(pattern, new LocalSearchScope(file))) return;
  }

  final PsiElementProcessor.CollectElements<XmlFile> collector = new PsiElementProcessor.CollectElements<XmlFile>();
  RelaxIncludeIndex.processBackwardDependencies((XmlFile)file, collector);

  if (processRncUsages(pattern, new LocalSearchScope(collector.toArray()))) return;

  final ASTNode astNode = ((RncDefineImpl)pattern).getNameNode();
  myHolder.registerProblem(astNode.getPsi(), "Unreferenced define", ProblemHighlightType.LIKE_UNUSED_SYMBOL, new MyFix<RncDefine>(pattern));
}
项目:intellij-ce-playground    文件:AnchorReferenceImpl.java   
@Override
public Result<Map<String, XmlTag>> compute() {
  final Map<String,XmlTag> resultMap = new HashMap<String, XmlTag>();
  XmlDocument document = HtmlUtil.getRealXmlDocument(myFile.getDocument());
  final XmlTag rootTag = document != null ? document.getRootTag():null;

  if (rootTag != null) {
    processXmlElements(rootTag,
      new PsiElementProcessor<XmlTag>() {
        @Override
        public boolean execute(@NotNull final XmlTag element) {
          final String anchorValue = getAnchorValue(element);

          if (anchorValue!=null) {
            resultMap.put(anchorValue, element);
          }
          return true;
        }
      }
    );
  }
  return new Result<Map<String, XmlTag>>(resultMap, myFile);
}
项目:intellij-ce-playground    文件:RngSchemaValidator.java   
@Override
protected void createAnnotation(ASTNode node, String message) {
  if (MISSING_START_ELEMENT.equals(message)) {
    final PsiFile psiFile = node.getPsi().getContainingFile();
    if (psiFile instanceof XmlFile) {
      final PsiElementProcessor.FindElement<XmlFile> processor = new PsiElementProcessor.FindElement<XmlFile>();
      RelaxIncludeIndex.processBackwardDependencies((XmlFile)psiFile, processor);
      if (processor.isFound()) {
        // files that are included from other files do not need a <start> element.
        myHolder.createWeakWarningAnnotation(node, message);
        return;
      }
    }
  } else if (message != null && message.startsWith(UNDEFINED_PATTERN)) {
    // we've got our own validation for that
    return;
  }
  myHolder.createErrorAnnotation(node, message);
}
项目:intellij-ce-playground    文件:PropertiesCopyHandler.java   
@Override
public boolean processChildren(PsiElementProcessor<PsiFileSystemItem> processor) {
  for (PropertiesFile propertiesFile : myResourceBundle.getPropertiesFiles()) {
    if (!propertiesFile.getContainingFile().processChildren(processor)) {
      return false;
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:AbstractPatternBasedConfigurationProducer.java   
public boolean isMultipleElementsSelected(ConfigurationContext context) {
  final DataContext dataContext = context.getDataContext();
  if (TestsUIUtil.isMultipleSelectionImpossible(dataContext)) return false;
  final LinkedHashSet<String> classes = new LinkedHashSet<String>();
  final PsiElementProcessor.CollectElementsWithLimit<PsiElement> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiElement>(2);
  final PsiElement[] locationElements = collectLocationElements(classes, dataContext);
  if (locationElements != null) {
    collectTestMembers(locationElements, false, false, processor);
  }
  else {
    collectContextElements(dataContext, false, false, classes, processor);
  }
  return processor.getCollection().size() > 1;
}
项目:intellij-ce-playground    文件:AbstractPatternBasedConfigurationProducer.java   
public boolean isConfiguredFromContext(ConfigurationContext context, Set<String> patterns) {
  final LinkedHashSet<String> classes = new LinkedHashSet<String>();
  final DataContext dataContext = context.getDataContext();
  if (TestsUIUtil.isMultipleSelectionImpossible(dataContext)) {
    return false;
  }
  final PsiElement[] locationElements = collectLocationElements(classes, dataContext);
  if (locationElements == null) {
    collectContextElements(dataContext, true, false, classes, new PsiElementProcessor.CollectElements<PsiElement>());
  }
  if (Comparing.equal(classes, patterns)) {
    return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:AbstractPatternBasedConfigurationProducer.java   
public void collectTestMembers(PsiElement[] psiElements,
                               boolean checkAbstract,
                               boolean checkIsTest,
                               PsiElementProcessor.CollectElements<PsiElement> collectingProcessor) {
  for (PsiElement psiElement : psiElements) {
    if (psiElement instanceof PsiClassOwner) {
      final PsiClass[] classes = ((PsiClassOwner)psiElement).getClasses();
      for (PsiClass aClass : classes) {
        if ((!checkIsTest && aClass.hasModifierProperty(PsiModifier.PUBLIC) || checkIsTest && isTestClass(aClass)) && 
            !collectingProcessor.execute(aClass)) {
          return;
        }
      }
    } else if (psiElement instanceof PsiClass) {
      if ((!checkIsTest && ((PsiClass)psiElement).hasModifierProperty(PsiModifier.PUBLIC) || checkIsTest && isTestClass((PsiClass)psiElement)) && 
          !collectingProcessor.execute(psiElement)) {
        return;
      }
    } else if (psiElement instanceof PsiMethod) {
      if (checkIsTest && isTestMethod(checkAbstract, psiElement) && !collectingProcessor.execute(psiElement)) {
        return;
      }
      if (!checkIsTest) {
        final PsiClass containingClass = ((PsiMethod)psiElement).getContainingClass();
        if (containingClass != null && containingClass.hasModifierProperty(PsiModifier.PUBLIC) && !collectingProcessor.execute(psiElement)) {
          return;
        }
      }
    } else if (psiElement instanceof PsiDirectory) {
      final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)psiElement);
      if (aPackage != null && !collectingProcessor.execute(aPackage)) {
        return;
      }
    }
  }
}
项目:intellij-ce-playground    文件:AbstractPatternBasedConfigurationProducer.java   
private boolean collectContextElements(DataContext dataContext,
                                       boolean checkAbstract,
                                       boolean checkIsTest, 
                                       LinkedHashSet<String> classes,
                                       PsiElementProcessor.CollectElements<PsiElement> processor) {
  PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
  if (elements != null) {
    collectTestMembers(elements, checkAbstract, checkIsTest, processor);
    for (PsiElement psiClass : processor.getCollection()) {
      classes.add(getQName(psiClass));
    }
    return true;
  }
  else {
    final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
    if (files != null) {
      Project project = CommonDataKeys.PROJECT.getData(dataContext);
      if (project != null) {
        final PsiManager psiManager = PsiManager.getInstance(project);
        for (VirtualFile file : files) {
          final PsiFile psiFile = psiManager.findFile(file);
          if (psiFile instanceof PsiClassOwner) {
            collectTestMembers(((PsiClassOwner)psiFile).getClasses(), checkAbstract, checkIsTest, processor);
            for (PsiElement psiMember : processor.getCollection()) {
              classes.add(((PsiClass)psiMember).getQualifiedName());
            }
          }
        }
        return true;
      }
    }
  }
  return false;
}
项目:epigraph    文件:SchemaRenameUtil.java   
public static void chooseAndProcessSuper(@NotNull PsiNamedElement element,
                                         @NotNull PsiElementProcessor<PsiNamedElement> processor,
                                         @Nullable Editor editor) {

  List<PsiNamedElement> maxSuperMembers = findMaxSuperMembers(element);
  afterChoosingSuperMember(element, maxSuperMembers, editor, processor);
}
项目:intellij-ce-playground    文件:MarkerType.java   
public static String getSubclassedClassTooltip(@NotNull PsiClass aClass) {
  PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5, new THashSet<PsiClass>());
  ClassInheritorsSearch.search(aClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));

  if (processor.isOverflow()) {
    return aClass.isInterface()
           ? DaemonBundle.message("interface.is.implemented.too.many")
           : DaemonBundle.message("class.is.subclassed.too.many");
  }

  PsiClass[] subclasses = processor.toArray(PsiClass.EMPTY_ARRAY);
  if (subclasses.length == 0) {
    final PsiElementProcessor.CollectElementsWithLimit<PsiFunctionalExpression> functionalImplementations =
      new PsiElementProcessor.CollectElementsWithLimit<PsiFunctionalExpression>(2, new THashSet<PsiFunctionalExpression>());
    FunctionalExpressionSearch.search(aClass).forEach(new PsiElementProcessorAdapter<PsiFunctionalExpression>(functionalImplementations));
    if (!functionalImplementations.getCollection().isEmpty()) {
      return "Has functional implementations";
    }
    return null;
  }

  Comparator<PsiClass> comparator = new PsiClassListCellRenderer().getComparator();
  Arrays.sort(subclasses, comparator);

  String start = aClass.isInterface()
                 ? DaemonBundle.message("interface.is.implemented.by.header")
                 : DaemonBundle.message("class.is.subclassed.by.header");
  @NonNls String pattern = "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#javaClass/{0}\">{0}</a>";
  return composeText(subclasses, start, pattern, IdeActions.ACTION_GOTO_IMPLEMENTATION);
}
项目:intellij-ce-playground    文件:MarkerType.java   
public static void navigateToSubclassedClass(MouseEvent e, @NotNull final PsiClass aClass) {
  if (DumbService.isDumb(aClass.getProject())) {
    DumbService.getInstance(aClass.getProject()).showDumbModeNotification("Navigation to overriding methods is not possible during index update");
    return;
  }

  final PsiElementProcessor.CollectElementsWithLimit<PsiClass> collectProcessor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(2, new THashSet<PsiClass>());
  final PsiElementProcessor.CollectElementsWithLimit<PsiFunctionalExpression> collectExprProcessor = new PsiElementProcessor.CollectElementsWithLimit<PsiFunctionalExpression>(2, new THashSet<PsiFunctionalExpression>());
  if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
    @Override
    public void run() {
      ClassInheritorsSearch.search(aClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(collectProcessor));
      if (collectProcessor.getCollection().size() < 2) {
        FunctionalExpressionSearch.search(aClass).forEach(new PsiElementProcessorAdapter<PsiFunctionalExpression>(collectExprProcessor));
      }
    }
  }, SEARCHING_FOR_OVERRIDDEN_METHODS, true, aClass.getProject(), (JComponent)e.getComponent())) {
    return;
  }

  final List<NavigatablePsiElement> inheritors = new ArrayList<NavigatablePsiElement>();
  inheritors.addAll(collectProcessor.getCollection());
  inheritors.addAll(collectExprProcessor.getCollection());
  if (inheritors.isEmpty()) return;
  final PsiClassOrFunctionalExpressionListCellRenderer renderer = new PsiClassOrFunctionalExpressionListCellRenderer();
  final SubclassUpdater subclassUpdater = new SubclassUpdater(aClass, renderer);
  Collections.sort(inheritors, renderer.getComparator());
  PsiElementListNavigator.openTargets(e, inheritors.toArray(new NavigatablePsiElement[inheritors.size()]), subclassUpdater.getCaption(inheritors.size()), CodeInsightBundle.message("goto.implementation.findUsages.title", aClass.getName()), renderer, subclassUpdater);
}
项目:intellij-ce-playground    文件:GrIntroduceFieldHandlerBase.java   
@Override
protected void showScopeChooser(PsiClass[] scopes, final Pass<PsiClass> callback, Editor editor) {
  PsiElementProcessor<PsiClass> processor = new PsiElementProcessor<PsiClass>() {
    @Override
    public boolean execute(@NotNull PsiClass element) {
      callback.pass(element);
      return false;
    }
  };

  NavigationUtil.getPsiElementPopup(scopes, new PsiClassListCellRenderer(), "Choose class to introduce field", processor).showInBestPositionFor(editor);
}
项目:intellij-ce-playground    文件:XsltCodeInsightUtil.java   
@Nullable
public static XmlTag findLastParam(XmlTag templateTag) {
    final ArrayList<XmlTag> list = new ArrayList<XmlTag>();
    final PsiElementProcessor.CollectFilteredElements<XmlTag> processor =
            new PsiElementProcessor.CollectFilteredElements<XmlTag>(XSLT_PARAM_FILTER, list);
    templateTag.processElements(processor, templateTag);

    return list.size() > 0 ? list.get(list.size() - 1) : null;
}
项目:intellij-ce-playground    文件:PackagePrefixFileSystemItemImpl.java   
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
  if (myIndex == myPackages.length - 1) {
    return myDirectory.processChildren(processor);
  }
  else {
    return processor.execute(new PackagePrefixFileSystemItemImpl(myDirectory, myIndex+1, myPackages));
  }
}
项目:intellij-ce-playground    文件:PsiTreeUtil.java   
public static boolean processElements(@NotNull PsiElementProcessor processor, @Nullable PsiElement... elements) {
  if (elements == null || elements.length == 0) return true;
  for (PsiElement element : elements) {
    if (!processElements(element, processor)) return false;
  }
  return true;
}