6843077: JSR 308: Annotations on types

Co-authored-by: Mahmood Ali <mali@csail.mit.edu>
Co-authored-by: Matt Papi <mpapi@csail.mit.edu>
Reviewed-by: jjg, mcimadamore, darcy
This commit is contained in:
Michael Ernst 2009-06-26 18:51:39 -07:00 committed by Jonathan Gibbons
parent 2b12b62ad4
commit 5a1465b9de
45 changed files with 1856 additions and 98 deletions

View file

@ -53,6 +53,7 @@ public interface MethodTree extends Tree {
Tree getReturnType();
List<? extends TypeParameterTree> getTypeParameters();
List<? extends VariableTree> getParameters();
List<? extends AnnotationTree> getReceiverAnnotations();
List<? extends ExpressionTree> getThrows();
BlockTree getBody();
Tree getDefaultValue(); // for annotation types

View file

@ -45,6 +45,9 @@ public interface Tree {
* Enumerates all kinds of trees.
*/
public enum Kind {
ANNOTATED_TYPE(AnnotatedTypeTree.class),
/**
* Used for instances of {@link AnnotationTree}.
*/

View file

@ -57,6 +57,7 @@ package com.sun.source.tree;
* @since 1.6
*/
public interface TreeVisitor<R,P> {
R visitAnnotatedType(AnnotatedTypeTree node, P p);
R visitAnnotation(AnnotationTree node, P p);
R visitMethodInvocation(MethodInvocationTree node, P p);
R visitAssert(AssertTree node, P p);

View file

@ -47,4 +47,5 @@ import javax.lang.model.element.Name;
public interface TypeParameterTree extends Tree {
Name getName();
List<? extends Tree> getBounds();
List<? extends AnnotationTree> getAnnotations();
}

View file

@ -244,6 +244,10 @@ public class SimpleTreeVisitor <R,P> implements TreeVisitor<R,P> {
return defaultAction(node, p);
}
public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
return defaultAction(node, p);
}
public R visitErroneous(ErroneousTree node, P p) {
return defaultAction(node, p);
}

View file

@ -120,19 +120,20 @@ public class TreePath implements Iterable<Tree> {
public Iterator<Tree> iterator() {
return new Iterator<Tree>() {
public boolean hasNext() {
return curr.parent != null;
return next != null;
}
public Tree next() {
curr = curr.parent;
return curr.leaf;
Tree t = next.leaf;
next = next.parent;
return t;
}
public void remove() {
throw new UnsupportedOperationException();
}
private TreePath curr;
private TreePath next = TreePath.this;
};
}

View file

@ -138,6 +138,7 @@ public class TreeScanner<R,P> implements TreeVisitor<R,P> {
r = scanAndReduce(node.getReturnType(), p, r);
r = scanAndReduce(node.getTypeParameters(), p, r);
r = scanAndReduce(node.getParameters(), p, r);
r = scanAndReduce(node.getReceiverAnnotations(), p, r);
r = scanAndReduce(node.getThrows(), p, r);
r = scanAndReduce(node.getBody(), p, r);
return r;
@ -354,7 +355,9 @@ public class TreeScanner<R,P> implements TreeVisitor<R,P> {
}
public R visitTypeParameter(TypeParameterTree node, P p) {
return scan(node.getBounds(), p);
R r = scan(node.getAnnotations(), p);
r = scanAndReduce(node.getBounds(), p, r);
return r;
}
public R visitWildcard(WildcardTree node, P p) {
@ -371,6 +374,12 @@ public class TreeScanner<R,P> implements TreeVisitor<R,P> {
return r;
}
public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
R r = scan(node.getAnnotations(), p);
r = scanAndReduce(node.getUnderlyingType(), p, r);
return r;
}
public R visitOther(Tree node, P p) {
return null;
}

View file

@ -35,6 +35,7 @@ import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.ErrorType;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import javax.tools.JavaCompiler.CompilationTask;
import com.sun.source.tree.ClassTree;
@ -182,7 +183,20 @@ public abstract class Trees {
/**
* Gets the original type from the ErrorType object.
* @param errorType The errorType for which we want to get the original type.
* @returns javax.lang.model.type.TypeMirror corresponding to the original type, replaced by the ErrorType.
* @return javax.lang.model.type.TypeMirror corresponding to the original type, replaced by the ErrorType.
*/
public abstract TypeMirror getOriginalType(ErrorType errorType);
/**
* Prints a message of the specified kind at the location of the
* tree within the provided compilation unit
*
* @param kind the kind of message
* @param msg the message, or an empty string if none
* @param t the tree to use as a position hint
* @param root the compilation unit that contains tree
*/
public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg,
com.sun.source.tree.Tree t,
com.sun.source.tree.CompilationUnitTree root);
}