6854796: update JSR308 impl with latest code from type-annotations repo
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:
parent
e03ee9130a
commit
d6b7dc0812
@ -53,25 +53,25 @@ public enum TargetType {
|
||||
//
|
||||
|
||||
/** 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 @@ public enum TargetType {
|
||||
//@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 @@ public enum TargetType {
|
||||
//@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 @@ public enum TargetType {
|
||||
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 @@ public enum TargetType {
|
||||
}
|
||||
|
||||
static enum TargetAttribute {
|
||||
HasLocation, HasParameter, HasBound;
|
||||
HasLocation, HasParameter, HasBound, IsLocal;
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public class TypeAnnotationPosition {
|
||||
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 @@ public class TypeAnnotationPosition {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1979,7 +1979,6 @@ public class Lower extends TreeTranslator {
|
||||
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();
|
||||
|
@ -774,11 +774,14 @@ public class ClassWriter extends ClassFile {
|
||||
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 @@ public class ClassWriter extends ClassFile {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -1912,8 +1912,8 @@ public class Code {
|
||||
if (length < Character.MAX_VALUE) {
|
||||
v.length = length;
|
||||
putVar(v);
|
||||
fillLocalVarPosition(v);
|
||||
}
|
||||
fillLocalVarPosition(v);
|
||||
}
|
||||
}
|
||||
state.defined.excl(adr);
|
||||
@ -1929,6 +1929,7 @@ public class Code {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1715,6 +1715,7 @@ public class Gen extends JCTree.Visitor {
|
||||
if (ta.position.pos == treePos) {
|
||||
ta.position.offset = code.cp;
|
||||
ta.position.lvarOffset[0] = code.cp;
|
||||
ta.position.isValidOffset = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1726,6 +1727,7 @@ public class Gen extends JCTree.Visitor {
|
||||
if (ta.position.pos == treePos) {
|
||||
ta.position.offset = code.cp;
|
||||
ta.position.lvarOffset[0] = code.cp;
|
||||
ta.position.isValidOffset = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1737,6 +1739,7 @@ public class Gen extends JCTree.Visitor {
|
||||
if (ta.position.pos == treePos) {
|
||||
ta.position.offset = code.cp;
|
||||
ta.position.lvarOffset[0] = code.cp;
|
||||
ta.position.isValidOffset = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
|
||||
public Todo todo;
|
||||
|
||||
/** Ordered list of compiler phases for each compilation unit. */
|
||||
protected enum CompileState {
|
||||
public enum CompileState {
|
||||
PARSE(1),
|
||||
ENTER(2),
|
||||
PROCESS(3),
|
||||
|
@ -1211,7 +1211,6 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
} else {
|
||||
if (!annos.isEmpty()) {
|
||||
illegal(0);
|
||||
if (permitTypeAnnotationsPushBack)
|
||||
typeAnnotationsPushedBack = annos;
|
||||
else
|
||||
|
@ -50,6 +50,7 @@ import javax.tools.StandardJavaFileManager;
|
||||
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.code.Symbol.*;
|
||||
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
}
|
||||
|
||||
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
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 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
this.context = currentContext;
|
||||
updateProcessingState(currentContext, true);
|
||||
compiler = JavaCompiler.instance(currentContext);
|
||||
if (procOnly && foundTypeProcessors)
|
||||
compiler.shouldStopPolicy = CompileState.FLOW;
|
||||
|
||||
if (true) {
|
||||
compiler.enterTrees(cleanTrees(roots));
|
||||
|
@ -37,6 +37,9 @@ import java.util.*;
|
||||
/**
|
||||
* 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 @@ public class JavacRoundEnvironment implements RoundEnvironment {
|
||||
* 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
|
||||
|
Loading…
Reference in New Issue
Block a user