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

Unified Diff: compiler/java/com/google/dart/compiler/parser/DartParser.java

Issue 8506019: Convert top level factory into method, issue 345 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/CompilerTestCase.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/CompilerTestCase.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698