Java Code Examples for com.intellij.psi.util.PsiTreeUtil#findChildrenOfAnyType()
The following examples show how to use
com.intellij.psi.util.PsiTreeUtil#findChildrenOfAnyType() .
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: LatteFoldingBuilder.java From intellij-latte with MIT License | 6 votes |
@SuppressWarnings("unchecked") @NotNull @Override public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { List<FoldingDescriptor> descriptors = new ArrayList<FoldingDescriptor>(); if (!quick) { Collection<LatteMacroClassic> nodes = PsiTreeUtil.findChildrenOfAnyType(root, LatteMacroClassic.class); for (PsiElement node : nodes) { int start = node.getFirstChild().getTextRange().getEndOffset(); int end = node.getLastChild().getTextRange().getEndOffset(); if (end == start) { continue; } if (node instanceof LatteMacroClassic) { start--; end--; } descriptors.add(new FoldingDescriptor(node, TextRange.create(start, end))); } } return descriptors.toArray(new FoldingDescriptor[descriptors.size()]); }
Example 2
Source File: AnnotationBackportUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public static boolean hasReference(@Nullable PhpDocComment docComment, String... className) { if(docComment == null) return false; Map<String, String> uses = AnnotationBackportUtil.getUseImportMap(docComment); for(PhpDocTag phpDocTag: PsiTreeUtil.findChildrenOfAnyType(docComment, PhpDocTag.class)) { if(!AnnotationBackportUtil.NON_ANNOTATION_TAGS.contains(phpDocTag.getName())) { PhpClass annotationReference = AnnotationBackportUtil.getAnnotationReference(phpDocTag, uses); if(annotationReference != null && PhpElementsUtil.isEqualClassName(annotationReference, className)) { return true; } } } return false; }
Example 3
Source File: AnnotationBackportUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public static PhpDocTag getReference(@Nullable PhpDocComment docComment, String className) { if(docComment == null) return null; Map<String, String> uses = AnnotationBackportUtil.getUseImportMap(docComment); for(PhpDocTag phpDocTag: PsiTreeUtil.findChildrenOfAnyType(docComment, PhpDocTag.class)) { if(AnnotationBackportUtil.NON_ANNOTATION_TAGS.contains(phpDocTag.getName())) { continue; } PhpClass annotationReference = AnnotationBackportUtil.getAnnotationReference(phpDocTag, uses); if(annotationReference != null && PhpElementsUtil.isEqualClassName(annotationReference, className)) { return phpDocTag; } } return null; }
Example 4
Source File: HaxeSymbolIndex.java From intellij-haxe with Apache License 2.0 | 5 votes |
@NotNull private static List<HaxeNamedComponent> getNamedComponents(@Nullable final HaxeClass cls) { final PsiElement body = PsiTreeUtil.getChildOfAnyType(cls, BODY_TYPES); final List<HaxeNamedComponent> components = new ArrayList<HaxeNamedComponent>(); if (body != null) { final Collection<HaxeNamedComponent> members = PsiTreeUtil.findChildrenOfAnyType(body, MEMBER_TYPES); for (HaxeNamedComponent member : members) { if (member instanceof HaxeMethod && ((HaxeMethod)member).isConstructor()) { continue; } components.add(member); } } return components; }
Example 5
Source File: PsiValImpl.java From reasonml-idea-plugin with MIT License | 4 votes |
@Nullable @Override public PsiElement getNameIdentifier() { Collection<PsiElement> elements = PsiTreeUtil.findChildrenOfAnyType(this, PsiLowerSymbol.class, PsiScopedExpr.class); return elements.isEmpty() ? null : elements.iterator().next(); }
Example 6
Source File: GrammarElementRef.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** Using for completion. Returns list of rules and tokens; the prefix * of current element is used as filter by IDEA later. */ @NotNull @Override public Object[] getVariants() { String prefix = myElement.getText(); RulesNode rules = PsiTreeUtil.getContextOfType(myElement, RulesNode.class); // find all rule defs (token, parser) Collection<? extends RuleSpecNode> ruleSpecNodes = PsiTreeUtil.findChildrenOfAnyType(rules, new Class[] { ParserRuleSpecNode.class, LexerRuleSpecNode.class} ); return ruleSpecNodes.toArray(); // // final ArrayList<LookupElement> list = new ArrayList<LookupElement>(); // PsiFile containingFile = myElement.getContainingFile(); // List<BnfRule> rules = containingFile instanceof BnfFile ? ((BnfFile)containingFile).getRules() : Collections.<BnfRule>emptyList(); // for (BnfRule rule : rules) { // boolean fakeRule = ParserGeneratorUtil.Rule.isFake(rule); // boolean privateRule = ParserGeneratorUtil.Rule.isPrivate(rule); // list.add(LookupElementBuilder.createWithIcon(rule).withBoldness(!privateRule).withStrikeoutness(fakeRule)); // } // if (GrammarUtil.isExternalReference(myElement)) { // BnfRule rule = PsiTreeUtil.getParentOfType(myElement, BnfRule.class); // String parserClass = ParserGeneratorUtil.getAttribute(rule, KnownAttribute.PARSER_UTIL_CLASS); // if (StringUtil.isNotEmpty(parserClass)) { // JavaHelper javaHelper = JavaHelper.getJavaHelper(myElement.getProject()); // for (NavigatablePsiElement element : javaHelper.getClassMethods(parserClass, true)) { // List<String> methodTypes = javaHelper.getMethodTypes(element); // if (methodTypes.size() > 3 && // methodTypes.get(0).equals("boolean") && // methodTypes.get(1).equals("com.intellij.lang.PsiBuilder") && // methodTypes.get(3).equals("int")) { // list.add(LookupElementBuilder.createWithIcon((PsiNamedElement)element)); // } // } // } // } // return ArrayUtil.toObjectArray(list); }