Index: compiler/java/com/google/dart/compiler/parser/DartParser.java |
diff --git a/compiler/java/com/google/dart/compiler/parser/DartParser.java b/compiler/java/com/google/dart/compiler/parser/DartParser.java |
index 842962ae23c956d921a00e3961b26e1b73cef37f..869f1510367d8de79256492f4d16e6e26e58b46d 100644 |
--- a/compiler/java/com/google/dart/compiler/parser/DartParser.java |
+++ b/compiler/java/com/google/dart/compiler/parser/DartParser.java |
@@ -45,7 +45,6 @@ import com.google.dart.compiler.ast.DartIfStatement; |
import com.google.dart.compiler.ast.DartImportDirective; |
import com.google.dart.compiler.ast.DartInitializer; |
import com.google.dart.compiler.ast.DartIntegerLiteral; |
-import com.google.dart.compiler.ast.DartInvocation; |
import com.google.dart.compiler.ast.DartLabel; |
import com.google.dart.compiler.ast.DartLibraryDirective; |
import com.google.dart.compiler.ast.DartMapLiteral; |
@@ -775,7 +774,21 @@ public class DartParser extends CompletionHooksParserBase { |
} |
if (modifiers.isFactory()) { |
- return done(parseFactory(modifiers)); |
+ // Factory is not allowed on top level. |
+ if (!allowStatic) { |
+ reportError(position(), ParserErrorCode.DISALLOWED_FACTORY_KEYWORD); |
+ modifiers = modifiers.removeFactory(); |
+ } |
+ // Do parse factory. |
+ DartMethodDefinition factoryNode = parseFactory(modifiers); |
+ // If factory is not allowed, ensure that it is valid as method. |
+ DartExpression actualName = factoryNode.getName(); |
+ if (!allowStatic && !(actualName instanceof DartIdentifier)) { |
+ DartExpression replacementName = new DartIdentifier(actualName.toString()); |
+ factoryNode.setName(replacementName); |
+ } |
+ // Done. |
+ return done(factoryNode); |
} |
final DartNode member; |