Skip to content

Commit

Permalink
Incomplete attempt to remove @pure annotations from generated methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmy committed Jan 19, 2021
1 parent 1a4fad0 commit 1bf4a5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ class JsonRpcDataProcessor extends AbstractClassProcessor {
equalsHashCodeUtil.addEquals(impl, fields, shouldIncludeSuper)
equalsHashCodeUtil.addHashCode(impl, fields, shouldIncludeSuper)

// Remove all @Pure annotations that are hard-wired by equalsHashCodeUtil and AccessorUtil above.
// This creates an undesired dependency towards xtend that adds no functionality.
impl.getDeclaredMethods.forEach [ method |
val purified = method.findAnnotation(Pure.findTypeGlobally)
if (purified !== null) {
//TODO:

This comment has been minimized.

Copy link
@jonahgraham

jonahgraham Feb 2, 2021

This is very close. I believe the line you want is:

method.removeAnnotation(purified)

so the whole thing is:

		impl.getDeclaredMethods.forEach [ method | 
			val purified = method.findAnnotation(Pure.findTypeGlobally)
			if (purified !== null) {
				method.removeAnnotation(purified)
			}
		]
// method.removeAnnotation appears to be a no-op and has to be replaced
// with the proper way of removing annotation from a method.
method.removeAnnotation(newAnnotationReference(Pure))
}
]

return impl
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.eclipse.xtext.xbase.lib.Pure;

@SuppressWarnings("all")
public class JsonRpcDataProcessor extends AbstractClassProcessor {
Expand Down Expand Up @@ -69,6 +70,13 @@ protected MutableClassDeclaration generateImpl(final MutableClassDeclaration imp
final Iterable<? extends MutableFieldDeclaration> fields = IterableExtensions.filter(impl.getDeclaredFields(), _function_1);
equalsHashCodeUtil.addEquals(impl, fields, shouldIncludeSuper);
equalsHashCodeUtil.addHashCode(impl, fields, shouldIncludeSuper);
final Consumer<MutableMethodDeclaration> _function_2 = (MutableMethodDeclaration method) -> {
final AnnotationReference purified = method.findAnnotation(context.findTypeGlobally(Pure.class));
if ((purified != null)) {
method.removeAnnotation(context.newAnnotationReference(Pure.class));
}
};
impl.getDeclaredMethods().forEach(_function_2);
return impl;
}

Expand Down

0 comments on commit 1bf4a5b

Please sign in to comment.