Search in sources :

Example 86 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.

the class GroovyTypedHandler method beforeCharTyped.

@Override
public Result beforeCharTyped(final char c, final Project project, final Editor editor, final PsiFile file, final FileType fileType) {
    int offsetBefore = editor.getCaretModel().getOffset();
    //important to calculate before inserting charTyped
    myJavaLTTyped = '<' == c && file instanceof GroovyFile && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && isAfterClassLikeIdentifier(offsetBefore, editor);
    if ('>' == c) {
        if (file instanceof GroovyFile && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) {
            if (JavaTypedHandler.handleJavaGT(editor, GroovyTokenTypes.mLT, GroovyTokenTypes.mGT, INVALID_INSIDE_REFERENCE))
                return Result.STOP;
        }
    }
    if (c == '@' && file instanceof GroovyFile) {
        autoPopupMemberLookup(project, editor, file12 -> {
            int offset = editor.getCaretModel().getOffset();
            PsiElement lastElement = file12.findElementAt(offset - 1);
            if (lastElement == null)
                return false;
            final PsiElement prevSibling = PsiTreeUtil.prevVisibleLeaf(lastElement);
            return prevSibling != null && ".".equals(prevSibling.getText());
        });
    }
    if (c == '&' && file instanceof GroovyFile) {
        autoPopupMemberLookup(project, editor, file1 -> {
            int offset = editor.getCaretModel().getOffset();
            PsiElement lastElement = file1.findElementAt(offset - 1);
            return lastElement != null && ".&".equals(lastElement.getText());
        });
    }
    return Result.CONTINUE;
}
Also used : GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElement(com.intellij.psi.PsiElement)

Example 87 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.

the class GroovyStatementSelectioner method inferBlockRange.

private static TextRange inferBlockRange(PsiElement first, PsiElement last) {
    while (true) {
        PsiElement prev = first.getPrevSibling();
        prev = skipWhitespaceBack(prev);
        if (isOneLineFeed(prev))
            prev = prev.getPrevSibling();
        prev = skipWhitespaceBack(prev);
        if (prev != null && prev.getNode().getElementType() == GroovyTokenTypes.mSEMI || prev instanceof GrStatement) {
            first = prev;
        } else {
            break;
        }
    }
    while (true) {
        PsiElement next = last.getNextSibling();
        next = skipWhitespacesForward(next);
        if (isOneLineFeed(next))
            next = next.getNextSibling();
        next = skipWhitespacesForward(next);
        if (next != null && next.getNode().getElementType() == GroovyTokenTypes.mSEMI || next instanceof GrStatement) {
            last = next;
        } else {
            break;
        }
    }
    return new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset());
}
Also used : TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Example 88 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.

the class GrHighlightExitPointHandler method computeUsages.

@Override
public void computeUsages(List<PsiElement> targets) {
    PsiElement parent = myTarget.getParent();
    if (!(parent instanceof GrReturnStatement) && !(parent instanceof GrThrowStatement))
        return;
    final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(parent);
    ControlFlowUtils.visitAllExitPoints(flowOwner, new ControlFlowUtils.ExitPointVisitor() {

        @Override
        public boolean visitExitPoint(Instruction instruction, @Nullable GrExpression returnValue) {
            final PsiElement returnElement = instruction.getElement();
            if (returnElement != null && isCorrectReturn(returnElement)) {
                final TextRange range = returnElement.getTextRange();
                myReadUsages.add(range);
            }
            return true;
        }
    });
}
Also used : GrControlFlowOwner(org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner) GrThrowStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) TextRange(com.intellij.openapi.util.TextRange) GrReturnStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement) ControlFlowUtils(org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils) Instruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction) PsiElement(com.intellij.psi.PsiElement)

Example 89 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.

the class GrImportFilteringRule method isVisible.

@Override
public boolean isVisible(@NotNull Usage usage) {
    if (usage instanceof PsiElementUsage) {
        final PsiElement psiElement = ((PsiElementUsage) usage).getElement();
        final PsiFile containingFile = psiElement.getContainingFile();
        if (containingFile instanceof GroovyFile) {
            // check whether the element is in the import list
            return PsiTreeUtil.getParentOfType(psiElement, GrImportStatement.class, true) == null;
        }
    }
    return true;
}
Also used : PsiFile(com.intellij.psi.PsiFile) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) PsiElement(com.intellij.psi.PsiElement) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElementUsage(com.intellij.usages.rules.PsiElementUsage)

Example 90 with PsiElement

use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.

the class GroovyBlockGenerator method addBinaryChildrenRecursively.

/**
   * Adds all children of specified element to given list
   *
   * @param elem
   * @param list
   * @param indent
   * @param aligner
   */
private void addBinaryChildrenRecursively(PsiElement elem, List<Block> list, Indent indent, @Nullable AlignmentProvider.Aligner aligner) {
    if (elem == null)
        return;
    // For binary expressions
    if ((elem instanceof GrBinaryExpression)) {
        GrBinaryExpression myExpr = ((GrBinaryExpression) elem);
        if (myExpr.getLeftOperand() instanceof GrBinaryExpression) {
            addBinaryChildrenRecursively(myExpr.getLeftOperand(), list, Indent.getContinuationWithoutFirstIndent(), aligner);
        }
        PsiElement op = ((GrBinaryExpression) elem).getOperationToken();
        for (ASTNode childNode : visibleChildren(elem.getNode())) {
            PsiElement psi = childNode.getPsi();
            if (!(psi instanceof GrBinaryExpression)) {
                if (op != psi && aligner != null) {
                    aligner.append(psi);
                }
                list.add(new GroovyBlock(childNode, indent, getChildWrap(childNode), myContext));
            }
        }
        if (myExpr.getRightOperand() instanceof GrBinaryExpression) {
            addBinaryChildrenRecursively(myExpr.getRightOperand(), list, Indent.getContinuationWithoutFirstIndent(), aligner);
        }
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)3198 Nullable (org.jetbrains.annotations.Nullable)493 PsiFile (com.intellij.psi.PsiFile)474 NotNull (org.jetbrains.annotations.NotNull)442 TextRange (com.intellij.openapi.util.TextRange)239 PsiReference (com.intellij.psi.PsiReference)227 Project (com.intellij.openapi.project.Project)222 VirtualFile (com.intellij.openapi.vfs.VirtualFile)210 ArrayList (java.util.ArrayList)195 ASTNode (com.intellij.lang.ASTNode)142 XmlTag (com.intellij.psi.xml.XmlTag)134 PsiClass (com.intellij.psi.PsiClass)115 Editor (com.intellij.openapi.editor.Editor)112 Document (com.intellij.openapi.editor.Document)109 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)85 PsiDirectory (com.intellij.psi.PsiDirectory)80 IElementType (com.intellij.psi.tree.IElementType)78 Module (com.intellij.openapi.module.Module)77 PsiMethod (com.intellij.psi.PsiMethod)73 UsageInfo (com.intellij.usageView.UsageInfo)70