Search in sources :

Example 66 with ASTNode

use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.

the class PyStringLiteralExpressionImpl method getStringValueTextRanges.

@NotNull
public List<TextRange> getStringValueTextRanges() {
    if (valueTextRanges == null) {
        int elStart = getTextRange().getStartOffset();
        List<TextRange> ranges = new ArrayList<>();
        for (ASTNode node : getStringNodes()) {
            TextRange range = getNodeTextRange(node.getText());
            int nodeOffset = node.getStartOffset() - elStart;
            ranges.add(TextRange.from(nodeOffset + range.getStartOffset(), range.getLength()));
        }
        valueTextRanges = Collections.unmodifiableList(ranges);
    }
    return valueTextRanges;
}
Also used : ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 67 with ASTNode

use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.

the class PyBinaryExpressionImpl method isOperator.

public boolean isOperator(String chars) {
    ASTNode child = getNode().getFirstChildNode();
    StringBuilder buf = new StringBuilder();
    while (child != null) {
        IElementType elType = child.getElementType();
        if (elType instanceof PyElementType && PyElementTypes.BINARY_OPS.contains(elType)) {
            buf.append(child.getText());
        }
        child = child.getTreeNext();
    }
    return buf.toString().equals(chars);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode)

Example 68 with ASTNode

use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.

the class PyTargetExpressionImpl method getName.

@Nullable
@Override
public String getName() {
    final PyTargetExpressionStub stub = getStub();
    if (stub != null) {
        return stub.getName();
    }
    ASTNode node = getNameElement();
    return node != null ? node.getText() : null;
}
Also used : PyTargetExpressionStub(com.jetbrains.python.psi.stubs.PyTargetExpressionStub) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with ASTNode

use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.

the class PyDecoratorImpl method isBuiltin.

public boolean isBuiltin() {
    ASTNode node = getNode().findChildByType(PythonDialectsTokenSetProvider.INSTANCE.getReferenceExpressionTokens());
    if (node != null) {
        PyReferenceExpression ref = (PyReferenceExpression) node.getPsi();
        PsiElement target = ref.getReference().resolve();
        return PyBuiltinCache.getInstance(this).isBuiltin(target);
    }
    return false;
}
Also used : ASTNode(com.intellij.lang.ASTNode) PsiElement(com.intellij.psi.PsiElement)

Example 70 with ASTNode

use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.

the class PyDecoratorImpl method setName.

public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
    final ASTNode node = getNode();
    final ASTNode nameNode = node.findChildByType(PyTokenTypes.IDENTIFIER);
    if (nameNode != null) {
        final ASTNode nameElement = PyUtil.createNewName(this, name);
        node.replaceChild(nameNode, nameElement);
        return this;
    } else {
        throw new IncorrectOperationException("No name node");
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Aggregations

ASTNode (com.intellij.lang.ASTNode)748 PsiElement (com.intellij.psi.PsiElement)142 NotNull (org.jetbrains.annotations.NotNull)132 IElementType (com.intellij.psi.tree.IElementType)127 Nullable (org.jetbrains.annotations.Nullable)99 TextRange (com.intellij.openapi.util.TextRange)91 ArrayList (java.util.ArrayList)53 IncorrectOperationException (com.intellij.util.IncorrectOperationException)35 PsiFile (com.intellij.psi.PsiFile)31 Annotation (com.intellij.lang.annotation.Annotation)22 CharTable (com.intellij.util.CharTable)22 Document (com.intellij.openapi.editor.Document)18 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)17 XmlTag (com.intellij.psi.xml.XmlTag)17 Project (com.intellij.openapi.project.Project)16 AbstractBlock (com.intellij.psi.formatter.common.AbstractBlock)16 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)16 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)15 CompositeElement (com.intellij.psi.impl.source.tree.CompositeElement)15 PsiReference (com.intellij.psi.PsiReference)14