diff --git a/src/ontology/OntologyInferenceAnnotatedTypeFactory.java b/src/ontology/OntologyInferenceAnnotatedTypeFactory.java index 9ca5aa1..49641f0 100644 --- a/src/ontology/OntologyInferenceAnnotatedTypeFactory.java +++ b/src/ontology/OntologyInferenceAnnotatedTypeFactory.java @@ -17,11 +17,13 @@ import ontology.qual.OntologyValue; import ontology.util.OntologyUtils; import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory; +import org.checkerframework.framework.qual.TypeUseLocation; import org.checkerframework.framework.type.AnnotatedTypeFactory; import org.checkerframework.framework.type.AnnotatedTypeMirror; import org.checkerframework.framework.type.treeannotator.ListTreeAnnotator; import org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator; import org.checkerframework.framework.type.treeannotator.TreeAnnotator; +import org.checkerframework.framework.util.defaults.QualifierDefaults; public class OntologyInferenceAnnotatedTypeFactory extends InferenceAnnotatedTypeFactory { @@ -51,6 +53,12 @@ public TreeAnnotator createTreeAnnotator() { this, realChecker, realTypeFactory, variableAnnotator, slotManager)); } + @Override + protected void addCheckedCodeDefaults(QualifierDefaults defaults) { + TypeUseLocation[] topLocations = {TypeUseLocation.ALL}; + defaults.addCheckedCodeDefaults(OntologyUtils.ONTOLOGY_TOP, topLocations); + } + public class OntologyInferenceTreeAnnotator extends InferenceTreeAnnotator { private final VariableAnnotator variableAnnotator; @@ -80,8 +88,7 @@ public Void visitNewClass(final NewClassTree newClassTree, final AnnotatedTypeMi atm.replaceAnnotation(cs.getValue()); } - variableAnnotator.visit(atm, newClassTree.getIdentifier()); - return null; + return super.visitNewClass(newClassTree, atm); } @Override diff --git a/testing/RawAnonymous.java b/testing/RawAnonymous.java new file mode 100644 index 0000000..43b3013 --- /dev/null +++ b/testing/RawAnonymous.java @@ -0,0 +1,18 @@ +// A corner case which is not handled by variable annotator and should be applied with defaults. +// If an anonymous class is created from a raw interface, the type argument of the raw type +// is substituted to wildcard. Take the followin case for instance, the anonymous class is +// class implements Comparator +// In this case the default is applied to the upper/lower bound + +import java.util.Comparator; + +abstract class Demo { + + void foo() { + new Comparator() { + public int compare(Object o1, Object o2) { + return 1; + } + }; + } +}