| 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 17 matching lines...) Expand all Loading... |
| 28 import com.google.dart.engine.constant.DeclaredVariables; | 28 import com.google.dart.engine.constant.DeclaredVariables; |
| 29 import com.google.dart.engine.context.AnalysisException; | 29 import com.google.dart.engine.context.AnalysisException; |
| 30 import com.google.dart.engine.element.ConstructorElement; | 30 import com.google.dart.engine.element.ConstructorElement; |
| 31 import com.google.dart.engine.element.LibraryElement; | 31 import com.google.dart.engine.element.LibraryElement; |
| 32 import com.google.dart.engine.element.ParameterElement; | 32 import com.google.dart.engine.element.ParameterElement; |
| 33 import com.google.dart.engine.error.CompileTimeErrorCode; | 33 import com.google.dart.engine.error.CompileTimeErrorCode; |
| 34 import com.google.dart.engine.error.ErrorCode; | 34 import com.google.dart.engine.error.ErrorCode; |
| 35 import com.google.dart.engine.internal.element.VariableElementImpl; | 35 import com.google.dart.engine.internal.element.VariableElementImpl; |
| 36 import com.google.dart.engine.internal.object.DartObjectImpl; | 36 import com.google.dart.engine.internal.object.DartObjectImpl; |
| 37 import com.google.dart.engine.internal.object.GenericState; | 37 import com.google.dart.engine.internal.object.GenericState; |
| 38 import com.google.dart.engine.internal.resolver.TestTypeProvider; | |
| 39 import com.google.dart.engine.internal.resolver.TypeProvider; | 38 import com.google.dart.engine.internal.resolver.TypeProvider; |
| 40 import com.google.dart.engine.resolver.ResolverTestCase; | 39 import com.google.dart.engine.resolver.ResolverTestCase; |
| 41 import com.google.dart.engine.source.Source; | 40 import com.google.dart.engine.source.Source; |
| 42 import com.google.dart.engine.utilities.collection.DirectedGraph; | 41 import com.google.dart.engine.utilities.collection.DirectedGraph; |
| 43 import com.google.dart.engine.utilities.logging.TestLogger; | 42 import com.google.dart.engine.utilities.logging.TestLogger; |
| 44 | 43 |
| 45 import java.util.HashMap; | 44 import java.util.HashMap; |
| 46 | 45 |
| 47 public class ConstantValueComputerTest extends ResolverTestCase { | 46 public class ConstantValueComputerTest extends ResolverTestCase { |
| 48 class ValidatingConstantVisitor extends ConstantVisitor { | 47 class ValidatingConstantVisitor extends ConstantVisitor { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 163 |
| 165 ConstantValueComputer computer = makeConstantValueComputer(); | 164 ConstantValueComputer computer = makeConstantValueComputer(); |
| 166 computer.add(unit); | 165 computer.add(unit); |
| 167 computer.computeValues(); | 166 computer.computeValues(); |
| 168 NodeList<CompilationUnitMember> members = unit.getDeclarations(); | 167 NodeList<CompilationUnitMember> members = unit.getDeclarations(); |
| 169 assertSizeOfList(2, members); | 168 assertSizeOfList(2, members); |
| 170 validate(true, ((TopLevelVariableDeclaration) members.get(0)).getVariables()
); | 169 validate(true, ((TopLevelVariableDeclaration) members.get(0)).getVariables()
); |
| 171 validate(true, ((TopLevelVariableDeclaration) members.get(1)).getVariables()
); | 170 validate(true, ((TopLevelVariableDeclaration) members.get(1)).getVariables()
); |
| 172 } | 171 } |
| 173 | 172 |
| 174 public void test_computeValues_empty() { | 173 public void test_computeValues_empty() throws Exception { |
| 175 ConstantValueComputer computer = makeConstantValueComputer(); | 174 ConstantValueComputer computer = makeConstantValueComputer(); |
| 176 computer.computeValues(); | 175 computer.computeValues(); |
| 177 } | 176 } |
| 178 | 177 |
| 179 public void test_computeValues_multipleSources() throws Exception { | 178 public void test_computeValues_multipleSources() throws Exception { |
| 180 Source librarySource = addNamedSource("/lib.dart", createSource(// | 179 Source librarySource = addNamedSource("/lib.dart", createSource(// |
| 181 "library lib;", | 180 "library lib;", |
| 182 "part 'part.dart';", | 181 "part 'part.dart';", |
| 183 "const int c = b;", | 182 "const int c = b;", |
| 184 "const int a = 0;")); | 183 "const int a = 0;")); |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 assertSizeOfMap(1, fieldsOfY); | 927 assertSizeOfMap(1, fieldsOfY); |
| 929 assertIntField(fieldsOfY, fieldName, 10L); | 928 assertIntField(fieldsOfY, fieldName, 10L); |
| 930 } | 929 } |
| 931 | 930 |
| 932 private EvaluationResultImpl evaluateInstanceCreationExpression(CompilationUni
t compilationUnit, | 931 private EvaluationResultImpl evaluateInstanceCreationExpression(CompilationUni
t compilationUnit, |
| 933 String name) throws AnalysisException { | 932 String name) throws AnalysisException { |
| 934 Expression expression = findTopLevelConstantExpression(compilationUnit, name
); | 933 Expression expression = findTopLevelConstantExpression(compilationUnit, name
); |
| 935 return ((InstanceCreationExpression) expression).getEvaluationResult(); | 934 return ((InstanceCreationExpression) expression).getEvaluationResult(); |
| 936 } | 935 } |
| 937 | 936 |
| 938 private ConstantValueComputer makeConstantValueComputer() { | 937 private ConstantValueComputer makeConstantValueComputer() throws AnalysisExcep
tion { |
| 939 return new ValidatingConstantValueComputer( | 938 return new ValidatingConstantValueComputer( |
| 940 new TestTypeProvider(), | 939 analysisContext.getTypeProvider(), |
| 941 analysisContext.getDeclaredVariables()); | 940 analysisContext.getDeclaredVariables()); |
| 942 } | 941 } |
| 943 | 942 |
| 944 private void validate(boolean shouldBeValid, VariableDeclarationList declarati
onList) { | 943 private void validate(boolean shouldBeValid, VariableDeclarationList declarati
onList) { |
| 945 for (VariableDeclaration declaration : declarationList.getVariables()) { | 944 for (VariableDeclaration declaration : declarationList.getVariables()) { |
| 946 VariableElementImpl element = (VariableElementImpl) declaration.getElement
(); | 945 VariableElementImpl element = (VariableElementImpl) declaration.getElement
(); |
| 947 assertNotNull(element); | 946 assertNotNull(element); |
| 948 EvaluationResultImpl result = element.getEvaluationResult(); | 947 EvaluationResultImpl result = element.getEvaluationResult(); |
| 949 if (shouldBeValid) { | 948 if (shouldBeValid) { |
| 950 assertInstanceOf(ValidResult.class, result); | 949 assertInstanceOf(ValidResult.class, result); |
| 951 Object value = ((ValidResult) result).getValue(); | 950 Object value = ((ValidResult) result).getValue(); |
| 952 assertNotNull(value); | 951 assertNotNull(value); |
| 953 } else { | 952 } else { |
| 954 assertInstanceOf(ErrorResult.class, result); | 953 assertInstanceOf(ErrorResult.class, result); |
| 955 } | 954 } |
| 956 } | 955 } |
| 957 } | 956 } |
| 958 } | 957 } |
| OLD | NEW |