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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ElementResolver.java

Issue 17586002: Resolve @Type.constructorName() and its arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Resolve @A() - unnamed constructor invocation. Created 7 years, 6 months 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
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 2061317da2c522595cb02869e2efb5ef9ce680ca..cdae7b5af52a4d1c970dbbc608063d83aa6af29f 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
@@ -102,6 +102,7 @@ import com.google.dart.engine.internal.scope.LabelScope;
import com.google.dart.engine.internal.scope.Namespace;
import com.google.dart.engine.internal.scope.NamespaceBuilder;
import com.google.dart.engine.internal.scope.Scope;
+import com.google.dart.engine.internal.type.InterfaceTypeImpl;
import com.google.dart.engine.resolver.ResolverErrorCode;
import com.google.dart.engine.scanner.Token;
import com.google.dart.engine.scanner.TokenType;
@@ -919,6 +920,28 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
recordResolution(identifier, element);
return null;
}
+
+ //
+ // May be annotation, 'const' constructor invocation.
+ //
+ if (node.getParent() instanceof Annotation && prefixElement instanceof ClassElement) {
+ Annotation annotation = (Annotation) node.getParent();
+ // look up ConstructorElement
+ ConstructorElement constructor;
+ {
+ InterfaceType interfaceType = (InterfaceType) prefix.getStaticType();
+ LibraryElement definingLibrary = resolver.getDefiningLibrary();
+ constructor = interfaceType.lookUpConstructor(identifier.getName(), definingLibrary);
+ }
+ // record elements
+ recordResolution(identifier, constructor);
+ annotation.setElement(constructor);
+ // resolve arguments
+ resolveAnnotationConstructorInvocationArguments(annotation, constructor);
+ // done
+ return null;
+ }
+
//
// Otherwise, the prefix is really an expression that happens to be a simple identifier and this
// is really equivalent to a property access node.
@@ -1023,7 +1046,28 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, node, node.getName());
}
}
+
recordResolution(node, element);
+
+ //
+ // May be annotation, 'const' constructor invocation.
+ //
+ if (node.getParent() instanceof Annotation && element instanceof ClassElement) {
+ Annotation annotation = (Annotation) node.getParent();
+ // look up ConstructorElement
+ ConstructorElement constructor;
+ {
+ InterfaceType interfaceType = new InterfaceTypeImpl((ClassElement) element);
+ LibraryElement definingLibrary = resolver.getDefiningLibrary();
+ constructor = interfaceType.lookUpConstructor(null, definingLibrary);
+ }
+ // record element
+ annotation.setElement(constructor);
+ // resolve arguments
+ resolveAnnotationConstructorInvocationArguments(annotation, constructor);
+ // done
+ return null;
+ }
return null;
}
@@ -1953,6 +1997,21 @@ public class ElementResolver extends SimpleASTVisitor<Void> {
node.setElement(propagatedElement == null ? staticElement : propagatedElement);
}
+ private void resolveAnnotationConstructorInvocationArguments(Annotation annotation,
+ ConstructorElement constructor) {
+ // TODO(scheglov) check that the constructor is 'const' (in ErrorVerifier)
+ // resolve arguments to parameters
+ ArgumentList argumentList = annotation.getArguments();
+ if (argumentList == null) {
+ // TODO(scheglov) report problem (in ErrorVerifier), no arguments for constructor invocation
+ } else {
+ ParameterElement[] parameters = resolveArgumentsToParameters(true, argumentList, constructor);
+ if (parameters != null) {
+ argumentList.setCorrespondingStaticParameters(parameters);
+ }
+ }
+ }
+
/**
* Given a list of arguments and the element that will be invoked using those argument, compute
* the list of parameters that correspond to the list of arguments. Return the parameters that

Powered by Google App Engine
This is Rietveld 408576698