Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/ast/ConstructorDeclaration.java |
=================================================================== |
--- editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/ast/ConstructorDeclaration.java (revision 15397) |
+++ editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/ast/ConstructorDeclaration.java (working copy) |
@@ -47,11 +47,16 @@ |
private Token externalKeyword; |
/** |
- * The token for the 'factory' or 'const' keyword. |
+ * The token for the 'const' keyword. |
*/ |
- private Token keyword; |
+ private Token constKeyword; |
/** |
+ * The token for the 'factory' keyword. |
+ */ |
+ private Token factoryKeyword; |
+ |
+ /** |
* The type of object being created. This can be different than the type in which the constructor |
* is being declared if the constructor is the implementation of a factory constructor. |
*/ |
@@ -74,9 +79,10 @@ |
private FormalParameterList parameters; |
/** |
- * The token for the colon before the initializers, or {@code null} if there are no initializers. |
+ * The token for the separator (colon or equals) before the initializers, or {@code null} if there |
+ * are no initializers. |
*/ |
- private Token colon; |
+ private Token separator; |
/** |
* The initializers associated with the constructor. |
@@ -84,6 +90,12 @@ |
private NodeList<ConstructorInitializer> initializers = new NodeList<ConstructorInitializer>(this); |
/** |
+ * The name of the constructor to which this constructor will be redirected, or {@code null} if |
+ * this is not a redirecting factory constructor. |
+ */ |
+ private ConstructorName redirectedConstructor; |
+ |
+ /** |
* The body of the constructor, or {@code null} if the constructor does not have a body. |
*/ |
private FunctionBody body; |
@@ -100,28 +112,34 @@ |
* @param externalKeyword the token for the 'external' keyword |
* @param comment the documentation comment associated with this constructor |
* @param metadata the annotations associated with this constructor |
- * @param keyword the token for the 'factory' or 'const' keyword |
+ * @param constKeyword the token for the 'const' keyword |
+ * @param factoryKeyword the token for the 'factory' keyword |
* @param returnType the return type of the constructor |
* @param period the token for the period before the constructor name |
* @param name the name of the constructor |
* @param parameters the parameters associated with the constructor |
- * @param colon the token for the colon before the initializers |
+ * @param separator the token for the colon or equals before the initializers |
* @param initializers the initializers associated with the constructor |
+ * @param redirectedConstructor the name of the constructor to which this constructor will be |
+ * redirected |
* @param body the body of the constructor |
*/ |
public ConstructorDeclaration(Comment comment, List<Annotation> metadata, Token externalKeyword, |
- Token keyword, Identifier returnType, Token period, SimpleIdentifier name, |
- FormalParameterList parameters, Token colon, List<ConstructorInitializer> initializers, |
+ Token constKeyword, Token factoryKeyword, Identifier returnType, Token period, |
+ SimpleIdentifier name, FormalParameterList parameters, Token separator, |
+ List<ConstructorInitializer> initializers, ConstructorName redirectedConstructor, |
FunctionBody body) { |
super(comment, metadata); |
this.externalKeyword = externalKeyword; |
- this.keyword = keyword; |
+ this.constKeyword = constKeyword; |
+ this.factoryKeyword = factoryKeyword; |
this.returnType = becomeParentOf(returnType); |
this.period = period; |
this.name = becomeParentOf(name); |
this.parameters = becomeParentOf(parameters); |
- this.colon = colon; |
+ this.separator = separator; |
this.initializers.addAll(initializers); |
+ this.redirectedConstructor = becomeParentOf(redirectedConstructor); |
this.body = becomeParentOf(body); |
} |
@@ -140,13 +158,12 @@ |
} |
/** |
- * Return the token for the colon before the initializers, or {@code null} if there are no |
- * initializers. |
+ * Return the token for the 'const' keyword. |
* |
- * @return the token for the colon before the initializers |
+ * @return the token for the 'const' keyword |
*/ |
- public Token getColon() { |
- return colon; |
+ public Token getConstKeyword() { |
+ return constKeyword; |
} |
@Override |
@@ -170,21 +187,21 @@ |
} |
/** |
- * Return the initializers associated with the constructor. |
+ * Return the token for the 'factory' keyword. |
* |
- * @return the initializers associated with the constructor |
+ * @return the token for the 'factory' keyword |
*/ |
- public NodeList<ConstructorInitializer> getInitializers() { |
- return initializers; |
+ public Token getFactoryKeyword() { |
+ return factoryKeyword; |
} |
/** |
- * Return the token for the 'factory' or 'const' keyword. |
+ * Return the initializers associated with the constructor. |
* |
- * @return the token for the 'factory' or 'const' keyword |
+ * @return the initializers associated with the constructor |
*/ |
- public Token getKeyword() { |
- return keyword; |
+ public NodeList<ConstructorInitializer> getInitializers() { |
+ return initializers; |
} |
/** |
@@ -217,6 +234,16 @@ |
} |
/** |
+ * Return the name of the constructor to which this constructor will be redirected, or |
+ * {@code null} if this is not a redirecting factory constructor. |
+ * |
+ * @return the name of the constructor to which this constructor will be redirected |
+ */ |
+ public ConstructorName getRedirectedConstructor() { |
+ return redirectedConstructor; |
+ } |
+ |
+ /** |
* Return the type of object being created. This can be different than the type in which the |
* constructor is being declared if the constructor is the implementation of a factory |
* constructor. |
@@ -228,6 +255,16 @@ |
} |
/** |
+ * Return the token for the separator (colon or equals) before the initializers, or {@code null} |
+ * if there are no initializers. |
+ * |
+ * @return the token for the separator (colon or equals) before the initializers |
+ */ |
+ public Token getSeparator() { |
+ return separator; |
+ } |
+ |
+ /** |
* Set the body of the constructor to the given function body. |
* |
* @param functionBody the body of the constructor |
@@ -237,12 +274,12 @@ |
} |
/** |
- * Set the token for the colon before the initializers to the given token. |
+ * Set the token for the 'const' keyword to the given token. |
* |
- * @param colon the token for the colon before the initializers |
+ * @param constKeyword the token for the 'const' keyword |
*/ |
- public void setColon(Token colon) { |
- this.colon = colon; |
+ public void setConstKeyword(Token constKeyword) { |
+ this.constKeyword = constKeyword; |
} |
/** |
@@ -255,12 +292,12 @@ |
} |
/** |
- * Set the token for the 'factory' or 'const' keyword to the given token. |
+ * Set the token for the 'factory' keyword to the given token. |
* |
- * @param keyword the token for the 'factory' or 'const' keyword |
+ * @param factoryKeyword the token for the 'factory' keyword |
*/ |
- public void setKeyword(Token keyword) { |
- this.keyword = keyword; |
+ public void setFactoryKeyword(Token factoryKeyword) { |
+ this.factoryKeyword = factoryKeyword; |
} |
/** |
@@ -291,6 +328,17 @@ |
} |
/** |
+ * Set the name of the constructor to which this constructor will be redirected to the given |
+ * constructor name. |
+ * |
+ * @param redirectedConstructor the name of the constructor to which this constructor will be |
+ * redirected |
+ */ |
+ public void setRedirectedConstructor(ConstructorName redirectedConstructor) { |
+ this.redirectedConstructor = becomeParentOf(redirectedConstructor); |
+ } |
+ |
+ /** |
* Set the type of object being created to the given type name. |
* |
* @param typeName the type of object being created |
@@ -299,6 +347,15 @@ |
returnType = becomeParentOf(typeName); |
} |
+ /** |
+ * Set the token for the separator (colon or equals) before the initializers to the given token. |
+ * |
+ * @param separator the token for the separator (colon or equals) before the initializers |
+ */ |
+ public void setSeparator(Token separator) { |
+ this.separator = separator; |
+ } |
+ |
@Override |
public void visitChildren(ASTVisitor<?> visitor) { |
super.visitChildren(visitor); |
@@ -311,9 +368,28 @@ |
@Override |
protected Token getFirstTokenAfterCommentAndMetadata() { |
- if (keyword != null) { |
- return keyword; |
+ Token leftMost = leftMost(externalKeyword, constKeyword, factoryKeyword); |
+ if (leftMost != null) { |
+ return leftMost; |
} |
return returnType.getBeginToken(); |
} |
+ |
+ /** |
+ * Return the left-most of the given tokens, or {@code null} if there are no tokens given or if |
+ * all of the given tokens are {@code null}. |
+ * |
+ * @param tokens the tokens being compared to find the left-most token |
+ * @return the left-most of the given tokens |
+ */ |
+ private Token leftMost(Token... tokens) { |
+ Token leftMost = null; |
+ int offset = Integer.MAX_VALUE; |
+ for (Token token : tokens) { |
+ if (token != null && token.getOffset() < offset) { |
+ leftMost = token; |
+ } |
+ } |
+ return leftMost; |
+ } |
} |