Java Code Examples for com.intellij.lang.ASTNode.getPsi()

The following are Jave code examples for showing how to use getPsi() of the com.intellij.lang.ASTNode class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: TS-IJ   File: TSClassNameAnnotator.java   Source Code and License Vote up 5 votes
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    PsiElement classElement = null;
    if (element instanceof  TSDatablockDecl) {
        TSDatablockDecl db = (TSDatablockDecl) element;

        //Find the first id node, this is kinda wonky since we have to account for whitespace nodes
        //datablock ClassName(...)
        ASTNode node = db.getNode();
        if (node == null) {
            return;
        }
        node = node.findChildByType(TSTypes.ID);
        if (node == null) {
            return;
        }
        classElement = node.getPsi();
    } else if (element instanceof TSObjectExpr) {
        TSObjectExpr obj = (TSObjectExpr) element;

        //Class name should be the second thing in the element:
        // new ClassName(...)
        classElement = PsiTreeUtil.getChildOfType(obj, TSClassNameExpr.class);

        if (classElement == null) {
            return;
        }
        classElement = classElement.getFirstChild();
    }
    if (classElement == null) {
        return;
    }

    //Only annotate if it's an id, can't really tell if it's an expr
    if (classElement.getNode().getElementType().equals(TSTypes.ID)) {
        createSuccessAnnotation(classElement, holder, TSSyntaxHighlighter.CLASSNAME);
    }
}
 
Example 2
Project: TS-IJ   File: TSPsiImplUtil.java   Source Code and License Vote up 5 votes
public static PsiElement getNameIdentifier(TSFnDeclStmt element) {
    ASTNode nameNode = element.getNode().findChildByType(TSTypes.ID);

    if (nameNode != null) {
        return nameNode.getPsi();
    }

    return null;
}
 
Example 3
Project: TS-IJ   File: TSPsiImplUtil.java   Source Code and License Vote up 5 votes
public static PsiElement getNameIdentifier(TSPackageDecl element) {
    ASTNode nameNode = element.getNode().findChildByType(TSTypes.ID);

    if (nameNode != null) {
        return nameNode.getPsi();
    }

    return null;
}
 
Example 4
Project: bamboo-soy   File: SoyFormattingModelBuilder.java   Source Code and License Vote up 5 votes
@Override
public TemplateLanguageBlock createTemplateLanguageBlock(
    @NotNull ASTNode node,
    @Nullable Wrap wrap,
    @Nullable Alignment alignment,
    @Nullable List<DataLanguageBlockWrapper> foreignChildren,
    @NotNull CodeStyleSettings codeStyleSettings) {
  final FormattingDocumentModelImpl documentModel =
      FormattingDocumentModelImpl.createOn(node.getPsi().getContainingFile());
  if (node.getPsi() instanceof TagElement) {
    return new SoyTagBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else if(node.getPsi() instanceof TagBlockElement) {
    return new SoyTagBlockBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else if (node.getPsi() instanceof SoyStatementList) {
    return new SoyStatementListBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else {
    return new SoyBlock(
      this,
      codeStyleSettings,
      node,
      foreignChildren,
      new HtmlPolicy(codeStyleSettings, documentModel));
  }
}
 
Example 5
Project: intellij-postfix-templates   File: CptPsiImplUtil.java   Source Code and License Vote up 5 votes
public static PsiElement getNameIdentifier(CptNamedElement element) {
	ASTNode keyNode = element.getNode().findChildByType(CptTypes.CLASS_NAME);
	if (keyNode != null) {
		return keyNode.getPsi();
	} else {
		return null;
	}
}
 
Example 6
Project: hybris-integration-intellij-idea-plugin   File: JspPropertyFoldingBuilder.java   Source Code and License Vote up 5 votes
@Override
public String getPlaceholderText(@NotNull ASTNode node) {
    final PsiElement element = node.getPsi();
    if (element instanceof XmlAttributeValue) {
        IProperty property = getResolvedProperty((XmlAttributeValue) element);
        return property == null ? element.getText() : "{" + property.getValue() + "}";
    }
    return element.getText();
}
 
Example 7
Project: hybris-integration-intellij-idea-plugin   File: ColumnsAlignmentStrategy.java   Source Code and License Vote up 5 votes
@Contract(pure = true)
private boolean isStartOfValueLine(@Nullable final ASTNode currentNode) {
    return null != currentNode
           && PsiTreeUtil.findChildOfType(
        currentNode.getTreeParent().getPsi(),
        ImpexValueGroup.class
    ) == currentNode.getPsi();
}
 
Example 8
Project: intellij-plugin   File: CoffigYamlFileImpl.java   Source Code and License Vote up 5 votes
public List<YAMLPsiElement> getYAMLElements() {
    final ArrayList<YAMLPsiElement> result = new ArrayList<>();
    for (ASTNode node : getNode().getChildren(null)) {
        final PsiElement psi = node.getPsi();
        if (psi instanceof YAMLPsiElement) {
            result.add((YAMLPsiElement) psi);
        }
    }
    return result;
}
 
Example 9
Project: intellij-crystal   File: CrystalPsiImplUtil.java   Source Code and License Vote up 5 votes
public static PsiElement getNameIdentifier(CrystalProperty element) {
    ASTNode keyNode = element.getNode().findChildByType(CrystalTypes.KEY);
    if (keyNode != null) {
        return keyNode.getPsi();
    } else {
        return null;
    }
}
 
Example 10
Project: AppleScript-IDEA   File: AppleScriptHandlerSelectorPartImpl.java   Source Code and License Vote up 4 votes
@Nullable
@Override
public PsiElement getNameIdentifier() {
  ASTNode paramNode = findParameterNode();
  return paramNode != null ? paramNode.getPsi() : null;
}
 
Example 11
Project: hybris-integration-intellij-idea-plugin   File: ColumnsAlignmentStrategy.java   Source Code and License Vote up 4 votes
@Contract(pure = true)
private boolean isStartOfTheFile(@Nullable final ASTNode currentNode) {
    return null != currentNode && currentNode.getPsi() instanceof ImpexFile;
}