Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checked default for inference annotated type factory #53

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/ontology/OntologyInferenceAnnotatedTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions testing/RawAnonymous.java
Original file line number Diff line number Diff line change
@@ -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 <anonymous> implements Comparator<? extends Object>
// 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;
}
};
}
}