Chromium Code Reviews| Index: pkg/compiler/lib/src/patch_parser.dart |
| diff --git a/pkg/compiler/lib/src/patch_parser.dart b/pkg/compiler/lib/src/patch_parser.dart |
| index a2ec63cf7006cdbfc964892a24ed6e9844cfe6db..79b8da3d9a4b95e261ca5be9f5e38c2d1506aa88 100644 |
| --- a/pkg/compiler/lib/src/patch_parser.dart |
| +++ b/pkg/compiler/lib/src/patch_parser.dart |
| @@ -133,6 +133,8 @@ import 'elements/modelx.dart' show |
| LibraryElementX, |
| MetadataAnnotationX, |
| SetterElementX; |
| +import 'js_backend/js_backend.dart' show |
| + JavaScriptBackend; |
| import 'library_loader.dart' show |
| LibraryLoader; |
| import 'parser/listener.dart' show |
| @@ -303,6 +305,7 @@ void patchElement(Compiler compiler, |
| patch, MessageKind.PATCH_NON_EXISTING, {'name': patch.name}); |
| return; |
| } |
| + |
| if (!(origin.isClass || |
| origin.isConstructor || |
| origin.isFunction || |
| @@ -365,6 +368,12 @@ checkNativeAnnotation(Compiler compiler, ClassElement cls) { |
| const NativeAnnotationHandler()); |
| } |
| +checkJsInteropAnnotation(Compiler compiler, element) { |
| + EagerAnnotationHandler.checkAnnotation(compiler, element, |
| + const JsInteropAnnotationHandler()); |
| +} |
| + |
| + |
| /// Abstract interface for pre-resolution detection of metadata. |
| /// |
| /// The detection is handled in two steps: |
| @@ -452,6 +461,39 @@ class NativeAnnotationHandler implements EagerAnnotationHandler<String> { |
| } |
| } |
| +/// Annotation handler for pre-resolution detection of `@Js(...)` |
| +/// annotations. |
| +class JsInteropAnnotationHandler implements EagerAnnotationHandler<bool> { |
| + const JsInteropAnnotationHandler(); |
| + |
| + bool hasJsNameAnnotation(MetadataAnnotation annotation) => |
| + annotation.beginToken != null && annotation.beginToken.next.value == 'Js'; |
| + |
| + bool apply(Compiler compiler, |
| + Element element, |
| + MetadataAnnotation annotation) { |
| + bool hasJsInterop = hasJsNameAnnotation(annotation); |
| + if (hasJsInterop) { |
| + element.markAsJsInterop(); |
| + } |
| + // Due to semantics of apply in the baseclass we have to return null to |
| + // indicate that no match was found. |
| + return hasJsInterop == true ? true : null; |
|
Siggi Cherem (dart-lang)
2015/10/13 02:08:53
nit: `return hasJsInterop ? true : null` (just rea
Jacob
2015/10/13 03:10:43
done
|
| + } |
| + |
| + @override |
| + void validate(Compiler compiler, |
| + Element element, |
| + MetadataAnnotation annotation, |
| + ConstantValue constant) { |
| + JavaScriptBackend backend = compiler.backend; |
| + if (constant.getType(compiler.coreTypes).element != |
| + backend.jsAnnotationClass) { |
| + compiler.internalError(annotation, 'Invalid @Js(...) annotation.'); |
| + } |
| + } |
| +} |
| + |
| /// Annotation handler for pre-resolution detection of `@patch` annotations. |
| class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { |
| const PatchAnnotationHandler(); |