author | jjg |
Thu, 04 Feb 2010 10:14:28 -0800 | |
changeset 4877 | b642d21c9f74 |
parent 4872 | 6c49b0ac56a6 |
child 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
4865
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
1 |
/* |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
2 |
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
4 |
* |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Sun designates this |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
10 |
* |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
16 |
* |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
20 |
* |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
23 |
* have any questions. |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
24 |
*/ |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
25 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.code; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
27 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
28 |
import javax.lang.model.element.ElementKind; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
29 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
30 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
31 |
import com.sun.tools.javac.tree.JCTree; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
32 |
import com.sun.tools.javac.tree.TreeInfo; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
33 |
import com.sun.tools.javac.tree.TreeScanner; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.tree.JCTree.*; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.util.Context; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.util.List; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.util.ListBuffer; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
38 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
39 |
/** |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
40 |
* Contains operations specific to processing type annotations |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
41 |
*/ |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
42 |
public class TypeAnnotations { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
43 |
private static final Context.Key<TypeAnnotations> key |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
44 |
= new Context.Key<TypeAnnotations>(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
45 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
46 |
public static TypeAnnotations instance(Context context) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
47 |
TypeAnnotations instance = context.get(key); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
48 |
if (instance == null) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
49 |
instance = new TypeAnnotations(context); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
50 |
return instance; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
51 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
52 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
53 |
protected TypeAnnotations(Context context) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
54 |
context.put(key, this); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
55 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
56 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
57 |
public void taFillAndLift(JCClassDecl tree, boolean visitBodies) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
58 |
new TypeAnnotationPositions().scan(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
59 |
new TypeAnnotationLift().scan(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
60 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
61 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
62 |
private static class TypeAnnotationPositions extends TreeScanner { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
63 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
64 |
private ListBuffer<JCTree> frames = ListBuffer.lb(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
65 |
private void push(JCTree t) { frames = frames.prepend(t); } |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
66 |
private JCTree pop() { return frames.next(); } |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
67 |
private JCTree peek2() { return frames.toList().tail.head; } |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
68 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
69 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
70 |
public void scan(JCTree tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
71 |
push(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
72 |
super.scan(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
73 |
pop(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
74 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
75 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
76 |
private boolean inClass = false; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
77 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
78 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
79 |
public void visitClassDef(JCClassDecl tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
80 |
if (!inClass) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
81 |
// Do not recurse into nested and inner classes since |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
82 |
// TransTypes.visitClassDef makes an invocation for each class |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
83 |
// separately. |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
84 |
inClass = true; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
85 |
try { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
86 |
super.visitClassDef(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
87 |
} finally { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
88 |
inClass = false; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
89 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
90 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
91 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
92 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
93 |
private TypeAnnotationPosition resolveFrame(JCTree tree, JCTree frame, |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
94 |
List<JCTree> path, TypeAnnotationPosition p) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
95 |
switch (frame.getKind()) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
96 |
case TYPE_CAST: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
97 |
p.type = TargetType.TYPECAST; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
98 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
99 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
100 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
101 |
case INSTANCE_OF: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
102 |
p.type = TargetType.INSTANCEOF; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
103 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
104 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
105 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
106 |
case NEW_CLASS: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
107 |
p.type = TargetType.NEW; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
108 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
109 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
110 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
111 |
case NEW_ARRAY: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
112 |
p.type = TargetType.NEW; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
113 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
114 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
115 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
116 |
case CLASS: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
117 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
118 |
if (((JCClassDecl)frame).extending == tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
119 |
p.type = TargetType.CLASS_EXTENDS; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
120 |
p.type_index = -1; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
121 |
} else if (((JCClassDecl)frame).implementing.contains(tree)) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
122 |
p.type = TargetType.CLASS_EXTENDS; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
123 |
p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
124 |
} else if (((JCClassDecl)frame).typarams.contains(tree)) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
125 |
p.type = TargetType.CLASS_TYPE_PARAMETER; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
126 |
p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
127 |
} else |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
128 |
throw new AssertionError(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
129 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
130 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
131 |
case METHOD: { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
132 |
JCMethodDecl frameMethod = (JCMethodDecl)frame; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
133 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
134 |
if (frameMethod.receiverAnnotations.contains(tree)) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
135 |
p.type = TargetType.METHOD_RECEIVER; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
136 |
else if (frameMethod.thrown.contains(tree)) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
137 |
p.type = TargetType.THROWS; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
138 |
p.type_index = frameMethod.thrown.indexOf(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
139 |
} else if (((JCMethodDecl)frame).restype == tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
140 |
p.type = TargetType.METHOD_RETURN_GENERIC_OR_ARRAY; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
141 |
} else if (frameMethod.typarams.contains(tree)) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
142 |
p.type = TargetType.METHOD_TYPE_PARAMETER; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
143 |
p.parameter_index = frameMethod.typarams.indexOf(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
144 |
} else |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
145 |
throw new AssertionError(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
146 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
147 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
148 |
case MEMBER_SELECT: { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
149 |
JCFieldAccess fieldFrame = (JCFieldAccess)frame; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
150 |
if ("class".contentEquals(fieldFrame.name)) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
151 |
p.type = TargetType.CLASS_LITERAL; |
4872
6c49b0ac56a6
6919986: [308] change size of type_index (of CLASS_EXTENDS and THROWS) from byte to short
jjg
parents:
4865
diff
changeset
|
152 |
p.pos = TreeInfo.innermostType(fieldFrame.selected).pos; |
4865
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
153 |
} else |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
154 |
throw new AssertionError(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
155 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
156 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
157 |
case PARAMETERIZED_TYPE: { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
158 |
TypeAnnotationPosition nextP; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
159 |
if (((JCTypeApply)frame).clazz == tree) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
160 |
nextP = p; // generic: RAW; noop |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
161 |
else if (((JCTypeApply)frame).arguments.contains(tree)) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
162 |
p.location = p.location.prepend( |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
163 |
((JCTypeApply)frame).arguments.indexOf(tree)); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
164 |
else |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
165 |
throw new AssertionError(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
166 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
167 |
List<JCTree> newPath = path.tail; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
168 |
return resolveFrame(newPath.head, newPath.tail.head, newPath, p); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
169 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
170 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
171 |
case ARRAY_TYPE: { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
172 |
p.location = p.location.prepend(0); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
173 |
List<JCTree> newPath = path.tail; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
174 |
return resolveFrame(newPath.head, newPath.tail.head, newPath, p); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
175 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
176 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
177 |
case TYPE_PARAMETER: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
178 |
if (path.tail.tail.head.getTag() == JCTree.CLASSDEF) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
179 |
JCClassDecl clazz = (JCClassDecl)path.tail.tail.head; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
180 |
p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
181 |
p.parameter_index = clazz.typarams.indexOf(path.tail.head); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
182 |
p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
183 |
} else if (path.tail.tail.head.getTag() == JCTree.METHODDEF) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
184 |
JCMethodDecl method = (JCMethodDecl)path.tail.tail.head; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
185 |
p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
186 |
p.parameter_index = method.typarams.indexOf(path.tail.head); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
187 |
p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
188 |
} else |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
189 |
throw new AssertionError(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
190 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
191 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
192 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
193 |
case VARIABLE: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
194 |
VarSymbol v = ((JCVariableDecl)frame).sym; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
195 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
196 |
switch (v.getKind()) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
197 |
case LOCAL_VARIABLE: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
198 |
p.type = TargetType.LOCAL_VARIABLE; break; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
199 |
case FIELD: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
200 |
p.type = TargetType.FIELD_GENERIC_OR_ARRAY; break; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
201 |
case PARAMETER: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
202 |
p.type = TargetType.METHOD_PARAMETER_GENERIC_OR_ARRAY; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
203 |
p.parameter_index = methodParamIndex(path, frame); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
204 |
break; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
205 |
default: throw new AssertionError(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
206 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
207 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
208 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
209 |
case ANNOTATED_TYPE: { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
210 |
List<JCTree> newPath = path.tail; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
211 |
return resolveFrame(newPath.head, newPath.tail.head, |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
212 |
newPath, p); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
213 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
214 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
215 |
case METHOD_INVOCATION: { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
216 |
JCMethodInvocation invocation = (JCMethodInvocation)frame; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
217 |
if (!invocation.typeargs.contains(tree)) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
218 |
throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
219 |
p.type = TargetType.METHOD_TYPE_ARGUMENT; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
220 |
p.pos = invocation.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
221 |
p.type_index = invocation.typeargs.indexOf(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
222 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
223 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
224 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
225 |
case EXTENDS_WILDCARD: |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
226 |
case SUPER_WILDCARD: { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
227 |
p.type = TargetType.WILDCARD_BOUND; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
228 |
List<JCTree> newPath = path.tail; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
229 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
230 |
TypeAnnotationPosition wildcard = |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
231 |
resolveFrame(newPath.head, newPath.tail.head, newPath, |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
232 |
new TypeAnnotationPosition()); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
233 |
if (!wildcard.location.isEmpty()) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
234 |
wildcard.type = wildcard.type.getGenericComplement(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
235 |
p.wildcard_position = wildcard; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
236 |
p.pos = frame.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
237 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
238 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
239 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
240 |
return p; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
241 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
242 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
243 |
private void setTypeAnnotationPos(List<JCTypeAnnotation> annotations, TypeAnnotationPosition position) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
244 |
for (JCTypeAnnotation anno : annotations) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
245 |
anno.annotation_position = position; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
246 |
anno.attribute_field.position = position; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
247 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
248 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
249 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
250 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
251 |
public void visitNewArray(JCNewArray tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
252 |
findPosition(tree, tree, tree.annotations); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
253 |
int dimAnnosCount = tree.dimAnnotations.size(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
254 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
255 |
// handle annotations associated with dimentions |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
256 |
for (int i = 0; i < dimAnnosCount; ++i) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
257 |
TypeAnnotationPosition p = new TypeAnnotationPosition(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
258 |
p.type = TargetType.NEW_GENERIC_OR_ARRAY; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
259 |
p.pos = tree.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
260 |
p.location = p.location.append(i); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
261 |
setTypeAnnotationPos(tree.dimAnnotations.get(i), p); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
262 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
263 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
264 |
// handle "free" annotations |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
265 |
int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
266 |
JCExpression elemType = tree.elemtype; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
267 |
while (elemType != null) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
268 |
if (elemType.getTag() == JCTree.ANNOTATED_TYPE) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
269 |
JCAnnotatedType at = (JCAnnotatedType)elemType; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
270 |
TypeAnnotationPosition p = new TypeAnnotationPosition(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
271 |
p.type = TargetType.NEW_GENERIC_OR_ARRAY; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
272 |
p.pos = tree.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
273 |
p.location = p.location.append(i); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
274 |
setTypeAnnotationPos(at.annotations, p); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
275 |
elemType = at.underlyingType; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
276 |
} else if (elemType.getTag() == JCTree.TYPEARRAY) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
277 |
++i; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
278 |
elemType = ((JCArrayTypeTree)elemType).elemtype; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
279 |
} else |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
280 |
break; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
281 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
282 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
283 |
// find annotations locations of initializer elements |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
284 |
scan(tree.elems); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
285 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
286 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
287 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
288 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
289 |
findPosition(tree, peek2(), tree.annotations); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
290 |
super.visitAnnotatedType(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
291 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
292 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
293 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
294 |
public void visitMethodDef(JCMethodDecl tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
295 |
TypeAnnotationPosition p = new TypeAnnotationPosition(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
296 |
p.type = TargetType.METHOD_RECEIVER; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
297 |
setTypeAnnotationPos(tree.receiverAnnotations, p); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
298 |
super.visitMethodDef(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
299 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
300 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
301 |
public void visitTypeParameter(JCTypeParameter tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
302 |
findPosition(tree, peek2(), tree.annotations); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
303 |
super.visitTypeParameter(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
304 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
305 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
306 |
void findPosition(JCTree tree, JCTree frame, List<JCTypeAnnotation> annotations) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
307 |
if (!annotations.isEmpty()) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
308 |
TypeAnnotationPosition p = |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
309 |
resolveFrame(tree, frame, frames.toList(), |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
310 |
new TypeAnnotationPosition()); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
311 |
if (!p.location.isEmpty()) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
312 |
p.type = p.type.getGenericComplement(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
313 |
setTypeAnnotationPos(annotations, p); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
314 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
315 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
316 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
317 |
private int methodParamIndex(List<JCTree> path, JCTree param) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
318 |
List<JCTree> curr = path; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
319 |
if (curr.head != param) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
320 |
curr = path.tail; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
321 |
JCMethodDecl method = (JCMethodDecl)curr.tail.head; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
322 |
return method.params.indexOf(param); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
323 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
324 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
325 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
326 |
private static class TypeAnnotationLift extends TreeScanner { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
327 |
List<Attribute.TypeCompound> recordedTypeAnnotations = List.nil(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
328 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
329 |
boolean isInner = false; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
330 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
331 |
public void visitClassDef(JCClassDecl tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
332 |
if (isInner) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
333 |
// tree is an inner class tree. stop now. |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
334 |
// TransTypes.visitClassDef makes an invocation for each class |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
335 |
// separately. |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
336 |
return; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
337 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
338 |
isInner = true; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
339 |
List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
340 |
recordedTypeAnnotations = List.nil(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
341 |
try { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
342 |
super.visitClassDef(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
343 |
} finally { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
344 |
tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
345 |
recordedTypeAnnotations = prevTAs; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
346 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
347 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
348 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
349 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
350 |
public void visitMethodDef(JCMethodDecl tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
351 |
List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
352 |
recordedTypeAnnotations = List.nil(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
353 |
try { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
354 |
super.visitMethodDef(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
355 |
} finally { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
356 |
tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
357 |
recordedTypeAnnotations = prevTAs; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
358 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
359 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
360 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
361 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
362 |
public void visitVarDef(JCVariableDecl tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
363 |
List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
364 |
recordedTypeAnnotations = List.nil(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
365 |
ElementKind kind = tree.sym.getKind(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
366 |
if (kind == ElementKind.LOCAL_VARIABLE && tree.mods.annotations.nonEmpty()) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
367 |
// need to lift the annotations |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
368 |
TypeAnnotationPosition position = new TypeAnnotationPosition(); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
369 |
position.pos = tree.pos; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
370 |
position.type = TargetType.LOCAL_VARIABLE; |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
371 |
for (Attribute.Compound attribute : tree.sym.attributes_field) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
372 |
Attribute.TypeCompound tc = |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
373 |
new Attribute.TypeCompound(attribute.type, attribute.values, position); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
374 |
recordedTypeAnnotations = recordedTypeAnnotations.append(tc); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
375 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
376 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
377 |
try { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
378 |
super.visitVarDef(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
379 |
} finally { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
380 |
if (kind.isField() || kind == ElementKind.LOCAL_VARIABLE) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
381 |
tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
382 |
recordedTypeAnnotations = kind.isField() ? prevTAs : prevTAs.appendList(recordedTypeAnnotations); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
383 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
384 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
385 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
386 |
@Override |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
387 |
public void visitApply(JCMethodInvocation tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
388 |
scan(tree.meth); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
389 |
scan(tree.typeargs); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
390 |
scan(tree.args); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
391 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
392 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
393 |
public void visitAnnotation(JCAnnotation tree) { |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
394 |
if (tree instanceof JCTypeAnnotation) |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
395 |
recordedTypeAnnotations = recordedTypeAnnotations.append(((JCTypeAnnotation)tree).attribute_field); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
396 |
super.visitAnnotation(tree); |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
397 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
398 |
} |
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
399 |
|
1e4422ac2495
6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff
changeset
|
400 |
} |