From e74033930be6f607846e2b60011c4c14e6fe1246 Mon Sep 17 00:00:00 2001 From: Aosen Xiong <82676488+Ao-senXiong@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:02:41 -0700 Subject: [PATCH] Update to EISOP 3.39-eisop1 from 3.34-eisop1 (#439) Co-authored-by: Haifeng Shi Co-authored-by: Werner Dietl --- build.gradle | 2 +- scripts/inference-dev | 2 +- .../inference/BaseInferrableChecker.java | 3 - .../ExistentialVariableInserter.java | 2 +- .../InferenceAnnotatedTypeFactory.java | 12 +- .../InferenceQualifierHierarchy.java | 39 +++-- .../inference/InferenceTypeHierarchy.java | 2 +- .../inference/InferenceValidator.java | 28 ++++ src/checkers/inference/InferenceVisitor.java | 140 ++++++++++++++++-- src/checkers/inference/InferrableChecker.java | 3 - src/checkers/inference/VariableAnnotator.java | 24 ++- .../inference/dataflow/InferenceAnalysis.java | 5 - .../inference/dataflow/InferenceTransfer.java | 8 +- .../inference/dataflow/InferenceValue.java | 2 +- .../inference/model/ComparableConstraint.java | 4 +- .../inference/model/SubtypeConstraint.java | 2 +- .../solver/backend/maxsat/MaxSatSolver.java | 14 +- .../inference/solver/frontend/Lattice.java | 2 +- .../solver/frontend/LatticeBuilder.java | 4 +- src/checkers/inference/util/ASTPathUtil.java | 6 +- .../util/ConstantToVariableAnnotator.java | 2 +- src/checkers/inference/util/JaifBuilder.java | 4 +- .../DataflowAnnotatedTypeFactory.java | 2 +- .../qual/DataFlowInferenceBottom.java | 2 +- src/dataflow/qual/DataFlowTop.java | 4 +- .../InterningAnnotatedTypeFactory.java | 4 +- .../SimpleFlowAnnotatedTypeFactory.java | 24 +-- .../inference/DataflowInferenceTest.java | 6 +- .../checkers/inference/IFlowSinkPropTest.java | 6 +- .../checkers/inference/IFlowSinkSatTest.java | 6 +- .../inference/IFlowSourcePropTest.java | 6 +- .../inference/IFlowSourceSatTest.java | 6 +- tests/checkers/inference/InterningTest.java | 6 +- tests/checkers/inference/NninfTest.java | 6 +- tests/checkers/inference/OsTrustedTest.java | 6 +- .../inference/test/CFInferenceTest.java | 9 +- 36 files changed, 268 insertions(+), 135 deletions(-) diff --git a/build.gradle b/build.gradle index d927c23a3..47c39b36a 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ dependencies { implementation group: 'com.google.errorprone', name: 'javac', version: "$errorproneJavacVersion" implementation 'org.plumelib:options:1.0.5' - implementation 'org.plumelib:plume-util:1.5.9' + implementation 'org.plumelib:plume-util:1.8.1' implementation 'com.google.guava:guava:31.1-jre' diff --git a/scripts/inference-dev b/scripts/inference-dev index f87e0cd27..c66bc1cb6 100755 --- a/scripts/inference-dev +++ b/scripts/inference-dev @@ -34,7 +34,7 @@ libDir="$cfiDir"/lib CFBuild="${cfDir}"/dataflow/"${classes}":"${cfDir}"/javacutil/"${classes}":"${cfDir}"/framework/"${classes}":"${cfDir}"/framework/"${resources}" CFBuild="${CFBuild}":"${cfDir}"/checker/"${classes}":"${cfDir}"/checker/"${resources}":"${annoToolsDir}"/scene-lib/bin -CFDepJars="${stubparserDir}"/javaparser-core/target/stubparser-3.25.2.jar:"${afuDir}"/annotation-file-utilities-all.jar +CFDepJars="${afuDir}"/annotation-file-utilities-all.jar # sanity check: ensure each jar in CFDepJars actually exists in the file system # total number of jars diff --git a/src/checkers/inference/BaseInferrableChecker.java b/src/checkers/inference/BaseInferrableChecker.java index b10a8cbe9..96e0c078f 100644 --- a/src/checkers/inference/BaseInferrableChecker.java +++ b/src/checkers/inference/BaseInferrableChecker.java @@ -6,12 +6,9 @@ import org.checkerframework.framework.flow.CFTransfer; import org.checkerframework.framework.flow.CFValue; import org.checkerframework.framework.type.GenericAnnotatedTypeFactory; -import org.checkerframework.javacutil.Pair; import java.lang.annotation.Annotation; import java.util.Collections; -import java.util.List; import java.util.Set; -import javax.lang.model.element.VariableElement; import checkers.inference.dataflow.InferenceAnalysis; import checkers.inference.dataflow.InferenceTransfer; diff --git a/src/checkers/inference/ExistentialVariableInserter.java b/src/checkers/inference/ExistentialVariableInserter.java index 0d61038ae..8d293ec53 100644 --- a/src/checkers/inference/ExistentialVariableInserter.java +++ b/src/checkers/inference/ExistentialVariableInserter.java @@ -159,7 +159,7 @@ public void matchAndReplacePrimary(final AnnotatedTypeMirror typeUse, final Anno } @Override - protected String defaultErrorMessage(org.checkerframework.framework.type.AnnotatedTypeMirror type1, org.checkerframework.framework.type.AnnotatedTypeMirror type2, Void aVoid) { + public String defaultErrorMessage(org.checkerframework.framework.type.AnnotatedTypeMirror type1, org.checkerframework.framework.type.AnnotatedTypeMirror type2, Void aVoid) { return "Input types should have identical structures. Input types are limited to those types" + "that can appear in a type variable bound:\n" + "type1=" + type1 + "\n" diff --git a/src/checkers/inference/InferenceAnnotatedTypeFactory.java b/src/checkers/inference/InferenceAnnotatedTypeFactory.java index 879852b71..a949467b2 100644 --- a/src/checkers/inference/InferenceAnnotatedTypeFactory.java +++ b/src/checkers/inference/InferenceAnnotatedTypeFactory.java @@ -1,8 +1,6 @@ package checkers.inference; -import checkers.inference.model.ConstantSlot; import checkers.inference.model.Slot; -import com.sun.source.util.TreePath; import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory; import org.checkerframework.framework.flow.CFAbstractAnalysis; import org.checkerframework.framework.flow.CFAnalysis; @@ -25,18 +23,14 @@ import org.checkerframework.framework.type.visitor.AnnotatedTypeScanner; import org.checkerframework.framework.util.AnnotatedTypes; import org.checkerframework.framework.util.defaults.QualifierDefaults; -import org.checkerframework.framework.util.dependenttypes.DependentTypesHelper; import org.checkerframework.javacutil.AnnotationBuilder; import org.checkerframework.javacutil.AnnotationMirrorSet; import org.checkerframework.javacutil.BugInCF; import org.checkerframework.javacutil.ElementUtils; -import org.checkerframework.javacutil.Pair; import org.checkerframework.javacutil.TreeUtils; import java.lang.annotation.Annotation; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -49,14 +43,12 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeParameterElement; -import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVariable; import checkers.inference.dataflow.InferenceAnalysis; import checkers.inference.model.ConstraintManager; -import checkers.inference.model.Slot; import checkers.inference.qual.VarAnnot; import checkers.inference.util.ConstantToVariableAnnotator; import checkers.inference.util.InferenceUtil; @@ -228,7 +220,7 @@ protected TypeHierarchy createTypeHierarchy() { @Override protected QualifierHierarchy createQualifierHierarchy() { - return new InferenceQualifierHierarchy(getSupportedTypeQualifiers(), elements); + return new InferenceQualifierHierarchy(getSupportedTypeQualifiers(), elements, realTypeFactory); } @Override @@ -352,7 +344,7 @@ public ParameterizedExecutableType methodFromUse(final MethodInvocationTree meth // Adapt parameters, which makes parameters and arguments be the same size for later // checking. List parameters = - AnnotatedTypes.adaptParameters(this, method, methodInvocationTree.getArguments()); + AnnotatedTypes.adaptParameters(this, method, methodInvocationTree.getArguments(), null); method.setParameterTypes(parameters); inferencePoly.replacePolys(methodInvocationTree, method); diff --git a/src/checkers/inference/InferenceQualifierHierarchy.java b/src/checkers/inference/InferenceQualifierHierarchy.java index 67ca38d18..83e500ed7 100644 --- a/src/checkers/inference/InferenceQualifierHierarchy.java +++ b/src/checkers/inference/InferenceQualifierHierarchy.java @@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableMap; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.framework.type.ElementQualifierHierarchy; +import org.checkerframework.framework.type.GenericAnnotatedTypeFactory; import org.checkerframework.framework.type.QualifierHierarchy; import org.checkerframework.framework.util.DefaultQualifierKindHierarchy; import org.checkerframework.framework.util.QualifierKind; @@ -19,6 +20,7 @@ import org.plumelib.util.StringsPlume; import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import java.lang.annotation.Annotation; import java.util.Collection; @@ -42,9 +44,10 @@ public class InferenceQualifierHierarchy extends ElementQualifierHierarchy { public InferenceQualifierHierarchy( Collection> qualifierClasses, - Elements elements + Elements elements, + GenericAnnotatedTypeFactory atypeFactory ) { - super(qualifierClasses, elements); + super(qualifierClasses, elements, atypeFactory); slotMgr = inferenceMain.getSlotManager(); constraintMgr = inferenceMain.getConstraintManager(); @@ -137,8 +140,10 @@ public static AnnotationMirror findVarAnnot(final Iterable rhsAnnos, - final Collection lhsAnnos ) { + public boolean isSubtypeShallow(final Collection rhsAnnos, + TypeMirror subType, + final Collection lhsAnnos, + TypeMirror superType ) { final AnnotationMirror rhsVarAnnot = findVarAnnot(rhsAnnos); final AnnotationMirror lhsVarAnnot = findVarAnnot(lhsAnnos); @@ -156,11 +161,11 @@ public boolean isSubtype(final Collection rhsAnnos, + " rhs=" + StringsPlume.join(", ", rhsAnnos) + "\n" + " lhs=" + StringsPlume.join(", ", lhsAnnos ); - return isSubtype(rhsVarAnnot, lhsVarAnnot); + return isSubtypeQualifiers(rhsVarAnnot, lhsVarAnnot); } @Override - public boolean isSubtype(final AnnotationMirror subtype, final AnnotationMirror supertype) { + public boolean isSubtypeQualifiers(final AnnotationMirror subtype, final AnnotationMirror supertype) { // NOTE: subtype and supertype are nullable because, for example, in BaseTypeVisitor::checkConstructorInvocation, // findAnnotationInSameHierarchy may return null since @VarAnnot and some constant real qualifier @@ -187,19 +192,21 @@ public boolean isSubtype(final AnnotationMirror subtype, final AnnotationMirror } @Override - public AnnotationMirror greatestLowerBound(AnnotationMirror a1, AnnotationMirror a2) { + public AnnotationMirror greatestLowerBoundQualifiers(AnnotationMirror a1, AnnotationMirror a2) { return merge(a1, a2, false); } @Override - public Set leastUpperBounds( + public Set leastUpperBoundsShallow( Collection annos1, - Collection annos2) { + TypeMirror tm1, + Collection annos2, + TypeMirror tm2) { if (InferenceMain.isHackMode(annos1.size() != annos2.size())) { Set result = new AnnotationMirrorSet(); for (AnnotationMirror a1 : annos1) { for (AnnotationMirror a2 : annos2) { - AnnotationMirror lub = leastUpperBound(a1, a2); + AnnotationMirror lub = leastUpperBoundQualifiersOnly(a1, a2); if (lub != null) { result.add(lub); } @@ -207,11 +214,11 @@ public Set leastUpperBounds( } return result; } - return super.leastUpperBounds(annos1, annos2); + return super.leastUpperBoundsShallow(annos1, tm1, annos2, tm2); } @Override - public AnnotationMirror leastUpperBound(final AnnotationMirror a1, final AnnotationMirror a2) { + public AnnotationMirror leastUpperBoundQualifiers(final AnnotationMirror a1, final AnnotationMirror a2) { return merge(a1, a2, true); } @@ -239,9 +246,9 @@ private AnnotationMirror merge(final AnnotationMirror a1, final AnnotationMirror if (!isA1VarAnnot && !isA2VarAnnot) { if (isLub) { - return realQualifierHierarchy.leastUpperBound(a1, a2); + return realQualifierHierarchy.leastUpperBoundQualifiersOnly(a1, a2); } else { - return realQualifierHierarchy.greatestLowerBound(a1, a2); + return realQualifierHierarchy.greatestLowerBoundQualifiersOnly(a1, a2); } } else { // two annotations are not under the same qualifier hierarchy @@ -262,9 +269,9 @@ private AnnotationMirror merge(final AnnotationMirror a1, final AnnotationMirror AnnotationMirror mergedType; if (isLub) { - mergedType = realQualifierHierarchy.leastUpperBound(realAnno1, realAnno2); + mergedType = realQualifierHierarchy.leastUpperBoundQualifiersOnly(realAnno1, realAnno2); } else { - mergedType = realQualifierHierarchy.greatestLowerBound(realAnno1, realAnno2); + mergedType = realQualifierHierarchy.greatestLowerBoundQualifiersOnly(realAnno1, realAnno2); } Slot constantSlot = slotMgr.createConstantSlot(mergedType); diff --git a/src/checkers/inference/InferenceTypeHierarchy.java b/src/checkers/inference/InferenceTypeHierarchy.java index 13c93d113..64aa32ab7 100644 --- a/src/checkers/inference/InferenceTypeHierarchy.java +++ b/src/checkers/inference/InferenceTypeHierarchy.java @@ -50,7 +50,7 @@ public boolean areEqual(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2) { public StructuralEqualityComparer createEqualityComparer() { return new InferenceEqualityComparer( this.areEqualVisitHistory, - InferenceQualifierHierarchy.findVarAnnot(qualifierHierarchy.getTopAnnotations())); + InferenceQualifierHierarchy.findVarAnnot(qualHierarchy.getTopAnnotations())); } private static class InferenceEqualityComparer extends StructuralEqualityComparer { diff --git a/src/checkers/inference/InferenceValidator.java b/src/checkers/inference/InferenceValidator.java index bb7988455..6b39b76ca 100644 --- a/src/checkers/inference/InferenceValidator.java +++ b/src/checkers/inference/InferenceValidator.java @@ -1,9 +1,15 @@ package checkers.inference; +import com.sun.source.tree.Tree; import org.checkerframework.common.basetype.BaseTypeChecker; import org.checkerframework.common.basetype.BaseTypeValidator; +import org.checkerframework.framework.qual.TypeUseLocation; import org.checkerframework.framework.type.AnnotatedTypeFactory; +import org.checkerframework.framework.type.AnnotatedTypeMirror; +import org.checkerframework.javacutil.AnnotationUtils; + +import javax.lang.model.element.AnnotationMirror; /** * A visitor to validate the types in a tree. @@ -29,4 +35,26 @@ public InferenceValidator(BaseTypeChecker checker, public void setInfer(boolean infer) { this.infer = infer; } + + @Override + protected void validateWildCardTargetLocation(AnnotatedTypeMirror.AnnotatedWildcardType type, Tree tree) { + + InferenceVisitor inferVisitor = (InferenceVisitor) visitor; + if (inferVisitor.ignoreTargetLocations) { + return; + } + + AnnotationMirror[] mirrors = new AnnotationMirror[0]; + for (AnnotationMirror am : type.getSuperBound().getAnnotations()) { + inferVisitor.annoIsNoneOf(type, am, + inferVisitor.locationToIllegalQuals.get(TypeUseLocation.LOWER_BOUND).toArray(mirrors), + "type.invalid.annotations.on.location", tree); + } + + for (AnnotationMirror am : type.getExtendsBound().getAnnotations()) { + inferVisitor.annoIsNoneOf(type, am, + inferVisitor.locationToIllegalQuals.get(TypeUseLocation.UPPER_BOUND).toArray(mirrors), + "type.invalid.annotations.on.location", tree); + } + } } diff --git a/src/checkers/inference/InferenceVisitor.java b/src/checkers/inference/InferenceVisitor.java index df07527fa..7ccd74518 100644 --- a/src/checkers/inference/InferenceVisitor.java +++ b/src/checkers/inference/InferenceVisitor.java @@ -6,6 +6,8 @@ import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory; import org.checkerframework.common.basetype.BaseTypeVisitor; import org.checkerframework.common.subtyping.qual.Unqualified; +import org.checkerframework.framework.qual.TargetLocations; +import org.checkerframework.framework.qual.TypeUseLocation; import org.checkerframework.framework.type.AnnotatedTypeMirror; import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType; import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; @@ -15,18 +17,20 @@ import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType; import org.checkerframework.framework.type.AnnotatedTypeParameterBounds; import org.checkerframework.framework.util.AnnotatedTypes; -import org.checkerframework.javacutil.AnnotationBuilder; -import org.checkerframework.javacutil.AnnotationUtils; -import org.checkerframework.javacutil.BugInCF; +import org.checkerframework.javacutil.*; 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; import java.util.logging.Logger; import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; @@ -79,11 +83,18 @@ public class InferenceVisitor> locationToIllegalQuals; + public InferenceVisitor(Checker checker, InferenceChecker ichecker, Factory factory, boolean infer) { super((infer) ? ichecker : checker, factory); this.realChecker = checker; this.infer = infer; ((InferenceValidator)typeValidator).setInfer(infer); + locationToIllegalQuals = createMapForIllegalQuals(); } @SuppressWarnings("unchecked") @@ -302,7 +313,7 @@ protected void annoIsNot(AnnotatedTypeMirror sourceType, AnnotationMirror effect annoIsNoneOf(sourceType, effectiveAnno, new AnnotationMirror[]{target}, msgKey, node); } - private void annoIsNoneOf(AnnotatedTypeMirror sourceType, AnnotationMirror effectiveAnno, + public void annoIsNoneOf(AnnotatedTypeMirror sourceType, AnnotationMirror effectiveAnno, AnnotationMirror[] targets, String msgKey, Tree node) { if (infer) { final SlotManager slotManager = InferenceMain.getInstance().getSlotManager(); @@ -489,13 +500,13 @@ protected void checkTypeArguments(Tree toptree, * @param extraArgs arguments to the error message key, before "found" and "expected" types */ @Override - protected void commonAssignmentCheck( + protected boolean commonAssignmentCheck( Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) { if (!validateTypeOf(varTree)) { - return; + return true; } AnnotatedTypeMirror var; @@ -516,11 +527,11 @@ protected void commonAssignmentCheck( assert var != null : "no variable found for tree: " + varTree; - commonAssignmentCheck(var, valueExp, errorKey, extraArgs); + return commonAssignmentCheck(var, valueExp, errorKey, extraArgs); } @Override - protected void commonAssignmentCheck( + protected boolean commonAssignmentCheck( AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @@ -583,7 +594,8 @@ protected void commonAssignmentCheck( mono.getCanonicalName(), mono.getCanonicalName(), valueType.toString()); - return; + // Assign success to false to report the error. + success = false; } } } @@ -606,6 +618,7 @@ protected void commonAssignmentCheck( errorKey, ArraysPlume.concatenate(extraArgs, valueTypeString, varTypeString)); } + return success; // ####### End Copied Code ######## } @@ -805,7 +818,7 @@ protected void checkExceptionParameter(CatchTree node) { if (exPar.getKind() != TypeKind.UNION) { if (!atypeFactory.getQualifierHierarchy() - .isSubtype(required, found)) { + .isSubtypeQualifiersOnly(required, found)) { checker.reportError(node.getParameter(), "exception.parameter.invalid", found, required); } @@ -814,7 +827,7 @@ protected void checkExceptionParameter(CatchTree node) { for (AnnotatedTypeMirror alterntive : aut.getAlternatives()) { AnnotationMirror foundAltern = alterntive .getAnnotationInHierarchy(required); - if (!atypeFactory.getQualifierHierarchy().isSubtype( + if (!atypeFactory.getQualifierHierarchy().isSubtypeQualifiersOnly( required, foundAltern)) { checker.reportError(node.getParameter(), "exception.parameter.invalid", foundAltern, required); @@ -848,4 +861,109 @@ protected void checkConstructorResult( } } + /** + * This method creates a mapping from type-use locations to a set of qualifiers which cannot be applied to that location. + * + * @return a mapping from type-use locations to a set of qualifiers which cannot be applied to that location + */ + protected Map> createMapForIllegalQuals() { + Map> locationToIllegalQuals = new HashMap<>(); + // First, init each type-use location to contain all type qualifiers. + Set> supportQualifiers = atypeFactory.getSupportedTypeQualifiers(); + Set supportedAnnos = new AnnotationMirrorSet(); + for (Class qual: supportQualifiers) { + supportedAnnos.add(new AnnotationBuilder(atypeFactory.getProcessingEnv(), qual).build()); + } + for (TypeUseLocation location : TypeUseLocation.values()) { + locationToIllegalQuals.put(location, new HashSet<>(supportedAnnos)); + } + // Then, delete some qualifiers which can be applied to that type-use location. + // this leaves only qualifiers not allowed on that location. + for (Class qual : supportQualifiers) { + Element elem = elements.getTypeElement(qual.getCanonicalName()); + TargetLocations tls = elem.getAnnotation(TargetLocations.class); + // @Target({ElementType.TYPE_USE})} together with no @TargetLocations(...) means that + // the qualifier can be written on any type use. + if (tls == null) { + for (TypeUseLocation location : TypeUseLocation.values()) { + Set amSet = locationToIllegalQuals.get(location); + amSet.remove(AnnotationUtils.getAnnotationByName(supportedAnnos, qual.getCanonicalName())); + } + continue; + } + for (TypeUseLocation location : tls.value()) { + if (location == TypeUseLocation.ALL) { + for (TypeUseLocation val : TypeUseLocation.values()) { + Set amSet = locationToIllegalQuals.get(val); + amSet.remove(AnnotationUtils.getAnnotationByName(supportedAnnos, qual.getCanonicalName())); + } + break; + } + Set amSet = locationToIllegalQuals.get(location); + amSet.remove(AnnotationUtils.getAnnotationByName(supportedAnnos, qual.getCanonicalName())); + } + } + return locationToIllegalQuals; + } + + @Override + protected void validateVariablesTargetLocation(Tree tree, AnnotatedTypeMirror type) { + if (!infer) { + super.validateVariablesTargetLocation(tree, type); + return; + } + + if (ignoreTargetLocations) { + return; + } + Element element = TreeUtils.elementFromTree(tree); + + if (element != null) { + ElementKind elemKind = element.getKind(); + TypeUseLocation location; + switch (elemKind) { + case LOCAL_VARIABLE: + location = TypeUseLocation.LOCAL_VARIABLE; + break; + case EXCEPTION_PARAMETER: + location = TypeUseLocation.EXCEPTION_PARAMETER; + break; + case PARAMETER: + if (((VariableTree) tree).getName().contentEquals("this")) { + location = TypeUseLocation.RECEIVER; + } else { + location = TypeUseLocation.PARAMETER; + } + break; + case RESOURCE_VARIABLE: + location = TypeUseLocation.RESOURCE_VARIABLE; + break; + case FIELD: + location = TypeUseLocation.FIELD; + break; + case ENUM_CONSTANT: + location = TypeUseLocation.CONSTRUCTOR_RESULT; + break; + default: + throw new BugInCF("Location not matched"); + } + AnnotationMirror[] mirrors = new AnnotationMirror[0]; + mainIsNoneOf(type, locationToIllegalQuals.get(location).toArray(mirrors), + "type.invalid.annotations.on.location", tree); + } + } + + @Override + protected void validateTargetLocation( + Tree tree, AnnotatedTypeMirror type, TypeUseLocation required) { + if (!this.infer) { + super.validateTargetLocation(tree, type, required); + } else { + if (ignoreTargetLocations) { + return; + } + mainIsNoneOf(type, locationToIllegalQuals.get(required).toArray(new AnnotationMirror[0]), + "type.invalid.annotations.on.location", tree); + } + } } diff --git a/src/checkers/inference/InferrableChecker.java b/src/checkers/inference/InferrableChecker.java index 3e63e4bbf..c5f99e6fc 100644 --- a/src/checkers/inference/InferrableChecker.java +++ b/src/checkers/inference/InferrableChecker.java @@ -6,12 +6,9 @@ import org.checkerframework.framework.flow.CFTransfer; import org.checkerframework.framework.flow.CFValue; import org.checkerframework.framework.type.GenericAnnotatedTypeFactory; -import org.checkerframework.javacutil.Pair; import java.lang.annotation.Annotation; -import java.util.List; import java.util.Set; import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.VariableElement; import checkers.inference.dataflow.InferenceAnalysis; import checkers.inference.model.ConstraintManager; diff --git a/src/checkers/inference/VariableAnnotator.java b/src/checkers/inference/VariableAnnotator.java index 7eea07d65..b4b48df17 100644 --- a/src/checkers/inference/VariableAnnotator.java +++ b/src/checkers/inference/VariableAnnotator.java @@ -14,10 +14,8 @@ import org.checkerframework.framework.type.visitor.AnnotatedTypeScanner; import org.checkerframework.javacutil.AnnotationBuilder; import org.checkerframework.javacutil.AnnotationMirrorSet; -import org.checkerframework.javacutil.AnnotationUtils; import org.checkerframework.javacutil.ElementUtils; import org.checkerframework.javacutil.BugInCF; -import org.checkerframework.javacutil.Pair; import org.checkerframework.javacutil.TreePathUtil; import org.checkerframework.javacutil.TreeUtils; import org.checkerframework.javacutil.TypesUtils; @@ -80,7 +78,7 @@ import checkers.inference.util.ASTPathUtil; import checkers.inference.util.CopyUtil; import checkers.inference.util.InferenceUtil; - +import org.plumelib.util.IPair; /** * VariableAnnotator takes a type and the tree that the type represents. It determines what locations on the tree @@ -108,12 +106,12 @@ public class VariableAnnotator extends AnnotatedTypeScanner { * annotation mirror for a tree is calculated (i.e least upper bound for * binary tree), and the calculated result is cached in the set. **/ - protected final Map>> treeToVarAnnoPair; + protected final Map>> treeToVarAnnoPair; /** Store elements that have already been annotated **/ private final Map elementToAtm; - private final Map, ExistentialVariableSlot> idsToExistentialSlots; + private final Map, ExistentialVariableSlot> idsToExistentialSlots; private final AnnotatedTypeFactory realTypeFactory; private final InferrableChecker realChecker; @@ -238,7 +236,7 @@ private SourceVariableSlot createVariable(final Tree tree) { // } // } - final Pair> varATMPair = Pair + final IPair> varATMPair = IPair .> of(varSlot, new AnnotationMirrorSet()); treeToVarAnnoPair.put(tree, varATMPair); @@ -273,7 +271,7 @@ public ConstantSlot createConstant(final AnnotationMirror value, final Tree tree // } Set annotations = new AnnotationMirrorSet(); annotations.add(constantSlot.getValue()); - final Pair> varATMPair = Pair + final IPair> varATMPair = IPair .> of(constantSlot, annotations); treeToVarAnnoPair.put(tree, varATMPair); @@ -311,7 +309,7 @@ ExistentialVariableSlot getOrCreateExistentialVariable(final AnnotatedTypeMirror */ ExistentialVariableSlot getOrCreateExistentialVariable(final Slot potentialVariable, final Slot alternativeSlot) { - final Pair idPair = Pair.of(potentialVariable.getId(), alternativeSlot.getId()); + final IPair idPair = IPair.of(potentialVariable.getId(), alternativeSlot.getId()); ExistentialVariableSlot existentialVariable = idsToExistentialSlots.get(idPair); if (existentialVariable == null) { @@ -436,7 +434,7 @@ private void addExistentialVariable(final AnnotatedTypeVariable typeVar, final T } potentialVariable = createVariable(typeTree); - final Pair> varATMPair = Pair + final IPair> varATMPair = IPair .> of( potentialVariable, typeVar.getAnnotations()); treeToVarAnnoPair.put(typeTree, varATMPair); @@ -517,7 +515,7 @@ private Slot addPrimaryVariable(AnnotatedTypeMirror atm, final Tree tree) { ((SourceVariableSlot) variable).setInsertable(false); } - final Pair> varATMPair = Pair + final IPair> varATMPair = IPair .of(variable, new AnnotationMirrorSet()); @@ -1542,12 +1540,12 @@ public void handleBinaryTree(AnnotatedTypeMirror atm, BinaryTree binaryTree) { AnnotatedTypeMirror a = inferenceTypeFactory.getAnnotatedType(binaryTree.getLeftOperand()); AnnotatedTypeMirror b = inferenceTypeFactory.getAnnotatedType(binaryTree.getRightOperand()); Set lubs = inferenceTypeFactory - .getQualifierHierarchy().leastUpperBounds(a.getEffectiveAnnotations(), - b.getEffectiveAnnotations()); + .getQualifierHierarchy().leastUpperBoundsShallow(a.getEffectiveAnnotations(), a.getUnderlyingType(), + b.getEffectiveAnnotations(), b.getUnderlyingType()); atm.clearAnnotations(); atm.addAnnotations(lubs); if (slotManager.getSlot(atm) instanceof VariableSlot) { - final Pair> varATMPair = Pair.>of( + final IPair> varATMPair = IPair.>of( slotManager.getSlot(atm), lubs); treeToVarAnnoPair.put(binaryTree, varATMPair); } else { diff --git a/src/checkers/inference/dataflow/InferenceAnalysis.java b/src/checkers/inference/dataflow/InferenceAnalysis.java index eb0d02f3f..6f8aa2811 100644 --- a/src/checkers/inference/dataflow/InferenceAnalysis.java +++ b/src/checkers/inference/dataflow/InferenceAnalysis.java @@ -1,11 +1,7 @@ package checkers.inference.dataflow; -import java.util.List; -import java.util.Set; import java.util.logging.Logger; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; @@ -17,7 +13,6 @@ import org.checkerframework.framework.type.GenericAnnotatedTypeFactory; import org.checkerframework.javacutil.AnnotationMirrorSet; import org.checkerframework.javacutil.BugInCF; -import org.checkerframework.javacutil.Pair; import checkers.inference.InferenceChecker; import checkers.inference.InferrableChecker; diff --git a/src/checkers/inference/dataflow/InferenceTransfer.java b/src/checkers/inference/dataflow/InferenceTransfer.java index 8ac9dfc19..5ac0f8c5b 100644 --- a/src/checkers/inference/dataflow/InferenceTransfer.java +++ b/src/checkers/inference/dataflow/InferenceTransfer.java @@ -14,7 +14,6 @@ import org.checkerframework.framework.type.AnnotatedTypeMirror; import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable; import org.checkerframework.javacutil.BugInCF; -import org.checkerframework.javacutil.Pair; import java.util.HashMap; import java.util.Map; @@ -35,6 +34,7 @@ import checkers.inference.model.Slot; import checkers.inference.model.VariableSlot; import checkers.inference.util.InferenceUtil; +import org.plumelib.util.IPair; /** * @@ -58,7 +58,7 @@ public class InferenceTransfer extends CFTransfer { // Type variables will have two refinement variables (one for each bound). This covers the // case where the correct, inferred RHS has no primary annotation - private final Map> createdTypeVarRefinementVariables = new HashMap<>(); + private final Map> createdTypeVarRefinementVariables = new HashMap<>(); private final InferenceAnnotatedTypeFactory typeFactory; @@ -320,7 +320,7 @@ private TransferResult createTypeVarRefinementVars(Node lhs, T final RefinementVariableSlot upperBoundRefVar; final RefinementVariableSlot lowerBoundRefVar; if (createdTypeVarRefinementVariables.containsKey(assignmentTree)) { - Pair ubToLb = createdTypeVarRefinementVariables.get(assignmentTree); + IPair ubToLb = createdTypeVarRefinementVariables.get(assignmentTree); upperBoundRefVar = ubToLb.first; lowerBoundRefVar = ubToLb.second; @@ -337,7 +337,7 @@ private TransferResult createTypeVarRefinementVars(Node lhs, T upperBoundSlot.getRefinedToSlots().add(upperBoundRefVar); lowerBoundSlot.getRefinedToSlots().add(lowerBoundRefVar); - createdTypeVarRefinementVariables.put(assignmentTree, Pair.of(upperBoundRefVar, lowerBoundRefVar)); + createdTypeVarRefinementVariables.put(assignmentTree, IPair.of(upperBoundRefVar, lowerBoundRefVar)); } upperBoundType.replaceAnnotation(slotManager.getAnnotation(upperBoundRefVar)); diff --git a/src/checkers/inference/dataflow/InferenceValue.java b/src/checkers/inference/dataflow/InferenceValue.java index b729a6b97..e593cbc53 100644 --- a/src/checkers/inference/dataflow/InferenceValue.java +++ b/src/checkers/inference/dataflow/InferenceValue.java @@ -68,7 +68,7 @@ public CFValue leastUpperBound(CFValue other) { // Delegate the LUB computation to inferenceQualifierHierarchy, by passing // the two VarAnnos getting from slotManager. - final AnnotationMirror lub = qualifierHierarchy.leastUpperBound(anno1, anno2); + final AnnotationMirror lub = qualifierHierarchy.leastUpperBoundQualifiersOnly(anno1, anno2); return analysis.createAbstractValue(AnnotationMirrorSet.singleton(lub), getLubType(other, null)); } diff --git a/src/checkers/inference/model/ComparableConstraint.java b/src/checkers/inference/model/ComparableConstraint.java index 443d2f3cc..0c58e32f1 100644 --- a/src/checkers/inference/model/ComparableConstraint.java +++ b/src/checkers/inference/model/ComparableConstraint.java @@ -44,8 +44,8 @@ protected static Constraint create(Slot first, Slot second, AnnotationLocation l ConstantSlot firstConst = (ConstantSlot) first; ConstantSlot secondConst = (ConstantSlot) second; - return realQualHierarchy.isSubtype(firstConst.getValue(), secondConst.getValue()) - || realQualHierarchy.isSubtype(secondConst.getValue(), firstConst.getValue()) + return realQualHierarchy.isSubtypeQualifiersOnly(firstConst.getValue(), secondConst.getValue()) + || realQualHierarchy.isSubtypeQualifiersOnly(secondConst.getValue(), firstConst.getValue()) ? AlwaysTrueConstraint.create() : AlwaysFalseConstraint.create(); } diff --git a/src/checkers/inference/model/SubtypeConstraint.java b/src/checkers/inference/model/SubtypeConstraint.java index 9b26a193d..b2f787372 100644 --- a/src/checkers/inference/model/SubtypeConstraint.java +++ b/src/checkers/inference/model/SubtypeConstraint.java @@ -66,7 +66,7 @@ protected static Constraint create(Slot subtype, Slot supertype, AnnotationLocat ConstantSlot subConstant = (ConstantSlot) subtype; ConstantSlot superConstant = (ConstantSlot) supertype; - return realQualHierarchy.isSubtype(subConstant.getValue(), superConstant.getValue()) + return realQualHierarchy.isSubtypeQualifiersOnly(subConstant.getValue(), superConstant.getValue()) ? AlwaysTrueConstraint.create() : AlwaysFalseConstraint.create(); } diff --git a/src/checkers/inference/solver/backend/maxsat/MaxSatSolver.java b/src/checkers/inference/solver/backend/maxsat/MaxSatSolver.java index 324302854..2986f7b23 100644 --- a/src/checkers/inference/solver/backend/maxsat/MaxSatSolver.java +++ b/src/checkers/inference/solver/backend/maxsat/MaxSatSolver.java @@ -13,7 +13,7 @@ import javax.lang.model.element.AnnotationMirror; import org.checkerframework.javacutil.BugInCF; -import org.plumelib.util.Pair; +import org.plumelib.util.IPair; import org.sat4j.core.VecInt; import org.sat4j.maxsat.SolverFactory; import org.sat4j.maxsat.WeightedMaxSatDecorator; @@ -54,7 +54,7 @@ protected enum MaxSatSolverArg implements SolverArg { protected final SlotManager slotManager; protected final List hardClauses = new LinkedList<>(); private List wellFormednessClauses = new LinkedList<>(); - protected final List> softClauses = new LinkedList<>(); + protected final List> softClauses = new LinkedList<>(); private MaxSATUnsatisfiableConstraintExplainer unsatisfiableConstraintExplainer; protected final File CNFData = new File(new File("").getAbsolutePath() + "/cnfData"); protected StringBuilder CNFInput = new StringBuilder(); @@ -145,7 +145,7 @@ public void encodeAllConstraints() { for (VecInt res : encoding) { if (res != null && res.size() != 0) { if (constraint instanceof PreferenceConstraint) { - softClauses.add(new Pair(res, ((PreferenceConstraint) constraint).getWeight())); + softClauses.add(IPair.of(res, ((PreferenceConstraint) constraint).getWeight())); } else { hardClauses.add(res); } @@ -186,8 +186,8 @@ private void addClausesToSolver(WeightedMaxSatDecorator solver) throws Contradic solver.addHardClause(wellFormednessClause); } - for (Pair softclause : softClauses) { - solver.addSoftClause(softclause.b, softclause.a); + for (IPair softclause : softClauses) { + solver.addSoftClause(softclause.second, softclause.first); } } @@ -281,8 +281,8 @@ protected void printClauses() { } System.out.println(); System.out.println("Soft clauses: "); - for (Pair softclause : softClauses) { - System.out.println(softclause.a + " w: " + softclause.b); + for (IPair softclause : softClauses) { + System.out.println(softclause.first + " w: " + softclause.second); } } diff --git a/src/checkers/inference/solver/frontend/Lattice.java b/src/checkers/inference/solver/frontend/Lattice.java index d46b8c0b1..89b2a0fb7 100644 --- a/src/checkers/inference/solver/frontend/Lattice.java +++ b/src/checkers/inference/solver/frontend/Lattice.java @@ -90,7 +90,7 @@ public Lattice(Map> subType, } public boolean isSubtype(AnnotationMirror a1, AnnotationMirror a2) { - return underlyingQualifierHierarchy.isSubtype(a1, a2); + return underlyingQualifierHierarchy.isSubtypeQualifiersOnly(a1, a2); } } diff --git a/src/checkers/inference/solver/frontend/LatticeBuilder.java b/src/checkers/inference/solver/frontend/LatticeBuilder.java index b386a81d6..e0b85bd25 100644 --- a/src/checkers/inference/solver/frontend/LatticeBuilder.java +++ b/src/checkers/inference/solver/frontend/LatticeBuilder.java @@ -108,10 +108,10 @@ public Lattice buildLattice(QualifierHierarchy qualHierarchy, Collection s Set subtypeOfi = new HashSet(); Set supertypeOfi = new HashSet(); for (AnnotationMirror j : allTypes) { - if (qualHierarchy.isSubtype(j, i)) { + if (qualHierarchy.isSubtypeQualifiersOnly(j, i)) { subtypeOfi.add(j); } - if (qualHierarchy.isSubtype(i, j)) { + if (qualHierarchy.isSubtypeQualifiersOnly(i, j)) { supertypeOfi.add(j); } } diff --git a/src/checkers/inference/util/ASTPathUtil.java b/src/checkers/inference/util/ASTPathUtil.java index a825598ad..1f4c7f038 100644 --- a/src/checkers/inference/util/ASTPathUtil.java +++ b/src/checkers/inference/util/ASTPathUtil.java @@ -15,7 +15,6 @@ import org.checkerframework.framework.type.visitor.AnnotatedTypeScanner; import org.checkerframework.framework.util.AnnotatedTypes; import org.checkerframework.javacutil.BugInCF; -import org.checkerframework.javacutil.Pair; import java.util.IdentityHashMap; import java.util.logging.Logger; @@ -27,6 +26,7 @@ import org.checkerframework.afu.scenelib.io.ASTIndex; import org.checkerframework.afu.scenelib.io.ASTPath; import org.checkerframework.afu.scenelib.io.ASTRecord; +import org.plumelib.util.IPair; /** * ASTPathUtil is a collection of utilities to create ASTRecord for existing trees, as well @@ -230,7 +230,7 @@ public Void visitWildcard(AnnotatedWildcardType type, ASTRecord current) { /** * Converts fully qualified class name into a pair of Strings (packageName -> className) */ - public static Pair splitFullyQualifiedClass(String fullClassname) { + public static IPair splitFullyQualifiedClass(String fullClassname) { String pkgName; String className; int lastPeriod = fullClassname.lastIndexOf("."); @@ -243,6 +243,6 @@ public static Pair splitFullyQualifiedClass(String fullClassname className = fullClassname.substring(lastPeriod + 1, fullClassname.length()); } - return Pair.of(pkgName, className); + return IPair.of(pkgName, className); } } diff --git a/src/checkers/inference/util/ConstantToVariableAnnotator.java b/src/checkers/inference/util/ConstantToVariableAnnotator.java index 892ea765f..23ebb982c 100644 --- a/src/checkers/inference/util/ConstantToVariableAnnotator.java +++ b/src/checkers/inference/util/ConstantToVariableAnnotator.java @@ -43,7 +43,7 @@ protected Void scan(AnnotatedTypeMirror type, Void aVoid) { * @param type A type annotated in the "real qualifier hierarch" */ protected void addVariablePrimaryAnnotation(final AnnotatedTypeMirror type) { - if (type.isAnnotatedInHierarchy(varAnnot)) { + if (type.hasAnnotationInHierarchy(varAnnot)) { return; } diff --git a/src/checkers/inference/util/JaifBuilder.java b/src/checkers/inference/util/JaifBuilder.java index 03bf0b0f8..aa0174f53 100644 --- a/src/checkers/inference/util/JaifBuilder.java +++ b/src/checkers/inference/util/JaifBuilder.java @@ -22,7 +22,7 @@ import com.sun.source.tree.Tree; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; /** * JaifBuilder creates Jaifs from a Map of ASTRecords to AnnotationMirrors. @@ -416,7 +416,7 @@ private ClassEntry getClassEntry(ClassDeclLocation location) { private ClassEntry getClassEntry(String fullyQualified) { ClassEntry classEntry = this.classesMap.get(fullyQualified); if (classEntry == null) { - Pair packageToClass = ASTPathUtil.splitFullyQualifiedClass(fullyQualified); + IPair packageToClass = ASTPathUtil.splitFullyQualifiedClass(fullyQualified); classEntry = new ClassEntry(packageToClass.first, packageToClass.second); this.classesMap.put(fullyQualified, classEntry); } diff --git a/src/dataflow/DataflowAnnotatedTypeFactory.java b/src/dataflow/DataflowAnnotatedTypeFactory.java index f2aad8a10..56bda64a1 100644 --- a/src/dataflow/DataflowAnnotatedTypeFactory.java +++ b/src/dataflow/DataflowAnnotatedTypeFactory.java @@ -126,7 +126,7 @@ public DataFlowQualifierHierarchy( Collection> qualifierClasses, Elements elements ) { - super(qualifierClasses, elements); + super(qualifierClasses, elements, DataflowAnnotatedTypeFactory.this); DATAFLOW_KIND = getQualifierKind(DATAFLOW); } diff --git a/src/dataflow/qual/DataFlowInferenceBottom.java b/src/dataflow/qual/DataFlowInferenceBottom.java index 1f3d8e5e7..44a68f37f 100644 --- a/src/dataflow/qual/DataFlowInferenceBottom.java +++ b/src/dataflow/qual/DataFlowInferenceBottom.java @@ -16,7 +16,7 @@ @InvisibleQualifier @SubtypeOf({ DataFlow.class }) @Target({ ElementType.TYPE_USE }) -@TargetLocations({ TypeUseLocation.EXPLICIT_LOWER_BOUND }) +@TargetLocations({ TypeUseLocation.ALL }) public @interface DataFlowInferenceBottom { } diff --git a/src/dataflow/qual/DataFlowTop.java b/src/dataflow/qual/DataFlowTop.java index ad9d6ae69..20dc906f6 100644 --- a/src/dataflow/qual/DataFlowTop.java +++ b/src/dataflow/qual/DataFlowTop.java @@ -13,7 +13,7 @@ @InvisibleQualifier @SubtypeOf({}) @Target({ ElementType.TYPE_USE }) -@TargetLocations({ TypeUseLocation.EXPLICIT_UPPER_BOUND }) +@TargetLocations({ TypeUseLocation.ALL }) public @interface DataFlowTop { -} \ No newline at end of file +} diff --git a/src/interning/InterningAnnotatedTypeFactory.java b/src/interning/InterningAnnotatedTypeFactory.java index 141efa41b..37dbff13f 100644 --- a/src/interning/InterningAnnotatedTypeFactory.java +++ b/src/interning/InterningAnnotatedTypeFactory.java @@ -90,7 +90,7 @@ protected TypeAnnotator createTypeAnnotator() { @Override public void addComputedTypeAnnotations(Element element, AnnotatedTypeMirror type) { - if (!type.isAnnotatedInHierarchy(INTERNED) && ElementUtils.isCompileTimeConstant(element)) + if (!type.hasAnnotationInHierarchy(INTERNED) && ElementUtils.isCompileTimeConstant(element)) type.addAnnotation(INTERNED); super.addComputedTypeAnnotations(element, type); } @@ -153,7 +153,7 @@ public Void visitDeclared(AnnotatedDeclaredType t, Void p) { // TODO: @Interned then the type would already receive an @Interned from the framework without // TODO: this case (I think from InheritFromClass) // TODO: IF this is true, perhaps remove item 6 I added to the class comment - } else if (typeFactory.fromElement(elt).hasAnnotation(INTERNED)) { + } else if (atypeFactory.fromElement(elt).hasAnnotation(INTERNED)) { // If the class/interface has an @Interned annotation, use it. t.replaceAnnotation(INTERNED); } diff --git a/src/sparta/checkers/SimpleFlowAnnotatedTypeFactory.java b/src/sparta/checkers/SimpleFlowAnnotatedTypeFactory.java index 442318701..07bcc2c4a 100644 --- a/src/sparta/checkers/SimpleFlowAnnotatedTypeFactory.java +++ b/src/sparta/checkers/SimpleFlowAnnotatedTypeFactory.java @@ -300,12 +300,12 @@ public FlowQualifierHierarchy( Collection> qualifierClasses, Elements elements ) { - super(qualifierClasses, elements); + super(qualifierClasses, elements, SimpleFlowAnnotatedTypeFactory.this); } @Override - public Set getTopAnnotations() { - return Collections.singleton(checker instanceof IFlowSinkChecker ? + public AnnotationMirrorSet getTopAnnotations() { + return AnnotationMirrorSet.singleton(checker instanceof IFlowSinkChecker ? NOSINK : ANYSOURCE); } @@ -320,8 +320,8 @@ public AnnotationMirror getTopAnnotation(AnnotationMirror start) { } @Override - public Set getBottomAnnotations() { - return Collections.singleton(checker instanceof IFlowSinkChecker ? + public AnnotationMirrorSet getBottomAnnotations() { + return AnnotationMirrorSet.singleton(checker instanceof IFlowSinkChecker ? ANYSINK : NOSOURCE); } @@ -336,12 +336,12 @@ public AnnotationMirror getBottomAnnotation(AnnotationMirror start) { } @Override - public @Nullable AnnotationMirror leastUpperBound(AnnotationMirror a1, AnnotationMirror a2) { + public @Nullable AnnotationMirror leastUpperBoundQualifiers(AnnotationMirror a1, AnnotationMirror a2) { if (!AnnotationUtils.areSameByName(getTopAnnotation(a1), getTopAnnotation(a2))) { return null; - } else if (isSubtype(a1, a2)) { + } else if (isSubtypeQualifiersOnly(a1, a2)) { return a2; - } else if (isSubtype(a2, a1)) { + } else if (isSubtypeQualifiersOnly(a2, a1)) { return a1; } else if (isSourceQualifier(a1)) { // Since the two annotations are same by name, they are both source qualifier. @@ -359,12 +359,12 @@ public AnnotationMirror getBottomAnnotation(AnnotationMirror start) { } @Override - public @Nullable AnnotationMirror greatestLowerBound(AnnotationMirror a1, AnnotationMirror a2) { + public @Nullable AnnotationMirror greatestLowerBoundQualifiers(AnnotationMirror a1, AnnotationMirror a2) { if (!AnnotationUtils.areSameByName(getTopAnnotation(a1), getTopAnnotation(a2))) { return null; - } else if (isSubtype(a1, a2)) { + } else if (isSubtypeQualifiersOnly(a1, a2)) { return a1; - } else if (isSubtype(a2, a1)) { + } else if (isSubtypeQualifiersOnly(a2, a1)) { return a2; } else if (isSourceQualifier(a1)) { // Since the two annotations are same by name, they are both source qualifier. @@ -382,7 +382,7 @@ public AnnotationMirror getBottomAnnotation(AnnotationMirror start) { } @Override - public boolean isSubtype(AnnotationMirror subtype, AnnotationMirror supertype) { + public boolean isSubtypeQualifiers(AnnotationMirror subtype, AnnotationMirror supertype) { if (isPolySourceQualifier(supertype) && isPolySourceQualifier(subtype)) { return true; } else if (isPolySourceQualifier(supertype) && isSourceQualifier(subtype)) { diff --git a/tests/checkers/inference/DataflowInferenceTest.java b/tests/checkers/inference/DataflowInferenceTest.java index bb530736f..2d4a82cb4 100644 --- a/tests/checkers/inference/DataflowInferenceTest.java +++ b/tests/checkers/inference/DataflowInferenceTest.java @@ -5,7 +5,7 @@ import java.util.List; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; import org.junit.runners.Parameterized.Parameters; import checkers.inference.test.CFInferenceTest; @@ -19,8 +19,8 @@ public DataflowInferenceTest(File testFile) { } @Override - public Pair> getSolverNameAndOptions() { - return Pair.> of(DataflowSolverEngine.class.getCanonicalName(), + public IPair> getSolverNameAndOptions() { + return IPair.> of(DataflowSolverEngine.class.getCanonicalName(), new ArrayList()); } diff --git a/tests/checkers/inference/IFlowSinkPropTest.java b/tests/checkers/inference/IFlowSinkPropTest.java index 3e65986ec..fbed0004c 100644 --- a/tests/checkers/inference/IFlowSinkPropTest.java +++ b/tests/checkers/inference/IFlowSinkPropTest.java @@ -2,7 +2,7 @@ import checkers.inference.test.CFInferenceTest; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; import org.junit.runners.Parameterized.Parameters; import sparta.checkers.IFlowSinkChecker; import sparta.checkers.propagation.IFlowSinkSolver; @@ -19,8 +19,8 @@ public IFlowSinkPropTest(File testFile) { } @Override - public Pair> getSolverNameAndOptions() { - return Pair.>of(IFlowSinkSolver.class.getCanonicalName(), new ArrayList()); + public IPair> getSolverNameAndOptions() { + return IPair.>of(IFlowSinkSolver.class.getCanonicalName(), new ArrayList()); } @Parameters diff --git a/tests/checkers/inference/IFlowSinkSatTest.java b/tests/checkers/inference/IFlowSinkSatTest.java index 2f3fd92af..89f8219e5 100644 --- a/tests/checkers/inference/IFlowSinkSatTest.java +++ b/tests/checkers/inference/IFlowSinkSatTest.java @@ -2,7 +2,7 @@ import checkers.inference.test.CFInferenceTest; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; import org.junit.runners.Parameterized.Parameters; import sparta.checkers.IFlowSinkChecker; import sparta.checkers.sat.SinkSolver; @@ -19,8 +19,8 @@ public IFlowSinkSatTest(File testFile) { } @Override - public Pair> getSolverNameAndOptions() { - return Pair.>of(SinkSolver.class.getCanonicalName(), new ArrayList()); + public IPair> getSolverNameAndOptions() { + return IPair.>of(SinkSolver.class.getCanonicalName(), new ArrayList()); } @Parameters diff --git a/tests/checkers/inference/IFlowSourcePropTest.java b/tests/checkers/inference/IFlowSourcePropTest.java index b616b2824..c48e5a336 100644 --- a/tests/checkers/inference/IFlowSourcePropTest.java +++ b/tests/checkers/inference/IFlowSourcePropTest.java @@ -2,7 +2,7 @@ import checkers.inference.test.CFInferenceTest; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; import org.junit.runners.Parameterized.Parameters; import sparta.checkers.IFlowSourceChecker; import sparta.checkers.propagation.IFlowSourceSolver; @@ -19,8 +19,8 @@ public IFlowSourcePropTest(File testFile) { } @Override - public Pair> getSolverNameAndOptions() { - return Pair.>of(IFlowSourceSolver.class.getCanonicalName(), new ArrayList()); + public IPair> getSolverNameAndOptions() { + return IPair.>of(IFlowSourceSolver.class.getCanonicalName(), new ArrayList()); } @Parameters diff --git a/tests/checkers/inference/IFlowSourceSatTest.java b/tests/checkers/inference/IFlowSourceSatTest.java index eae20a3fb..16fcd997f 100644 --- a/tests/checkers/inference/IFlowSourceSatTest.java +++ b/tests/checkers/inference/IFlowSourceSatTest.java @@ -2,7 +2,7 @@ import checkers.inference.test.CFInferenceTest; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; import org.junit.runners.Parameterized.Parameters; import sparta.checkers.IFlowSourceChecker; import sparta.checkers.sat.SourceSolver; @@ -19,8 +19,8 @@ public IFlowSourceSatTest(File testFile) { } @Override - public Pair> getSolverNameAndOptions() { - return Pair.>of(SourceSolver.class.getCanonicalName(), new ArrayList()); + public IPair> getSolverNameAndOptions() { + return IPair.>of(SourceSolver.class.getCanonicalName(), new ArrayList()); } @Parameters diff --git a/tests/checkers/inference/InterningTest.java b/tests/checkers/inference/InterningTest.java index 17896d37e..77da94088 100644 --- a/tests/checkers/inference/InterningTest.java +++ b/tests/checkers/inference/InterningTest.java @@ -3,7 +3,7 @@ import checkers.inference.solver.MaxSat2TypeSolver; import checkers.inference.test.CFInferenceTest; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; import org.junit.runners.Parameterized.Parameters; import java.io.File; @@ -18,8 +18,8 @@ public InterningTest(File testFile) { } @Override - public Pair> getSolverNameAndOptions() { - return Pair.>of(MaxSat2TypeSolver.class.getCanonicalName(), new ArrayList()); + public IPair> getSolverNameAndOptions() { + return IPair.>of(MaxSat2TypeSolver.class.getCanonicalName(), new ArrayList()); } @Parameters diff --git a/tests/checkers/inference/NninfTest.java b/tests/checkers/inference/NninfTest.java index 5522609a6..a09341ab9 100644 --- a/tests/checkers/inference/NninfTest.java +++ b/tests/checkers/inference/NninfTest.java @@ -3,7 +3,7 @@ import checkers.inference.solver.MaxSat2TypeSolver; import checkers.inference.test.CFInferenceTest; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; import org.junit.runners.Parameterized.Parameters; import java.io.File; @@ -18,8 +18,8 @@ public NninfTest(File testFile) { } @Override - public Pair> getSolverNameAndOptions() { - return Pair.of(MaxSat2TypeSolver.class.getCanonicalName(), new ArrayList<>()); + public IPair> getSolverNameAndOptions() { + return IPair.of(MaxSat2TypeSolver.class.getCanonicalName(), new ArrayList<>()); } @Parameters diff --git a/tests/checkers/inference/OsTrustedTest.java b/tests/checkers/inference/OsTrustedTest.java index 5551acaed..73c00f6c2 100644 --- a/tests/checkers/inference/OsTrustedTest.java +++ b/tests/checkers/inference/OsTrustedTest.java @@ -3,7 +3,7 @@ import checkers.inference.solver.MaxSat2TypeSolver; import checkers.inference.test.CFInferenceTest; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; +import org.plumelib.util.IPair; import org.junit.runners.Parameterized.Parameters; import java.io.File; @@ -18,8 +18,8 @@ public OsTrustedTest(File testFile) { } @Override - public Pair> getSolverNameAndOptions() { - return Pair.>of(MaxSat2TypeSolver.class.getCanonicalName(), new ArrayList()); + public IPair> getSolverNameAndOptions() { + return IPair.>of(MaxSat2TypeSolver.class.getCanonicalName(), new ArrayList()); } @Parameters diff --git a/tests/checkers/inference/test/CFInferenceTest.java b/tests/checkers/inference/test/CFInferenceTest.java index b2ee3f9df..7383b8747 100644 --- a/tests/checkers/inference/test/CFInferenceTest.java +++ b/tests/checkers/inference/test/CFInferenceTest.java @@ -2,7 +2,6 @@ import org.checkerframework.framework.test.CheckerFrameworkPerFileTest; import org.checkerframework.framework.test.TestUtilities; -import org.checkerframework.javacutil.Pair; import org.checkerframework.javacutil.SystemUtil; import java.io.File; @@ -11,6 +10,8 @@ import javax.annotation.processing.AbstractProcessor; +import org.plumelib.util.IPair; +import org.plumelib.util.SystemPlume; import org.junit.Test; public abstract class CFInferenceTest extends CheckerFrameworkPerFileTest { @@ -27,10 +28,10 @@ public CFInferenceTest(File testFile, Class checker } public boolean useHacks() { - return SystemUtil.getBooleanSystemProperty("use.hacks"); + return SystemPlume.getBooleanSystemProperty("use.hacks"); } - public abstract Pair> getSolverNameAndOptions(); + public abstract IPair> getSolverNameAndOptions(); public List getAdditionalInferenceOptions() { return new ArrayList(); @@ -48,7 +49,7 @@ public String getPathToInferenceScript() { @Test public void run() { boolean shouldEmitDebugInfo = TestUtilities.getShouldEmitDebugInfo(); - Pair> solverArgs = getSolverNameAndOptions(); + IPair> solverArgs = getSolverNameAndOptions(); final File testDataDir = new File("testdata");