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.
Add lost qualifier to viewpointtest type checker (#827)
Co-authored-by: Werner Dietl <wdietl@gmail.com>
- Loading branch information
1 parent
ad93496
commit 101aae1
Showing
14 changed files
with
218 additions
and
15 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
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
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
41 changes: 41 additions & 0 deletions
41
framework/src/test/java/viewpointtest/ViewpointTestQualifierHierarchy.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,41 @@ | ||
package viewpointtest; | ||
|
||
import org.checkerframework.framework.type.GenericAnnotatedTypeFactory; | ||
import org.checkerframework.framework.type.NoElementQualifierHierarchy; | ||
import org.checkerframework.framework.type.QualifierHierarchy; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Collection; | ||
|
||
import javax.lang.model.element.AnnotationMirror; | ||
import javax.lang.model.util.Elements; | ||
|
||
import viewpointtest.quals.Bottom; | ||
import viewpointtest.quals.Lost; | ||
|
||
/** The {@link QualifierHierarchy} for the Viewpoint Test Checker. */ | ||
public class ViewpointTestQualifierHierarchy extends NoElementQualifierHierarchy { | ||
/** | ||
* Creates a ViewpointTestQualifierHierarchy from the given classes. | ||
* | ||
* @param qualifierClasses classes of annotations that are the qualifiers | ||
* @param elements element utils | ||
* @param atypeFactory the associated type factory | ||
*/ | ||
public ViewpointTestQualifierHierarchy( | ||
Collection<Class<? extends Annotation>> qualifierClasses, | ||
Elements elements, | ||
GenericAnnotatedTypeFactory<?, ?, ?, ?> atypeFactory) { | ||
super(qualifierClasses, elements, atypeFactory); | ||
} | ||
|
||
@Override | ||
public boolean isSubtypeQualifiers(AnnotationMirror subAnno, AnnotationMirror superAnno) { | ||
// Lost is not reflexive and the only subtype is Bottom. | ||
if (atypeFactory.areSameByClass(superAnno, Lost.class) | ||
&& !atypeFactory.areSameByClass(subAnno, Bottom.class)) { | ||
return false; | ||
} | ||
return super.isSubtypeQualifiers(subAnno, superAnno); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
framework/src/test/java/viewpointtest/ViewpointTestVisitor.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,28 @@ | ||
package viewpointtest; | ||
|
||
import com.sun.source.tree.NewClassTree; | ||
|
||
import org.checkerframework.common.basetype.BaseTypeChecker; | ||
import org.checkerframework.common.basetype.BaseTypeVisitor; | ||
import org.checkerframework.framework.type.AnnotatedTypeMirror; | ||
|
||
/** The visitor for the Viewpoint Test Checker. */ | ||
public class ViewpointTestVisitor extends BaseTypeVisitor<ViewpointTestAnnotatedTypeFactory> { | ||
/** | ||
* Create a new ViewpointTestVisitor. | ||
* | ||
* @param checker the checker to which this visitor belongs | ||
*/ | ||
public ViewpointTestVisitor(BaseTypeChecker checker) { | ||
super(checker); | ||
} | ||
|
||
@Override | ||
public Void visitNewClass(NewClassTree tree, Void p) { | ||
AnnotatedTypeMirror Type = atypeFactory.getAnnotatedType(tree); | ||
if (Type.hasAnnotation(atypeFactory.TOP) || Type.hasAnnotation(atypeFactory.LOST)) { | ||
checker.reportError(tree, "new.class.type.invalid", Type.getAnnotations()); | ||
} | ||
return super.visitNewClass(tree, p); | ||
} | ||
} |
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
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,22 @@ | ||
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; | ||
|
||
/** | ||
* The {@link Lost} qualifier indicates that a relationship cannot be expressed. It is the result of | ||
* viewpoint adaptation that combines {@link Top} and {@link ReceiverDependentQual}. | ||
* | ||
* <p>It is not reflexive in the subtyping relationship and the only subtype for {@link Lost} is | ||
* {@link Bottom}. | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
@SubtypeOf({Top.class}) | ||
public @interface Lost {} |
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,36 @@ | ||
import viewpointtest.quals.*; | ||
|
||
public class LostNonReflexive { | ||
@ReceiverDependentQual Object f; | ||
|
||
@SuppressWarnings({"inconsistent.constructor.type", "super.invocation.invalid"}) | ||
@ReceiverDependentQual LostNonReflexive(@ReceiverDependentQual Object args) {} | ||
|
||
@ReceiverDependentQual Object get() { | ||
return null; | ||
} | ||
|
||
void set(@ReceiverDependentQual Object o) {} | ||
|
||
void test(@Top LostNonReflexive obj, @Bottom Object bottomObj) { | ||
// :: error: (assignment.type.incompatible) | ||
this.f = obj.f; | ||
this.f = bottomObj; | ||
|
||
// :: error: (assignment.type.incompatible) | ||
@A Object aObj = obj.get(); | ||
// :: error: (assignment.type.incompatible) | ||
@B Object bObj = obj.get(); | ||
// :: error: (assignment.type.incompatible) | ||
@Bottom Object botObj = obj.get(); | ||
|
||
// :: error: (argument.type.incompatible) :: error: (new.class.type.invalid) | ||
new LostNonReflexive(obj.f); | ||
// :: error: (new.class.type.invalid) | ||
new LostNonReflexive(bottomObj); | ||
|
||
// :: error: (argument.type.incompatible) | ||
this.set(obj.f); | ||
this.set(bottomObj); | ||
} | ||
} |
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
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
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
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
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