Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Side by Side Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 10885031: Issue 3968. Support for redirecting factory constructors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.type; 4 package com.google.dart.compiler.type;
5 5
6 import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; 6 import static com.google.dart.compiler.common.ErrorExpectation.assertErrors;
7 import static com.google.dart.compiler.common.ErrorExpectation.errEx; 7 import static com.google.dart.compiler.common.ErrorExpectation.errEx;
8 8
9 import com.google.common.base.Joiner; 9 import com.google.common.base.Joiner;
10 import com.google.common.collect.Iterables; 10 import com.google.common.collect.Iterables;
(...skipping 18 matching lines...) Expand all
29 import com.google.dart.compiler.ast.DartFieldDefinition; 29 import com.google.dart.compiler.ast.DartFieldDefinition;
30 import com.google.dart.compiler.ast.DartForInStatement; 30 import com.google.dart.compiler.ast.DartForInStatement;
31 import com.google.dart.compiler.ast.DartFunctionExpression; 31 import com.google.dart.compiler.ast.DartFunctionExpression;
32 import com.google.dart.compiler.ast.DartIdentifier; 32 import com.google.dart.compiler.ast.DartIdentifier;
33 import com.google.dart.compiler.ast.DartInvocation; 33 import com.google.dart.compiler.ast.DartInvocation;
34 import com.google.dart.compiler.ast.DartMapLiteralEntry; 34 import com.google.dart.compiler.ast.DartMapLiteralEntry;
35 import com.google.dart.compiler.ast.DartMethodDefinition; 35 import com.google.dart.compiler.ast.DartMethodDefinition;
36 import com.google.dart.compiler.ast.DartNewExpression; 36 import com.google.dart.compiler.ast.DartNewExpression;
37 import com.google.dart.compiler.ast.DartNode; 37 import com.google.dart.compiler.ast.DartNode;
38 import com.google.dart.compiler.ast.DartParameter; 38 import com.google.dart.compiler.ast.DartParameter;
39 import com.google.dart.compiler.ast.DartTypeNode;
39 import com.google.dart.compiler.ast.DartUnit; 40 import com.google.dart.compiler.ast.DartUnit;
40 import com.google.dart.compiler.ast.DartUnqualifiedInvocation; 41 import com.google.dart.compiler.ast.DartUnqualifiedInvocation;
41 import com.google.dart.compiler.common.SourceInfo; 42 import com.google.dart.compiler.common.SourceInfo;
42 import com.google.dart.compiler.parser.ParserErrorCode; 43 import com.google.dart.compiler.parser.ParserErrorCode;
43 import com.google.dart.compiler.resolver.ClassElement; 44 import com.google.dart.compiler.resolver.ClassElement;
45 import com.google.dart.compiler.resolver.ClassNodeElement;
44 import com.google.dart.compiler.resolver.Element; 46 import com.google.dart.compiler.resolver.Element;
45 import com.google.dart.compiler.resolver.ElementKind; 47 import com.google.dart.compiler.resolver.ElementKind;
46 import com.google.dart.compiler.resolver.MethodElement; 48 import com.google.dart.compiler.resolver.MethodElement;
47 import com.google.dart.compiler.resolver.NodeElement; 49 import com.google.dart.compiler.resolver.NodeElement;
48 import com.google.dart.compiler.resolver.ResolverErrorCode; 50 import com.google.dart.compiler.resolver.ResolverErrorCode;
49 import com.google.dart.compiler.resolver.TypeErrorCode; 51 import com.google.dart.compiler.resolver.TypeErrorCode;
50 52
51 import java.io.Reader; 53 import java.io.Reader;
52 import java.io.StringReader; 54 import java.io.StringReader;
53 import java.net.URI; 55 import java.net.URI;
(...skipping 3996 matching lines...) Expand 10 before | Expand all | Expand 10 after
4050 AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( 4052 AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode(
4051 "// filler filler filler filler filler filler filler filler filler fille r", 4053 "// filler filler filler filler filler filler filler filler filler fille r",
4052 "class A {", 4054 "class A {",
4053 " A.foo() {}", 4055 " A.foo() {}",
4054 " foo() {}", 4056 " foo() {}",
4055 "}")); 4057 "}"));
4056 assertErrors( 4058 assertErrors(
4057 libraryResult.getErrors(), 4059 libraryResult.getErrors(),
4058 errEx(ResolverErrorCode.CONSTRUCTOR_WITH_NAME_OF_MEMBER, 3, 3, 5)); 4060 errEx(ResolverErrorCode.CONSTRUCTOR_WITH_NAME_OF_MEMBER, 3, 3, 5));
4059 } 4061 }
4060 4062
4061 /** 4063 /**
4062 * <p> 4064 * <p>
4063 * http://code.google.com/p/dart/issues/detail?id=3904 4065 * http://code.google.com/p/dart/issues/detail?id=3904
4064 */ 4066 */
4065 public void test_reifiedClasses() throws Exception { 4067 public void test_reifiedClasses() throws Exception {
4066 AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( 4068 AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode(
4067 "// filler filler filler filler filler filler filler filler filler fille r", 4069 "// filler filler filler filler filler filler filler filler filler fille r",
4068 "class A {}", 4070 "class A {}",
4069 "process(x) {}", 4071 "process(x) {}",
4070 "main() {", 4072 "main() {",
4071 " process(A);", 4073 " process(A);",
4072 "}")); 4074 "}"));
4073 assertErrors(libraryResult.getErrors()); 4075 assertErrors(libraryResult.getErrors());
4074 } 4076 }
4075 4077
4078 /**
4079 * TODO(scheglov)
4080 * <p>
4081 * http://code.google.com/p/dart/issues/detail?id=3968
4082 */
4083 public void test_redirectingFactoryConstructor() throws Exception {
4084 AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode(
4085 "// filler filler filler filler filler filler filler filler filler fille r",
4086 "class A {",
4087 " A() {}",
4088 " A.named() {}",
4089 "}",
4090 "",
4091 "class B {",
4092 " factory B.foo() = A;",
4093 " factory B.bar() = A.named;",
4094 "}",
4095 ""));
4096 assertErrors(libraryResult.getErrors());
4097 // prepare "class A"
4098 ClassElement elementA = findNode(DartClass.class, "class A").getElement();
4099 Type typeA = elementA.getType();
4100 // = A;
4101 {
4102 DartTypeNode typeNode = findNode(DartTypeNode.class, "A;");
4103 Type type = typeNode.getType();
4104 assertSame(typeA, type);
4105 }
4106 // = A.named;
4107 {
4108 DartTypeNode typeNode = findNode(DartTypeNode.class, "A.named;");
4109 Type type = typeNode.getType();
4110 assertSame(typeA, type);
4111 // .named
4112 DartIdentifier nameNode = findNode(DartIdentifier.class, "named;");
4113 NodeElement nameElement = nameNode.getElement();
4114 assertNotNull(nameElement);
4115 assertSame(elementA.lookupConstructor("named"), nameElement);
4116 }
4117 }
4118
4119 public void test_redirectingFactoryConstructor_notConst_fromConst() throws Exc eption {
4120 AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode(
4121 "// filler filler filler filler filler filler filler filler filler fille r",
4122 "class A {",
4123 " A.named() {}",
4124 "}",
4125 "",
4126 "class B {",
4127 " const factory B.bar() = A.named;",
4128 "}",
4129 ""));
4130 assertErrors(
4131 libraryResult.getErrors(),
4132 errEx(ResolverErrorCode.REDIRECTION_CONSTRUCTOR_TARGET_MUST_BE_CONST, 7, 29, 5));
4133 }
4134
4076 private <T extends DartNode> T findNode(final Class<T> clazz, String pattern) { 4135 private <T extends DartNode> T findNode(final Class<T> clazz, String pattern) {
4077 final int index = testSource.indexOf(pattern); 4136 final int index = testSource.indexOf(pattern);
4078 assertTrue(index != -1); 4137 assertTrue(index != -1);
4079 final AtomicReference<T> result = new AtomicReference<T>(); 4138 final AtomicReference<T> result = new AtomicReference<T>();
4080 testUnit.accept(new ASTVisitor<Void>() { 4139 testUnit.accept(new ASTVisitor<Void>() {
4081 @Override 4140 @Override
4082 @SuppressWarnings("unchecked") 4141 @SuppressWarnings("unchecked")
4083 public Void visitNode(DartNode node) { 4142 public Void visitNode(DartNode node) {
4084 SourceInfo sourceInfo = node.getSourceInfo(); 4143 SourceInfo sourceInfo = node.getSourceInfo();
4085 if (sourceInfo.getOffset() <= index 4144 if (sourceInfo.getOffset() <= index
4086 && index < sourceInfo.getEnd() 4145 && index < sourceInfo.getEnd()
4087 && clazz.isInstance(node)) { 4146 && clazz.isInstance(node)) {
4088 result.set((T) node); 4147 result.set((T) node);
4089 } 4148 }
4090 return super.visitNode(node); 4149 return super.visitNode(node);
4091 } 4150 }
4092 }); 4151 });
4093 return result.get(); 4152 return result.get();
4094 } 4153 }
4095 } 4154 }
OLDNEW
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698