Search in sources :

Example 76 with GrExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.

the class GroovyParameterInfoHandler method appendParameterText.

private static void appendParameterText(PsiParameter param, PsiSubstitutor substitutor, StringBuilder buffer) {
    if (param instanceof GrParameter) {
        GrParameter grParam = (GrParameter) param;
        GroovyPresentationUtil.appendParameterPresentation(grParam, substitutor, TypePresentation.PRESENTABLE, buffer);
        final GrExpression initializer = grParam.getInitializerGroovy();
        if (initializer != null) {
            buffer.append(" = ").append(initializer.getText());
        } else if (grParam.isOptional()) {
            buffer.append(" = null");
        }
    } else {
        PsiType t = param.getType();
        PsiType paramType = substitutor.substitute(t);
        buffer.append(paramType.getPresentableText());
        String name = param.getName();
        if (name != null) {
            buffer.append(" ");
            buffer.append(name);
        }
    }
}
Also used : GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)

Example 77 with GrExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.

the class NotAndParenthesesSurrounder method surroundExpression.

@Override
protected TextRange surroundExpression(@NotNull GrExpression expression, @Nullable PsiElement context) {
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(expression.getProject());
    final GrUnaryExpression template = (GrUnaryExpression) factory.createExpressionFromText("!(a)", context);
    assert template.getOperand() != null;
    GroovyExpressionSurrounder.replaceToOldExpression(((GrParenthesizedExpression) template.getOperand()).getOperand(), expression);
    final GrExpression result = expression.replaceWithExpression(template, true);
    final int endOffset = result.getTextRange().getEndOffset();
    return new TextRange(endOffset, endOffset);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrUnaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) TextRange(com.intellij.openapi.util.TextRange)

Example 78 with GrExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project android by JetBrains.

the class GradleEditorValueExtractor method visitReferenceExpression.

@Override
public void visitReferenceExpression(GrReferenceExpression expression) {
    if (expression.getParent() instanceof GrMethodCallExpression) {
        // This is a reference expression which points to the method name. We're not interested in it, so, just return.
        return;
    }
    GrExpression qualifier = expression.getQualifierExpression();
    if (qualifier == null) {
        myContext.addCachedVariable(expression.getText(), expression.getTextRange());
        return;
    }
    myContext.rememberVariableQualifier(qualifier.getText());
    PsiElement dotToken = expression.getDotToken();
    if (dotToken == null) {
        return;
    }
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.findSingle(GroovyLanguage.INSTANCE);
    for (PsiElement e = dotToken.getNextSibling(); e != null; e = e.getNextSibling()) {
        ASTNode node = e.getNode();
        if (node == null) {
            if (e instanceof PsiWhiteSpace) {
                continue;
            }
            e.accept(myVisitor);
            return;
        }
        IElementType type = node.getElementType();
        if (type == GroovyTokenTypes.mIDENT) {
            myContext.addCachedVariable(e.getText(), e.getTextRange());
        } else if (parserDefinition.getWhitespaceTokens().contains(type) || parserDefinition.getCommentTokens().contains(type)) {
            continue;
        } else {
            e.accept(myVisitor);
        }
        return;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ParserDefinition(com.intellij.lang.ParserDefinition) GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) ASTNode(com.intellij.lang.ASTNode) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 79 with GrExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project android by JetBrains.

the class GradleEditorValueExtractor method visitGStringExpression.

@Override
public void visitGStringExpression(GrString expression) {
    GroovyPsiElement[] parts = expression.getAllContentParts();
    boolean registeredAssignment = false;
    for (GroovyPsiElement part : parts) {
        if (part instanceof GrStringContent) {
            if (!myInterestedInReferencesOnly && !registeredAssignment && !part.getTextRange().isEmpty()) {
                registeredAssignment = true;
                String text = expression.getText();
                TextRange range = expression.getTextRange();
                if (text.startsWith("'") || text.startsWith("\"")) {
                    text = text.substring(1);
                    range = TextRange.create(range.getStartOffset() + 1, range.getEndOffset());
                }
                if (text.endsWith("'") || text.endsWith("\"")) {
                    text = text.substring(0, text.length() - 1);
                    range = TextRange.create(range.getStartOffset(), range.getEndOffset() - 1);
                }
                myContext.addCachedValue(text, range);
            }
        } else if (part instanceof GrStringInjection) {
            GrExpression injectedExpression = ((GrStringInjection) part).getExpression();
            if (injectedExpression != null) {
                injectedExpression.accept(myVisitor);
            }
        }
    }
}
Also used : GrStringContent(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringContent) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) TextRange(com.intellij.openapi.util.TextRange) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString) GrStringInjection(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection)

Example 80 with GrExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project android by JetBrains.

the class AndroidGradleSpellcheckingStrategy method isPrint.

private static boolean isPrint(PsiElement element) {
    PsiElement parent0 = element.getParent();
    if (parent0 == null) {
        return false;
    }
    PsiElement parent1 = parent0.getParent();
    if (parent1 == null) {
        return false;
    }
    PsiElement parent2 = parent1.getParent();
    if (parent2 == null) {
        return false;
    }
    if (parent2 instanceof GrCommandArgumentList) {
        parent2 = parent2.getParent();
    }
    if (parent2 instanceof GrApplicationStatement) {
        GrApplicationStatement call = (GrApplicationStatement) parent2;
        GrExpression propertyExpression = call.getInvokedExpression();
        if (propertyExpression instanceof GrReferenceExpression) {
            GrReferenceExpression propertyRef = (GrReferenceExpression) propertyExpression;
            String property = propertyRef.getReferenceName();
            if ("print".equals(property) || "println".equals(property)) {
                return true;
            }
        }
    }
    return false;
}
Also used : GrCommandArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrApplicationStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Aggregations

GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)312 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)93 Nullable (org.jetbrains.annotations.Nullable)68 PsiElement (com.intellij.psi.PsiElement)62 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)43 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)43 NotNull (org.jetbrains.annotations.NotNull)37 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)35 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)33 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)29 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)27 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)26 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)26 PsiType (com.intellij.psi.PsiType)24 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)23 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)23 IElementType (com.intellij.psi.tree.IElementType)22 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)18 ArrayList (java.util.ArrayList)16 GrReturnStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement)16