[Checkers] Status Update: Conditional Expressions and TypeVariables
Mahmood Ali
mahmood at MIT.EDU
Fri Mar 14 01:07:04 EDT 2008
Hi everyone,
I have been able to work for a bit today on the framework. I have
been working on getting the conditional expression and some other
things, and I am very satisfied with it.
__CONDITIONAL EXPRESSIONS__
I have finally implemented the type inference for conditional
expression types using the least upper bound type. The framework uses
Javac type system to find the least upper bound for the true and false
expressions and then tries to view those expressions as of that base
type (using asSuperOf) to climb the type hierarchy and find implicit
annotations.
The annotated type mirror returned of a conditional expression is
actually AnnotatedDeclaredType. I have been thinking of introducing a
new type: AnnotatedIntersectType. Now I agree with Matt as that
complicate the type API and diverges from the Types API. I was able
to modify AnnotatedTypeMirror without changing anything else basically.
For the individual checkers they need to override
unify(Collection<AnnotationMirror>, Collection<AnnotationMirror>) to
find what the appropriate type is. Please review the method
specification to see how to override it.
For further explanation, please check the final note in the email.
__TYPE VARIABLES__
Currently we do basically nothing for methods with type variables
defined in the method tree, like in '<T extends Number> max(T n1, T
n2)'. This is opposed to type variables defined in the class tree,
like for methods 'T get(int)', which is actually handled through
asMemberOf().
This is a bit annoying since some of my case studies rely on this case
being handled. In the next day or two, I am planning to be working on
this to get it to a working condition whenever I have some time.
Regards,
Mahmood
Further explanation:
The complicated thing about conditional expressions has been about how
to handle intersect types. For example, consider the following
expressions (with 'class StringList extends ArrayList<@NonNull String>
{ }')
1. Object o1 = true ? new Integer(3) : new Date();
2. Object o2 = true ? new ArrayList<Integer>() : new LinkedList<Date>();
3. Object o3 = true ? new StringList() : new LinkedList<@NonNull
String>();
The conditional expression types are actually:
1.
> java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>
2.
> java.util.AbstractList<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<?
> >>>&java.util.AbstractCollection<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<?
> >>>&java.util.List<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<?
> >>>&java.util.Collection<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<?
> >>>&java.lang.Cloneable&java.io.Serializable&java.lang.Iterable<?
> extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?
> extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?
> >>>
3.
> java
> .util
> .AbstractList
> <java.lang.String>&java.lang.Cloneable&java.io.Serializable
Needless to say that it looks a bit complicated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/mailman/private/checkers/attachments/20080314/6bd1172a/attachment.htm
More information about the checkers
mailing list