forked from typetools/checker-framework
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mier Ta <topnessman@sina.com> Co-authored-by: Lian Sun <57457122+lnsun@users.noreply.github.com> Co-authored-by: xingweitian <13183370+xingweitian@users.noreply.github.com> Co-authored-by: xingweitian <xingweitian@gmail.com> Co-authored-by: d367wang <d367wang@uwaterloo.ca> Co-authored-by: Werner Dietl <wdietl@gmail.com>
- Loading branch information
1 parent
95ba662
commit d6b7519
Showing
17 changed files
with
931 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
530 changes: 530 additions & 0 deletions
530
framework/src/main/java/org/checkerframework/framework/type/AbstractViewpointAdapter.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
framework/src/main/java/org/checkerframework/framework/type/ViewpointAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.checkerframework.framework.type; | ||
|
||
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType; | ||
|
||
import java.util.List; | ||
|
||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.ExecutableElement; | ||
|
||
/** | ||
* A viewpoint adapter. | ||
* | ||
* <p>Viewpoint adaptation applies to member/field accesses, constructor invocations, method | ||
* invocations, and type parameter bound instantiations. | ||
*/ | ||
public interface ViewpointAdapter { | ||
|
||
/** | ||
* Viewpoint adapts a member/field access. | ||
* | ||
* <p>Developer notes: When this method is invoked on a member/field with a type given by a type | ||
* parameter, the type arguments are correctly substituted, and memberType is already in a good | ||
* shape. Only annotations on the memberType should be replaced by the viewpoint adapted ones. | ||
* | ||
* @param receiverType receiver type through which the member/field is accessed. | ||
* @param memberElement element of the accessed member/field. | ||
* @param memberType accessed type of the member/field. After the method returns, it will be | ||
* mutated to the viewpoint adapted result. | ||
*/ | ||
void viewpointAdaptMember( | ||
AnnotatedTypeMirror receiverType, | ||
Element memberElement, | ||
AnnotatedTypeMirror memberType); | ||
|
||
/** | ||
* Viewpoint adapts a constructor invocation. Takes an unsubstituted method invocation type and | ||
* performs the viewpoint adaption in place, modifying the parameter. | ||
* | ||
* @param receiverType receiver type through which a constructor is invoked. | ||
* @param constructorElt element of the invoked constructor. | ||
* @param constructorType invoked type of the constructor with type variables not substituted. | ||
* After the method returns, it will be mutated to the viewpoint adapted constructor type. | ||
*/ | ||
void viewpointAdaptConstructor( | ||
AnnotatedTypeMirror receiverType, | ||
ExecutableElement constructorElt, | ||
AnnotatedExecutableType constructorType); | ||
|
||
/** | ||
* Viewpoint adapts a method invocation. Takes an unsubstituted method invocation type and | ||
* performs the viewpoint adaption in place, modifying the parameter. | ||
* | ||
* @param receiverType receiver type through which a method is invoked. | ||
* @param methodElt element of the invoked method. Only used to determine whether this type | ||
* should be viewpoint adapted | ||
* @param methodType invoked type of the method with type variables not substituted. After the | ||
* method returns, it will be mutated to the viewpoint adapted method type. | ||
*/ | ||
void viewpointAdaptMethod( | ||
AnnotatedTypeMirror receiverType, | ||
ExecutableElement methodElt, | ||
AnnotatedExecutableType methodType); | ||
|
||
/** | ||
* Viewpoint adapts a type parameter bound when being instantiated. | ||
* | ||
* @param receiverType receiver type through which the type parameter is instantiated. | ||
* @param typeParameterBounds a list of type parameter bounds. After the method returns, it will | ||
* be mutated to the viewpoint adapted type parameter bounds. | ||
*/ | ||
void viewpointAdaptTypeParameterBounds( | ||
AnnotatedTypeMirror receiverType, | ||
List<AnnotatedTypeParameterBounds> typeParameterBounds); | ||
} |
20 changes: 20 additions & 0 deletions
20
...ork/src/test/java/org/checkerframework/framework/test/junit/ViewpointTestCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package tests; | ||
|
||
import org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
public class ViewpointTestCheckerTest extends CheckerFrameworkPerDirectoryTest { | ||
|
||
/** @param testFiles the files containing test code, which will be type-checked */ | ||
public ViewpointTestCheckerTest(List<File> testFiles) { | ||
super(testFiles, viewpointtest.ViewpointTestChecker.class, "viewpointtest"); | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static String[] getTestDirs() { | ||
return new String[] {"viewpointtest"}; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
framework/src/test/java/viewpointtest/ViewpointTestAnnotatedTypeFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package viewpointtest; | ||
|
||
import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory; | ||
import org.checkerframework.common.basetype.BaseTypeChecker; | ||
import org.checkerframework.framework.type.AbstractViewpointAdapter; | ||
|
||
import viewpointtest.quals.A; | ||
import viewpointtest.quals.B; | ||
import viewpointtest.quals.Bottom; | ||
import viewpointtest.quals.PolyVP; | ||
import viewpointtest.quals.ReceiverDependentQual; | ||
import viewpointtest.quals.Top; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Set; | ||
|
||
public class ViewpointTestAnnotatedTypeFactory extends BaseAnnotatedTypeFactory { | ||
|
||
public ViewpointTestAnnotatedTypeFactory(BaseTypeChecker checker) { | ||
super(checker); | ||
this.postInit(); | ||
} | ||
|
||
@Override | ||
protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() { | ||
return getBundledTypeQualifiers( | ||
A.class, | ||
B.class, | ||
Bottom.class, | ||
PolyVP.class, | ||
ReceiverDependentQual.class, | ||
Top.class); | ||
} | ||
|
||
@Override | ||
protected AbstractViewpointAdapter createViewpointAdapter() { | ||
return new ViewpointTestViewpointAdapter(this); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
framework/src/test/java/viewpointtest/ViewpointTestChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package viewpointtest; | ||
|
||
import org.checkerframework.common.basetype.BaseTypeChecker; | ||
|
||
public class ViewpointTestChecker extends BaseTypeChecker {} |
45 changes: 45 additions & 0 deletions
45
framework/src/test/java/viewpointtest/ViewpointTestViewpointAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package viewpointtest; | ||
|
||
import org.checkerframework.framework.type.AbstractViewpointAdapter; | ||
import org.checkerframework.framework.type.AnnotatedTypeFactory; | ||
import org.checkerframework.framework.type.AnnotatedTypeMirror; | ||
import org.checkerframework.javacutil.AnnotationBuilder; | ||
import org.checkerframework.javacutil.AnnotationUtils; | ||
|
||
import viewpointtest.quals.ReceiverDependentQual; | ||
import viewpointtest.quals.Top; | ||
|
||
import javax.lang.model.element.AnnotationMirror; | ||
|
||
public class ViewpointTestViewpointAdapter extends AbstractViewpointAdapter { | ||
|
||
private final AnnotationMirror TOP, RECEIVERDEPENDENTQUAL; | ||
|
||
/** | ||
* The class constructor. | ||
* | ||
* @param atypeFactory | ||
*/ | ||
public ViewpointTestViewpointAdapter(AnnotatedTypeFactory atypeFactory) { | ||
super(atypeFactory); | ||
TOP = AnnotationBuilder.fromClass(atypeFactory.getElementUtils(), Top.class); | ||
RECEIVERDEPENDENTQUAL = | ||
AnnotationBuilder.fromClass( | ||
atypeFactory.getElementUtils(), ReceiverDependentQual.class); | ||
} | ||
|
||
@Override | ||
protected AnnotationMirror extractAnnotationMirror(AnnotatedTypeMirror atm) { | ||
return atm.getAnnotationInHierarchy(TOP); | ||
} | ||
|
||
@Override | ||
protected AnnotationMirror combineAnnotationWithAnnotation( | ||
AnnotationMirror receiverAnnotation, AnnotationMirror declaredAnnotation) { | ||
|
||
if (AnnotationUtils.areSame(declaredAnnotation, RECEIVERDEPENDENTQUAL)) { | ||
return receiverAnnotation; | ||
} | ||
return declaredAnnotation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package viewpointtest.quals; | ||
|
||
import org.checkerframework.framework.qual.SubtypeOf; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
@SubtypeOf({Top.class}) | ||
public @interface A {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package viewpointtest.quals; | ||
|
||
import org.checkerframework.framework.qual.SubtypeOf; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
@SubtypeOf({Top.class}) | ||
public @interface B {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package viewpointtest.quals; | ||
|
||
import org.checkerframework.framework.qual.DefaultFor; | ||
import org.checkerframework.framework.qual.SubtypeOf; | ||
import org.checkerframework.framework.qual.TypeUseLocation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
@SubtypeOf({A.class, B.class, ReceiverDependentQual.class}) | ||
@DefaultFor(TypeUseLocation.LOWER_BOUND) | ||
public @interface Bottom {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package viewpointtest.quals; | ||
|
||
import org.checkerframework.framework.qual.PolymorphicQualifier; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
@PolymorphicQualifier(Top.class) | ||
public @interface PolyVP {} |
15 changes: 15 additions & 0 deletions
15
framework/src/test/java/viewpointtest/quals/ReceiverDependentQual.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package viewpointtest.quals; | ||
|
||
import org.checkerframework.framework.qual.SubtypeOf; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
@SubtypeOf({Top.class}) | ||
public @interface ReceiverDependentQual {} |
Oops, something went wrong.