diff --git a/src/main/java/pico/common/ExtendedViewpointAdapter.java b/src/main/java/pico/common/ExtendedViewpointAdapter.java deleted file mode 100644 index a02de53..0000000 --- a/src/main/java/pico/common/ExtendedViewpointAdapter.java +++ /dev/null @@ -1,11 +0,0 @@ -package pico.common; - -import org.checkerframework.framework.type.AnnotatedTypeMirror; -import org.checkerframework.framework.type.ViewpointAdapter; - -import javax.lang.model.element.AnnotationMirror; - -public interface ExtendedViewpointAdapter extends ViewpointAdapter { - AnnotatedTypeMirror rawCombineAnnotationWithType(AnnotationMirror anno, AnnotatedTypeMirror type); - AnnotationMirror rawCombineAnnotationWithAnnotation(AnnotationMirror anno, AnnotationMirror type); -} diff --git a/src/main/java/pico/common/ViewpointAdapterGettable.java b/src/main/java/pico/common/ViewpointAdapterGettable.java deleted file mode 100644 index 70ed93a..0000000 --- a/src/main/java/pico/common/ViewpointAdapterGettable.java +++ /dev/null @@ -1,5 +0,0 @@ -package pico.common; - -public interface ViewpointAdapterGettable { - ExtendedViewpointAdapter getViewpointAdapter(); -} diff --git a/src/main/java/pico/inference/PICOInferenceAnnotatedTypeFactory.java b/src/main/java/pico/inference/PICOInferenceAnnotatedTypeFactory.java index fac8e3a..c2eb390 100644 --- a/src/main/java/pico/inference/PICOInferenceAnnotatedTypeFactory.java +++ b/src/main/java/pico/inference/PICOInferenceAnnotatedTypeFactory.java @@ -10,15 +10,11 @@ import checkers.inference.VariableAnnotator; import checkers.inference.model.ConstraintManager; import checkers.inference.model.Slot; -import checkers.inference.model.SourceVariableSlot; import checkers.inference.util.InferenceViewpointAdapter; import com.sun.source.tree.BinaryTree; import com.sun.source.tree.ClassTree; -import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.MethodTree; -import com.sun.source.tree.NewArrayTree; -import com.sun.source.tree.NewClassTree; import com.sun.source.tree.Tree; import com.sun.source.tree.TypeCastTree; import com.sun.source.util.TreePath; @@ -32,28 +28,19 @@ import org.checkerframework.framework.type.typeannotator.ListTypeAnnotator; import org.checkerframework.framework.type.typeannotator.TypeAnnotator; import org.checkerframework.javacutil.*; -import pico.common.ExtendedViewpointAdapter; -import pico.common.ViewpointAdapterGettable; import pico.common.PICOTypeUtil; import pico.typecheck.PICONoInitAnnotatedTypeFactory; import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.TypeElement; -import javax.lang.model.type.DeclaredType; import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import java.lang.annotation.Annotation; -import java.util.Collection; -import java.util.Collections; import java.util.Set; import static pico.typecheck.PICOAnnotationMirrorHolder.*; -import static pico.typecheck.PICOAnnotationMirrorHolder.RECEIVER_DEPENDANT_MUTABLE; /** * Propagates correct constraints on trees and types using TreeAnnotators and TypeAnnotators. @@ -63,7 +50,7 @@ * type on that type. This ensures that that VariableSlot doesn't enter solver and solver doesn't * give solution to the VariableSlot, and there won't be annotations inserted to implicit locations. */ -public class PICOInferenceAnnotatedTypeFactory extends InferenceAnnotatedTypeFactory implements ViewpointAdapterGettable { +public class PICOInferenceAnnotatedTypeFactory extends InferenceAnnotatedTypeFactory { public PICOInferenceAnnotatedTypeFactory(InferenceChecker inferenceChecker, boolean withCombineConstraints, BaseAnnotatedTypeFactory realTypeFactory, InferrableChecker realChecker, SlotManager slotManager, ConstraintManager constraintManager) { super(inferenceChecker, withCombineConstraints, realTypeFactory, realChecker, slotManager, constraintManager); // Always call postInit() at the end of ATF constructor! @@ -145,9 +132,8 @@ public AnnotatedDeclaredType getSelfType(Tree tree) { return type; } - @Override - public ExtendedViewpointAdapter getViewpointAdapter() { - return (ExtendedViewpointAdapter) viewpointAdapter; + public PICOInferenceViewpointAdapter getViewpointAdapter() { + return (PICOInferenceViewpointAdapter) viewpointAdapter; } @Override diff --git a/src/main/java/pico/inference/PICOInferenceExtendedViewpointAdapter.java b/src/main/java/pico/inference/PICOInferenceExtendedViewpointAdapter.java deleted file mode 100644 index 3df3cd5..0000000 --- a/src/main/java/pico/inference/PICOInferenceExtendedViewpointAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -package pico.inference; - -import org.checkerframework.framework.type.AnnotatedTypeFactory; -import org.checkerframework.framework.type.AnnotatedTypeMirror; -import pico.common.ExtendedViewpointAdapter; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; - -public class PICOInferenceExtendedViewpointAdapter extends PICOInferenceViewpointAdapter implements ExtendedViewpointAdapter { - - public PICOInferenceExtendedViewpointAdapter(AnnotatedTypeFactory atypeFactory) { - super(atypeFactory); - } - - /** - * (Extended behaviour) viewpoint adapt super clause to its class declaration. Class declaration acts like receiver. - * @param classType class declaration itself - * @param superEle element of extends / implements clause - * @param superType type of extends / implements clause - */ - public void viewpointAdaptSuperClause(AnnotatedTypeMirror.AnnotatedDeclaredType classType, Element superEle, AnnotatedTypeMirror.AnnotatedDeclaredType superType) { -// AnnotatedTypeMirror adapted = combineTypeWithType(classType, superType); - AnnotationMirror adapted = combineAnnotationWithAnnotation(extractAnnotationMirror(classType), extractAnnotationMirror(superType)); - superType.replaceAnnotation(adapted); - - } - - public AnnotatedTypeMirror rawCombineAnnotationWithType(AnnotationMirror anno, AnnotatedTypeMirror type) { - return combineAnnotationWithType(anno, type); - } - - @Override - public AnnotationMirror rawCombineAnnotationWithAnnotation(AnnotationMirror anno, AnnotationMirror type) { - return combineAnnotationWithAnnotation(anno, type); - } -} diff --git a/src/main/java/pico/inference/PICOInferenceRealTypeFactory.java b/src/main/java/pico/inference/PICOInferenceRealTypeFactory.java index dd12c53..c929f43 100644 --- a/src/main/java/pico/inference/PICOInferenceRealTypeFactory.java +++ b/src/main/java/pico/inference/PICOInferenceRealTypeFactory.java @@ -3,7 +3,6 @@ import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -19,7 +18,6 @@ import checkers.inference.BaseInferenceRealTypeFactory; import com.sun.source.tree.NewClassTree; import com.sun.tools.javac.tree.JCTree; -import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory; import org.checkerframework.common.basetype.BaseTypeChecker; import org.checkerframework.framework.qual.RelevantJavaTypes; import org.checkerframework.framework.qual.TypeUseLocation; @@ -34,8 +32,6 @@ import com.sun.source.tree.Tree; -import pico.common.ExtendedViewpointAdapter; -import pico.common.ViewpointAdapterGettable; import pico.common.PICOTypeUtil; import pico.typecheck.PICONoInitAnnotatedTypeFactory; import pico.typecheck.PICOViewpointAdapter; @@ -56,7 +52,7 @@ * to InitializationAnnotatedTypeFactory as if there is only one mutability qualifier hierarchy. * This class has lots of copied code from PICOAnnotatedTypeFactory. The two should be in sync. */ -public class PICOInferenceRealTypeFactory extends BaseInferenceRealTypeFactory implements ViewpointAdapterGettable { +public class PICOInferenceRealTypeFactory extends BaseInferenceRealTypeFactory { private static final List IMMUTABLE_ALIASES = Arrays.asList( "com.google.errorprone.annotations.Immutable", @@ -249,8 +245,8 @@ public AnnotatedTypeMirror getTypeOfExtendsImplements(Tree clause) { return fromTypeTree; } - public ExtendedViewpointAdapter getViewpointAdapter() { - return (ExtendedViewpointAdapter) viewpointAdapter; + public PICOInferenceViewpointAdapter getViewpointAdapter() { + return (PICOInferenceViewpointAdapter) viewpointAdapter; } @Override diff --git a/src/main/java/pico/inference/PICOInferenceViewpointAdapter.java b/src/main/java/pico/inference/PICOInferenceViewpointAdapter.java index 38a7fda..92f68da 100644 --- a/src/main/java/pico/inference/PICOInferenceViewpointAdapter.java +++ b/src/main/java/pico/inference/PICOInferenceViewpointAdapter.java @@ -4,7 +4,6 @@ import checkers.inference.util.InferenceViewpointAdapter; import org.checkerframework.framework.type.AnnotatedTypeFactory; import org.checkerframework.framework.type.AnnotatedTypeMirror; -import pico.common.ExtendedViewpointAdapter; import pico.common.PICOTypeUtil; import static pico.typecheck.PICOAnnotationMirrorHolder.READONLY; @@ -12,7 +11,7 @@ import javax.lang.model.element.Element; import javax.lang.model.type.TypeKind; -public class PICOInferenceViewpointAdapter extends InferenceViewpointAdapter implements ExtendedViewpointAdapter { +public class PICOInferenceViewpointAdapter extends InferenceViewpointAdapter { public PICOInferenceViewpointAdapter(AnnotatedTypeFactory atypeFactory) { super(atypeFactory); @@ -41,16 +40,6 @@ protected AnnotatedTypeMirror combineAnnotationWithType(AnnotationMirror receive return super.combineAnnotationWithType(receiverAnnotation, declared); } - @Override - public AnnotatedTypeMirror rawCombineAnnotationWithType(AnnotationMirror anno, AnnotatedTypeMirror type) { - return combineAnnotationWithType(anno, type); - } - - @Override - public AnnotationMirror rawCombineAnnotationWithAnnotation(AnnotationMirror anno, AnnotationMirror type) { - return rawCombineAnnotationWithAnnotation(anno, type); - } - @Override protected AnnotationMirror extractAnnotationMirror(AnnotatedTypeMirror atm) { // since the introduction of vp-is-valid rules, real am may be used? diff --git a/src/main/java/pico/inference/PICOInferenceVisitor.java b/src/main/java/pico/inference/PICOInferenceVisitor.java index da8b28c..db3991e 100644 --- a/src/main/java/pico/inference/PICOInferenceVisitor.java +++ b/src/main/java/pico/inference/PICOInferenceVisitor.java @@ -26,7 +26,6 @@ import com.sun.source.tree.UnaryTree; import com.sun.source.tree.VariableTree; import com.sun.source.util.TreePath; -import org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey; import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory; import org.checkerframework.framework.type.AnnotatedTypeFactory.ParameterizedExecutableType; import org.checkerframework.framework.type.AnnotatedTypeMirror; @@ -35,10 +34,7 @@ import org.checkerframework.framework.type.QualifierHierarchy; import org.checkerframework.framework.util.AnnotatedTypes; import org.checkerframework.javacutil.*; -import pico.common.ExtendedViewpointAdapter; -import pico.common.ViewpointAdapterGettable; import pico.common.PICOTypeUtil; -import qual.ReceiverDependantMutable; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; @@ -50,9 +46,7 @@ import javax.lang.model.type.TypeMirror; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Set; @@ -153,8 +147,8 @@ private void isAdaptedSubtype(AnnotatedTypeMirror lhs, AnnotatedTypeMirror rhs, return; } // todo:haifeng we should do the viewpointAdapt in baseTypeValidator.java#visitDeclared 299 function:getTypeDeclarationBounds - ExtendedViewpointAdapter vpa = ((ViewpointAdapterGettable)atypeFactory).getViewpointAdapter(); - AnnotatedTypeMirror adapted = vpa.rawCombineAnnotationWithType(extractVarAnnot(lhs), + PICOInferenceViewpointAdapter vpa = ((PICOInferenceRealTypeFactory)atypeFactory).getViewpointAdapter(); + AnnotatedTypeMirror adapted = vpa.combineAnnotationWithType(extractVarAnnot(lhs), rhs); mainIsSubtype(adapted, extractVarAnnot(lhs), msgKey, node); } @@ -164,8 +158,8 @@ private Constraint createAdaptedSubtypeConstraint(AnnotatedTypeMirror lhs, Annot final ConstraintManager constraintManager = InferenceMain.getInstance().getConstraintManager(); final SlotManager slotManager = InferenceMain.getInstance().getSlotManager(); - ExtendedViewpointAdapter vpa = ((ViewpointAdapterGettable)atypeFactory).getViewpointAdapter(); - AnnotatedTypeMirror adapted = vpa.rawCombineAnnotationWithType(extractVarAnnot(lhs), rhs); + PICOInferenceViewpointAdapter vpa = ((PICOInferenceAnnotatedTypeFactory)atypeFactory).getViewpointAdapter(); + AnnotatedTypeMirror adapted = vpa.combineAnnotationWithType(extractVarAnnot(lhs), rhs); return constraintManager.createSubtypeConstraint( slotManager.getSlot(adapted), slotManager.getSlot(lhs) @@ -589,7 +583,7 @@ private void flexibleOverrideChecker(MethodTree node) { types, atypeFactory, enclosingType, pair.getValue()); // Viewpoint adapt super method executable type to current class bound(is this always class bound?) // to allow flexible overriding - ((ViewpointAdapterGettable) atypeFactory).getViewpointAdapter().viewpointAdaptMethod(enclosingType, pair.getValue() , overriddenMethod); // todo: should we cast it? + ((PICOInferenceRealTypeFactory)atypeFactory).getViewpointAdapter().viewpointAdaptMethod(enclosingType, pair.getValue() , overriddenMethod); // todo: should we cast it? AnnotatedExecutableType overrider = atypeFactory.getAnnotatedType(node); if (!checkOverride(node, overrider, enclosingType, overriddenMethod, overriddenType)) { // Stop at the first mismatch; this makes a difference only if @@ -1122,7 +1116,7 @@ protected boolean commonAssignmentCheck( AnnotatedTypeMirror varAdapted = var.shallowCopy(true); // Viewpoint adapt varAdapted to the bound. PICOInferenceAnnotatedTypeFactory#viewpointAdaptMember() // mutates varAdapted, so after the below method is called, varAdapted is the result adapted to bound - ((ViewpointAdapterGettable) atypeFactory).getViewpointAdapter().viewpointAdaptMember(bound, element, varAdapted); + ((PICOInferenceRealTypeFactory)atypeFactory).getViewpointAdapter().viewpointAdaptMember(bound, element, varAdapted); // Pass varAdapted here as lhs type. // Caution: cannot pass var directly. Modifying type in PICOInferenceTreeAnnotator# // visitVariable() will cause wrong type to be gotton here, as on inference side, diff --git a/src/main/java/pico/typecheck/PICONoInitAnnotatedTypeFactory.java b/src/main/java/pico/typecheck/PICONoInitAnnotatedTypeFactory.java index 6a71dcd..9f8826b 100644 --- a/src/main/java/pico/typecheck/PICONoInitAnnotatedTypeFactory.java +++ b/src/main/java/pico/typecheck/PICONoInitAnnotatedTypeFactory.java @@ -36,9 +36,7 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import pico.common.ExtendedViewpointAdapter; import pico.common.PICOTypeUtil; -import pico.common.ViewpointAdapterGettable; import qual.Bottom; import qual.Immutable; import qual.Mutable; @@ -58,8 +56,7 @@ // and explicitly annotated classes with @Immutable on its declaration public class PICONoInitAnnotatedTypeFactory extends GenericAnnotatedTypeFactory< - PICONoInitValue, PICONoInitStore, PICONoInitTransfer, PICONoInitAnalysis> - implements ViewpointAdapterGettable { + PICONoInitValue, PICONoInitStore, PICONoInitTransfer, PICONoInitAnalysis> { public PICONoInitAnnotatedTypeFactory(BaseTypeChecker checker) { super(checker); @@ -198,8 +195,8 @@ public Void visitBinary(BinaryTree node, AnnotatedTypeMirror type) { } - public ExtendedViewpointAdapter getViewpointAdapter() { - return (ExtendedViewpointAdapter) viewpointAdapter; + public PICOViewpointAdapter getViewpointAdapter() { + return (PICOViewpointAdapter) viewpointAdapter; } @Override diff --git a/src/main/java/pico/typecheck/PICONoInitVisitor.java b/src/main/java/pico/typecheck/PICONoInitVisitor.java index 8ff2477..f5b1a02 100644 --- a/src/main/java/pico/typecheck/PICONoInitVisitor.java +++ b/src/main/java/pico/typecheck/PICONoInitVisitor.java @@ -47,9 +47,7 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import pico.common.ExtendedViewpointAdapter; import pico.common.PICOTypeUtil; -import pico.common.ViewpointAdapterGettable; public class PICONoInitVisitor extends BaseTypeVisitor { @@ -106,9 +104,9 @@ public boolean isValidUse(AnnotatedTypeMirror.AnnotatedArrayType type, Tree tree } private boolean isAdaptedSubtype(AnnotationMirror lhs, AnnotationMirror rhs) { - ExtendedViewpointAdapter vpa = - ((ViewpointAdapterGettable) atypeFactory).getViewpointAdapter(); - AnnotationMirror adapted = vpa.rawCombineAnnotationWithAnnotation(lhs, rhs); + PICOViewpointAdapter vpa = + atypeFactory.getViewpointAdapter(); + AnnotationMirror adapted = vpa.combineAnnotationWithAnnotation(lhs, rhs); return atypeFactory.getQualifierHierarchy().isSubtypeQualifiersOnly(adapted, lhs); } diff --git a/src/main/java/pico/typecheck/PICOViewpointAdapter.java b/src/main/java/pico/typecheck/PICOViewpointAdapter.java index a6b8bcf..6449f15 100644 --- a/src/main/java/pico/typecheck/PICOViewpointAdapter.java +++ b/src/main/java/pico/typecheck/PICOViewpointAdapter.java @@ -17,9 +17,7 @@ import org.checkerframework.javacutil.AnnotationUtils; import org.checkerframework.javacutil.BugInCF; -import pico.common.ExtendedViewpointAdapter; - -public class PICOViewpointAdapter extends AbstractViewpointAdapter implements ExtendedViewpointAdapter { +public class PICOViewpointAdapter extends AbstractViewpointAdapter { public PICOViewpointAdapter(AnnotatedTypeFactory atypeFactory) { super(atypeFactory); @@ -56,15 +54,4 @@ protected AnnotationMirror combineAnnotationWithAnnotation(AnnotationMirror rece throw new BugInCF("Unknown declared modifier: " + declaredAnnotation); } } - - public AnnotatedTypeMirror rawCombineAnnotationWithType(AnnotationMirror anno, AnnotatedTypeMirror type) { -// System.err.println("VPA: " + anno + " ->" + type); - return combineAnnotationWithType(anno, type); - } - - @Override - public AnnotationMirror rawCombineAnnotationWithAnnotation(AnnotationMirror anno, AnnotationMirror type) { -// System.err.println("VPA: " + anno + " ->" + type); - return combineAnnotationWithAnnotation(anno, type); - } }