Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/utilities/ast/ASTNodes.java |
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/utilities/ast/ASTNodes.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/utilities/ast/ASTNodes.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c7a2dee17bb5905219910d8324e22e21282c1b95 |
--- /dev/null |
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/utilities/ast/ASTNodes.java |
@@ -0,0 +1,58 @@ |
+/* |
+ * Copyright (c) 2012, the Dart project authors. |
+ * |
+ * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except |
+ * in compliance with the License. You may obtain a copy of the License at |
+ * |
+ * http://www.eclipse.org/legal/epl-v10.html |
+ * |
+ * Unless required by applicable law or agreed to in writing, software distributed under the License |
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
+ * or implied. See the License for the specific language governing permissions and limitations under |
+ * the License. |
+ */ |
+package com.google.dart.engine.utilities.ast; |
+ |
+import com.google.dart.engine.ast.ASTNode; |
+import com.google.dart.engine.ast.BinaryExpression; |
+import com.google.dart.engine.ast.PostfixExpression; |
+import com.google.dart.engine.ast.PrefixExpression; |
+import com.google.dart.engine.scanner.TokenType; |
+ |
+/** |
+ * Utility methods for {@link ASTNode}s. |
+ */ |
+public class ASTNodes { |
Brian Wilkerson
2013/01/07 21:27:18
I don't like creating utility classes for methods
scheglov
2013/01/07 22:45:41
OK, I will move these methods to SimpleIdentifier.
|
+ |
+ /** |
+ * Looks to see if given {@link ASTNode} is used to read value. |
+ */ |
+ public static boolean inGetterContext(ASTNode node) { |
+ if (node.getParent() instanceof BinaryExpression) { |
Brian Wilkerson
2013/01/07 21:27:18
The new AST structure uses AssignmentExpression ra
|
+ BinaryExpression expr = (BinaryExpression) node.getParent(); |
+ if (expr.getLeftOperand() == node && expr.getOperator().getType() == TokenType.EQ) { |
+ return false; |
+ } |
+ } |
+ return true; |
+ } |
+ |
+ /** |
+ * Looks to see if given {@link ASTNode} is used to write value. |
+ */ |
+ public static boolean inSetterContext(ASTNode node) { |
+ if (node.getParent() instanceof PrefixExpression) { |
+ PrefixExpression expr = (PrefixExpression) node.getParent(); |
+ return expr.getOperand() == node && expr.getOperator().getType().isIncrementOperator(); |
+ } |
+ if (node.getParent() instanceof PostfixExpression) { |
+ return true; |
+ } |
+ if (node.getParent() instanceof BinaryExpression) { |
Brian Wilkerson
2013/01/07 21:27:18
Ditto.
|
+ BinaryExpression expr = (BinaryExpression) node.getParent(); |
+ return expr.getLeftOperand() == node && expr.getOperator().getType().isAssignmentOperator(); |
+ } |
+ return false; |
+ } |
+ |
+} |