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

Side by Side Diff: compiler/java/com/google/dart/compiler/resolver/MemberBuilder.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
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 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.common.base.Objects;
9 import com.google.dart.compiler.DartCompilerContext; 9 import com.google.dart.compiler.DartCompilerContext;
10 import com.google.dart.compiler.ErrorCode; 10 import com.google.dart.compiler.ErrorCode;
11 import com.google.dart.compiler.PackageLibraryManager;
12 import com.google.dart.compiler.Source;
13 import com.google.dart.compiler.ast.ASTVisitor; 11 import com.google.dart.compiler.ast.ASTVisitor;
14 import com.google.dart.compiler.ast.DartBlock; 12 import com.google.dart.compiler.ast.DartBlock;
15 import com.google.dart.compiler.ast.DartClass; 13 import com.google.dart.compiler.ast.DartClass;
16 import com.google.dart.compiler.ast.DartExpression; 14 import com.google.dart.compiler.ast.DartExpression;
17 import com.google.dart.compiler.ast.DartField; 15 import com.google.dart.compiler.ast.DartField;
18 import com.google.dart.compiler.ast.DartFieldDefinition; 16 import com.google.dart.compiler.ast.DartFieldDefinition;
19 import com.google.dart.compiler.ast.DartFunction; 17 import com.google.dart.compiler.ast.DartFunction;
20 import com.google.dart.compiler.ast.DartFunctionTypeAlias; 18 import com.google.dart.compiler.ast.DartFunctionTypeAlias;
21 import com.google.dart.compiler.ast.DartIdentifier; 19 import com.google.dart.compiler.ast.DartIdentifier;
22 import com.google.dart.compiler.ast.DartMethodDefinition; 20 import com.google.dart.compiler.ast.DartMethodDefinition;
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 DartBlock dartBlock = method.getFunction().getBody(); 575 DartBlock dartBlock = method.getFunction().getBody();
578 if (dartBlock != null && !(dartBlock instanceof DartNativeBlock)) { 576 if (dartBlock != null && !(dartBlock instanceof DartNativeBlock)) {
579 resolutionError(method.getName(), 577 resolutionError(method.getName(),
580 ResolverErrorCode.CONST_CONSTRUCTOR_CANNOT_HAVE_BODY ); 578 ResolverErrorCode.CONST_CONSTRUCTOR_CANNOT_HAVE_BODY );
581 } 579 }
582 } 580 }
583 } 581 }
584 582
585 if (modifiers.isFactory()) { 583 if (modifiers.isFactory()) {
586 if (modifiers.isConstant()) { 584 if (modifiers.isConstant()) {
587 // Allow const factory ... native ... ; type of constructors, used in core libraries 585 // Allow const factory ... native ... ; type of constructors, used in core libraries.
586 // Allow const factory redirecting.
588 DartBlock dartBlock = method.getFunction().getBody(); 587 DartBlock dartBlock = method.getFunction().getBody();
589 if (dartBlock == null || !(dartBlock instanceof DartNativeBlock)) { 588 if (!(dartBlock instanceof DartNativeBlock || method.getRedirectedType Name() != null)) {
590 resolutionError(method.getName(), ResolverErrorCode.FACTORY_CANNOT_B E_CONST); 589 resolutionError(method.getName(), ResolverErrorCode.FACTORY_CANNOT_B E_CONST);
591 } 590 }
592 } 591 }
593 } 592 }
594 // TODO(ngeoffray): Add more checks on the modifiers. For 593 // TODO(ngeoffray): Add more checks on the modifiers. For
595 // example const and missing body. 594 // example const and missing body.
596 } 595 }
597 596
598 private void checkConstructor(MethodElement element, DartMethodDefinition me thod) { 597 private void checkConstructor(MethodElement element, DartMethodDefinition me thod) {
599 if (Elements.isNonFactoryConstructor(element) && method.getFunction() != n ull 598 if (Elements.isNonFactoryConstructor(element) && method.getFunction() != n ull
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 */ 678 */
680 private void reportDuplicateDeclaration(ErrorCode errorCode, Element element ) { 679 private void reportDuplicateDeclaration(ErrorCode errorCode, Element element ) {
681 String name = 680 String name =
682 element instanceof MethodElement 681 element instanceof MethodElement
683 ? Elements.getRawMethodName((MethodElement) element) 682 ? Elements.getRawMethodName((MethodElement) element)
684 : element.getName(); 683 : element.getName();
685 resolutionError(element.getNameLocation(), errorCode, name); 684 resolutionError(element.getNameLocation(), errorCode, name);
686 } 685 }
687 } 686 }
688 } 687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698