com.intellij.psi.util.PsiTreeUtil#findChildOfType ( )源码实例Demo

下面列出了com.intellij.psi.util.PsiTreeUtil#findChildOfType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Nullable
public static InflateContainer matchInflate(PsiLocalVariable psiLocalVariable) {
    PsiType psiType = psiLocalVariable.getType();
    if(psiType instanceof PsiClassReferenceType) {
        PsiMethodCallExpression psiMethodCallExpression = PsiTreeUtil.findChildOfType(psiLocalVariable, PsiMethodCallExpression.class);
        if(psiMethodCallExpression != null) {
            PsiMethod psiMethod = psiMethodCallExpression.resolveMethod();

            // @TODO: replace "inflate"; resolve method and check nethod calls
            if(psiMethod != null && psiMethod.getName().equals("inflate")) {
                PsiExpression[] expressions = psiMethodCallExpression.getArgumentList().getExpressions();
                if(expressions.length > 0 && expressions[0] instanceof PsiReferenceExpression) {
                    PsiFile xmlFile = AndroidUtils.findXmlResource((PsiReferenceExpression) expressions[0]);
                    if(xmlFile != null) {
                        return new InflateContainer(xmlFile, ((PsiLocalVariable) psiLocalVariable));
                    }
                }
            }
        }
    }

    return null;
}
 
源代码2 项目: intellij-plugin-v4   文件: TokenVocabResolver.java
/**
 * Tries to find a declaration named {@code ruleName} in the {@code tokenVocab} file if it exists.
 */
@Nullable
public static PsiElement resolveInTokenVocab(GrammarElementRefNode reference, String ruleName) {
	String tokenVocab = MyPsiUtils.findTokenVocabIfAny((ANTLRv4FileRoot) reference.getContainingFile());

	if (tokenVocab != null) {
		PsiFile tokenVocabFile = findRelativeFile(tokenVocab, reference.getContainingFile());

		if (tokenVocabFile != null) {
			GrammarSpecNode lexerGrammar = PsiTreeUtil.findChildOfType(tokenVocabFile, GrammarSpecNode.class);
			PsiElement node = MyPsiUtils.findSpecNode(lexerGrammar, ruleName);

			if (node instanceof LexerRuleSpecNode) {
				// fragments are not visible to the parser
				if (!((LexerRuleSpecNode) node).isFragment()) {
					return node;
				}
			}
			if (node instanceof TokenSpecNode) {
				return node;
			}
		}
	}

	return null;
}
 
@Override
public void visitFile(PsiFile file) {
    // @TODO: detection of routing files in right way
    // routing.yml
    // comment.routing.yml
    // routing/foo.yml
    if(!YamlHelper.isRoutingFile(file)) {
        return;
    }

    YAMLDocument document = PsiTreeUtil.findChildOfType(file, YAMLDocument.class);
    if(document == null) {
        return;
    }

    YAMLValue topLevelValue = document.getTopLevelValue();
    if(topLevelValue != null) {
        YamlHelper.attachDuplicateKeyInspection(topLevelValue, holder);
    }
}
 
源代码4 项目: reasonml-idea-plugin   文件: LetParsingTest.java
public void testRecord() {
    PsiLet let = first(letExpressions(parseCode("let r = { one = 1; two = 2 }")));

    PsiLetBinding binding = first(PsiTreeUtil.findChildrenOfType(let, PsiLetBinding.class));
    assertNotNull(binding);
    PsiRecord record = PsiTreeUtil.findChildOfType(binding, PsiRecord.class);
    assertNotNull(record);
    Collection<PsiRecordField> fields = record.getFields();
    assertSize(2, fields);
    Iterator<PsiRecordField> itFields = fields.iterator();
    assertEquals("one = 1", itFields.next().getText());
    assertEquals("two = 2", itFields.next().getText());
}
 
