Java Code Examples for com.intellij.psi.util.PsiTreeUtil#findChildrenOfAnyType()

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#findChildrenOfAnyType() . These examples are extracted from open source projects. 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 Project: intellij-latte   File: LatteFoldingBuilder.java    License: MIT License 6 votes vote down vote up
@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
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
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 Project: intellij-haxe   File: HaxeSymbolIndex.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: reasonml-idea-plugin   File: PsiValImpl.java    License: MIT License 4 votes vote down vote up
@Nullable
@Override
public PsiElement getNameIdentifier() {
    Collection<PsiElement> elements = PsiTreeUtil.findChildrenOfAnyType(this, PsiLowerSymbol.class, PsiScopedExpr.class);
    return elements.isEmpty() ? null : elements.iterator().next();
}
 
Example 6
/** 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);
	}