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 package com.google.dart.compiler.ast; | 5 package com.google.dart.compiler.ast; |
6 | 6 |
7 import com.google.dart.compiler.common.Symbol; | 7 import com.google.dart.compiler.common.Symbol; |
8 import com.google.dart.compiler.resolver.MethodElement; | 8 import com.google.dart.compiler.resolver.MethodElement; |
9 | 9 |
10 import java.util.Collections; | 10 import java.util.Collections; |
11 import java.util.List; | 11 import java.util.List; |
12 | 12 |
13 /** | 13 /** |
14 * Represents a Dart method definition. | 14 * Represents a Dart method definition. |
15 */ | 15 */ |
16 public class DartMethodDefinition extends DartClassMember<DartExpression> { | 16 public class DartMethodDefinition extends DartClassMember<DartExpression> { |
17 | 17 |
18 protected DartFunction function; | 18 protected DartFunction function; |
19 private MethodElement element; | 19 private MethodElement element; |
20 private DartMethodDefinition normalizedNode = this; | 20 private DartMethodDefinition normalizedNode = this; |
21 private final List<DartTypeParameter> typeParameters; | |
22 | 21 |
23 public static DartMethodDefinition create(DartExpression name, | 22 public static DartMethodDefinition create(DartExpression name, |
24 DartFunction function, | 23 DartFunction function, |
25 Modifiers modifiers, | 24 Modifiers modifiers, |
26 List<DartInitializer> initializers, | 25 List<DartInitializer> initializers)
{ |
27 List<DartTypeParameter> typeParamete
rs) { | |
28 if (initializers == null) { | 26 if (initializers == null) { |
29 return new DartMethodDefinition(name, function, modifiers, typeParameters)
; | 27 return new DartMethodDefinition(name, function, modifiers); |
30 } else { | 28 } else { |
31 return new DartMethodWithInitializersDefinition(name, function, modifiers,
initializers); | 29 return new DartMethodWithInitializersDefinition(name, function, modifiers, |
| 30 initializers); |
32 } | 31 } |
33 } | 32 } |
34 | 33 |
35 private DartMethodDefinition(DartExpression name, DartFunction function, Modif
iers modifiers, | 34 private DartMethodDefinition(DartExpression name, DartFunction function, Modif
iers modifiers) { |
36 List<DartTypeParameter> typeParameters) { | |
37 super(name, modifiers); | 35 super(name, modifiers); |
38 this.function = becomeParentOf(function); | 36 this.function = becomeParentOf(function); |
39 this.typeParameters = typeParameters; | |
40 } | 37 } |
41 | 38 |
42 public DartFunction getFunction() { | 39 public DartFunction getFunction() { |
43 return function; | 40 return function; |
44 } | 41 } |
45 | 42 |
46 @Override | 43 @Override |
47 public MethodElement getSymbol() { | 44 public MethodElement getSymbol() { |
48 return element; | 45 return element; |
49 } | 46 } |
(...skipping 10 matching lines...) Expand all Loading... |
60 | 57 |
61 @Override | 58 @Override |
62 public DartMethodDefinition getNormalizedNode() { | 59 public DartMethodDefinition getNormalizedNode() { |
63 return normalizedNode; | 60 return normalizedNode; |
64 } | 61 } |
65 | 62 |
66 public List<DartInitializer> getInitializers() { | 63 public List<DartInitializer> getInitializers() { |
67 return Collections.emptyList(); | 64 return Collections.emptyList(); |
68 } | 65 } |
69 | 66 |
70 public List<DartTypeParameter> getTypeParameters() { | |
71 return typeParameters; | |
72 } | |
73 | |
74 @Override | 67 @Override |
75 public void traverse(DartVisitor v, DartContext ctx) { | 68 public void traverse(DartVisitor v, DartContext ctx) { |
76 if (v.visit(this, ctx)) { | 69 if (v.visit(this, ctx)) { |
77 function = becomeParentOf(v.accept(function)); | 70 function = becomeParentOf(v.accept(function)); |
78 } | 71 } |
79 v.endVisit(this, ctx); | 72 v.endVisit(this, ctx); |
80 } | 73 } |
81 | 74 |
82 @Override | 75 @Override |
83 public void visitChildren(DartPlainVisitor<?> visitor) { | 76 public void visitChildren(DartPlainVisitor<?> visitor) { |
84 super.visitChildren(visitor); | 77 super.visitChildren(visitor); |
85 function.accept(visitor); | 78 function.accept(visitor); |
86 } | 79 } |
87 | 80 |
88 @Override | 81 @Override |
89 public <R> R accept(DartPlainVisitor<R> visitor) { | 82 public <R> R accept(DartPlainVisitor<R> visitor) { |
90 return visitor.visitMethodDefinition(this); | 83 return visitor.visitMethodDefinition(this); |
91 } | 84 } |
92 | 85 |
93 private static class DartMethodWithInitializersDefinition extends DartMethodDe
finition { | 86 private static class DartMethodWithInitializersDefinition extends DartMethodDe
finition { |
94 | 87 |
95 private final List<DartInitializer> initializers; | 88 private final List<DartInitializer> initializers; |
96 | 89 |
97 DartMethodWithInitializersDefinition(DartExpression name, | 90 DartMethodWithInitializersDefinition(DartExpression name, |
98 DartFunction function, | 91 DartFunction function, |
99 Modifiers modifiers, | 92 Modifiers modifiers, |
100 List<DartInitializer> initializers) { | 93 List<DartInitializer> initializers) { |
101 super(name, function, modifiers, null); | 94 super(name, function, modifiers); |
102 this.initializers = becomeParentOf(initializers); | 95 this.initializers = becomeParentOf(initializers); |
103 } | 96 } |
104 | 97 |
105 @Override | 98 @Override |
106 public List<DartInitializer> getInitializers() { | 99 public List<DartInitializer> getInitializers() { |
107 return initializers; | 100 return initializers; |
108 } | 101 } |
109 | 102 |
110 @Override | 103 @Override |
111 public void traverse(DartVisitor v, DartContext ctx) { | 104 public void traverse(DartVisitor v, DartContext ctx) { |
112 if (v.visit(this, ctx)) { | 105 if (v.visit(this, ctx)) { |
113 function = becomeParentOf(v.accept(function)); | 106 function = becomeParentOf(v.accept(function)); |
114 v.acceptWithInsertRemove(this, initializers); | 107 v.acceptWithInsertRemove(this, initializers); |
115 } | 108 } |
116 v.endVisit(this, ctx); | 109 v.endVisit(this, ctx); |
117 } | 110 } |
118 | 111 |
119 @Override | 112 @Override |
120 public void visitChildren(DartPlainVisitor<?> visitor) { | 113 public void visitChildren(DartPlainVisitor<?> visitor) { |
121 super.visitChildren(visitor); | 114 super.visitChildren(visitor); |
122 visitor.visit(initializers); | 115 visitor.visit(initializers); |
123 if (getTypeParameters() != null) { | |
124 visitor.visit(getTypeParameters()); | |
125 } | |
126 } | 116 } |
127 } | 117 } |
128 } | 118 } |
OLD | NEW |