源代码5 项目: reasonml-idea-plugin   文件: FunctorTest.java
public void testFunctorInstanciation() {
    PsiInnerModule module = (PsiInnerModule) first(moduleExpressions(parseCode("module Printing = Make (struct let encode = encode_record end)")));

    assertNull(module.getBody());
    PsiFunctorCall call = PsiTreeUtil.findChildOfType(module, PsiFunctorCall.class);
    assertNotNull(call);
    assertEquals("Make (struct let encode = encode_record end)", call.getText());
}
 
源代码6 项目: intellij-latte   文件: LatteElementFactory.java
public static LattePhpClassUsage createClassRootUsage(Project project, String name) {
	final LatteFile file = createFileWithPhpMacro(project, "\\" + name);
	LattePhpClassUsage firstChild = PsiTreeUtil.findChildOfType(file, LattePhpClassUsage.class);
	if (firstChild != null) {
		try {
			return firstChild;

		} catch (NullPointerException e) {
			return null;
		}
	}
	return null;
}
 
源代码7 项目: reasonml-idea-plugin   文件: IfParsingTest.java
public void testBasicIfParsing() {
    PsiFile psiFile = parseCode("let _ = if x then ()");
    PsiIfStatement e = firstOfType(psiFile, PsiIfStatement.class);

    assertNotNull(e);
    assertNotNull(e.getBinaryCondition());
    PsiScopedExpr ifScope = PsiTreeUtil.findChildOfType(e, PsiScopedExpr.class);
    assertNotNull(ifScope);
    assertEquals("()", ifScope.getText());
}
 
源代码8 项目: reasonml-idea-plugin   文件: FunctionCallTest.java
public void testCall() {
    PsiLet e = first(letExpressions(parseCode("let _ = string_of_int(1)")));

    PsiFunctionCallParams callParams = PsiTreeUtil.findChildOfType(e.getBinding(), PsiFunctionCallParams.class);
    Collection<PsiElement> parameters = callParams.getParametersList();
    assertEquals(1, parameters.size());
}
 
源代码9 项目: reasonml-idea-plugin   文件: FunctorTest.java
public void testFunctorInstanciation() {
    PsiInnerModule module = (PsiInnerModule) first(moduleExpressions(parseCode("module Printing = Make({ let encode = encode_record; });")));

    assertNull(module.getBody());
    PsiFunctorCall call = PsiTreeUtil.findChildOfType(module, PsiFunctorCall.class);
    assertNotNull(call);
    assertEquals("Make({ let encode = encode_record; })", call.getText());
}
 
源代码10 项目: reasonml-idea-plugin   文件: PsiClassField.java
@Nullable
@Override
public PsiElement getNameIdentifier() {
    return PsiTreeUtil.findChildOfType(this, PsiLowerSymbol.class);
}
 
源代码11 项目: BashSupport   文件: BashPsiElementFactory.java
public static PsiElement createHeredocStartMarker(Project project, String name) {
    String data = String.format("cat << %s\n%s", name, name);
    return PsiTreeUtil.findChildOfType(createDummyBashFile(project, data), BashHereDocStartMarker.class);
}
 
源代码12 项目: intellij-xquery   文件: XQueryFile.java
public XQueryDefaultFunctionNamespaceDecl getDefaultNamespaceFunctionDeclaration() {
    return PsiTreeUtil.findChildOfType(this, XQueryDefaultFunctionNamespaceDecl.class);
}
 
源代码13 项目: reasonml-idea-plugin   文件: PsiTypeImpl.java
@Nullable
@Override
public PsiElement getNameIdentifier() {
    PsiTypeConstrName constr = findChildByClass(PsiTypeConstrName.class);
    return constr == null ? null : PsiTreeUtil.findChildOfType(constr, PsiLowerSymbol.class);
}
 
源代码14 项目: intellij-xquery   文件: XQueryFile.java
public XQueryQueryBody getQueryBody() {
    return PsiTreeUtil.findChildOfType(this, XQueryQueryBody.class);
}
 
源代码15 项目: intellij-xquery   文件: XQueryFile.java
public boolean isLibraryModule() {
    XQueryModuleDecl moduleDecl = PsiTreeUtil.findChildOfType(this, XQueryModuleDecl.class);
    return moduleDecl != null;
}
 
