| Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java
|
| diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java
|
| index 7e02c7b70abd9ae9182ba31941b7cbb8df7c43a0..5a8c1fcabdf9b84131af462d3255ac9651edf8b0 100644
|
| --- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java
|
| +++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java
|
| @@ -22,6 +22,7 @@ import com.google.dart.engine.ast.BinaryExpression;
|
| import com.google.dart.engine.ast.BreakStatement;
|
| import com.google.dart.engine.ast.Combinator;
|
| import com.google.dart.engine.ast.CommentReference;
|
| +import com.google.dart.engine.ast.CompilationUnit;
|
| import com.google.dart.engine.ast.ConstructorDeclaration;
|
| import com.google.dart.engine.ast.ConstructorFieldInitializer;
|
| import com.google.dart.engine.ast.ConstructorName;
|
| @@ -36,6 +37,7 @@ import com.google.dart.engine.ast.ImportDirective;
|
| import com.google.dart.engine.ast.IndexExpression;
|
| import com.google.dart.engine.ast.InstanceCreationExpression;
|
| import com.google.dart.engine.ast.LibraryDirective;
|
| +import com.google.dart.engine.ast.MethodDeclaration;
|
| import com.google.dart.engine.ast.MethodInvocation;
|
| import com.google.dart.engine.ast.NamedExpression;
|
| import com.google.dart.engine.ast.NodeList;
|
| @@ -216,6 +218,32 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
|
| }
|
|
|
| /**
|
| + * Checks if the given 'super' expression is used in the valid context.
|
| + *
|
| + * @param node the 'super' expression to analyze
|
| + * @return {@code true} if the given 'super' expression is in the valid context
|
| + */
|
| + private static boolean isSuperInValidContext(SuperExpression node) {
|
| + for (ASTNode n = node; n != null; n = n.getParent()) {
|
| + if (n instanceof CompilationUnit) {
|
| + return false;
|
| + }
|
| + if (n instanceof ConstructorDeclaration) {
|
| + ConstructorDeclaration constructor = (ConstructorDeclaration) n;
|
| + return constructor.getFactoryKeyword() == null;
|
| + }
|
| + if (n instanceof ConstructorFieldInitializer) {
|
| + return false;
|
| + }
|
| + if (n instanceof MethodDeclaration) {
|
| + MethodDeclaration method = (MethodDeclaration) n;
|
| + return !method.isStatic();
|
| + }
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + /**
|
| * The resolver driving this participant.
|
| */
|
| private ResolverVisitor resolver;
|
| @@ -637,6 +665,9 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
|
| Expression target = node.getRealTarget();
|
| Element staticElement;
|
| Element propagatedElement;
|
| + if (target instanceof SuperExpression && !isSuperInValidContext((SuperExpression) target)) {
|
| + return null;
|
| + }
|
| if (target == null) {
|
| staticElement = resolveInvokedElement(methodName);
|
| propagatedElement = null;
|
| @@ -828,8 +859,10 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
|
| @Override
|
| public Void visitPropertyAccess(PropertyAccess node) {
|
| Expression target = node.getRealTarget();
|
| + if (target instanceof SuperExpression && !isSuperInValidContext((SuperExpression) target)) {
|
| + return null;
|
| + }
|
| SimpleIdentifier propertyName = node.getPropertyName();
|
| -
|
| resolvePropertyAccess(target, propertyName);
|
| return null;
|
| }
|
| @@ -921,6 +954,14 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
|
| }
|
|
|
| @Override
|
| + public Void visitSuperExpression(SuperExpression node) {
|
| + if (!isSuperInValidContext(node)) {
|
| + resolver.reportError(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node);
|
| + }
|
| + return super.visitSuperExpression(node);
|
| + }
|
| +
|
| + @Override
|
| public Void visitTypeParameter(TypeParameter node) {
|
| TypeName bound = node.getBound();
|
| if (bound != null) {
|
|
|