| Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/LibraryImportScope.java
|
| diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/LibraryImportScope.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/LibraryImportScope.java
|
| index e8e7254c149d04c97fa3b66e8ada858540651fdd..136ad3d1a64624190584d6d4eeb8a7cfeaa9d1d8 100644
|
| --- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/LibraryImportScope.java
|
| +++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/scope/LibraryImportScope.java
|
| @@ -13,12 +13,24 @@
|
| */
|
| package com.google.dart.engine.internal.scope;
|
|
|
| +import com.google.dart.engine.ast.ASTNode;
|
| +import com.google.dart.engine.ast.FunctionDeclaration;
|
| +import com.google.dart.engine.ast.FunctionTypeAlias;
|
| +import com.google.dart.engine.ast.Identifier;
|
| +import com.google.dart.engine.ast.MethodDeclaration;
|
| +import com.google.dart.engine.ast.SimpleFormalParameter;
|
| +import com.google.dart.engine.ast.TypeArgumentList;
|
| +import com.google.dart.engine.ast.TypeName;
|
| +import com.google.dart.engine.ast.TypeParameter;
|
| +import com.google.dart.engine.ast.VariableDeclarationList;
|
| import com.google.dart.engine.element.Element;
|
| import com.google.dart.engine.element.ImportElement;
|
| import com.google.dart.engine.element.LibraryElement;
|
| import com.google.dart.engine.error.AnalysisError;
|
| import com.google.dart.engine.error.AnalysisErrorListener;
|
| import com.google.dart.engine.error.CompileTimeErrorCode;
|
| +import com.google.dart.engine.error.ErrorCode;
|
| +import com.google.dart.engine.error.StaticTypeWarningCode;
|
| import com.google.dart.engine.internal.element.MultiplyDefinedElementImpl;
|
|
|
| import java.util.ArrayList;
|
| @@ -31,6 +43,51 @@ import java.util.ArrayList;
|
| */
|
| public class LibraryImportScope extends Scope {
|
| /**
|
| + * @return {@code true} if the given {@link Identifier} is the part of type annotation.
|
| + */
|
| + private static boolean isTypeAnnotation(Identifier identifier) {
|
| + ASTNode parent = identifier.getParent();
|
| + if (parent instanceof TypeName) {
|
| + ASTNode parent2 = parent.getParent();
|
| + if (parent2 instanceof FunctionDeclaration) {
|
| + FunctionDeclaration decl = (FunctionDeclaration) parent2;
|
| + return decl.getReturnType() == parent;
|
| + }
|
| + if (parent2 instanceof FunctionTypeAlias) {
|
| + FunctionTypeAlias decl = (FunctionTypeAlias) parent2;
|
| + return decl.getReturnType() == parent;
|
| + }
|
| + if (parent2 instanceof MethodDeclaration) {
|
| + MethodDeclaration decl = (MethodDeclaration) parent2;
|
| + return decl.getReturnType() == parent;
|
| + }
|
| + if (parent2 instanceof VariableDeclarationList) {
|
| + VariableDeclarationList decl = (VariableDeclarationList) parent2;
|
| + return decl.getType() == parent;
|
| + }
|
| + if (parent2 instanceof SimpleFormalParameter) {
|
| + SimpleFormalParameter decl = (SimpleFormalParameter) parent2;
|
| + return decl.getType() == parent;
|
| + }
|
| + if (parent2 instanceof TypeParameter) {
|
| + TypeParameter decl = (TypeParameter) parent2;
|
| + return decl.getBound() == parent;
|
| + }
|
| + if (parent2 instanceof TypeArgumentList) {
|
| + ASTNode parent3 = parent2.getParent();
|
| + if (parent3 instanceof TypeName) {
|
| + TypeName typeName = (TypeName) parent3;
|
| + if ((typeName).getTypeArguments() == parent2) {
|
| + return isTypeAnnotation(typeName.getName());
|
| + }
|
| + }
|
| + }
|
| + return false;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + /**
|
| * The element representing the library in which this scope is enclosed.
|
| */
|
| private LibraryElement definingLibrary;
|
| @@ -77,7 +134,7 @@ public class LibraryImportScope extends Scope {
|
| }
|
|
|
| @Override
|
| - protected Element lookup(String name, LibraryElement referencingLibrary) {
|
| + protected Element lookup(Identifier identifier, String name, LibraryElement referencingLibrary) {
|
| Element foundElement = localLookup(name, referencingLibrary);
|
| if (foundElement != null) {
|
| return foundElement;
|
| @@ -109,12 +166,17 @@ public class LibraryImportScope extends Scope {
|
| }
|
| // TODO (jwren) Change the error message to include a list of all library names instead of
|
| // just the first two
|
| + ErrorCode errorCode = isTypeAnnotation(identifier) ? StaticTypeWarningCode.AMBIGUOUS_IMPORT
|
| + : CompileTimeErrorCode.AMBIGUOUS_IMPORT;
|
| errorListener.onError(new AnalysisError(
|
| getSource(),
|
| - CompileTimeErrorCode.AMBIGUOUS_IMPORT,
|
| + identifier.getOffset(),
|
| + identifier.getLength(),
|
| + errorCode,
|
| foundEltName,
|
| libName1,
|
| libName2));
|
| + return foundElement;
|
| }
|
| if (foundElement != null) {
|
| defineWithoutChecking(foundElement);
|
|
|