OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 import static com.google.dart.engine.element.ElementFactory.classElement; | 50 import static com.google.dart.engine.element.ElementFactory.classElement; |
51 import static com.google.dart.engine.element.ElementFactory.constructorElement; | 51 import static com.google.dart.engine.element.ElementFactory.constructorElement; |
52 import static com.google.dart.engine.element.ElementFactory.functionElement; | 52 import static com.google.dart.engine.element.ElementFactory.functionElement; |
53 import static com.google.dart.engine.element.ElementFactory.library; | 53 import static com.google.dart.engine.element.ElementFactory.library; |
54 import static com.google.dart.engine.element.ElementFactory.methodElement; | 54 import static com.google.dart.engine.element.ElementFactory.methodElement; |
55 | 55 |
56 public class ScopeBuilderTest extends EngineTestCase { | 56 public class ScopeBuilderTest extends EngineTestCase { |
57 public void test_scopeFor_ClassDeclaration() throws AnalysisException { | 57 public void test_scopeFor_ClassDeclaration() throws AnalysisException { |
58 GatheringErrorListener listener = new GatheringErrorListener(); | 58 GatheringErrorListener listener = new GatheringErrorListener(); |
59 Scope scope = ScopeBuilder.scopeFor(createResolvedClassDeclaration(), listen
er); | 59 Scope scope = ScopeBuilder.scopeFor(createResolvedClassDeclaration(), listen
er); |
60 assertInstanceOf(ClassScope.class, scope); | 60 assertInstanceOf(LibraryScope.class, scope); |
61 } | 61 } |
62 | 62 |
63 public void test_scopeFor_ClassTypeAlias() throws AnalysisException { | 63 public void test_scopeFor_ClassTypeAlias() throws AnalysisException { |
64 GatheringErrorListener listener = new GatheringErrorListener(); | 64 GatheringErrorListener listener = new GatheringErrorListener(); |
65 Scope scope = ScopeBuilder.scopeFor(createResolvedClassTypeAlias(), listener
); | 65 Scope scope = ScopeBuilder.scopeFor(createResolvedClassTypeAlias(), listener
); |
66 assertInstanceOf(ClassScope.class, scope); | 66 assertInstanceOf(LibraryScope.class, scope); |
67 } | 67 } |
68 | 68 |
69 public void test_scopeFor_CompilationUnit() throws AnalysisException { | 69 public void test_scopeFor_CompilationUnit() throws AnalysisException { |
70 GatheringErrorListener listener = new GatheringErrorListener(); | 70 GatheringErrorListener listener = new GatheringErrorListener(); |
71 Scope scope = ScopeBuilder.scopeFor(createResolvedCompilationUnit(), listene
r); | 71 Scope scope = ScopeBuilder.scopeFor(createResolvedCompilationUnit(), listene
r); |
72 assertInstanceOf(LibraryScope.class, scope); | 72 assertInstanceOf(LibraryScope.class, scope); |
73 } | 73 } |
74 | 74 |
75 public void test_scopeFor_ConstructorDeclaration() throws AnalysisException { | 75 public void test_scopeFor_ConstructorDeclaration() throws AnalysisException { |
76 GatheringErrorListener listener = new GatheringErrorListener(); | 76 GatheringErrorListener listener = new GatheringErrorListener(); |
77 Scope scope = ScopeBuilder.scopeFor(createResolvedConstructorDeclaration(),
listener); | 77 Scope scope = ScopeBuilder.scopeFor(createResolvedConstructorDeclaration(),
listener); |
| 78 assertInstanceOf(ClassScope.class, scope); |
| 79 } |
| 80 |
| 81 public void test_scopeFor_ConstructorDeclaration_parameters() throws AnalysisE
xception { |
| 82 GatheringErrorListener listener = new GatheringErrorListener(); |
| 83 Scope scope = ScopeBuilder.scopeFor( |
| 84 createResolvedConstructorDeclaration().getParameters(), |
| 85 listener); |
78 assertInstanceOf(FunctionScope.class, scope); | 86 assertInstanceOf(FunctionScope.class, scope); |
79 } | 87 } |
80 | 88 |
81 public void test_scopeFor_FunctionDeclaration() throws AnalysisException { | 89 public void test_scopeFor_FunctionDeclaration() throws AnalysisException { |
82 GatheringErrorListener listener = new GatheringErrorListener(); | 90 GatheringErrorListener listener = new GatheringErrorListener(); |
83 Scope scope = ScopeBuilder.scopeFor(createResolvedFunctionDeclaration(), lis
tener); | 91 Scope scope = ScopeBuilder.scopeFor(createResolvedFunctionDeclaration(), lis
tener); |
| 92 assertInstanceOf(LibraryScope.class, scope); |
| 93 } |
| 94 |
| 95 public void test_scopeFor_FunctionDeclaration_parameters() throws AnalysisExce
ption { |
| 96 GatheringErrorListener listener = new GatheringErrorListener(); |
| 97 Scope scope = ScopeBuilder.scopeFor( |
| 98 createResolvedFunctionDeclaration().getFunctionExpression().getParameter
s(), |
| 99 listener); |
84 assertInstanceOf(FunctionScope.class, scope); | 100 assertInstanceOf(FunctionScope.class, scope); |
85 } | 101 } |
86 | 102 |
87 public void test_scopeFor_FunctionTypeAlias() throws AnalysisException { | 103 public void test_scopeFor_FunctionTypeAlias() throws AnalysisException { |
88 GatheringErrorListener listener = new GatheringErrorListener(); | 104 GatheringErrorListener listener = new GatheringErrorListener(); |
89 Scope scope = ScopeBuilder.scopeFor(createResolvedFunctionTypeAlias(), liste
ner); | 105 Scope scope = ScopeBuilder.scopeFor(createResolvedFunctionTypeAlias(), liste
ner); |
| 106 assertInstanceOf(LibraryScope.class, scope); |
| 107 } |
| 108 |
| 109 public void test_scopeFor_FunctionTypeAlias_parameters() throws AnalysisExcept
ion { |
| 110 GatheringErrorListener listener = new GatheringErrorListener(); |
| 111 Scope scope = ScopeBuilder.scopeFor(createResolvedFunctionTypeAlias().getPar
ameters(), listener); |
90 assertInstanceOf(FunctionTypeScope.class, scope); | 112 assertInstanceOf(FunctionTypeScope.class, scope); |
91 } | 113 } |
92 | 114 |
93 public void test_scopeFor_MethodDeclaration() throws AnalysisException { | 115 public void test_scopeFor_MethodDeclaration() throws AnalysisException { |
94 GatheringErrorListener listener = new GatheringErrorListener(); | 116 GatheringErrorListener listener = new GatheringErrorListener(); |
95 Scope scope = ScopeBuilder.scopeFor(createResolvedMethodDeclaration(), liste
ner); | 117 Scope scope = ScopeBuilder.scopeFor(createResolvedMethodDeclaration(), liste
ner); |
| 118 assertInstanceOf(ClassScope.class, scope); |
| 119 } |
| 120 |
| 121 public void test_scopeFor_MethodDeclaration_body() throws AnalysisException { |
| 122 GatheringErrorListener listener = new GatheringErrorListener(); |
| 123 Scope scope = ScopeBuilder.scopeFor(createResolvedMethodDeclaration().getBod
y(), listener); |
96 assertInstanceOf(FunctionScope.class, scope); | 124 assertInstanceOf(FunctionScope.class, scope); |
97 } | 125 } |
98 | 126 |
99 public void test_scopeFor_notInCompilationUnit() { | 127 public void test_scopeFor_notInCompilationUnit() { |
100 GatheringErrorListener listener = new GatheringErrorListener(); | 128 GatheringErrorListener listener = new GatheringErrorListener(); |
101 try { | 129 try { |
102 ScopeBuilder.scopeFor(identifier("x"), listener); | 130 ScopeBuilder.scopeFor(identifier("x"), listener); |
103 fail("Expected AnalysisException"); | 131 fail("Expected AnalysisException"); |
104 } catch (AnalysisException exception) { | 132 } catch (AnalysisException exception) { |
105 // Expected | 133 // Expected |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 null, | 250 null, |
223 identifier(methodName), | 251 identifier(methodName), |
224 formalParameterList()); | 252 formalParameterList()); |
225 classNode.getMembers().add(methodNode); | 253 classNode.getMembers().add(methodNode); |
226 MethodElement methodElement = methodElement(methodName, null); | 254 MethodElement methodElement = methodElement(methodName, null); |
227 methodNode.getName().setStaticElement(methodElement); | 255 methodNode.getName().setStaticElement(methodElement); |
228 ((ClassElementImpl) classNode.getElement()).setMethods(new MethodElement[] {
methodElement}); | 256 ((ClassElementImpl) classNode.getElement()).setMethods(new MethodElement[] {
methodElement}); |
229 return methodNode; | 257 return methodNode; |
230 } | 258 } |
231 } | 259 } |
OLD | NEW |