|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcheckers.types.AnnotatedTypeFactory
checkers.javari.JavariAnnotatedTypeFactory
public class JavariAnnotatedTypeFactory
Generates a AnnotatedTypeMirror with Javari annotations from a Tree
or a Element parameter.
Implicit annotations are added as follows:
1. Qualified class types without annotations receive the
\@Mutable
annotation.
2. Qualified executable types receivers without annotations
are annotated with the qualified executable type owner's
annotation.
3. Qualified declared types are annotated with their
underlying type's element annotations.
4. Qualified types whose elements correspond to fields, and
all its subtypes, are annotated with \@ReadOnly
,
\@Mutable
or \@PolyRead), according to the
qualified type of {@code this}.
Field Summary |
---|
Fields inherited from class checkers.types.AnnotatedTypeFactory |
---|
annoRelations, annotations, atypes, checker, elements, env, root, trees, types, visitorState |
Constructor Summary | |
---|---|
JavariAnnotatedTypeFactory(JavariChecker checker,
CompilationUnitTree root)
Creates a new JavariAnnotatedTypeFactory that operates on a
particular AST. |
Method Summary | |
---|---|
protected void |
annotateImplicit(Element element,
AnnotatedTypeMirror type)
Adds annotations to qualified types according to their provided element, as follows: Qualified class types without annotations corresponding to class or interface elements receive the \@Mutable
annotation. |
protected void |
annotateImplicit(Tree tree,
AnnotatedTypeMirror type)
Adds implicit annotations to a qualified type, based on its tree, as follows: 1. |
protected void |
annotateInheritedFromClass(AnnotatedTypeMirror type)
Does nothing. |
AnnotatedTypeMirror.AnnotatedDeclaredType |
getSelfType(Tree tree)
Returns a type of the class and the field this . |
boolean |
hasImmutabilityAnnotation(AnnotatedTypeMirror type)
|
AnnotatedTypeMirror.AnnotatedExecutableType |
methodFromUse(MethodInvocationTree tree)
Determines the type of the invoked method based on the passed method invocation tree. |
void |
postAsMemberOf(AnnotatedTypeMirror type,
AnnotatedTypeMirror owner,
Element element)
We modify this callback method to replace @ThisMutable
implicit annotations with the qualified supertype annotation,
if the owner doesn't have a @ReadOnly annotation;
otherwise one could violate the typesystem as follows:
\@PolyRead Object breakJavari(\@PolyRead Object s) \@ReadOnly {
tmObject = s;
return null;
}
If ThisMutable tmObject were resolved as \@ReadOnly tmObject , the code above would be legal. |
Collection<AnnotationMirror> |
unify(Collection<AnnotationMirror> c1,
Collection<AnnotationMirror> c2)
Returns a singleton collection with the most restrictive immutability annotation that is a supertype of the annotations on both collections. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JavariAnnotatedTypeFactory(JavariChecker checker, CompilationUnitTree root)
JavariAnnotatedTypeFactory
that operates on a
particular AST.
checker
- the checker to which this factory belongsroot
- the AST on which this type factory operatesMethod Detail |
---|
public boolean hasImmutabilityAnnotation(AnnotatedTypeMirror type)
type
- an annotated type mirror
protected void annotateImplicit(Tree tree, AnnotatedTypeMirror type)
@ThisMutable
.
2. Qualified class types without annotations receive the
\@Mutable
annotation.
3. Qualified executable types receivers without annotations
are annotated with the qualified executable type owner's
annotation.
4. Qualified declared types are annotated with their
underlying type's element annotations.
5. Qualified types whose elements correspond to fields, and
all its subtypes, are annotated with \@ReadOnly
,
\@Mutable
or \@PolyRead), according to the
qualified type of {@code this}.
annotateImplicit
in class AnnotatedTypeFactory
tree
- an AST nodetype
- the type obtained from tree
protected void annotateImplicit(Element element, AnnotatedTypeMirror type)
\@Mutable
annotation.
@ReadOnly
or
@ThisMutable
, according to the supertype.
annotateImplicit
in class AnnotatedTypeFactory
element
- an elementtype
- the type obtained from elt
protected void annotateInheritedFromClass(AnnotatedTypeMirror type)
annotateInheritedFromClass
in class AnnotatedTypeFactory
type
- the type for which class annotations will be inherited if
there are no annotations already presentpublic AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType(Tree tree)
this
.
On Javari, this means to retrieve the annotations present at
the method receiver, if any, applied to the qualified type of
the enclosing class.
getSelfType
in class AnnotatedTypeFactory
public Collection<AnnotationMirror> unify(Collection<AnnotationMirror> c1, Collection<AnnotationMirror> c2)
unify
in class AnnotatedTypeFactory
c1
- type qualifiers for the first typec2
- tyep qualifiers for the second type
public AnnotatedTypeMirror.AnnotatedExecutableType methodFromUse(MethodInvocationTree tree)
\@PolyRead
at the raw level on return values by looking at the
mutability of any parameters marked as \@PolyRead
. For
this purpose, a \@PolyRead
annotation on the receiver
counts as if this
were being passed as an argument to a
parameter marked as \@PolyRead
.
\@PolyRead
receive
\@Mutable
arguments, the return value is resolved as
\@Mutable
.
\@PolyRead
receive
\@Mutable
or @ThisMutable
arguments and the
condition above is not satisfied, the return value is
resolved as @ThisMutable
.
\@PolyRead
receive
\@Mutable
or \@PolyRead
arguments and none of
the condition above is satisfied, the return value is resolved
as \@PolyRead
.
@ReadOnly
.
methodFromUse
in class AnnotatedTypeFactory
tree
- the method invocation tree
public void postAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, Element element)
@ThisMutable
implicit annotations with the qualified supertype annotation,
if the owner doesn't have a @ReadOnly
annotation;
otherwise one could violate the typesystem as follows:
\@PolyRead Object breakJavari(\@PolyRead Object s) \@ReadOnly {
tmObject = s;
return null;
}
If ThisMutable tmObject
were resolved as \@ReadOnly tmObject
, the code above would be legal. One could
then create such a class, invoke this method, and obtain \@Mutable
access to tmObject
from a \@ReadOnly
reference to it, without errors.
postAsMemberOf
in class AnnotatedTypeFactory
type
- the annotated type of the elementowner
- the annotated type of the receiver of the accessing treeelement
- the element of the field or method
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |