Skip to content

Commit

Permalink
Remove dummy interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Ao-senXiong committed Jun 1, 2024
1 parent f5a5ad7 commit 2789ede
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 126 deletions.
11 changes: 0 additions & 11 deletions src/main/java/pico/common/ExtendedViewpointAdapter.java

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/java/pico/common/ViewpointAdapterGettable.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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!
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

10 changes: 3 additions & 7 deletions src/main/java/pico/inference/PICOInferenceRealTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<String> IMMUTABLE_ALIASES = Arrays.asList(
"com.google.errorprone.annotations.Immutable",
Expand Down Expand Up @@ -249,8 +245,8 @@ public AnnotatedTypeMirror getTypeOfExtendsImplements(Tree clause) {
return fromTypeTree;
}

public ExtendedViewpointAdapter getViewpointAdapter() {
return (ExtendedViewpointAdapter) viewpointAdapter;
public PICOInferenceViewpointAdapter getViewpointAdapter() {
return (PICOInferenceViewpointAdapter) viewpointAdapter;
}

@Override
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/pico/inference/PICOInferenceViewpointAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
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;

import javax.lang.model.element.AnnotationMirror;
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);
Expand Down Expand Up @@ -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?
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/pico/inference/PICOInferenceVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -198,8 +195,8 @@ public Void visitBinary(BinaryTree node, AnnotatedTypeMirror type) {

}

public ExtendedViewpointAdapter getViewpointAdapter() {
return (ExtendedViewpointAdapter) viewpointAdapter;
public PICOViewpointAdapter getViewpointAdapter() {
return (PICOViewpointAdapter) viewpointAdapter;
}

@Override
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/pico/typecheck/PICONoInitVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PICONoInitAnnotatedTypeFactory> {

Expand Down Expand Up @@ -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);
}

Expand Down
15 changes: 1 addition & 14 deletions src/main/java/pico/typecheck/PICOViewpointAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2789ede

Please sign in to comment.