use of com.sun.source.tree.VariableTree in project checker-framework by typetools.
the class Analysis method init.
/**
* Initialize the analysis with a new control flow graph.
*/
protected void init(ControlFlowGraph cfg) {
this.cfg = cfg;
thenStores = new IdentityHashMap<>();
elseStores = new IdentityHashMap<>();
blockCount = maxCountBeforeWidening == -1 ? null : new IdentityHashMap<>();
inputs = new IdentityHashMap<>();
storesAtReturnStatements = new IdentityHashMap<>();
worklist = new Worklist(cfg);
nodeValues = new IdentityHashMap<>();
finalLocalValues = new HashMap<>();
worklist.add(cfg.getEntryBlock());
List<LocalVariableNode> parameters = null;
UnderlyingAST underlyingAST = cfg.getUnderlyingAST();
if (underlyingAST.getKind() == Kind.METHOD) {
MethodTree tree = ((CFGMethod) underlyingAST).getMethod();
parameters = new ArrayList<>();
for (VariableTree p : tree.getParameters()) {
LocalVariableNode var = new LocalVariableNode(p);
parameters.add(var);
// TODO: document that LocalVariableNode has no block that it
// belongs to
}
} else if (underlyingAST.getKind() == Kind.LAMBDA) {
LambdaExpressionTree lambda = ((CFGLambda) underlyingAST).getLambdaTree();
parameters = new ArrayList<>();
for (VariableTree p : lambda.getParameters()) {
LocalVariableNode var = new LocalVariableNode(p);
parameters.add(var);
// TODO: document that LocalVariableNode has no block that it
// belongs to
}
} else {
// nothing to do
}
S initialStore = transferFunction.initialStore(underlyingAST, parameters);
Block entry = cfg.getEntryBlock();
thenStores.put(entry, initialStore);
elseStores.put(entry, initialStore);
inputs.put(entry, new TransferInput<>(null, this, initialStore));
}
use of com.sun.source.tree.VariableTree in project checker-framework by typetools.
the class FlowExpressions method getParametersOfEnclosingMethod.
/**
* Returns Receiver objects for the formal parameters of the method in which path is enclosed.
*
* @param annotationProvider annotationProvider
* @param path TreePath that is enclosed by the method
* @return list of Receiver objects for the formal parameters of the method in which path is
* enclosed
*/
public static List<Receiver> getParametersOfEnclosingMethod(AnnotationProvider annotationProvider, TreePath path) {
MethodTree methodTree = TreeUtils.enclosingMethod(path);
if (methodTree == null) {
return null;
}
List<Receiver> internalArguments = new ArrayList<>();
for (VariableTree arg : methodTree.getParameters()) {
internalArguments.add(internalReprOf(annotationProvider, new LocalVariableNode(arg)));
}
return internalArguments;
}
use of com.sun.source.tree.VariableTree in project checker-framework by typetools.
the class InitializationAnnotatedTypeFactory method getInitializedInvariantFields.
/**
* Returns the (non-static) fields that have the invariant annotation and are initialized in a
* given store.
*/
public List<VariableTree> getInitializedInvariantFields(Store store, TreePath path) {
// TODO: Instead of passing the TreePath around, can we use
// getCurrentClassTree?
ClassTree currentClass = TreeUtils.enclosingClass(path);
List<VariableTree> fields = InitializationChecker.getAllFields(currentClass);
List<VariableTree> initializedFields = new ArrayList<>();
for (VariableTree field : fields) {
VariableElement fieldElem = TreeUtils.elementFromDeclaration(field);
if (!ElementUtils.isStatic(fieldElem)) {
// Does this field need to satisfy the invariant?
if (hasFieldInvariantAnnotation(field)) {
// Has the field been initialized?
if (store.isFieldInitialized(fieldElem)) {
initializedFields.add(field);
}
}
}
}
return initializedFields;
}
use of com.sun.source.tree.VariableTree in project checker-framework by typetools.
the class InitializationAnnotatedTypeFactory method areAllFieldsCommittedOnly.
/**
* Are all fields committed-only?
*/
protected boolean areAllFieldsCommittedOnly(ClassTree classTree) {
if (!useFbc) {
// initialized objects.
return true;
}
for (Tree member : classTree.getMembers()) {
if (!member.getKind().equals(Tree.Kind.VARIABLE)) {
continue;
}
VariableTree var = (VariableTree) member;
VariableElement varElt = TreeUtils.elementFromDeclaration(var);
// var is not committed-only
if (getDeclAnnotation(varElt, NotOnlyInitialized.class) != null) {
// not of constructor which is where this is used
if (!varElt.getModifiers().contains(Modifier.STATIC)) {
return false;
}
}
}
return true;
}
use of com.sun.source.tree.VariableTree in project checker-framework by typetools.
the class InitializationAnnotatedTypeFactory method getUninitializedInvariantFields.
/**
* Returns the (non-static) fields that have the invariant annotation and are not yet
* initialized in a given store.
*/
public List<VariableTree> getUninitializedInvariantFields(Store store, TreePath path, boolean isStatic, List<? extends AnnotationMirror> receiverAnnotations) {
ClassTree currentClass = TreeUtils.enclosingClass(path);
List<VariableTree> fields = InitializationChecker.getAllFields(currentClass);
List<VariableTree> violatingFields = new ArrayList<>();
for (VariableTree field : fields) {
if (isUnused(field, receiverAnnotations)) {
// don't consider unused fields
continue;
}
VariableElement fieldElem = TreeUtils.elementFromDeclaration(field);
if (ElementUtils.isStatic(fieldElem) == isStatic) {
// Does this field need to satisfy the invariant?
if (hasFieldInvariantAnnotation(field)) {
// Has the field been initialized?
if (!store.isFieldInitialized(fieldElem)) {
violatingFields.add(field);
}
}
}
}
return violatingFields;
}
Aggregations