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

Use AnnotationMirrorSet and remove usage of Set<AnnotationMirror> #454

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion src/checkers/inference/InferenceAnnotatedTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected void postDirectSuperTypes(
// annotateImplicit(element,type) to be called on the supertype which will overwrite the
// annotations from type
// with those for the declaration of the super type
Set<AnnotationMirror> annotations = type.getEffectiveAnnotations();
AnnotationMirrorSet annotations = type.getEffectiveAnnotations();
for (AnnotatedTypeMirror supertype : supertypes) {
if (!annotations.equals(supertype.getEffectiveAnnotations())) {
supertype.clearAnnotations();
Expand Down
2 changes: 1 addition & 1 deletion src/checkers/inference/InferenceQualifierHierarchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public Set<? extends AnnotationMirror> leastUpperBoundsShallow(
Collection<? extends AnnotationMirror> annos2,
TypeMirror tm2) {
if (InferenceMain.isHackMode(annos1.size() != annos2.size())) {
Set<AnnotationMirror> result = new AnnotationMirrorSet();
AnnotationMirrorSet result = new AnnotationMirrorSet();
for (AnnotationMirror a1 : annos1) {
for (AnnotationMirror a2 : annos2) {
AnnotationMirror lub = leastUpperBoundQualifiersOnly(a1, a2);
Expand Down
25 changes: 12 additions & 13 deletions src/checkers/inference/InferenceVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -84,7 +83,7 @@ public class InferenceVisitor<
* Map from type-use location to a list of qualifiers which cannot be used on that location.
* This is used to create the inequality constraint in inference.
*/
protected final Map<TypeUseLocation, Set<AnnotationMirror>> locationToIllegalQuals;
protected final Map<TypeUseLocation, AnnotationMirrorSet> locationToIllegalQuals;

public InferenceVisitor(
Checker checker, InferenceChecker ichecker, Factory factory, boolean infer) {
Expand Down Expand Up @@ -820,9 +819,9 @@ public boolean maybeAddRefinementVariableConstraints(
return inferenceRefinementVariable;
}

protected Set<AnnotationMirror> filterThrowCatchBounds(
protected AnnotationMirrorSet filterThrowCatchBounds(
Set<? extends AnnotationMirror> originals) {
Set<AnnotationMirror> throwBounds = new HashSet<>();
AnnotationMirrorSet throwBounds = new AnnotationMirrorSet();

for (AnnotationMirror throwBound : originals) {
if (atypeFactory.areSameByClass(throwBound, VarAnnot.class)) {
Expand All @@ -847,7 +846,7 @@ protected void checkThrownExpression(ThrowTree node) {
if (infer) {
// TODO: We probably want to unify this code with BaseTypeVisitor
AnnotatedTypeMirror throwType = atypeFactory.getAnnotatedType(node.getExpression());
Set<AnnotationMirror> throwBounds =
AnnotationMirrorSet throwBounds =
filterThrowCatchBounds(getThrowUpperBoundAnnotations());

final AnnotationMirror varAnnot =
Expand Down Expand Up @@ -915,7 +914,7 @@ protected void checkExceptionParameter(CatchTree node) {

if (infer) {
// TODO: Unify with BaseTypeVisitor implementation
Set<AnnotationMirror> requiredAnnotations =
AnnotationMirrorSet requiredAnnotations =
filterThrowCatchBounds(getExceptionParameterLowerBoundAnnotations());
AnnotatedTypeMirror exPar = atypeFactory.getAnnotatedType(node.getParameter());

Expand Down Expand Up @@ -983,18 +982,18 @@ protected void checkConstructorResult(
* @return a mapping from type-use locations to a set of qualifiers which cannot be applied to
* that location
*/
protected Map<TypeUseLocation, Set<AnnotationMirror>> createMapForIllegalQuals() {
Map<TypeUseLocation, Set<AnnotationMirror>> locationToIllegalQuals = new HashMap<>();
protected Map<TypeUseLocation, AnnotationMirrorSet> createMapForIllegalQuals() {
Map<TypeUseLocation, AnnotationMirrorSet> locationToIllegalQuals = new HashMap<>();
// First, init each type-use location to contain all type qualifiers.
Set<Class<? extends Annotation>> supportQualifiers =
atypeFactory.getSupportedTypeQualifiers();
Set<AnnotationMirror> supportedAnnos = new AnnotationMirrorSet();
AnnotationMirrorSet supportedAnnos = new AnnotationMirrorSet();
for (Class<? extends Annotation> qual : supportQualifiers) {
supportedAnnos.add(
new AnnotationBuilder(atypeFactory.getProcessingEnv(), qual).build());
}
for (TypeUseLocation location : TypeUseLocation.values()) {
locationToIllegalQuals.put(location, new HashSet<>(supportedAnnos));
locationToIllegalQuals.put(location, new AnnotationMirrorSet(supportedAnnos));
}
// Then, delete some qualifiers which can be applied to that type-use location.
// this leaves only qualifiers not allowed on that location.
Expand All @@ -1005,7 +1004,7 @@ protected Map<TypeUseLocation, Set<AnnotationMirror>> createMapForIllegalQuals()
// the qualifier can be written on any type use.
if (tls == null) {
for (TypeUseLocation location : TypeUseLocation.values()) {
Set<AnnotationMirror> amSet = locationToIllegalQuals.get(location);
AnnotationMirrorSet amSet = locationToIllegalQuals.get(location);
amSet.remove(
AnnotationUtils.getAnnotationByName(
supportedAnnos, qual.getCanonicalName()));
Expand All @@ -1015,14 +1014,14 @@ protected Map<TypeUseLocation, Set<AnnotationMirror>> createMapForIllegalQuals()
for (TypeUseLocation location : tls.value()) {
if (location == TypeUseLocation.ALL) {
for (TypeUseLocation val : TypeUseLocation.values()) {
Set<AnnotationMirror> amSet = locationToIllegalQuals.get(val);
AnnotationMirrorSet amSet = locationToIllegalQuals.get(val);
amSet.remove(
AnnotationUtils.getAnnotationByName(
supportedAnnos, qual.getCanonicalName()));
}
break;
}
Set<AnnotationMirror> amSet = locationToIllegalQuals.get(location);
AnnotationMirrorSet amSet = locationToIllegalQuals.get(location);
amSet.remove(
AnnotationUtils.getAnnotationByName(
supportedAnnos, qual.getCanonicalName()));
Expand Down
2 changes: 1 addition & 1 deletion src/checkers/inference/VariableAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public ConstantSlot createConstant(final AnnotationMirror value, final Tree tree
//
// }
// }
Set<AnnotationMirror> annotations = new AnnotationMirrorSet();
AnnotationMirrorSet annotations = new AnnotationMirrorSet();
annotations.add(constantSlot.getValue());
final IPair<Slot, Set<? extends AnnotationMirror>> varATMPair =
IPair.<Slot, Set<? extends AnnotationMirror>>of(constantSlot, annotations);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package checkers.inference.solver.backend.maxsat.encoder;

import org.checkerframework.javacutil.AnnotationMirrorSet;
import org.checkerframework.javacutil.AnnotationUtils;
import org.sat4j.core.VecInt;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.lang.model.element.AnnotationMirror;

Expand All @@ -33,8 +32,7 @@ public MaxSATSubtypeConstraintEncoder(
* For subtype constraint, if supertype is constant slot, then the subtype cannot be the super
* type of supertype, same for subtype
*/
protected VecInt[] getMustNotBe(
Set<AnnotationMirror> mustNotBe, Slot vSlot, ConstantSlot cSlot) {
protected VecInt[] getMustNotBe(AnnotationMirrorSet mustNotBe, Slot vSlot, ConstantSlot cSlot) {

List<Integer> resultList = new ArrayList<Integer>();

Expand Down Expand Up @@ -114,7 +112,7 @@ public VecInt[] encodeVariable_Variable(VariableSlot subtype, VariableSlot super

@Override
public VecInt[] encodeVariable_Constant(VariableSlot subtype, ConstantSlot supertype) {
final Set<AnnotationMirror> mustNotBe = new HashSet<>();
final AnnotationMirrorSet mustNotBe = new AnnotationMirrorSet();
if (AnnotationUtils.areSame(supertype.getValue(), lattice.bottom)) {
return VectorUtils.asVecArray(
MathUtils.mapIdToMatrixEntry(
Expand All @@ -132,7 +130,7 @@ public VecInt[] encodeVariable_Constant(VariableSlot subtype, ConstantSlot super

@Override
public VecInt[] encodeConstant_Variable(ConstantSlot subtype, VariableSlot supertype) {
final Set<AnnotationMirror> mustNotBe = new HashSet<>();
final AnnotationMirrorSet mustNotBe = new AnnotationMirrorSet();
if (AnnotationUtils.areSame(subtype.getValue(), lattice.top)) {
return VectorUtils.asVecArray(
MathUtils.mapIdToMatrixEntry(
Expand Down
15 changes: 7 additions & 8 deletions src/checkers/inference/solver/frontend/LatticeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -69,7 +68,7 @@ public LatticeBuilder() {
public Lattice buildLattice(QualifierHierarchy qualHierarchy, Collection<Slot> slots) {
clear();

Set<AnnotationMirror> supportedAnnos = new AnnotationMirrorSet();
AnnotationMirrorSet supportedAnnos = new AnnotationMirrorSet();
Set<Class<? extends Annotation>> annoClasses =
InferenceMain.getInstance().getRealTypeFactory().getSupportedTypeQualifiers();
for (Class<? extends Annotation> ac : annoClasses) {
Expand All @@ -95,8 +94,8 @@ public Lattice buildLattice(QualifierHierarchy qualHierarchy, Collection<Slot> s

// Calculate subtypes map and supertypes map
for (AnnotationMirror i : allTypes) {
Set<AnnotationMirror> subtypeOfi = new HashSet<AnnotationMirror>();
Set<AnnotationMirror> supertypeOfi = new HashSet<AnnotationMirror>();
AnnotationMirrorSet subtypeOfi = new AnnotationMirrorSet();
AnnotationMirrorSet supertypeOfi = new AnnotationMirrorSet();
for (AnnotationMirror j : allTypes) {
if (qualHierarchy.isSubtypeQualifiersOnly(j, i)) {
subtypeOfi.add(j);
Expand All @@ -111,7 +110,7 @@ public Lattice buildLattice(QualifierHierarchy qualHierarchy, Collection<Slot> s

// Calculate incomparable types map
for (AnnotationMirror i : allTypes) {
Set<AnnotationMirror> incomparableOfi = new HashSet<AnnotationMirror>();
AnnotationMirrorSet incomparableOfi = new AnnotationMirrorSet();
for (AnnotationMirror j : allTypes) {
if (!subType.get(i).contains(j) && !subType.get(j).contains(i)) {
incomparableOfi.add(j);
Expand Down Expand Up @@ -145,7 +144,7 @@ public Lattice buildLattice(QualifierHierarchy qualHierarchy, Collection<Slot> s
*/
public TwoQualifiersLattice buildTwoTypeLattice(AnnotationMirror top, AnnotationMirror bottom) {
clear();
Set<AnnotationMirror> tempSet = new AnnotationMirrorSet();
AnnotationMirrorSet tempSet = new AnnotationMirrorSet();
tempSet.add(top);
tempSet.add(bottom);
allTypes = Collections.unmodifiableSet(tempSet);
Expand All @@ -154,8 +153,8 @@ public TwoQualifiersLattice buildTwoTypeLattice(AnnotationMirror top, Annotation
numTypes = 2;

// Calculate subertypes map and supertypes map.
Set<AnnotationMirror> topSet = new AnnotationMirrorSet();
Set<AnnotationMirror> bottomSet = new AnnotationMirrorSet();
AnnotationMirrorSet topSet = new AnnotationMirrorSet();
AnnotationMirrorSet bottomSet = new AnnotationMirrorSet();
topSet.add(top);
bottomSet.add(bottom);
subType.put(top, Collections.unmodifiableSet(allTypes));
Expand Down
4 changes: 2 additions & 2 deletions src/checkers/inference/util/InferenceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public class InferenceUtil {
*
* @return the set of cleared annotations
*/
public static Set<AnnotationMirror> clearAnnos(final AnnotatedTypeMirror atm) {
public static AnnotationMirrorSet clearAnnos(final AnnotatedTypeMirror atm) {

final Set<AnnotationMirror> oldAnnos = new AnnotationMirrorSet();
final AnnotationMirrorSet oldAnnos = new AnnotationMirrorSet();
oldAnnos.addAll(atm.getAnnotations());

atm.clearAnnotations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected List<Solver<?>> separateGraph(
protected InferenceResult mergeInferenceResults(
List<Pair<Map<Integer, AnnotationMirror>, Collection<Constraint>>> inferenceResults) {
Map<Integer, AnnotationMirror> solutions = new HashMap<>();
Map<Integer, Set<AnnotationMirror>> dataflowResults = new HashMap<>();
Map<Integer, AnnotationMirrorSet> dataflowResults = new HashMap<>();

for (Pair<Map<Integer, AnnotationMirror>, Collection<Constraint>> inferenceResult :
inferenceResults) {
Expand All @@ -122,7 +122,7 @@ protected InferenceResult mergeInferenceResults(
Integer id = entry.getKey();
AnnotationMirror dataflowAnno = entry.getValue();
if (AnnotationUtils.areSameByName(dataflowAnno, DATAFLOW_NAME)) {
Set<AnnotationMirror> datas = dataflowResults.get(id);
AnnotationMirrorSet datas = dataflowResults.get(id);
if (datas == null) {
datas = new AnnotationMirrorSet();
dataflowResults.put(id, datas);
Expand All @@ -136,7 +136,7 @@ protected InferenceResult mergeInferenceResults(
}
}

for (Map.Entry<Integer, Set<AnnotationMirror>> entry : dataflowResults.entrySet()) {
for (Map.Entry<Integer, AnnotationMirrorSet> entry : dataflowResults.entrySet()) {
Set<String> dataTypes = new HashSet<String>();
Set<String> dataRoots = new HashSet<String>();
for (AnnotationMirror anno : entry.getValue()) {
Expand Down
2 changes: 1 addition & 1 deletion src/sparta/checkers/SimpleFlowAnnotatedTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public Void visitNewClass(NewClassTree node, AnnotatedTypeMirror p) {
.constructorFromUse(node)
.executableType
.getReturnType();
Set<AnnotationMirror> defaultedSet = defaulted.getAnnotations();
AnnotationMirrorSet defaultedSet = defaulted.getAnnotations();
// The default of OTHERWISE locations such as constructor results
// is {}{}, but for constructor results we really want bottom.
// So if the result is {}{}, then change it to {}->ANY (bottom)
Expand Down
Loading