1 /* |
1 /* |
2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
28 import com.sun.tools.javac.util.*; |
28 import com.sun.tools.javac.util.*; |
29 import com.sun.tools.javac.code.*; |
29 import com.sun.tools.javac.code.*; |
30 import com.sun.tools.javac.code.Symbol.*; |
30 import com.sun.tools.javac.code.Symbol.*; |
31 import com.sun.tools.javac.tree.*; |
31 import com.sun.tools.javac.tree.*; |
32 import com.sun.tools.javac.tree.JCTree.*; |
32 import com.sun.tools.javac.tree.JCTree.*; |
|
33 |
|
34 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
33 |
35 |
34 /** Enter annotations on symbols. Annotations accumulate in a queue, |
36 /** Enter annotations on symbols. Annotations accumulate in a queue, |
35 * which is processed at the top level of any set of recursive calls |
37 * which is processed at the top level of any set of recursive calls |
36 * requesting it be processed. |
38 * requesting it be processed. |
37 * |
39 * |
146 log.error(a.annotationType.pos(), |
148 log.error(a.annotationType.pos(), |
147 "not.annotation.type", a.type.toString()); |
149 "not.annotation.type", a.type.toString()); |
148 return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil()); |
150 return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil()); |
149 } |
151 } |
150 List<JCExpression> args = a.args; |
152 List<JCExpression> args = a.args; |
151 if (args.length() == 1 && args.head.getTag() != JCTree.ASSIGN) { |
153 if (args.length() == 1 && !args.head.hasTag(ASSIGN)) { |
152 // special case: elided "value=" assumed |
154 // special case: elided "value=" assumed |
153 args.head = make.at(args.head.pos). |
155 args.head = make.at(args.head.pos). |
154 Assign(make.Ident(names.value), args.head); |
156 Assign(make.Ident(names.value), args.head); |
155 } |
157 } |
156 ListBuffer<Pair<MethodSymbol,Attribute>> buf = |
158 ListBuffer<Pair<MethodSymbol,Attribute>> buf = |
157 new ListBuffer<Pair<MethodSymbol,Attribute>>(); |
159 new ListBuffer<Pair<MethodSymbol,Attribute>>(); |
158 for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) { |
160 for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) { |
159 JCExpression t = tl.head; |
161 JCExpression t = tl.head; |
160 if (t.getTag() != JCTree.ASSIGN) { |
162 if (!t.hasTag(ASSIGN)) { |
161 log.error(t.pos(), "annotation.value.must.be.name.value"); |
163 log.error(t.pos(), "annotation.value.must.be.name.value"); |
162 continue; |
164 continue; |
163 } |
165 } |
164 JCAssign assign = (JCAssign)t; |
166 JCAssign assign = (JCAssign)t; |
165 if (assign.lhs.getTag() != JCTree.IDENT) { |
167 if (!assign.lhs.hasTag(IDENT)) { |
166 log.error(t.pos(), "annotation.value.must.be.name.value"); |
168 log.error(t.pos(), "annotation.value.must.be.name.value"); |
167 continue; |
169 continue; |
168 } |
170 } |
169 JCIdent left = (JCIdent)assign.lhs; |
171 JCIdent left = (JCIdent)assign.lhs; |
170 Symbol method = rs.resolveQualifiedMethod(left.pos(), |
172 Symbol method = rs.resolveQualifiedMethod(left.pos(), |
220 } |
222 } |
221 return new Attribute.Class(types, |
223 return new Attribute.Class(types, |
222 (((JCFieldAccess) tree).selected).type); |
224 (((JCFieldAccess) tree).selected).type); |
223 } |
225 } |
224 if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) { |
226 if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) { |
225 if (tree.getTag() != JCTree.ANNOTATION) { |
227 if (!tree.hasTag(ANNOTATION)) { |
226 log.error(tree.pos(), "annotation.value.must.be.annotation"); |
228 log.error(tree.pos(), "annotation.value.must.be.annotation"); |
227 expected = syms.errorType; |
229 expected = syms.errorType; |
228 } |
230 } |
229 return enterAnnotation((JCAnnotation)tree, expected, env); |
231 return enterAnnotation((JCAnnotation)tree, expected, env); |
230 } |
232 } |
231 if (expected.tag == TypeTags.ARRAY) { // should really be isArray() |
233 if (expected.tag == TypeTags.ARRAY) { // should really be isArray() |
232 if (tree.getTag() != JCTree.NEWARRAY) { |
234 if (!tree.hasTag(NEWARRAY)) { |
233 tree = make.at(tree.pos). |
235 tree = make.at(tree.pos). |
234 NewArray(null, List.<JCExpression>nil(), List.of(tree)); |
236 NewArray(null, List.<JCExpression>nil(), List.of(tree)); |
235 } |
237 } |
236 JCNewArray na = (JCNewArray)tree; |
238 JCNewArray na = (JCNewArray)tree; |
237 if (na.elemtype != null) { |
239 if (na.elemtype != null) { |