@Override public void afterVisitBinaryExpression(BinaryExpression node) { if (node.astOperator() == BinaryOperator.ASSIGN) { Expression rhs = node.astRight(); ResolvedClass resolvedClass = mTypes.get(rhs); if (resolvedClass != null) { Expression lhs = node.astLeft(); mTypes.put(lhs, resolvedClass); ResolvedNode variable = mContext.resolve(lhs); if (variable instanceof ResolvedVariable) { mVariableTypes.put((ResolvedVariable) variable, resolvedClass); } } } }
@Override public void visitBinaryExpression(BinaryExpression node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); int operatorId = ((node.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT); bin.astOperator(GENERIC_BINARY_OPERATORS.get(operatorId)); bin.astLeft(((lombok.ast.Expression) toTree(node.left))); bin.astRight(((lombok.ast.Expression) toTree(node.right))); set(node, setPosition(node, bin)); }
@Override public void visitCompoundAssignment(CompoundAssignment node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); int operatorId = node.operator; bin.astOperator(ASSIGN_BINARY_OPERATORS.get(operatorId)); bin.astLeft((lombok.ast.Expression) toTree(node.lhs)); bin.astRight((lombok.ast.Expression) toTree(node.expression)); set(node, setPosition(node, bin)); }
@Override public void visitBinaryExpression(BinaryExpression node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); int operatorId = ((node.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT); bin.astOperator(GENERIC_BINARY_OPERATORS.get(operatorId)); bin.astLeft(((lombok.ast.Expression) toTree(node.left))); bin.astRight(((lombok.ast.Expression) toTree(node.right))); set(node, setPosition(node, bin)); }
@Override public void visitCompoundAssignment(CompoundAssignment node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); int operatorId = node.operator; bin.astOperator(ASSIGN_BINARY_OPERATORS.get(operatorId)); bin.astLeft((lombok.ast.Expression) toTree(node.lhs)); bin.astRight((lombok.ast.Expression) toTree(node.expression)); set(node, setPosition(node, bin)); }
@Override public void visitCompoundAssignment(CompoundAssignment node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); int operatorId = node.operator; bin.astOperator(ASSIGN_BINARY_OPERATORS.get(operatorId)); bin.astLeft((lombok.ast.Expression) toTree(node.lhs)); bin.astRight((lombok.ast.Expression) toTree(node.expression)); set(node, setPosition(node, bin)); }
@Override public void visitBinaryExpression(BinaryExpression node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); int operatorId = ((node.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT); bin.astOperator(GENERIC_BINARY_OPERATORS.get(operatorId)); bin.astLeft(((lombok.ast.Expression) toTree(node.left))); bin.astRight(((lombok.ast.Expression) toTree(node.right))); set(node, setPosition(node, bin)); }
/** * Checks whether the given expression is purely a non-null check, e.g. it will return * true for expressions like "a != null" and "a != null && b != null" and * "b == null || c != null". */ private static boolean isNullCheck(Expression expression) { if (expression instanceof BinaryExpression) { BinaryExpression binExp = (BinaryExpression) expression; if (binExp.astLeft() instanceof NullLiteral || binExp.astRight() instanceof NullLiteral) { return true; } else { return isNullCheck(binExp.astLeft()) && isNullCheck(binExp.astRight()); } } else { return false; } } }
@Override public void visitAssignment(Assignment node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); bin.astLeft((lombok.ast.Expression) toTree(node.lhs)); bin.astRight(((lombok.ast.Expression) toTree(node.expression))); bin.astOperator(BinaryOperator.ASSIGN); setPosition(node, bin); set(node, bin); }
@Override public void visitAssignment(Assignment node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); bin.astLeft((lombok.ast.Expression) toTree(node.lhs)); bin.astRight(((lombok.ast.Expression) toTree(node.expression))); bin.astOperator(BinaryOperator.ASSIGN); setPosition(node, bin); set(node, bin); }
@Override public void visitAssignment(Assignment node) { lombok.ast.BinaryExpression bin = new lombok.ast.BinaryExpression(); bin.astLeft((lombok.ast.Expression) toTree(node.lhs)); bin.astRight(((lombok.ast.Expression) toTree(node.expression))); bin.astOperator(BinaryOperator.ASSIGN); setPosition(node, bin); set(node, bin); }
@Nullable private static String getLhs(@NonNull MethodInvocation call) { Node parent = call.getParent(); if (parent instanceof Cast) { parent = parent.getParent(); } if (parent instanceof VariableDefinitionEntry) { VariableDefinitionEntry vde = (VariableDefinitionEntry) parent; return vde.astName().astValue(); } else if (parent instanceof BinaryExpression) { BinaryExpression be = (BinaryExpression) parent; Expression left = be.astLeft(); if (left instanceof VariableReference || left instanceof Select) { return be.astLeft().toString(); } else if (left instanceof ArrayAccess) { ArrayAccess aa = (ArrayAccess) left; return aa.astOperand().toString(); } } return null; }
@Override public boolean visitBinaryExpression(BinaryExpression node) { BinaryOperator operator = node.astOperator(); if (operator == BinaryOperator.ASSIGN || operator == BinaryOperator.OR_ASSIGN) { Expression left = node.astLeft(); String variable; if (left instanceof Select && ((Select) left).astOperand() instanceof This) { variable = ((Select) left).astIdentifier().astValue(); } else { variable = left.toString(); } mVariables.add(variable); } return super.visitBinaryExpression(node); } }
@Override public boolean visitBinaryExpression(BinaryExpression node) { if (node.astOperator() == BinaryOperator.ASSIGN) { Expression rhs = node.astRight(); if (rhs instanceof VariableReference) { ResolvedNode resolved = mContext.resolve(rhs); //noinspection SuspiciousMethodCalls if (resolved != null && mVariables.contains(resolved)) { ResolvedNode resolvedLhs = mContext.resolve(node.astLeft()); if (resolvedLhs instanceof ResolvedVariable) { ResolvedVariable variable = (ResolvedVariable) resolvedLhs; mVariables.add(variable); } else if (resolvedLhs instanceof ResolvedField) { mEscapes = true; } } } } return super.visitBinaryExpression(node); }
@Override public boolean visitBinaryExpression(BinaryExpression node) { if (node.astOperator() == BinaryOperator.ASSIGN) { Expression rhs = node.astRight(); if (rhs instanceof VariableReference) { JavaParser.ResolvedNode resolved = mContext.resolve(rhs); //noinspection SuspiciousMethodCalls if (resolved != null && mVariables.contains(resolved)) { JavaParser.ResolvedNode resolvedLhs = mContext.resolve(node.astLeft()); if (resolvedLhs instanceof JavaParser.ResolvedVariable) { JavaParser.ResolvedVariable variable = (JavaParser.ResolvedVariable) resolvedLhs; mVariables.add(variable); } } } } return super.visitBinaryExpression(node); }
@Override public boolean visitBinaryExpression(BinaryExpression node) { BinaryOperator operator = node.astOperator(); int start = posOfStructure(node, node.rawOperator(), true); int end = node.getPosition().getEnd(); if (operator == BinaryOperator.PLUS) { if (tryStringCombine(node)) return true; } JCExpression lhs = toExpression(node.astLeft()); JCExpression rhs = toExpression(node.astRight()); if (operator == BinaryOperator.ASSIGN) { return set(node, setPos(start, end, treeMaker.Assign(lhs, rhs))); } if (operator.isAssignment()) { return set(node, setPos(start, end, treeMaker.Assignop(BINARY_OPERATORS.get(operator), lhs, rhs))); } return set(node, setPos(start, end, treeMaker.Binary(BINARY_OPERATORS.get(operator), lhs, rhs))); }
@Override public boolean visitBinaryExpression(BinaryExpression node) { BinaryOperator operator = node.astOperator(); int start = posOfStructure(node, node.rawOperator(), true); int end = node.getPosition().getEnd(); if (operator == BinaryOperator.PLUS) { if (tryStringCombine(node)) return true; } JCExpression lhs = toExpression(node.astLeft()); JCExpression rhs = toExpression(node.astRight()); if (operator == BinaryOperator.ASSIGN) { return set(node, setPos(start, end, treeMaker.Assign(lhs, rhs))); } if (operator.isAssignment()) { return set(node, setPos(start, end, treeMaker.Assignop(BINARY_OPERATORS.get(operator), lhs, rhs))); } return set(node, setPos(start, end, treeMaker.Binary(BINARY_OPERATORS.get(operator), lhs, rhs))); }
private static PermissionRequirement parse( @NonNull ResolvedAnnotation annotation, @NonNull Expression expression) { if (expression instanceof Select) { return new Single(annotation, expression.toString()); } else if (expression instanceof BinaryExpression) { BinaryExpression binaryExpression = (BinaryExpression) expression; BinaryOperator operator = binaryExpression.astOperator(); if (operator == BinaryOperator.LOGICAL_AND || operator == BinaryOperator.LOGICAL_OR || operator == BinaryOperator.BITWISE_XOR) { PermissionRequirement left = parse(annotation, binaryExpression.astLeft()); PermissionRequirement right = parse(annotation, binaryExpression.astRight()); return new Complex(annotation, operator, left, right); } } return NONE; }
/** Adds any variables referenced in the given expression into the given list */ private static void addReferencedVariables(Collection<String> variables, Expression expression) { if (expression instanceof BinaryExpression) { BinaryExpression binary = (BinaryExpression) expression; addReferencedVariables(variables, binary.astLeft()); addReferencedVariables(variables, binary.astRight()); } else if (expression instanceof UnaryExpression) { UnaryExpression unary = (UnaryExpression) expression; addReferencedVariables(variables, unary.astOperand()); } else if (expression instanceof VariableReference) { VariableReference reference = (VariableReference) expression; variables.add(reference.astIdentifier().astValue()); } else if (expression instanceof Select) { Select select = (Select) expression; if (select.astOperand() instanceof This) { variables.add(select.astIdentifier().astValue()); } } }
@Override public boolean visitBinaryExpression(BinaryExpression node) { BinaryOperator operator = node.astOperator(); int start = posOfStructure(node, node.rawOperator(), true); int end = node.getPosition().getEnd(); if (operator == BinaryOperator.PLUS) { if (tryStringCombine(node)) return true; } JCExpression lhs = toExpression(node.astLeft()); JCExpression rhs = toExpression(node.astRight()); if (operator == BinaryOperator.ASSIGN) { return set(node, setPos(start, end, treeMaker.Assign(lhs, rhs))); } if (operator.isAssignment()) { return set(node, setPos(start, end, treeMaker.Assignop(BINARY_OPERATORS.get(operator), lhs, rhs))); } return set(node, setPos(start, end, treeMaker.Binary(BINARY_OPERATORS.get(operator), lhs, rhs))); }