use of org.checkerframework.dataflow.cfg.node.ClassNameNode in project checker-framework by typetools.
the class CFGTranslationPhaseOne method visitIdentifier.
@Override
public Node visitIdentifier(IdentifierTree tree, Void p) {
Node node;
if (TreeUtils.isFieldAccess(tree)) {
Node receiver = getReceiver(tree);
node = new FieldAccessNode(tree, receiver);
} else {
Element element = TreeUtils.elementFromUse(tree);
switch(element.getKind()) {
case FIELD:
// Note that "this"/"super" is a field, but not a field access.
if (element.getSimpleName().contentEquals("this")) {
node = new ExplicitThisNode(tree);
} else {
node = new SuperNode(tree);
}
break;
case EXCEPTION_PARAMETER:
case LOCAL_VARIABLE:
case RESOURCE_VARIABLE:
case PARAMETER:
node = new LocalVariableNode(tree);
break;
case PACKAGE:
node = new PackageNameNode(tree);
break;
default:
if (ElementUtils.isTypeDeclaration(element)) {
node = new ClassNameNode(tree);
break;
} else if (ElementUtils.isBindingVariable(element)) {
// Note: BINDING_VARIABLE should be added as a direct case above when instanceof pattern
// matching and Java15 are supported.
node = new LocalVariableNode(tree);
break;
}
throw new BugInCF("bad element kind " + element.getKind());
}
}
if (node instanceof ClassNameNode) {
extendWithClassNameNode((ClassNameNode) node);
} else {
extendWithNode(node);
}
return node;
}
use of org.checkerframework.dataflow.cfg.node.ClassNameNode in project checker-framework by typetools.
the class CFGTranslationPhaseOne method getReceiver.
/**
* Note 1: Requires {@code tree} to be a field or method access tree.
*
* <p>Note 2: Visits the receiver and adds all necessary blocks to the CFG.
*
* @param tree the field access tree containing the receiver
* @return the receiver of the field access
*/
private Node getReceiver(ExpressionTree tree) {
assert TreeUtils.isFieldAccess(tree) || TreeUtils.isMethodAccess(tree);
if (tree.getKind() == Tree.Kind.MEMBER_SELECT) {
MemberSelectTree mtree = (MemberSelectTree) tree;
return scan(mtree.getExpression(), null);
} else {
Element ele = TreeUtils.elementFromUse(tree);
TypeElement declaringClass = ElementUtils.enclosingTypeElement(ele);
TypeMirror type = ElementUtils.getType(declaringClass);
if (ElementUtils.isStatic(ele)) {
ClassNameNode node = new ClassNameNode(type, declaringClass);
extendWithClassNameNode(node);
return node;
} else {
Node node = new ImplicitThisNode(type);
extendWithNode(node);
return node;
}
}
}
use of org.checkerframework.dataflow.cfg.node.ClassNameNode in project checker-framework by typetools.
the class CFGTranslationPhaseOne method visitMemberSelect.
@Override
public Node visitMemberSelect(MemberSelectTree tree, Void p) {
Node expr = scan(tree.getExpression(), p);
if (!TreeUtils.isFieldAccess(tree)) {
// Could be a selector of a class or package
Element element = TreeUtils.elementFromUse(tree);
if (ElementUtils.isTypeElement(element)) {
ClassNameNode result = new ClassNameNode(tree, expr);
extendWithClassNameNode(result);
return result;
} else if (element.getKind() == ElementKind.PACKAGE) {
Node result = new PackageNameNode(tree, (PackageNameNode) expr);
extendWithNode(result);
return result;
} else {
throw new BugInCF("Unexpected element kind: " + element.getKind());
}
}
Node node = new FieldAccessNode(tree, expr);
Element element = TreeUtils.elementFromUse(tree);
if (ElementUtils.isStatic(element) || expr instanceof ImplicitThisNode || expr instanceof ExplicitThisNode) {
// No NullPointerException can be thrown, use normal node
extendWithNode(node);
} else {
extendWithNodeWithException(node, nullPointerExceptionType);
}
return node;
}
Aggregations