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 |
Brian Wilkerson
2012/06/05 14:44:03
nit: copyright year
| |
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.resolver; | 5 package com.google.dart.compiler.resolver; |
6 | 6 |
7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
8 import com.google.common.base.Objects; | |
8 import com.google.dart.compiler.DartCompilerContext; | 9 import com.google.dart.compiler.DartCompilerContext; |
9 import com.google.dart.compiler.ErrorCode; | 10 import com.google.dart.compiler.ErrorCode; |
10 import com.google.dart.compiler.ast.ASTVisitor; | 11 import com.google.dart.compiler.ast.ASTVisitor; |
11 import com.google.dart.compiler.ast.DartBlock; | 12 import com.google.dart.compiler.ast.DartBlock; |
12 import com.google.dart.compiler.ast.DartClass; | 13 import com.google.dart.compiler.ast.DartClass; |
13 import com.google.dart.compiler.ast.DartExpression; | 14 import com.google.dart.compiler.ast.DartExpression; |
14 import com.google.dart.compiler.ast.DartField; | 15 import com.google.dart.compiler.ast.DartField; |
15 import com.google.dart.compiler.ast.DartFieldDefinition; | 16 import com.google.dart.compiler.ast.DartFieldDefinition; |
16 import com.google.dart.compiler.ast.DartFunctionTypeAlias; | 17 import com.google.dart.compiler.ast.DartFunctionTypeAlias; |
17 import com.google.dart.compiler.ast.DartIdentifier; | 18 import com.google.dart.compiler.ast.DartIdentifier; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 addMethod(currentHolder, element); | 146 addMethod(currentHolder, element); |
146 break; | 147 break; |
147 } | 148 } |
148 } else { | 149 } else { |
149 // This is a top-level element, and an element was already created in | 150 // This is a top-level element, and an element was already created in |
150 // TopLevelElementBuilder. | 151 // TopLevelElementBuilder. |
151 Elements.addMethod(currentHolder, element); | 152 Elements.addMethod(currentHolder, element); |
152 assertTopLevel(method); | 153 assertTopLevel(method); |
153 } | 154 } |
154 if (element != null) { | 155 if (element != null) { |
156 checkTopLevelMainFunction(method); | |
155 checkModifiers(element, method); | 157 checkModifiers(element, method); |
156 recordElement(method, element); | 158 recordElement(method, element); |
157 recordElement(method.getName(), element); | 159 recordElement(method.getName(), element); |
158 ResolutionContext previous = context; | 160 ResolutionContext previous = context; |
159 context = context.extend(element.getName()); | 161 context = context.extend(element.getName()); |
160 EnclosingElement previousEnclosingElement = enclosingElement; | 162 EnclosingElement previousEnclosingElement = enclosingElement; |
161 enclosingElement = element; | 163 enclosingElement = element; |
162 resolveFunction(method.getFunction(), element); | 164 resolveFunction(method.getFunction(), element); |
163 enclosingElement = previousEnclosingElement; | 165 enclosingElement = previousEnclosingElement; |
164 context = previous; | 166 context = previous; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 } else { | 443 } else { |
442 // Multiple qualifiers (Foo.bar.baz) | 444 // Multiple qualifiers (Foo.bar.baz) |
443 resolutionError(method.getName(), | 445 resolutionError(method.getName(), |
444 ResolverErrorCode.TOO_MANY_QUALIFIERS_FOR_METHOD); | 446 ResolverErrorCode.TOO_MANY_QUALIFIERS_FOR_METHOD); |
445 } | 447 } |
446 } | 448 } |
447 | 449 |
448 return ElementKind.NONE; | 450 return ElementKind.NONE; |
449 } | 451 } |
450 | 452 |
453 /** | |
454 * Checks that top-level "main()" has no parameters. | |
455 */ | |
456 private void checkTopLevelMainFunction(DartMethodDefinition method) { | |
457 if (Objects.equal(method.getName().toSource(), "main") | |
458 && currentHolder instanceof LibraryElement | |
459 && !method.getFunction().getParameters().isEmpty()) { | |
460 resolutionError(method.getName(), ResolverErrorCode.MAIN_FUNCTION_PARAME TERS); | |
461 } | |
462 } | |
463 | |
451 private void checkModifiers(MethodElement element, DartMethodDefinition meth od) { | 464 private void checkModifiers(MethodElement element, DartMethodDefinition meth od) { |
452 Modifiers modifiers = method.getModifiers(); | 465 Modifiers modifiers = method.getModifiers(); |
453 boolean isNonFactoryConstructor = Elements.isNonFactoryConstructor(element ); | 466 boolean isNonFactoryConstructor = Elements.isNonFactoryConstructor(element ); |
454 // TODO(ngeoffray): The errors should report the position of the modifier. | 467 // TODO(ngeoffray): The errors should report the position of the modifier. |
455 if (isNonFactoryConstructor) { | 468 if (isNonFactoryConstructor) { |
456 if (modifiers.isStatic()) { | 469 if (modifiers.isStatic()) { |
457 resolutionError(method.getName(), ResolverErrorCode.CONSTRUCTOR_CANNOT _BE_STATIC); | 470 resolutionError(method.getName(), ResolverErrorCode.CONSTRUCTOR_CANNOT _BE_STATIC); |
458 } | 471 } |
459 if (modifiers.isAbstract()) { | 472 if (modifiers.isAbstract()) { |
460 resolutionError(method.getName(), ResolverErrorCode.CONSTRUCTOR_CANNOT _BE_ABSTRACT); | 473 resolutionError(method.getName(), ResolverErrorCode.CONSTRUCTOR_CANNOT _BE_ABSTRACT); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 */ | 577 */ |
565 private void reportDuplicateDeclaration(ErrorCode errorCode, Element element ) { | 578 private void reportDuplicateDeclaration(ErrorCode errorCode, Element element ) { |
566 String name = | 579 String name = |
567 element instanceof MethodElement | 580 element instanceof MethodElement |
568 ? Elements.getRawMethodName((MethodElement) element) | 581 ? Elements.getRawMethodName((MethodElement) element) |
569 : element.getName(); | 582 : element.getName(); |
570 resolutionError(element.getNameLocation(), errorCode, name); | 583 resolutionError(element.getNameLocation(), errorCode, name); |
571 } | 584 } |
572 } | 585 } |
573 } | 586 } |
OLD | NEW |