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 class ClassElementParser extends PartialParser { | 5 class ClassElementParser extends PartialParser { |
6 ClassElementParser(Listener listener) : super(listener); | 6 ClassElementParser(Listener listener) : super(listener); |
7 | 7 |
8 Token parseClassBody(Token token) => fullParseClassBody(token); | 8 Token parseClassBody(Token token) => fullParseClassBody(token); |
9 } | 9 } |
10 | 10 |
11 class PartialClassElement extends ClassElement { | 11 class PartialClassElement extends ClassElement { |
12 final Token beginToken; | 12 final Token beginToken; |
13 final Token endToken; | 13 final Token endToken; |
14 Node cachedNode; | 14 Node cachedNode; |
15 | 15 |
16 PartialClassElement(SourceString name, | 16 PartialClassElement(SourceString name, |
17 Token this.beginToken, | 17 Token this.beginToken, |
18 Token this.endToken, | 18 Token this.endToken, |
19 CompilationUnitElement enclosing, | 19 CompilationUnitElement enclosing, |
20 int id) | 20 int id) |
21 : super(name, enclosing, id); | 21 : super(name, enclosing, id); |
22 | 22 |
23 ClassNode parseNode(DiagnosticListener diagnosticListener) { | 23 ClassNode parseNode(DiagnosticListener diagnosticListener) { |
24 if (cachedNode != null) return cachedNode; | 24 if (cachedNode != null) return cachedNode; |
25 MemberListener listener = new MemberListener(diagnosticListener, this); | 25 MemberListener listener = new MemberListener(diagnosticListener, this); |
26 Parser parser = new ClassElementParser(listener); | 26 Parser parser = new ClassElementParser(listener); |
27 Token token = parser.parseTopLevelDeclaration(beginToken); | 27 Token token = parser.parseTopLevelDeclaration(beginToken); |
28 assert(token === endToken.next); | 28 assert(token === endToken.next); |
29 cachedNode = listener.popNode(); | 29 cachedNode = listener.popNode(); |
30 assert(listener.nodes.isEmpty()); | 30 assert(listener.nodes.isEmpty()); |
31 return cachedNode; | 31 return cachedNode; |
32 } | 32 } |
33 | 33 |
34 Token position() => beginToken; | 34 Token position() => beginToken; |
35 | 35 |
36 bool isInterface() => beginToken.stringValue === "interface"; | 36 bool isInterface() => beginToken.stringValue === "interface"; |
37 | |
38 PartialClassElement cloneTo(CompilationUnitElement enclosing, | |
39 DiagnosticListener listener) { | |
40 parseNode(listener); | |
41 PartialClassElement result = | |
42 new PartialClassElement(name, beginToken, endToken, enclosing, id); | |
43 cloneMembersTo(result, listener); | |
44 result.cachedNode = cachedNode; | |
45 result.scriptOverride = getScript(); | |
46 return result; | |
47 } | |
48 } | 37 } |
49 | 38 |
50 class MemberListener extends NodeListener { | 39 class MemberListener extends NodeListener { |
51 final ClassElement enclosingElement; | 40 final ClassElement enclosingElement; |
52 | 41 |
53 MemberListener(DiagnosticListener listener, | 42 MemberListener(DiagnosticListener listener, |
54 Element enclosingElement) | 43 Element enclosingElement) |
55 : this.enclosingElement = enclosingElement, | 44 : this.enclosingElement = enclosingElement, |
56 super(listener, enclosingElement.getCompilationUnit()); | 45 super(listener, enclosingElement.getCompilationUnit()); |
57 | 46 |
58 bool isConstructorName(Node nameNode) { | 47 bool isConstructorName(Node nameNode) { |
59 if (enclosingElement === null || | 48 if (enclosingElement === null || |
60 enclosingElement.kind != ElementKind.CLASS) { | 49 enclosingElement.kind != ElementKind.CLASS) { |
61 return false; | 50 return false; |
62 } | 51 } |
63 SourceString name; | 52 SourceString name; |
64 if (nameNode.asIdentifier() !== null) { | 53 if (nameNode.asIdentifier() !== null) { |
65 name = nameNode.asIdentifier().source; | 54 name = nameNode.asIdentifier().source; |
66 } else { | 55 } else { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 129 } |
141 | 130 |
142 void endInitializers(int count, Token beginToken, Token endToken) { | 131 void endInitializers(int count, Token beginToken, Token endToken) { |
143 pushNode(null); | 132 pushNode(null); |
144 } | 133 } |
145 | 134 |
146 void addMember(Element memberElement) { | 135 void addMember(Element memberElement) { |
147 enclosingElement.addMember(memberElement, listener); | 136 enclosingElement.addMember(memberElement, listener); |
148 } | 137 } |
149 } | 138 } |
OLD | NEW |