OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of scanner; | 5 part of scanner; |
6 | 6 |
7 class ClassElementParser extends PartialParser { | 7 class ClassElementParser extends PartialParser { |
8 ClassElementParser(Listener listener) : super(listener); | 8 ClassElementParser(Listener listener) : super(listener); |
9 | 9 |
10 Token parseClassBody(Token token) => fullParseClassBody(token); | 10 Token parseClassBody(Token token) => fullParseClassBody(token); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 SourceString name; | 81 SourceString name; |
82 if (nameNode.asIdentifier() != null) { | 82 if (nameNode.asIdentifier() != null) { |
83 name = nameNode.asIdentifier().source; | 83 name = nameNode.asIdentifier().source; |
84 } else { | 84 } else { |
85 Send send = nameNode.asSend(); | 85 Send send = nameNode.asSend(); |
86 name = send.receiver.asIdentifier().source; | 86 name = send.receiver.asIdentifier().source; |
87 } | 87 } |
88 return enclosingElement.name == name; | 88 return enclosingElement.name == name; |
89 } | 89 } |
90 | 90 |
| 91 // TODO(johnniwinther): Remove this method. |
91 SourceString getMethodNameHack(Node methodName) { | 92 SourceString getMethodNameHack(Node methodName) { |
92 Send send = methodName.asSend(); | 93 Send send = methodName.asSend(); |
93 if (send == null) return methodName.asIdentifier().source; | 94 if (send == null) return methodName.asIdentifier().source; |
94 Identifier receiver = send.receiver.asIdentifier(); | 95 Identifier receiver = send.receiver.asIdentifier(); |
95 Identifier selector = send.selector.asIdentifier(); | 96 Identifier selector = send.selector.asIdentifier(); |
96 Operator operator = selector.asOperator(); | 97 Operator operator = selector.asOperator(); |
97 if (operator != null) { | 98 if (operator != null) { |
98 assert(identical(receiver.source.stringValue, 'operator')); | 99 assert(identical(receiver.source.stringValue, 'operator')); |
99 // TODO(ahe): It is a hack to compare to ')', but it beats | 100 // TODO(ahe): It is a hack to compare to ')', but it beats |
100 // parsing the node. | 101 // parsing the node. |
101 bool isUnary = identical(operator.token.next.next.stringValue, ')'); | 102 bool isUnary = identical(operator.token.next.next.stringValue, ')'); |
102 return Elements.constructOperatorName(operator.source, isUnary); | 103 return Elements.constructOperatorName(operator.source, isUnary); |
103 } else { | 104 } else { |
104 if (receiver == null) { | 105 if (receiver == null) { |
105 listener.cancel('library prefix in named factory constructor not ' | 106 listener.cancel('library prefix in named factory constructor not ' |
106 'implemented', node: send.receiver); | 107 'implemented', node: send.receiver); |
107 } | 108 } |
108 if (receiver.source != enclosingElement.name) { | 109 if (receiver.source != enclosingElement.name) { |
109 listener.onDeprecatedFeature(receiver, 'interface factories'); | 110 listener.reportErrorCode(receiver, |
| 111 MessageKind.INVALID_CONSTRUCTOR_NAME, |
| 112 {'name': enclosingElement.name}); |
110 } | 113 } |
111 return Elements.constructConstructorName(receiver.source, | 114 return Elements.constructConstructorName(receiver.source, |
112 selector.source); | 115 selector.source); |
113 } | 116 } |
114 } | 117 } |
115 | 118 |
116 void endMethod(Token getOrSet, Token beginToken, Token endToken) { | 119 void endMethod(Token getOrSet, Token beginToken, Token endToken) { |
117 super.endMethod(getOrSet, beginToken, endToken); | 120 super.endMethod(getOrSet, beginToken, endToken); |
118 FunctionExpression method = popNode(); | 121 FunctionExpression method = popNode(); |
119 pushNode(null); | 122 pushNode(null); |
(...skipping 16 matching lines...) Expand all Loading... |
136 } | 139 } |
137 | 140 |
138 void endFactoryMethod(Token beginToken, Token endToken) { | 141 void endFactoryMethod(Token beginToken, Token endToken) { |
139 super.endFactoryMethod(beginToken, endToken); | 142 super.endFactoryMethod(beginToken, endToken); |
140 FunctionExpression method = popNode(); | 143 FunctionExpression method = popNode(); |
141 pushNode(null); | 144 pushNode(null); |
142 SourceString name = getMethodNameHack(method.name); | 145 SourceString name = getMethodNameHack(method.name); |
143 Identifier singleIdentifierName = method.name.asIdentifier(); | 146 Identifier singleIdentifierName = method.name.asIdentifier(); |
144 if (singleIdentifierName != null && singleIdentifierName.source == name) { | 147 if (singleIdentifierName != null && singleIdentifierName.source == name) { |
145 if (name != enclosingElement.name) { | 148 if (name != enclosingElement.name) { |
146 listener.onDeprecatedFeature(method.name, 'interface factories'); | 149 listener.reportErrorCode(singleIdentifierName, |
| 150 MessageKind.INVALID_UNNAMED_CONSTRUCTOR_NAME, |
| 151 {'name': enclosingElement.name}); |
147 } | 152 } |
148 } | 153 } |
149 ElementKind kind = ElementKind.FUNCTION; | 154 ElementKind kind = ElementKind.FUNCTION; |
150 Element memberElement = | 155 Element memberElement = |
151 new PartialFunctionElement(name, beginToken, null, endToken, | 156 new PartialFunctionElement(name, beginToken, null, endToken, |
152 kind, method.modifiers, enclosingElement); | 157 kind, method.modifiers, enclosingElement); |
153 addMember(memberElement); | 158 addMember(memberElement); |
154 } | 159 } |
155 | 160 |
156 void endFields(int count, Token beginToken, Token endToken) { | 161 void endFields(int count, Token beginToken, Token endToken) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 193 |
189 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 194 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
190 popNode(); // Discard arguments. | 195 popNode(); // Discard arguments. |
191 if (periodBeforeName != null) { | 196 if (periodBeforeName != null) { |
192 popNode(); // Discard name. | 197 popNode(); // Discard name. |
193 } | 198 } |
194 popNode(); // Discard node (Send or Identifier). | 199 popNode(); // Discard node (Send or Identifier). |
195 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); | 200 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); |
196 } | 201 } |
197 } | 202 } |
OLD | NEW |