| Index: lib/compiler/implementation/compiler.dart
|
| diff --git a/lib/compiler/implementation/compiler.dart b/lib/compiler/implementation/compiler.dart
|
| index 6b130e442bb074e78040abd5a662f3bb11e6d8d2..b2a5a6b2961d760e714d8216a2a0013af3a84733 100644
|
| --- a/lib/compiler/implementation/compiler.dart
|
| +++ b/lib/compiler/implementation/compiler.dart
|
| @@ -534,7 +534,7 @@ class Compiler implements DiagnosticListener {
|
| Uri resolved = patchBase.resolve(argument.dartString.slowToString());
|
| LibraryElement importedLibrary =
|
| scanner.loadLibrary(resolved, argument);
|
| - scanner.importLibrary(original, importedLibrary, tag, patch);
|
| + scanner.importLibrary(original, importedLibrary, tag, patch.script);
|
| if (resolved.scheme == "dart") {
|
| delayedPatches[resolved.path] = importedLibrary;
|
| }
|
| @@ -556,43 +556,34 @@ class Compiler implements DiagnosticListener {
|
| while (!patches.isEmpty()) {
|
| Element patchElement = patches.head;
|
| Element originalElement = lookup(patchElement.name);
|
| - // Getters and setters are kept inside a synthetic field.
|
| - if (patchElement.kind === ElementKind.ABSTRACT_FIELD) {
|
| - if (originalElement !== null &&
|
| - originalElement.kind !== ElementKind.ABSTRACT_FIELD) {
|
| - internalError("Cannot patch non-getter/setter with getter/setter",
|
| - element: originalElement);
|
| - }
|
| - AbstractFieldElement patchField = patchElement;
|
| + assert(patchElement.kind !== ElementKind.ABSTRACT_FIELD);
|
| + if (originalElement !== null &&
|
| + originalElement.kind === ElementKind.ABSTRACT_FIELD) {
|
| AbstractFieldElement originalField = originalElement;
|
| - if (patchField.getter !== null) {
|
| - if (originalField === null || originalField.getter === null) {
|
| - original.addGetterOrSetter(clonePatch(patchField.getter),
|
| - originalField,
|
| - this);
|
| - if (originalField === null && patchField.setter !== null) {
|
| - // It exists now, so find it for the setter patching.
|
| - originalField = lookup(patchElement.name);
|
| - }
|
| - } else {
|
| - patchMember(originalField.getter, patchField.getter);
|
| - }
|
| - }
|
| - if (patchField.setter !== null) {
|
| - if (originalField === null || originalField.setter === null) {
|
| - original.addGetterOrSetter(clonePatch(patchField.setter),
|
| - originalField,
|
| - this);
|
| - } else {
|
| - patchMember(originalField.setter, patchField.setter);
|
| - }
|
| + if (patchElement.kind === ElementKind.GETTER) {
|
| + originalElement = originalField.getter;
|
| + } else if (patchElement.kind === ElementKind.SETTER) {
|
| + originalElement = originalField.setter;
|
| + } else {
|
| + internalError("Cannot patch a getter/setter field with a "
|
| + "non-getter/setter patch", element: originalElement);
|
| }
|
| - } else if (originalElement === null) {
|
| + }
|
| + if (originalElement === null) {
|
| + // The original library does not have an element with the same name
|
| + // as the patch library element.
|
| + // In this case, the patch library element must not be marked as
|
| + // "patch", and its name must make it private.
|
| if (isPatchElement(patchElement)) {
|
| internalError("Cannot patch non-existing member '"
|
| "${patchElement.name.slowToString()}'.");
|
| }
|
| - original.addMember(clonePatch(patchElement), this);
|
| + if (!patchElement.name.isPrivate()) {
|
| + internalError("Cannot add non-private member '"
|
| + "${patchElement.name.slowToString()}' from patch.");
|
| + }
|
| + Element cloneElement = patchElement.cloneTo(original, this);
|
| + original.addMember(cloneElement, this);
|
| } else {
|
| patchMember(originalElement, patchElement);
|
| }
|
| @@ -606,20 +597,6 @@ class Compiler implements DiagnosticListener {
|
| return !element.metadata.isEmpty();
|
| }
|
|
|
| - Element clonePatch(Element patchElement) {
|
| - // The original library does not have an element with the same name
|
| - // as the patch library element.
|
| - // In this case, the patch library element must not be marked as "patch",
|
| - // and its name must make it private.
|
| - if (!patchElement.name.isPrivate()) {
|
| - internalError("Cannot add non-private member '"
|
| - "${patchElement.name.slowToString()}' from patch.");
|
| - }
|
| - // TODO(lrn): Create a copy of patchElement that isn't added to any
|
| - // object/library yet, but which takes its source from patchElement.
|
| - throw "Adding members from patch is unsupported";
|
| - }
|
| -
|
| void patchMember(Element originalElement, Element patchElement) {
|
| // The original library has an element with the same name as the patch
|
| // library element.
|
| @@ -978,7 +955,7 @@ class Compiler implements DiagnosticListener {
|
| throw 'Cannot find tokens to produce error message.';
|
| }
|
| if (uri === null && currentElement !== null) {
|
| - uri = currentElement.getCompilationUnit().script.uri;
|
| + uri = currentElement.getScript().uri;
|
| }
|
| return SourceSpan.withCharacterOffsets(begin, end,
|
| (beginOffset, endOffset) => new SourceSpan(uri, beginOffset, endOffset));
|
| @@ -1002,7 +979,7 @@ class Compiler implements DiagnosticListener {
|
| element = currentElement;
|
| }
|
| Token position = element.position();
|
| - Uri uri = element.getCompilationUnit().script.uri;
|
| + Uri uri = element.getScript().uri;
|
| return (position === null)
|
| ? new SourceSpan(uri, 0, 0)
|
| : spanFromTokens(position, position, uri);
|
|
|