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

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#findChildOfAnyType() . 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: CSharpCodeBodyProxyImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public PsiElement getElement()
{
	ASTNode node = myMethodElement.getNode().findChildByType(CSharpElements.METHOD_BODIES);
	if(node != null)
	{
		CSharpMethodBodyImpl psi = (CSharpMethodBodyImpl) node.getPsi();
		return psi.getInnerElement();
	}


	DotNetElement element = PsiTreeUtil.findChildOfAnyType(myMethodElement, DotNetStatement.class, DotNetExpression.class);
	if(element != null)
	{
		return element;
	}

	node = myMethodElement.getNode().findChildByType(CSharpTokens.SEMICOLON);
	if(node != null)
	{
		return node.getPsi();
	}
	return null;
}
 
Example 2
Source File: YamlHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Bridge to allow YAMLKeyValue adding child key-values elements.
 * Yaml plugin provides key adding only on YAMLMapping
 *
 * ser<caret>vice:
 *   foo: "aaa"
 *
 */
@Nullable
public static YAMLKeyValue putKeyValue(@NotNull YAMLKeyValue yamlKeyValue, @NotNull String keyName, @NotNull String valueText) {

    // create "foo: foo"
    YAMLKeyValue newYamlKeyValue = YAMLElementGenerator.getInstance(yamlKeyValue.getProject())
        .createYamlKeyValue(keyName, valueText);

    YAMLMapping childOfAnyType = PsiTreeUtil.findChildOfAnyType(yamlKeyValue, YAMLMapping.class);
    if(childOfAnyType == null) {
        return null;
    }

    childOfAnyType.putKeyValue(newYamlKeyValue);

    return newYamlKeyValue;
}
 
Example 3
Source File: ANTLRv4FoldingBuilder.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static void addRuleRefFoldingDescriptors(List<FoldingDescriptor> descriptors, PsiElement root) {
    for (RuleSpecNode specNode : PsiTreeUtil.findChildrenOfType(root, RuleSpecNode.class)) {
        GrammarElementRefNode refNode = PsiTreeUtil.findChildOfAnyType(specNode, GrammarElementRefNode.class);
        if (refNode == null) continue;
        PsiElement nextSibling = refNode.getNextSibling();
        if (nextSibling == null) continue;
        int startOffset = nextSibling.getTextOffset();

        ASTNode backward = TreeUtil.findChildBackward(specNode.getNode(), SEMICOLON);
        if (backward == null) continue;
        int endOffset = backward.getTextRange().getEndOffset();
        if (startOffset >= endOffset) continue;

        descriptors.add(new FoldingDescriptor(specNode, new TextRange(startOffset, endOffset)));

    }
}
 
Example 4
Source File: CSharpAssemblyBlock.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
public <T> T getValue(PsiFile file, Class<T> clazz)
{
	CSharpDummyDeclarationImpl childOfAnyType = PsiTreeUtil.findChildOfAnyType(file, CSharpDummyDeclarationImpl.class);
	if(childOfAnyType == null)
	{
		return null;
	}

	return CSharpAttributeUtil.findSingleAttributeValue(childOfAnyType, myAttributeType, clazz);
}
 
Example 5
Source File: EventAnnotationStubIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void visitPhpDocTag(PhpDocTag element) {
    String name = StringUtils.stripStart(element.getName(), "@");
    if(!"Event".equalsIgnoreCase(name)) {
        return;
    }

    PhpDocComment phpDocComment = ObjectUtils.tryCast(element.getParent(), PhpDocComment.class);
    if(phpDocComment == null) {
        return;
    }

    PhpPsiElement nextPsiSibling = phpDocComment.getNextPsiSibling();
    if(nextPsiSibling == null || nextPsiSibling.getNode().getElementType() != PhpElementTypes.CLASS_CONSTANTS) {
        return;
    }

    ClassConstImpl childOfAnyType = PsiTreeUtil.findChildOfAnyType(nextPsiSibling, ClassConstImpl.class);
    if(childOfAnyType == null) {
        return;
    }

    PsiElement defaultValue = childOfAnyType.getDefaultValue();
    if(!(defaultValue instanceof StringLiteralExpression)) {
        return;
    }

    String contents = ((StringLiteralExpression) defaultValue).getContents();

    String fqn = StringUtils.stripStart(childOfAnyType.getFQN(), "\\");

    map.put(contents, new DispatcherEvent(
        fqn,
        findClassInstance(phpDocComment, element))
    );
}
 
Example 6
Source File: ANTLRv4FindUsagesProvider.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement element) {
	PsiElement rule = PsiTreeUtil.findChildOfAnyType(element,
													 new Class[]{LexerRuleRefNode.class, ParserRuleRefNode.class});
	if ( rule!=null ) return rule.getText();
	return "n/a";
}