Search in sources :

Example 11 with GrAssignmentExpression

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

the class GdkMethodUtil method getClosureMixins.

private static Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>> getClosureMixins(final GrStatement statement) {
    if (!(statement instanceof GrAssignmentExpression))
        return null;
    final GrAssignmentExpression assignment = (GrAssignmentExpression) statement;
    return CachedValuesManager.getCachedValue(statement, new CachedValueProvider<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>>() {

        @Nullable
        @Override
        public Result<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>> compute() {
            Pair<PsiClassType, GrReferenceExpression> original = getTypeToMixIn(assignment);
            if (original == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            final Pair<GrSignature, String> signatures = getTypeToMix(assignment);
            if (signatures == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            final String name = signatures.second;
            final List<GrMethod> methods = ContainerUtil.newArrayList();
            final PsiClass closure = JavaPsiFacade.getInstance(statement.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, statement.getResolveScope());
            if (closure == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            signatures.first.accept(new GrSignatureVisitor() {

                @Override
                public void visitClosureSignature(GrClosureSignature signature) {
                    super.visitClosureSignature(signature);
                    GrMethod method = createMethod(signature, name, assignment, closure);
                    methods.add(method);
                }
            });
            return Result.create(Trinity.create(original.first, original.second, methods), PsiModificationTracker.MODIFICATION_COUNT);
        }
    });
}
Also used : Trinity(com.intellij.openapi.util.Trinity) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrSignatureVisitor(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable) Pair(com.intellij.openapi.util.Pair)

Example 12 with GrAssignmentExpression

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

the class ConditionalUtils method isAssignment.

public static boolean isAssignment(GrStatement statement, @NonNls String value) {
    if (statement == null) {
        return false;
    }
    if (!(statement instanceof GrExpression)) {
        return false;
    }
    final GrExpression expression = (GrExpression) statement;
    if (!(expression instanceof GrAssignmentExpression)) {
        return false;
    }
    final GrAssignmentExpression assignment = (GrAssignmentExpression) expression;
    final GrExpression rhs = assignment.getRValue();
    if (rhs == null) {
        return false;
    }
    final String rhsText = rhs.getText();
    return value.equals(rhsText);
}
Also used : GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)

Example 13 with GrAssignmentExpression

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

the class GroovyTrivialIfInspection method isSimplifiableAssignmentNegated.

public static boolean isSimplifiableAssignmentNegated(GrIfStatement ifStatement) {
    GrStatement thenBranch = ifStatement.getThenBranch();
    thenBranch = ConditionalUtils.stripBraces(thenBranch);
    GrStatement elseBranch = ifStatement.getElseBranch();
    elseBranch = ConditionalUtils.stripBraces(elseBranch);
    if (ConditionalUtils.isAssignment(thenBranch, "false") && ConditionalUtils.isAssignment(elseBranch, "true")) {
        final GrAssignmentExpression thenExpression = (GrAssignmentExpression) thenBranch;
        final GrAssignmentExpression elseExpression = (GrAssignmentExpression) elseBranch;
        final IElementType thenSign = thenExpression.getOperationTokenType();
        final IElementType elseSign = elseExpression.getOperationTokenType();
        if (!thenSign.equals(elseSign)) {
            return false;
        }
        final GrExpression thenLhs = thenExpression.getLValue();
        final GrExpression elseLhs = elseExpression.getLValue();
        return EquivalenceChecker.expressionsAreEquivalent(thenLhs, elseLhs);
    } else {
        return false;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Example 14 with GrAssignmentExpression

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

the class GroovyTrivialIfInspection method isSimplifiableImplicitAssignmentNegated.

public static boolean isSimplifiableImplicitAssignmentNegated(GrIfStatement ifStatement) {
    if (ifStatement.getElseBranch() != null) {
        return false;
    }
    GrStatement thenBranch = ifStatement.getThenBranch();
    thenBranch = ConditionalUtils.stripBraces(thenBranch);
    final PsiElement nextStatement = PsiTreeUtil.skipSiblingsBackward(ifStatement, PsiWhiteSpace.class);
    if (!(nextStatement instanceof GrStatement)) {
        return false;
    }
    GrStatement elseBranch = (GrStatement) nextStatement;
    elseBranch = ConditionalUtils.stripBraces(elseBranch);
    if (ConditionalUtils.isAssignment(thenBranch, "false") && ConditionalUtils.isAssignment(elseBranch, "true")) {
        final GrAssignmentExpression thenExpression = (GrAssignmentExpression) thenBranch;
        final GrAssignmentExpression elseExpression = (GrAssignmentExpression) elseBranch;
        final IElementType thenSign = thenExpression.getOperationTokenType();
        final IElementType elseSign = elseExpression.getOperationTokenType();
        if (!thenSign.equals(elseSign)) {
            return false;
        }
        final GrExpression thenLhs = thenExpression.getLValue();
        final GrExpression elseLhs = elseExpression.getLValue();
        return EquivalenceChecker.expressionsAreEquivalent(thenLhs, elseLhs);
    } else {
        return false;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Example 15 with GrAssignmentExpression

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

the class ConditionalUtils method isAssignment.

public static boolean isAssignment(GrStatement statement, String value) {
    if (statement == null) {
        return false;
    }
    if (!(statement instanceof GrAssignmentExpression)) {
        return false;
    }
    final GrAssignmentExpression assignment = (GrAssignmentExpression) statement;
    final GrExpression rhs = assignment.getRValue();
    if (rhs == null) {
        return false;
    }
    final String rhsText = rhs.getText();
    return value.equals(rhsText);
}
Also used : GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)

Aggregations

GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)34 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)26 PsiElement (com.intellij.psi.PsiElement)16 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)12 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)8 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)7 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)6 IElementType (com.intellij.psi.tree.IElementType)5 GrReturnStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement)5 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)4 PsiFile (com.intellij.psi.PsiFile)3 PsiType (com.intellij.psi.PsiType)3 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)3 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)3 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)3 GrApplicationStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement)3 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)3 ASTNode (com.intellij.lang.ASTNode)2