源代码16 项目: elm-plugin   文件: ElmPsiImplUtil.java
public static ElmUpperCasePath getModuleName(ElmImportClause module) {
    return PsiTreeUtil.findChildOfType(module, ElmUpperCasePath.class);
}
 
@SuppressWarnings("unchecked")
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {

	final IElementType elementType = element.getNode().getElementType();

       // highlight TO-DO items
       if(elementType == JSGraphQLEndpointDocTokenTypes.DOCTEXT) {
		final String elementText = element.getText().toLowerCase();
		if(isTodoToken(elementText)) {
			setTextAttributes(element, holder, CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
               holder.getCurrentAnnotationSession().putUserData(TODO_ELEMENT, element);
			return;
		} else {
               PsiElement prevSibling = element.getPrevSibling();
               while (prevSibling != null) {
                   if(prevSibling == holder.getCurrentAnnotationSession().getUserData(TODO_ELEMENT)) {
                       setTextAttributes(element, holder, CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
                       return;
                   }
                   prevSibling = prevSibling.getPrevSibling();
               }
           }
	}

	final PsiComment comment = PsiTreeUtil.getContextOfType(element, PsiComment.class);
	if (comment != null && JSGraphQLEndpointDocPsiUtil.isDocumentationComment(comment)) {
		final TextAttributesKey textAttributesKey = ATTRIBUTES.get(elementType);
		if (textAttributesKey != null) {
			setTextAttributes(element, holder, textAttributesKey);
		}
		// highlight invalid argument names after @param
		if(elementType == JSGraphQLEndpointDocTokenTypes.DOCVALUE) {
			final JSGraphQLEndpointFieldDefinition field = PsiTreeUtil.getNextSiblingOfType(comment, JSGraphQLEndpointFieldDefinition.class);
			if(field != null) {
				final JSGraphQLEndpointDocTag tag = PsiTreeUtil.getParentOfType(element, JSGraphQLEndpointDocTag.class);
				if(tag != null && tag.getDocName().getText().equals("@param")) {
					final String paramName = element.getText();
					final JSGraphQLEndpointInputValueDefinitions arguments = PsiTreeUtil.findChildOfType(field, JSGraphQLEndpointInputValueDefinitions.class);
					if(arguments == null) {
						// no arguments so invalid use of @param
						holder.createErrorAnnotation(element, "Invalid use of @param. The property has no arguments");
					} else {
						final JSGraphQLEndpointInputValueDefinition[] inputValues = PsiTreeUtil.getChildrenOfType(arguments, JSGraphQLEndpointInputValueDefinition.class);
						boolean found = false;
						if(inputValues != null) {
							for (JSGraphQLEndpointInputValueDefinition inputValue: inputValues) {
								if(inputValue.getInputValueDefinitionIdentifier().getText().equals(paramName)) {
									found = true;
									break;
								}
							}
						}
						if(!found) {
							holder.createErrorAnnotation(element, "@param name '" + element.getText() + "' doesn't match any of the field arguments");
						}

					}
				}
			}
		}
	}
}
 
源代码18 项目: reasonml-idea-plugin   文件: LocalOpenTest.java
public void testLocalList() {
    PsiElement expression = parseCode("ModA.ModB.[call()];");
    PsiLocalOpen o = PsiTreeUtil.findChildOfType(expression, PsiLocalOpen.class);
    assertEquals("[call()]", o.getText());
}
 
源代码19 项目: reasonml-idea-plugin   文件: FunctionCallTest.java
public void testIssue120() {
    PsiLet e = first(letExpressions(parseCode("let _ = f(x == U.I, 1)")));

    PsiFunctionCallParams params = PsiTreeUtil.findChildOfType(e, PsiFunctionCallParams.class);
    assertSize(2, params.getParametersList());
}
 
源代码20 项目: intellij-xquery   文件: XQueryElementFactory.java
public static XQueryVarName createVariableReference(Project project, String namespaceName,
                                                    String localVariableName) {
    final XQueryFile file = createFile(project, "$" + namespaceName + ":" + localVariableName);
    return PsiTreeUtil.findChildOfType(file, XQueryVarName.class);
}