use of org.checkerframework.dataflow.cfg.node.ImplicitThisNode in project checker-framework by typetools.
the class CFGTranslationPhaseOne method visitBindingPattern17.
/**
* Visit a BindingPatternTree
*
* @param bindingPatternTree a BindingPatternTree, typed as Tree to be backward-compatible
* @param p parameter
* @return the result of visiting the binding pattern tree
*/
public Node visitBindingPattern17(Tree bindingPatternTree, Void p) {
ClassTree enclosingClass = TreePathUtil.enclosingClass(getCurrentPath());
TypeElement classElem = TreeUtils.elementFromDeclaration(enclosingClass);
Node receiver = new ImplicitThisNode(classElem.asType());
VariableTree varTree = TreeUtils.bindingPatternTreeGetVariable(bindingPatternTree);
LocalVariableNode varNode = new LocalVariableNode(varTree, receiver);
extendWithNode(varNode);
return varNode;
}
use of org.checkerframework.dataflow.cfg.node.ImplicitThisNode 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.ImplicitThisNode in project checker-framework by typetools.
the class CFGTranslationPhaseOne method visitVariable.
@Override
public Node visitVariable(VariableTree tree, Void p) {
// see JLS 14.4
boolean isField = false;
if (getCurrentPath().getParentPath() != null) {
Tree.Kind kind = TreeUtils.getKindRecordAsClass(getCurrentPath().getParentPath().getLeaf());
// CLASS includes records.
if (kind == Tree.Kind.CLASS || kind == Tree.Kind.INTERFACE || kind == Tree.Kind.ENUM) {
isField = true;
}
}
Node node = null;
ClassTree enclosingClass = TreePathUtil.enclosingClass(getCurrentPath());
TypeElement classElem = TreeUtils.elementFromDeclaration(enclosingClass);
Node receiver = new ImplicitThisNode(classElem.asType());
if (isField) {
ExpressionTree initializer = tree.getInitializer();
assert initializer != null;
node = translateAssignment(tree, new FieldAccessNode(tree, TreeUtils.elementFromDeclaration(tree), receiver), initializer);
} else {
// local variable definition
VariableDeclarationNode decl = new VariableDeclarationNode(tree);
extendWithNode(decl);
// initializer
ExpressionTree initializer = tree.getInitializer();
if (initializer != null) {
node = translateAssignment(tree, new LocalVariableNode(tree, receiver), initializer);
}
}
return node;
}
use of org.checkerframework.dataflow.cfg.node.ImplicitThisNode 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