/** * Checks of is the given tree is a {@link MemberSelectExpressionTree} which is selecting with <code>this</code> or <code>super</code> * @param tree The tree to check. * @return true when the tree is a select on <code>this</code> or <code>super</code> * @see #isSelectOnThisOrSuper(MemberSelectExpressionTree) */ public static boolean isSelectOnThisOrSuper(AssignmentExpressionTree tree) { ExpressionTree variable = ExpressionUtils.skipParentheses(tree.variable()); return variable.is(Tree.Kind.MEMBER_SELECT) && isSelectOnThisOrSuper((MemberSelectExpressionTree) variable); }
/** * Checks of is the given tree is a {@link MemberSelectExpressionTree} which is selecting with <code>this</code> or <code>super</code> * @param tree The tree to check. * @return true when the tree is a select on <code>this</code> or <code>super</code> * @see #isSelectOnThisOrSuper(MemberSelectExpressionTree) */ public static boolean isSelectOnThisOrSuper(AssignmentExpressionTree tree) { ExpressionTree variable = ExpressionUtils.skipParentheses(tree.variable()); return variable.is(Tree.Kind.MEMBER_SELECT) && isSelectOnThisOrSuper((MemberSelectExpressionTree) variable); }
public static IdentifierTree extractIdentifier(AssignmentExpressionTree tree) { ExpressionTree variable = skipParentheses(tree.variable()); if (variable.is(Tree.Kind.IDENTIFIER)) { return (IdentifierTree) variable; } if (variable.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree selectTree = (MemberSelectExpressionTree) variable; if (isSelectOnThisOrSuper(selectTree)) { return selectTree.identifier(); } } // This should not be possible. throw new IllegalArgumentException("Can not extract identifier."); }
public static IdentifierTree extractIdentifier(AssignmentExpressionTree tree) { ExpressionTree variable = skipParentheses(tree.variable()); if (variable.is(Tree.Kind.IDENTIFIER)) { return (IdentifierTree) variable; } if (variable.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree selectTree = (MemberSelectExpressionTree) variable; if (isSelectOnThisOrSuper(selectTree)) { return selectTree.identifier(); } } // This should not be possible. throw new IllegalArgumentException("Can not extract identifier."); }
/** * In case of simple assignments, only the expression is evaluated, as we only use the reference to the variable to store the result. * For SE-Based checks, only a single value should be unstacked if its the case. For other cases, two values should be unstacked. * See JLS8-15.26 * * @param tree The assignment tree * @return true if the tree is a simple assignment * @see #extractIdentifier(AssignmentExpressionTree) */ public static boolean isSimpleAssignment(AssignmentExpressionTree tree) { if (!tree.is(Tree.Kind.ASSIGNMENT)) { // This can't possibly be a simple assignment. return false; } ExpressionTree variable = ExpressionUtils.skipParentheses(tree.variable()); return variable.is(Tree.Kind.IDENTIFIER) || isSelectOnThisOrSuper(tree); }
private void executeMemberSelect(MemberSelectExpressionTree mse) { if (!"class".equals(mse.identifier().name())) { ProgramState.Pop unstackMSE = programState.unstackValue(1); programState = unstackMSE.state; } if (ExpressionUtils.isSelectOnThisOrSuper(mse)) { executeIdentifier(mse.identifier()); } else { SymbolicValue mseValue = constraintManager.createSymbolicValue(mse); programState = programState.stackValue(mseValue); } }
private void executeMemberSelect(MemberSelectExpressionTree mse) { if (!"class".equals(mse.identifier().name())) { ProgramState.Pop unstackMSE = programState.unstackValue(1); programState = unstackMSE.state; } if (ExpressionUtils.isSelectOnThisOrSuper(mse)) { executeIdentifier(mse.identifier()); } else { SymbolicValue mseValue = constraintManager.createSymbolicValue(mse); programState = programState.stackValue(mseValue); } }
/** * In case of simple assignments, only the expression is evaluated, as we only use the reference to the variable to store the result. * For SE-Based checks, only a single value should be unstacked if its the case. For other cases, two values should be unstacked. * See JLS8-15.26 * * @param tree The assignment tree * @return true if the tree is a simple assignment * @see #extractIdentifier(AssignmentExpressionTree) */ public static boolean isSimpleAssignment(AssignmentExpressionTree tree) { if (!tree.is(Tree.Kind.ASSIGNMENT)) { // This can't possibly be a simple assignment. return false; } ExpressionTree variable = ExpressionUtils.skipParentheses(tree.variable()); return variable.is(Tree.Kind.IDENTIFIER) || isSelectOnThisOrSuper(tree); }
@CheckForNull private Symbol learnedConstraintOnInitializedFinalField(Tree syntaxTree) { Symbol result = null; if (syntaxTree.is(Tree.Kind.IDENTIFIER)) { result = ((IdentifierTree) syntaxTree).symbol(); } else if (syntaxTree.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree mset = (MemberSelectExpressionTree) syntaxTree; if (ExpressionUtils.isSelectOnThisOrSuper(mset)) { result = mset.identifier().symbol(); } } if (isFinalFieldWithInitializer(result)) { return result; } return null; }
@CheckForNull private Symbol learnedConstraintOnInitializedFinalField(Tree syntaxTree) { Symbol result = null; if (syntaxTree.is(Tree.Kind.IDENTIFIER)) { result = ((IdentifierTree) syntaxTree).symbol(); } else if (syntaxTree.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree mset = (MemberSelectExpressionTree) syntaxTree; if (ExpressionUtils.isSelectOnThisOrSuper(mset)) { result = mset.identifier().symbol(); } } if (isFinalFieldWithInitializer(result)) { return result; } return null; }
private void executeAssignment(AssignmentExpressionTree tree) { ProgramState.Pop unstack; SymbolicValue value; if (tree.is(Tree.Kind.ASSIGNMENT)) { unstack = ExpressionUtils.isSimpleAssignment(tree) ? programState.unstackValue(1) : programState.unstackValue(2); value = unstack.values.get(0); } else { unstack = programState.unstackValue(2); value = constraintManager.createSymbolicValue(tree); } programState = unstack.state; Symbol symbol = null; if (tree.variable().is(Tree.Kind.IDENTIFIER) || ExpressionUtils.isSelectOnThisOrSuper(tree)) { symbol = ExpressionUtils.extractIdentifier(tree).symbol(); programState = programState.put(symbol, value); } programState = programState.stackValue(value, symbol); }
private void executeAssignment(AssignmentExpressionTree tree) { ProgramState.Pop unstack; SymbolicValue value; if (tree.is(Tree.Kind.ASSIGNMENT)) { unstack = ExpressionUtils.isSimpleAssignment(tree) ? programState.unstackValue(1) : programState.unstackValue(2); value = unstack.values.get(0); } else { unstack = programState.unstackValue(2); value = constraintManager.createSymbolicValue(tree); } programState = unstack.state; Symbol symbol = null; if (tree.variable().is(Tree.Kind.IDENTIFIER) || ExpressionUtils.isSelectOnThisOrSuper(tree)) { symbol = ExpressionUtils.extractIdentifier(tree).symbol(); programState = programState.put(symbol, value); } programState = programState.stackValue(value, symbol); }
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) { if (arg.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) arg; IdentifierTree identifier = memberSelectExpressionTree.identifier(); if (ExpressionUtils.isSelectOnThisOrSuper(memberSelectExpressionTree)) { return isIdentifierDynamicString(methodTree, identifier, currentlyChecking, firstLevel); } return !isConstant(identifier.symbol()); } else if (arg.is(Tree.Kind.IDENTIFIER)) { return isIdentifierDynamicString(methodTree, (IdentifierTree) arg, currentlyChecking, firstLevel); } else if (arg.is(Tree.Kind.PLUS)) { BinaryExpressionTree binaryArg = (BinaryExpressionTree) arg; return isDynamicString(methodTree, binaryArg.rightOperand(), currentlyChecking) || isDynamicString(methodTree, binaryArg.leftOperand(), currentlyChecking); } else if (arg.is(Tree.Kind.METHOD_INVOCATION)) { return false; } return !arg.is(Tree.Kind.STRING_LITERAL, Tree.Kind.NULL_LITERAL); }
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) { if (arg.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) arg; IdentifierTree identifier = memberSelectExpressionTree.identifier(); if (ExpressionUtils.isSelectOnThisOrSuper(memberSelectExpressionTree)) { return isIdentifierDynamicString(methodTree, identifier, currentlyChecking, firstLevel); } return !isConstant(identifier.symbol()); } else if (arg.is(Tree.Kind.IDENTIFIER)) { return isIdentifierDynamicString(methodTree, (IdentifierTree) arg, currentlyChecking, firstLevel); } else if (arg.is(Tree.Kind.PLUS)) { BinaryExpressionTree binaryArg = (BinaryExpressionTree) arg; return isDynamicString(methodTree, binaryArg.rightOperand(), currentlyChecking) || isDynamicString(methodTree, binaryArg.leftOperand(), currentlyChecking); } else if (arg.is(Tree.Kind.METHOD_INVOCATION)) { return false; } return !arg.is(Tree.Kind.STRING_LITERAL, Tree.Kind.NULL_LITERAL); }