--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Attribute.java Mon Sep 08 10:50:59 2014 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Attribute.java Mon Sep 08 13:11:28 2014 +0200
@@ -151,7 +151,7 @@
* access this attribute.
*/
public final List<Pair<MethodSymbol,Attribute>> values;
- public final TypeAnnotationPosition position;
+ public TypeAnnotationPosition position;
private boolean synthesized = false;
@@ -179,9 +179,53 @@
@Override
public TypeAnnotationPosition getPosition() {
+ if (hasUnknownPosition()) {
+ if (values.size() != 0) {
+ Name valueName = values.head.fst.name.table.names.value;
+ Pair<MethodSymbol, Attribute> res = getElemPair(valueName);
+ position = res == null ? null : res.snd.getPosition();
+ }
+ }
return position;
}
+ public boolean isContainerTypeCompound() {
+ if (isSynthesized() && values.size() == 1)
+ return getFirstEmbeddedTC() != null;
+ return false;
+ }
+
+ private Compound getFirstEmbeddedTC() {
+ if (values.size() == 1) {
+ Pair<MethodSymbol, Attribute> val = values.get(0);
+ if (val.fst.getSimpleName().contentEquals("value")
+ && val.snd instanceof Array) {
+ Array arr = (Array) val.snd;
+ if (arr.values.length != 0
+ && arr.values[0] instanceof Attribute.TypeCompound)
+ return (Attribute.TypeCompound) arr.values[0];
+ }
+ }
+ return null;
+ }
+
+ public boolean tryFixPosition() {
+ if (!isContainerTypeCompound())
+ return false;
+
+ Compound from = getFirstEmbeddedTC();
+ if (from != null && from.position != null &&
+ from.position.type != TargetType.UNKNOWN) {
+ position = from.position;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean hasUnknownPosition() {
+ return position.type == TargetType.UNKNOWN;
+ }
+
public void accept(Visitor v) { v.visitCompound(this); }
/**
@@ -250,12 +294,6 @@
valmap.put(value.fst, value.snd);
return valmap;
}
-
- public TypeCompound toTypeCompound() {
- // It is safe to alias the position.
- return new TypeCompound(this, this.position);
- }
-
}
public static class TypeCompound extends Compound {