8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound
authoremc
Thu, 27 Mar 2014 18:41:28 -0400
changeset 23798 ca0f80391182
parent 23797 756821688d0a
child 23799 daa645653200
8035768: Move TypeAnnotationPosition from Attribute.Compound to Attribute.TypeCompound Summary: Move position field into Compound, making Compound into a kind of "proto-annotation", representing the situation before we know what an Annotation's kink is Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java	Wed Mar 26 17:50:33 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java	Thu Mar 27 18:41:28 2014 -0400
@@ -141,6 +141,7 @@
          *  access this attribute.
          */
         public final List<Pair<MethodSymbol,Attribute>> values;
+        public TypeAnnotationPosition position;
 
         private boolean synthesized = false;
 
@@ -154,10 +155,67 @@
         }
 
         public Compound(Type type,
-                        List<Pair<MethodSymbol,Attribute>> values) {
+                        List<Pair<MethodSymbol,Attribute>> values,
+                        TypeAnnotationPosition position) {
             super(type);
             this.values = values;
+            this.position = position;
         }
+
+        public Compound(Type type,
+                        List<Pair<MethodSymbol,Attribute>> values) {
+            this(type, values, null);
+        }
+
+        @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); }
 
         /**
@@ -215,16 +273,6 @@
             return (DeclaredType) type;
         }
 
-        @Override
-        public TypeAnnotationPosition getPosition() {
-            if (values.size() != 0) {
-                Name valueName = values.head.fst.name.table.names.value;
-                Pair<MethodSymbol, Attribute> res = getElemPair(valueName);
-                    return res == null ? null : res.snd.getPosition();
-            }
-            return null;
-        }
-
         public Map<MethodSymbol, Attribute> getElementValues() {
             Map<MethodSymbol, Attribute> valmap = new LinkedHashMap<>();
             for (Pair<MethodSymbol, Attribute> value : values)
@@ -234,62 +282,15 @@
     }
 
     public static class TypeCompound extends Compound {
-        public TypeAnnotationPosition position;
-
         public TypeCompound(Compound compound,
-                TypeAnnotationPosition position) {
-            this(compound.type, compound.values, position);
-        }
-        public TypeCompound(Type type,
-                List<Pair<MethodSymbol, Attribute>> values,
-                TypeAnnotationPosition position) {
-            super(type, values);
-            this.position = position;
-        }
-
-        @Override
-        public TypeAnnotationPosition getPosition() {
-            if (hasUnknownPosition()) {
-                position = super.getPosition();
-            }
-            return position;
-        }
-
-        public boolean hasUnknownPosition() {
-            return position.type == TargetType.UNKNOWN;
+                             TypeAnnotationPosition position) {
+            super(compound.type, compound.values, position);
         }
 
-        public boolean isContainerTypeCompound() {
-            if (isSynthesized() && values.size() == 1)
-                return getFirstEmbeddedTC() != null;
-            return false;
-        }
-
-        private TypeCompound 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;
-
-            TypeCompound from = getFirstEmbeddedTC();
-            if (from != null && from.position != null &&
-                    from.position.type != TargetType.UNKNOWN) {
-                position = from.position;
-                return true;
-            }
-            return false;
+        public TypeCompound(Type type,
+                             List<Pair<MethodSymbol,Attribute>> values,
+                             TypeAnnotationPosition position) {
+            super(type, values, position);
         }
     }