コード例 #1
0
 /**
  * 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<>();
   AnnotationMirror invariant = getFieldInvariantAnnotation();
   for (VariableTree field : fields) {
     if (isUnused(field, receiverAnnotations)) {
       continue; // don't consider unused fields
     }
     VariableElement fieldElem = TreeUtils.elementFromDeclaration(field);
     if (ElementUtils.isStatic(fieldElem) == isStatic) {
       // Does this field need to satisfy the invariant?
       if (getAnnotatedType(field).hasEffectiveAnnotation(invariant)) {
         // Has the field been initialized?
         if (!store.isFieldInitialized(fieldElem)) {
           violatingFields.add(field);
         }
       }
     }
   }
   return violatingFields;
 }
コード例 #2
0
 /**
  * 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<>();
   AnnotationMirror invariant = getFieldInvariantAnnotation();
   for (VariableTree field : fields) {
     VariableElement fieldElem = TreeUtils.elementFromDeclaration(field);
     if (!ElementUtils.isStatic(fieldElem)) {
       // Does this field need to satisfy the invariant?
       if (getAnnotatedType(field).hasEffectiveAnnotation(invariant)) {
         // Has the field been initialized?
         if (store.isFieldInitialized(fieldElem)) {
           initializedFields.add(field);
         }
       }
     }
   }
   return initializedFields;
 }