6854796: update JSR308 impl with latest code from type-annotations repo
Reviewed-by: jjg, mcimadamore, darcy
Contributed-by: mernst@cs.washington.edu, mali@csail.mit.edu, mpapi@csail.mit.edu
--- a/langtools/src/share/classes/com/sun/tools/javac/code/TargetType.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/TargetType.java Fri Jun 26 19:47:12 2009 -0700
@@ -53,25 +53,25 @@
//
/** For annotations on typecasts. */
- TYPECAST(0x00),
+ TYPECAST(0x00, IsLocal),
/** For annotations on a type argument or nested array of a typecast. */
- TYPECAST_GENERIC_OR_ARRAY(0x01, HasLocation),
+ TYPECAST_GENERIC_OR_ARRAY(0x01, HasLocation, IsLocal),
/** For annotations on type tests. */
- INSTANCEOF(0x02),
+ INSTANCEOF(0x02, IsLocal),
/** For annotations on a type argument or nested array of a type test. */
- INSTANCEOF_GENERIC_OR_ARRAY(0x03, HasLocation),
+ INSTANCEOF_GENERIC_OR_ARRAY(0x03, HasLocation, IsLocal),
/** For annotations on object creation expressions. */
- NEW(0x04),
+ NEW(0x04, IsLocal),
/**
* For annotations on a type argument or nested array of an object creation
* expression.
*/
- NEW_GENERIC_OR_ARRAY(0x05, HasLocation),
+ NEW_GENERIC_OR_ARRAY(0x05, HasLocation, IsLocal),
/** For annotations on the method receiver. */
@@ -81,10 +81,10 @@
//@Deprecated METHOD_RECEIVER_GENERIC_OR_ARRAY(0x07, HasLocation),
/** For annotations on local variables. */
- LOCAL_VARIABLE(0x08),
+ LOCAL_VARIABLE(0x08, IsLocal),
/** For annotations on a type argument or nested array of a local. */
- LOCAL_VARIABLE_GENERIC_OR_ARRAY(0x09, HasLocation),
+ LOCAL_VARIABLE_GENERIC_OR_ARRAY(0x09, HasLocation, IsLocal),
// handled by regular annotations
//@Deprecated METHOD_RETURN(0x0A),
@@ -138,17 +138,17 @@
//@Deprecated THROWS_GENERIC_OR_ARRAY(0x17, HasLocation),
/** For annotations in type arguments of object creation expressions. */
- NEW_TYPE_ARGUMENT(0x18),
- NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x19, HasLocation),
+ NEW_TYPE_ARGUMENT(0x18, IsLocal),
+ NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x19, HasLocation, IsLocal),
- METHOD_TYPE_ARGUMENT(0x1A),
- METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x1B, HasLocation),
+ METHOD_TYPE_ARGUMENT(0x1A, IsLocal),
+ METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY(0x1B, HasLocation, IsLocal),
WILDCARD_BOUND(0x1C, HasBound),
WILDCARD_BOUND_GENERIC_OR_ARRAY(0x1D, HasBound, HasLocation),
- CLASS_LITERAL(0x1E),
- CLASS_LITERAL_GENERIC_OR_ARRAY(0x1F, HasLocation),
+ CLASS_LITERAL(0x1E, IsLocal),
+ CLASS_LITERAL_GENERIC_OR_ARRAY(0x1F, HasLocation, IsLocal),
METHOD_TYPE_PARAMETER(0x20, HasParameter),
@@ -218,6 +218,17 @@
return flags.contains(HasBound);
}
+ /**
+ * Returns whether or not this TargetType represents an annotation whose
+ * target is exclusively a tree in a method body
+ *
+ * Note: wildcard bound targets could target a local tree and a class
+ * member declaration signature tree
+ */
+ public boolean isLocal() {
+ return flags.contains(IsLocal);
+ }
+
public int targetTypeValue() {
return this.targetTypeValue;
}
@@ -261,6 +272,6 @@
}
static enum TargetAttribute {
- HasLocation, HasParameter, HasBound;
+ HasLocation, HasParameter, HasBound, IsLocal;
}
}
--- a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java Fri Jun 26 19:47:12 2009 -0700
@@ -45,6 +45,7 @@
public int pos = -1;
// For typecasts, type tests, new (and locals, as start_pc).
+ public boolean isValidOffset = false;
public int offset = -1;
// For locals. arrays same length
@@ -177,4 +178,17 @@
sb.append(']');
return sb.toString();
}
+
+ /**
+ * Indicates whether the target tree of the annotation has been optimized
+ * away from classfile or not.
+ * @return true if the target has not been optimized away
+ */
+ public boolean emitToClassfile() {
+ if (type == TargetType.WILDCARD_BOUND
+ || type == TargetType.WILDCARD_BOUND_GENERIC_OR_ARRAY)
+ return wildcard_position.isValidOffset;
+ else
+ return !type.isLocal() || isValidOffset;
+ }
}
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java Fri Jun 26 19:47:12 2009 -0700
@@ -1979,7 +1979,6 @@
c.members_field = new Scope(c);
c.flags_field = flags;
c.attributes_field = tree.packge.attributes_field;
- tree.packge.attributes_field = List.nil();
ClassType ctype = (ClassType) c.type;
ctype.supertype_field = syms.objectType;
ctype.interfaces_field = List.nil();
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Fri Jun 26 19:47:12 2009 -0700
@@ -774,11 +774,14 @@
ListBuffer<Attribute.TypeCompound> invisibles = ListBuffer.lb();
for (Attribute.TypeCompound tc : typeAnnos) {
- switch (getRetention(tc.type.tsym)) {
- case SOURCE: break;
- case CLASS: invisibles.append(tc); break;
- case RUNTIME: visibles.append(tc); break;
- default: ;// /* fail soft */ throw new AssertionError(vis);
+ if (tc.position.type == TargetType.UNKNOWN
+ || !tc.position.emitToClassfile())
+ continue;
+ switch (getRetention(tc.type.tsym)) {
+ case SOURCE: break;
+ case CLASS: invisibles.append(tc); break;
+ case RUNTIME: visibles.append(tc); break;
+ default: ;// /* fail soft */ throw new AssertionError(vis);
}
}
@@ -905,12 +908,11 @@
}
void writeTypeAnnotation(Attribute.TypeCompound c) {
- // ignore UNKNOWN attributes - improve testing
- if (debugJSR308)
- System.out.println("TA: writing " + c + " at " + c.position
- + " in " + log.currentSourceFile());
- writeCompoundAttribute(c);
- writePosition(c.position);
+ if (debugJSR308)
+ System.out.println("TA: writing " + c + " at " + c.position
+ + " in " + log.currentSourceFile());
+ writeCompoundAttribute(c);
+ writePosition(c.position);
}
void writePosition(TypeAnnotationPosition p) {
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java Fri Jun 26 19:47:12 2009 -0700
@@ -1912,8 +1912,8 @@
if (length < Character.MAX_VALUE) {
v.length = length;
putVar(v);
+ fillLocalVarPosition(v);
}
- fillLocalVarPosition(v);
}
}
state.defined.excl(adr);
@@ -1929,6 +1929,7 @@
p.lvarOffset[0] = (int)lv.start_pc;
p.lvarLength[0] = (int)lv.length;
p.lvarIndex[0] = (int)lv.reg;
+ p.isValidOffset = true;
p = p.wildcard_position;
}
}
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java Fri Jun 26 19:47:12 2009 -0700
@@ -1715,6 +1715,7 @@
if (ta.position.pos == treePos) {
ta.position.offset = code.cp;
ta.position.lvarOffset[0] = code.cp;
+ ta.position.isValidOffset = true;
}
}
@@ -1726,6 +1727,7 @@
if (ta.position.pos == treePos) {
ta.position.offset = code.cp;
ta.position.lvarOffset[0] = code.cp;
+ ta.position.isValidOffset = true;
}
}
@@ -1737,6 +1739,7 @@
if (ta.position.pos == treePos) {
ta.position.offset = code.cp;
ta.position.lvarOffset[0] = code.cp;
+ ta.position.isValidOffset = true;
}
}
}
--- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Jun 26 19:47:12 2009 -0700
@@ -477,7 +477,7 @@
public Todo todo;
/** Ordered list of compiler phases for each compilation unit. */
- protected enum CompileState {
+ public enum CompileState {
PARSE(1),
ENTER(2),
PROCESS(3),
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Jun 26 19:47:12 2009 -0700
@@ -1211,7 +1211,6 @@
}
} else {
if (!annos.isEmpty()) {
- illegal(0);
if (permitTypeAnnotationsPushBack)
typeAnnotationsPushedBack = annos;
else
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Fri Jun 26 19:47:12 2009 -0700
@@ -50,6 +50,7 @@
import javax.tools.JavaFileObject;
import javax.tools.DiagnosticListener;
+import com.sun.source.util.AbstractTypeProcessor;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
import com.sun.tools.javac.api.JavacTaskImpl;
@@ -58,6 +59,7 @@
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.jvm.*;
import com.sun.tools.javac.main.JavaCompiler;
+import com.sun.tools.javac.main.JavaCompiler.CompileState;
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.model.JavacTypes;
import com.sun.tools.javac.parser.*;
@@ -93,6 +95,7 @@
private final boolean lint;
private final boolean procOnly;
private final boolean fatalErrors;
+ private boolean foundTypeProcessors;
private final JavacFiler filer;
private final JavacMessager messager;
@@ -153,6 +156,7 @@
options.get("-Xprint") != null;
fatalErrors = options.get("fatalEnterError") != null;
platformAnnotations = initPlatformAnnotations();
+ foundTypeProcessors = false;
// Initialize services before any processors are initialzied
// in case processors use them.
@@ -670,6 +674,7 @@
}
if (matchedNames.size() > 0 || ps.contributed) {
+ foundTypeProcessors = foundTypeProcessors || (ps.processor instanceof AbstractTypeProcessor);
boolean processingResult = callProcessor(ps.processor, typeElements, renv);
ps.contributed = true;
ps.removeSupportedOptions(unmatchedProcessorOptions);
@@ -916,7 +921,7 @@
compiler.log.nerrors += messager.errorCount();
if (compiler.errorCount() == 0)
compiler.log.nerrors++;
- } else if (procOnly) {
+ } else if (procOnly && !foundTypeProcessors) {
compiler.todo.clear();
} else { // Final compilation
compiler.close(false);
@@ -924,6 +929,8 @@
this.context = currentContext;
updateProcessingState(currentContext, true);
compiler = JavaCompiler.instance(currentContext);
+ if (procOnly && foundTypeProcessors)
+ compiler.shouldStopPolicy = CompileState.FLOW;
if (true) {
compiler.enterTrees(cleanTrees(roots));
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java Fri Jun 26 19:12:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java Fri Jun 26 19:47:12 2009 -0700
@@ -37,6 +37,9 @@
/**
* Object providing state about a prior round of annotation processing.
*
+ * <p>The methods in this class do not take type annotations into account,
+ * as target types, not java elements.
+ *
* <p><b>This is NOT part of any API supported by Sun Microsystems.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
@@ -105,9 +108,6 @@
* elements are {@linkplain #getSpecifiedTypeElements specified
* types} and any types nested within them.
*
- * <p>This method will not return type annotations, which annotate
- * types, not elements.
- *
* @param a annotation type being requested
* @return the elements annotated with the given annotation type,
* or an empty set if there are none