use of com.sun.source.tree.IdentifierTree in project checker-framework by typetools.
the class TreeParserTest method parsesIdentifiers.
@Test
public void parsesIdentifiers() {
String value = "id";
ExpressionTree parsed = parser.parseTree(value);
Assert.assertTrue(parsed instanceof IdentifierTree);
}
use of com.sun.source.tree.IdentifierTree in project checker-framework by typetools.
the class InterningVisitor method isReferenceEqualityImplementation.
/**
* Returns true if the given equals() method implements reference equality.
*
* @param equalsMethod an overriding implementation of Object.equals()
* @return true if the given equals() method implements reference equality
*/
private boolean isReferenceEqualityImplementation(MethodTree equalsMethod) {
BlockTree body = equalsMethod.getBody();
List<? extends StatementTree> bodyStatements = body.getStatements();
if (bodyStatements.size() == 1) {
StatementTree bodyStatement = bodyStatements.get(0);
if (bodyStatement.getKind() == Tree.Kind.RETURN) {
ExpressionTree returnExpr = TreeUtils.withoutParens(((ReturnTree) bodyStatement).getExpression());
if (returnExpr.getKind() == Tree.Kind.EQUAL_TO) {
BinaryTree bt = (BinaryTree) returnExpr;
ExpressionTree lhsTree = bt.getLeftOperand();
ExpressionTree rhsTree = bt.getRightOperand();
if (lhsTree.getKind() == Tree.Kind.IDENTIFIER && rhsTree.getKind() == Tree.Kind.IDENTIFIER) {
Name leftName = ((IdentifierTree) lhsTree).getName();
Name rightName = ((IdentifierTree) rhsTree).getName();
Name paramName = equalsMethod.getParameters().get(0).getName();
if ((leftName.contentEquals("this") && rightName == paramName) || (leftName == paramName && rightName.contentEquals("this"))) {
return true;
}
}
}
}
}
return false;
}
use of com.sun.source.tree.IdentifierTree in project checker-framework by typetools.
the class CFGTranslationPhaseOne method extendWithAssignmentForConditionalExpr.
/**
* Extend the CFG with an assignment for either the true or false case of a conditional
* expression, assigning the value of the expression for the case to the synthetic variable for
* the conditional expression
*
* @param condExprVarTree tree for synthetic variable for conditional expression
* @param caseExprTree expression tree for the case
* @param caseExprNode node for the case
*/
private void extendWithAssignmentForConditionalExpr(VariableTree condExprVarTree, ExpressionTree caseExprTree, Node caseExprNode) {
Pair<IdentifierTree, LocalVariableNode> treeAndLocalVarNode = extendWithVarUseNode(condExprVarTree);
AssignmentTree assign = treeBuilder.buildAssignment(treeAndLocalVarNode.first, caseExprTree);
handleArtificialTree(assign);
AssignmentNode assignmentNode = new AssignmentNode(assign, treeAndLocalVarNode.second, caseExprNode);
assignmentNode.setInSource(false);
extendWithNode(assignmentNode);
}
use of com.sun.source.tree.IdentifierTree in project checker-framework by typetools.
the class CFGTranslationPhaseOne method extendWithVarUseNode.
/**
* Extend the CFG with a {@link LocalVariableNode} representing a use of some variable
*
* @param varTree tree for the variable
* @return a pair whose first element is the synthetic {@link IdentifierTree} for the use, and
* whose second element is the {@link LocalVariableNode} representing the use
*/
private Pair<IdentifierTree, LocalVariableNode> extendWithVarUseNode(VariableTree varTree) {
IdentifierTree condExprVarUseTree = treeBuilder.buildVariableUse(varTree);
handleArtificialTree(condExprVarUseTree);
LocalVariableNode condExprVarUseNode = new LocalVariableNode(condExprVarUseTree);
condExprVarUseNode.setInSource(false);
extendWithNode(condExprVarUseNode);
return Pair.of(condExprVarUseTree, condExprVarUseNode);
}
use of com.sun.source.tree.IdentifierTree in project checker-framework by typetools.
the class CFGTranslationPhaseOne method box.
/**
* If the input node is an unboxed primitive type, insert a call to the appropriate valueOf
* method, otherwise leave it alone.
*
* @param node in input node
* @return a Node representing the boxed version of the input, which may simply be the input node
*/
protected Node box(Node node) {
// For boxing conversion, see JLS 5.1.7
if (TypesUtils.isPrimitive(node.getType())) {
PrimitiveType primitive = types.getPrimitiveType(node.getType().getKind());
TypeMirror boxedType = types.getDeclaredType(types.boxedClass(primitive));
TypeElement boxedElement = (TypeElement) ((DeclaredType) boxedType).asElement();
IdentifierTree classTree = treeBuilder.buildClassUse(boxedElement);
handleArtificialTree(classTree);
// No need to handle possible errors from evaluating a class literal here
// since this is synthetic code that can't fail.
ClassNameNode className = new ClassNameNode(classTree);
className.setInSource(false);
insertNodeAfter(className, node);
MemberSelectTree valueOfSelect = treeBuilder.buildValueOfMethodAccess(classTree);
handleArtificialTree(valueOfSelect);
MethodAccessNode valueOfAccess = new MethodAccessNode(valueOfSelect, className);
valueOfAccess.setInSource(false);
insertNodeAfter(valueOfAccess, className);
MethodInvocationTree valueOfCall = treeBuilder.buildMethodInvocation(valueOfSelect, (ExpressionTree) node.getTree());
handleArtificialTree(valueOfCall);
Node boxed = new MethodInvocationNode(valueOfCall, valueOfAccess, Collections.singletonList(node), getCurrentPath());
boxed.setInSource(false);
// Add Throwable to account for unchecked exceptions
addToConvertedLookupMap(node.getTree(), boxed);
insertNodeWithExceptionsAfter(boxed, uncheckedExceptionTypes, valueOfAccess);
return boxed;
} else {
return node;
}
}
Aggregations