|
33 | 33 | import com.sun.source.tree.VariableTree;
|
34 | 34 | import com.sun.source.tree.WhileLoopTree;
|
35 | 35 | import com.sun.source.util.TreePath;
|
36 |
| -import java.lang.annotation.Annotation; |
37 | 36 | import java.util.List;
|
38 |
| -import java.util.Set; |
39 | 37 | import javax.annotation.processing.ProcessingEnvironment;
|
40 | 38 | import javax.lang.model.element.AnnotationMirror;
|
41 | 39 | import javax.lang.model.element.Element;
|
|
55 | 53 | import org.checkerframework.framework.type.AnnotatedTypeFactory;
|
56 | 54 | import org.checkerframework.framework.type.AnnotatedTypeMirror;
|
57 | 55 | import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType;
|
58 |
| -import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; |
59 | 56 | import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType;
|
60 | 57 | import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType;
|
61 | 58 | import org.checkerframework.javacutil.AnnotationMirrorSet;
|
@@ -147,16 +144,6 @@ public boolean isValidUse(AnnotatedPrimitiveType type, Tree tree) {
|
147 | 144 | return true;
|
148 | 145 | }
|
149 | 146 |
|
150 |
| - private boolean containsSameByName( |
151 |
| - Set<Class<? extends Annotation>> quals, AnnotationMirror anno) { |
152 |
| - for (Class<? extends Annotation> q : quals) { |
153 |
| - if (atypeFactory.areSameByClass(anno, q)) { |
154 |
| - return true; |
155 |
| - } |
156 |
| - } |
157 |
| - return false; |
158 |
| - } |
159 |
| - |
160 | 147 | @Override
|
161 | 148 | protected boolean commonAssignmentCheck(
|
162 | 149 | Tree varTree,
|
@@ -751,27 +738,19 @@ public Void visitNewClass(NewClassTree tree, Void p) {
|
751 | 738 | if (enclosingExpr != null) {
|
752 | 739 | checkForNullability(enclosingExpr, DEREFERENCE_OF_NULLABLE);
|
753 | 740 | }
|
754 |
| - AnnotatedDeclaredType type = atypeFactory.getAnnotatedType(tree); |
755 |
| - ExpressionTree identifier = tree.getIdentifier(); |
756 |
| - if (identifier instanceof AnnotatedTypeTree) { |
757 |
| - AnnotatedTypeTree t = (AnnotatedTypeTree) identifier; |
758 |
| - for (AnnotationMirror a : atypeFactory.getAnnotatedType(t).getPrimaryAnnotations()) { |
759 |
| - // is this an annotation of the nullness checker? |
760 |
| - boolean nullnessCheckerAnno = containsSameByName(atypeFactory.getNullnessAnnotations(), a); |
761 |
| - if (nullnessCheckerAnno && !AnnotationUtils.areSame(NONNULL, a)) { |
762 |
| - // The type is not non-null => warning |
763 |
| - checker.reportWarning(tree, "new.class", type.getPrimaryAnnotations()); |
764 |
| - // Note that other consistency checks are made by isValid. |
| 741 | + |
| 742 | + AnnotationMirrorSet explicitAnnos = atypeFactory.getExplicitNewClassAnnos(tree); |
| 743 | + AnnotationMirror nullnessAnno = |
| 744 | + qualHierarchy.findAnnotationInSameHierarchy(explicitAnnos, NONNULL); |
| 745 | + if (nullnessAnno != null) { |
| 746 | + if (atypeFactory.areSameByClass(nullnessAnno, NonNull.class)) { |
| 747 | + if (warnRedundantAnnotations) { |
| 748 | + checker.reportWarning(tree, "redundant.anno", NONNULL); |
765 | 749 | }
|
766 |
| - } |
767 |
| - if (t.toString().contains("@PolyNull")) { |
768 |
| - // TODO: this is a hack, but PolyNull gets substituted |
769 |
| - // afterwards |
770 |
| - checker.reportWarning(tree, "new.class", type.getPrimaryAnnotations()); |
| 750 | + } else { |
| 751 | + checker.reportWarning(tree, "new.class"); |
771 | 752 | }
|
772 | 753 | }
|
773 |
| - // TODO: It might be nicer to introduce a framework-level |
774 |
| - // isValidNewClassType or some such. |
775 | 754 | return super.visitNewClass(tree, p);
|
776 | 755 | }
|
777 | 756 |
|
|
0 commit comments