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);
}
});
}
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);
}
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;
}
}
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;
}
}
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);
}
Aggregations