aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakosyakov2013-07-02 13:37:18 (EDT)
committerGerrit Code Review @ Eclipse.org2013-07-04 08:26:34 (EDT)
commitc45a5e9b70a9241d11b87d41a2d9fb9f3fb4419e (patch)
treeef80338fe76c4cd13cc3e341a8a7faaad42c9f15
parent95a156398b3ef75674fe4af1013775238d060c5c (diff)
downloadorg.eclipse.xtext-c45a5e9b70a9241d11b87d41a2d9fb9f3fb4419e.zip
org.eclipse.xtext-c45a5e9b70a9241d11b87d41a2d9fb9f3fb4419e.tar.gz
org.eclipse.xtext-c45a5e9b70a9241d11b87d41a2d9fb9f3fb4419e.tar.bz2
[Bug 408569]: resolved - make MutableAnnotationReference removablerefs/changes/98/14198/2
Change-Id: Ia87747934c6c7ffd4b5a5d7fdd00f66fde62e2e6 Signed-off-by: akosyakov <anton.kosyakov@itemis.de>
-rw-r--r--plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/macro/declaration/JvmBasedDeclarations.xtend25
-rw-r--r--plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmAnnotationReferenceImpl.java4
-rw-r--r--plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmElementImpl.java38
-rw-r--r--plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmNamedElementImpl.java28
-rw-r--r--plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableAnnotationReference.java2
-rw-r--r--plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableElement.java18
-rw-r--r--plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableNamedElement.java7
-rw-r--r--tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.xtend140
-rw-r--r--tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.java73
9 files changed, 240 insertions, 95 deletions
diff --git a/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/macro/declaration/JvmBasedDeclarations.xtend b/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/macro/declaration/JvmBasedDeclarations.xtend
index 7d0c8b4..2362b7b 100644
--- a/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/macro/declaration/JvmBasedDeclarations.xtend
+++ b/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/macro/declaration/JvmBasedDeclarations.xtend
@@ -8,6 +8,7 @@
package org.eclipse.xtend.core.macro.declaration
import com.google.common.collect.ImmutableList
+import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration
import org.eclipse.xtend.lib.macro.declaration.CompilationStrategy
import org.eclipse.xtend.lib.macro.declaration.MutableAnnotationReference
@@ -16,6 +17,7 @@ import org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeDeclaration
import org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeElementDeclaration
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
import org.eclipse.xtend.lib.macro.declaration.MutableConstructorDeclaration
+import org.eclipse.xtend.lib.macro.declaration.MutableElement
import org.eclipse.xtend.lib.macro.declaration.MutableEnumerationTypeDeclaration
import org.eclipse.xtend.lib.macro.declaration.MutableExecutableDeclaration
import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration
@@ -46,16 +48,12 @@ import org.eclipse.xtext.common.types.JvmMember
import org.eclipse.xtext.common.types.JvmOperation
import org.eclipse.xtext.common.types.JvmVisibility
import org.eclipse.xtext.common.types.TypesFactory
-import org.eclipse.xtext.xbase.lib.Procedures.Procedure1
-import org.eclipse.emf.ecore.util.EcoreUtil
-import org.eclipse.xtext.xbase.compiler.DocumentationAdapter
import org.eclipse.xtext.common.types.impl.JvmMemberImplCustom
+import org.eclipse.xtext.xbase.compiler.DocumentationAdapter
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1
+import org.eclipse.emf.ecore.EObject
-abstract class JvmNamedElementImpl<T extends JvmIdentifiableElement> extends AbstractElementImpl<T> implements MutableNamedElement {
-
- override getSimpleName() {
- delegate.simpleName
- }
+abstract class JvmElementImpl<T extends EObject> extends AbstractElementImpl<T> implements MutableElement {
override remove() {
if (delegate.eContainer == null)
@@ -65,9 +63,18 @@ abstract class JvmNamedElementImpl<T extends JvmIdentifiableElement> extends Abs
throw new IllegalStateException("Couldn't remove "+delegate.toString)
}
+}
+
+abstract class JvmNamedElementImpl<T extends JvmIdentifiableElement> extends JvmElementImpl<T> implements MutableNamedElement {
+
+ override getSimpleName() {
+ delegate.simpleName
+ }
+
override toString() {
class.name+"["+simpleName+"]"
}
+
}
abstract class JvmAnnotationTargetImpl<T extends JvmAnnotationTarget> extends JvmNamedElementImpl<T> implements MutableAnnotationTarget {
@@ -652,7 +659,7 @@ class JvmAnnotationTypeElementDeclarationImpl extends JvmMemberDeclarationImpl<J
}
-class JvmAnnotationReferenceImpl extends AbstractElementImpl<JvmAnnotationReference> implements MutableAnnotationReference {
+class JvmAnnotationReferenceImpl extends JvmElementImpl<JvmAnnotationReference> implements MutableAnnotationReference {
override getAnnotationTypeDeclaration() {
compilationUnit.toTypeDeclaration(delegate.annotation) as AnnotationTypeDeclaration
diff --git a/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmAnnotationReferenceImpl.java b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmAnnotationReferenceImpl.java
index 64b7f26..450f57d 100644
--- a/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmAnnotationReferenceImpl.java
+++ b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmAnnotationReferenceImpl.java
@@ -10,9 +10,9 @@ package org.eclipse.xtend.core.macro.declaration;
import com.google.common.base.Objects;
import java.util.Collection;
import org.eclipse.emf.common.util.EList;
-import org.eclipse.xtend.core.macro.declaration.AbstractElementImpl;
import org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl;
import org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeDeclarationImpl;
+import org.eclipse.xtend.core.macro.declaration.JvmElementImpl;
import org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration;
import org.eclipse.xtend.lib.macro.declaration.MutableAnnotationReference;
import org.eclipse.xtend.lib.macro.declaration.MutableTypeDeclaration;
@@ -31,7 +31,7 @@ import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all")
-public class JvmAnnotationReferenceImpl extends AbstractElementImpl<JvmAnnotationReference> implements MutableAnnotationReference {
+public class JvmAnnotationReferenceImpl extends JvmElementImpl<JvmAnnotationReference> implements MutableAnnotationReference {
public AnnotationTypeDeclaration getAnnotationTypeDeclaration() {
CompilationUnitImpl _compilationUnit = this.getCompilationUnit();
JvmAnnotationReference _delegate = this.getDelegate();
diff --git a/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmElementImpl.java b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmElementImpl.java
new file mode 100644
index 0000000..766c9e7
--- /dev/null
+++ b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmElementImpl.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.eclipse.xtend.core.macro.declaration;
+
+import com.google.common.base.Objects;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.xtend.core.macro.declaration.AbstractElementImpl;
+import org.eclipse.xtend.lib.macro.declaration.MutableElement;
+
+@SuppressWarnings("all")
+public abstract class JvmElementImpl<T extends EObject> extends AbstractElementImpl<T> implements MutableElement {
+ public void remove() {
+ T _delegate = this.getDelegate();
+ EObject _eContainer = _delegate.eContainer();
+ boolean _equals = Objects.equal(_eContainer, null);
+ if (_equals) {
+ return;
+ }
+ T _delegate_1 = this.getDelegate();
+ EcoreUtil.remove(_delegate_1);
+ T _delegate_2 = this.getDelegate();
+ EObject _eContainer_1 = _delegate_2.eContainer();
+ boolean _notEquals = (!Objects.equal(_eContainer_1, null));
+ if (_notEquals) {
+ T _delegate_3 = this.getDelegate();
+ String _string = _delegate_3.toString();
+ String _plus = ("Couldn\'t remove " + _string);
+ IllegalStateException _illegalStateException = new IllegalStateException(_plus);
+ throw _illegalStateException;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmNamedElementImpl.java b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmNamedElementImpl.java
index 2b25d80..2fd7047 100644
--- a/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmNamedElementImpl.java
+++ b/plugins/org.eclipse.xtend.core/xtend-gen/org/eclipse/xtend/core/macro/declaration/JvmNamedElementImpl.java
@@ -7,42 +7,18 @@
*/
package org.eclipse.xtend.core.macro.declaration;
-import com.google.common.base.Objects;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.xtend.core.macro.declaration.AbstractElementImpl;
+import org.eclipse.xtend.core.macro.declaration.JvmElementImpl;
import org.eclipse.xtend.lib.macro.declaration.MutableNamedElement;
import org.eclipse.xtext.common.types.JvmIdentifiableElement;
@SuppressWarnings("all")
-public abstract class JvmNamedElementImpl<T extends JvmIdentifiableElement> extends AbstractElementImpl<T> implements MutableNamedElement {
+public abstract class JvmNamedElementImpl<T extends JvmIdentifiableElement> extends JvmElementImpl<T> implements MutableNamedElement {
public String getSimpleName() {
T _delegate = this.getDelegate();
String _simpleName = _delegate.getSimpleName();
return _simpleName;
}
- public void remove() {
- T _delegate = this.getDelegate();
- EObject _eContainer = _delegate.eContainer();
- boolean _equals = Objects.equal(_eContainer, null);
- if (_equals) {
- return;
- }
- T _delegate_1 = this.getDelegate();
- EcoreUtil.remove(_delegate_1);
- T _delegate_2 = this.getDelegate();
- EObject _eContainer_1 = _delegate_2.eContainer();
- boolean _notEquals = (!Objects.equal(_eContainer_1, null));
- if (_notEquals) {
- T _delegate_3 = this.getDelegate();
- String _string = _delegate_3.toString();
- String _plus = ("Couldn\'t remove " + _string);
- IllegalStateException _illegalStateException = new IllegalStateException(_plus);
- throw _illegalStateException;
- }
- }
-
public String toString() {
Class<? extends JvmNamedElementImpl> _class = this.getClass();
String _name = _class.getName();
diff --git a/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableAnnotationReference.java b/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableAnnotationReference.java
index 7f48c48..2bc2330 100644
--- a/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableAnnotationReference.java
+++ b/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableAnnotationReference.java
@@ -16,7 +16,7 @@ import com.google.common.annotations.Beta;
* @author Sven Efftinge
*/
@Beta
-public interface MutableAnnotationReference extends AnnotationReference {
+public interface MutableAnnotationReference extends AnnotationReference, MutableElement {
/**
* Sets the annotation property of the given name
diff --git a/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableElement.java b/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableElement.java
new file mode 100644
index 0000000..d9311d3
--- /dev/null
+++ b/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableElement.java
@@ -0,0 +1,18 @@
+package org.eclipse.xtend.lib.macro.declaration;
+
+import com.google.common.annotations.Beta;
+
+/**
+ *
+ * @author Anton Kosyakov
+ *
+ */
+@Beta
+public interface MutableElement extends Element {
+
+ /**
+ * Removes this element from its container and renders it invalid.
+ */
+ public void remove();
+
+}
diff --git a/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableNamedElement.java b/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableNamedElement.java
index 6ee61ba..e1308e2 100644
--- a/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableNamedElement.java
+++ b/plugins/org.eclipse.xtend.lib/src/org/eclipse/xtend/lib/macro/declaration/MutableNamedElement.java
@@ -13,15 +13,10 @@ import com.google.common.annotations.Beta;
* @author Sven Efftinge
*/
@Beta
-public interface MutableNamedElement extends NamedElement {
+public interface MutableNamedElement extends NamedElement, MutableElement {
/**
* @param simpleName the simple name of this element
*/
void setSimpleName(String simpleName);
-
- /**
- * Removes this element from its container and renders it invalid.
- */
- public void remove();
}
diff --git a/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.xtend b/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.xtend
index 2e24724..f31bcda 100644
--- a/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.xtend
+++ b/tests/org.eclipse.xtend.core.tests/src/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.xtend
@@ -7,7 +7,42 @@ import org.junit.Test
import static org.junit.Assert.*
abstract class AbstractReusableActiveAnnotationTests {
-
+
+ @Test def void testRemoveAnnotation() {
+ assertProcessing(
+ 'myannotation/RemoveAnnotation.xtend' -> '''
+ package myannotation
+
+ import org.eclipse.xtend.lib.macro.Active
+ import org.eclipse.xtend.lib.macro.TransformationContext
+ import org.eclipse.xtend.lib.macro.AbstractClassProcessor
+ import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
+
+ @Active(typeof(RemoveAnnotationProcessor))
+ annotation RemoveAnnotation{ }
+ class RemoveAnnotationProcessor extends AbstractClassProcessor {
+
+ override doTransform(MutableClassDeclaration clazz, extension TransformationContext context) {
+ clazz.findAnnotation(RemoveAnnotation.newTypeReference.type).remove
+ }
+
+ }
+ ''',
+ 'myusercode/UserCode.xtend' -> '''
+ package myusercode
+
+ /**
+ * MAKE ME LOWER CASE!
+ */
+ @myannotation.RemoveAnnotation class MyClass {
+ }
+ '''
+ ) [
+ val clazz = typeLookup.findClass('myusercode.MyClass')
+ assertEquals(0, clazz.annotations.size)
+ ]
+ }
+
@Test def void testChangeJavaDoc() {
assertProcessing(
'myannotation/ChangeDocAnnotation.xtend' -> '''
@@ -18,7 +53,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.AbstractClassProcessor
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
-
+
@Active(typeof(ChangeDocProcessor))
annotation ChangeDoc{ }
class ChangeDocProcessor extends AbstractClassProcessor {
@@ -40,10 +75,10 @@ abstract class AbstractReusableActiveAnnotationTests {
'''
) [
val clazz = typeLookup.findClass('myusercode.MyClass')
- assertEquals("make me lower case!",clazz.docComment)
+ assertEquals("make me lower case!", clazz.docComment)
]
}
-
+
@Test def void testAddConstructor() {
assertProcessing(
'myannotation/AddConstructorAnnotation.xtend' -> '''
@@ -54,7 +89,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.AbstractClassProcessor
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
-
+
@Active(typeof(AddConstructorProcessor))
annotation AddConstructor{ }
class AddConstructorProcessor extends AbstractClassProcessor {
@@ -90,7 +125,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.AbstractClassProcessor
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
-
+
@Active(typeof(AddConstructorProcessor))
annotation AddConstructor{ }
class AddConstructorProcessor extends AbstractClassProcessor {
@@ -115,7 +150,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertTrue(clazz.declaredConstructors.head.parameters.isEmpty)
]
}
-
+
@Test def void testSwapExpressions() {
assertProcessing(
'myannotation/SwapAnnotation.xtend' -> '''
@@ -126,7 +161,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration
-
+
@Active(typeof(SwapProcessor))
annotation Swap{ }
class SwapProcessor implements TransformationParticipant<MutableMethodDeclaration> {
@@ -156,6 +191,7 @@ abstract class AbstractReusableActiveAnnotationTests {
// no compile errors
]
}
+
@Test def void testSwapExpressions_01() {
assertProcessing(
'myannotation/SwapAnnotation.xtend' -> '''
@@ -166,7 +202,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration
-
+
@Active(typeof(SwapProcessor))
annotation Swap{ }
class SwapProcessor implements TransformationParticipant<MutableFieldDeclaration> {
@@ -192,6 +228,7 @@ abstract class AbstractReusableActiveAnnotationTests {
// no compile errors
]
}
+
@Test def void testSimpleModification() {
assertProcessing(
'myannotation/AbstractAnnotation.xtend' -> '''
@@ -202,7 +239,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
-
+
@Active(typeof(AbstractProcessor))
annotation Abstract { }
class AbstractProcessor implements TransformationParticipant<MutableClassDeclaration> {
@@ -228,7 +265,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertTrue(clazz.isAbstract)
]
}
-
+
@Test def void testParameterAnnotation() {
assertProcessing(
'myannotation/AbstractAnnotation.xtend' -> '''
@@ -239,7 +276,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableParameterDeclaration
-
+
@Active(typeof(ParamProcessor))
annotation Param { }
class ParamProcessor implements TransformationParticipant<MutableParameterDeclaration> {
@@ -265,7 +302,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertTrue(clazz.declaredMethods.head.parameters.forall[simpleName.endsWith('foo')])
]
}
-
+
@Test def void testSetDocumentation() {
assertProcessing(
'myannotation/AbstractAnnotation.xtend' -> '''
@@ -276,7 +313,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
-
+
@Active(typeof(AbstractProcessor))
annotation Abstract { }
class AbstractProcessor implements TransformationParticipant<MutableClassDeclaration> {
@@ -302,10 +339,10 @@ abstract class AbstractReusableActiveAnnotationTests {
'''
) [
val clazz = typeLookup.findClass('myusercode.MyClass')
- assertEquals('Hello World',clazz.docComment)
+ assertEquals('Hello World', clazz.docComment)
]
}
-
+
@Test def void testAddAnnotationValue() {
assertProcessing(
'myannotation/AbstractAnnotation.xtend' -> '''
@@ -316,7 +353,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTarget
-
+
@Active(typeof(AddAnnotationProcessor))
annotation AddAnnotation { }
class AddAnnotationProcessor implements TransformationParticipant<MutableAnnotationTarget> {
@@ -354,16 +391,17 @@ abstract class AbstractReusableActiveAnnotationTests {
'''
) [
val clazz = typeLookup.findClass('myusercode.MyClass')
- val annotation = clazz.findAnnotation(typeReferenceProvider.newTypeReference('myannotation.MyAnnotation').type)
- assertEquals(#['foo','bar','baz'],annotation.getValue('value'))
- assertEquals('foo',annotation.getValue('singleValue'))
- assertEquals(#[true,false,true],annotation.getValue('booleans'))
- assertEquals(true,annotation.getValue('singleBoolean'))
- assertEquals(#[1,2,3],annotation.getValue('numbers'))
- assertEquals(1,annotation.getValue('singleNumber'))
+ val annotation = clazz.findAnnotation(
+ typeReferenceProvider.newTypeReference('myannotation.MyAnnotation').type)
+ assertEquals(#['foo', 'bar', 'baz'], annotation.getValue('value'))
+ assertEquals('foo', annotation.getValue('singleValue'))
+ assertEquals(#[true, false, true], annotation.getValue('booleans'))
+ assertEquals(true, annotation.getValue('singleBoolean'))
+ assertEquals(#[1, 2, 3], annotation.getValue('numbers'))
+ assertEquals(1, annotation.getValue('singleNumber'))
]
}
-
+
@Test def void testCreateTypeFromUsage() {
assertProcessing(
'myannotation/SomeAnnotation.xtend' -> '''
@@ -408,7 +446,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertTrue(typeLookup.findClass('myusercode.DoesNotExist').simpleName == 'DoesNotExist')
]
}
-
+
@Test def void testPropertyAnnotation() {
assertProcessing(
'myannotation/PropertyAnnotation.xtend' -> "
@@ -461,7 +499,6 @@ abstract class AbstractReusableActiveAnnotationTests {
val getter = clazz.declaredMethods.head
assertEquals('getMyField', getter.simpleName)
assertEquals('String', getter.returnType.toString)
-
val setter = clazz.findMethod('setMyField', getter.returnType)
assertEquals('setMyField', setter.simpleName)
assertEquals('void', setter.returnType.toString)
@@ -469,7 +506,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertEquals('String', setter.parameters.head.type.toString)
]
}
-
+
@Test def void testThrowsAndTypeParam() {
assertProcessing(
'myannotation/AbstractAnnotation.xtend' -> '''
@@ -480,7 +517,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration
-
+
@Active(typeof(ThrowsAndTypeParamProcessor))
annotation ThrowsAndTypeParam { }
class ThrowsAndTypeParamProcessor implements TransformationParticipant<MutableMethodDeclaration> {
@@ -513,7 +550,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertEquals(1, method.exceptions.size)
]
}
-
+
@Test def void testValidation() {
assertProcessing(
'myannotation/AbstractAnnotation.xtend' -> '''
@@ -525,7 +562,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableNamedElement
import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration
-
+
@Active(typeof(ValidatedProcessor))
annotation Validated { }
class ValidatedProcessor implements TransformationParticipant<MutableNamedElement> {
@@ -560,7 +597,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertEquals('warning', problemSupport.getProblems(method).head.message)
]
}
-
+
@Test def void testIntroduceNewTypes() {
assertProcessing(
'myannotation/NewTypesAddingAnnotation.xtend' -> '''
@@ -571,7 +608,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.RegisterGlobalsContext
import org.eclipse.xtend.lib.macro.RegisterGlobalsParticipant
import org.eclipse.xtend.lib.macro.declaration.ClassDeclaration
-
+
@Active(typeof(NewTypesAddingAnnotationProcessor))
annotation NewTypesAddingAnnotation { }
class NewTypesAddingAnnotationProcessor implements RegisterGlobalsParticipant<ClassDeclaration> {
@@ -601,6 +638,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertNotNull(typeLookup.findAnnotationType('myusercode.MyClassAnnotation'))
]
}
+
@Test def void testIntroduceNewTypeAndWorkWithIt() {
assertProcessing(
'myannotation/NewTypesAddingAnnotation.xtend' -> '''
@@ -614,7 +652,7 @@ abstract class AbstractReusableActiveAnnotationTests {
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
-
+
@Active(typeof(NewTypesAddingAnnotationProcessor))
annotation NewTypesAddingAnnotation { }
class NewTypesAddingAnnotationProcessor implements RegisterGlobalsParticipant<ClassDeclaration>, TransformationParticipant<MutableClassDeclaration> {
@@ -648,14 +686,14 @@ abstract class AbstractReusableActiveAnnotationTests {
assertEquals(declaredClass.qualifiedName, clazz.extendedClass.type.qualifiedName)
]
}
-
+
val THREE_ANNOTATIONS = 'three.xtend' -> '''
import java.util.List
import org.eclipse.xtend.lib.macro.Active
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.TransformationParticipant
import org.eclipse.xtend.lib.macro.declaration.MutableNamedElement
-
+
@Active(typeof(Aprocessor))
annotation _A {}
class Aprocessor implements TransformationParticipant<MutableNamedElement> {
@@ -683,9 +721,10 @@ abstract class AbstractReusableActiveAnnotationTests {
override num() { '_C' }
}
'''
-
+
@Test def void testDeterministicExecutionOrder_01() {
- assertProcessing(THREE_ANNOTATIONS,
+ assertProcessing(
+ THREE_ANNOTATIONS,
'MyClass.xtend' -> '''
class MyClass {
@_A @_B @_C String field
@@ -693,13 +732,15 @@ abstract class AbstractReusableActiveAnnotationTests {
'''
) [
val myClass = typeLookup.findClass('MyClass')
- assertEquals('field_A_B_C',myClass.declaredFields.head.simpleName)
+ assertEquals('field_A_B_C', myClass.declaredFields.head.simpleName)
]
}
-
+
@Test def void testDeterministicExecutionOrder_02() {
+
// annotation processors are called in the order their annotations first occur in the file
- assertProcessing(THREE_ANNOTATIONS,
+ assertProcessing(
+ THREE_ANNOTATIONS,
'MyClass.xtend' -> '''
class MyClass {
@_A @_B @_C String field1
@@ -708,14 +749,16 @@ abstract class AbstractReusableActiveAnnotationTests {
'''
) [
val myClass = typeLookup.findClass('MyClass')
- assertEquals('field1_A_B_C',myClass.declaredFields.head.simpleName)
- assertEquals('field2_A_B_C',myClass.declaredFields.get(1).simpleName)
+ assertEquals('field1_A_B_C', myClass.declaredFields.head.simpleName)
+ assertEquals('field2_A_B_C', myClass.declaredFields.get(1).simpleName)
]
}
-
+
@Test def void testDeterministicExecutionOrder_03() {
+
// annotation processors are called in the order their annotations first occur in the file
- assertProcessing(THREE_ANNOTATIONS,
+ assertProcessing(
+ THREE_ANNOTATIONS,
'MyClass.xtend' -> '''
@_A @_B @_C class MyClass {
}
@@ -725,6 +768,7 @@ abstract class AbstractReusableActiveAnnotationTests {
assertNotNull(myClass)
]
}
-
- def void assertProcessing(Pair<String,String> macroFile, Pair<String,String> clientFile, (CompilationUnitImpl)=>void expectations)
-} \ No newline at end of file
+
+ def void assertProcessing(Pair<String, String> macroFile, Pair<String, String> clientFile,
+ (CompilationUnitImpl)=>void expectations)
+}
diff --git a/tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.java b/tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.java
index c050877..9ee07b0 100644
--- a/tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.java
+++ b/tests/org.eclipse.xtend.core.tests/xtend-gen/org/eclipse/xtend/core/tests/macro/AbstractReusableActiveAnnotationTests.java
@@ -34,6 +34,70 @@ import org.junit.Test;
@SuppressWarnings("all")
public abstract class AbstractReusableActiveAnnotationTests {
@Test
+ public void testRemoveAnnotation() {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package myannotation");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("import org.eclipse.xtend.lib.macro.Active");
+ _builder.newLine();
+ _builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
+ _builder.newLine();
+ _builder.append("import org.eclipse.xtend.lib.macro.AbstractClassProcessor");
+ _builder.newLine();
+ _builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("@Active(typeof(RemoveAnnotationProcessor))");
+ _builder.newLine();
+ _builder.append("annotation RemoveAnnotation{ }");
+ _builder.newLine();
+ _builder.append("class RemoveAnnotationProcessor extends AbstractClassProcessor {");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("override doTransform(MutableClassDeclaration clazz, extension TransformationContext context) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("clazz.findAnnotation(RemoveAnnotation.newTypeReference.type).remove");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ Pair<String,String> _mappedTo = Pair.<String, String>of("myannotation/RemoveAnnotation.xtend", _builder.toString());
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("package myusercode");
+ _builder_1.newLine();
+ _builder_1.newLine();
+ _builder_1.append("/**");
+ _builder_1.newLine();
+ _builder_1.append(" ");
+ _builder_1.append("* MAKE ME LOWER CASE!");
+ _builder_1.newLine();
+ _builder_1.append(" ");
+ _builder_1.append("*/");
+ _builder_1.newLine();
+ _builder_1.append("@myannotation.RemoveAnnotation class MyClass {");
+ _builder_1.newLine();
+ _builder_1.append("}");
+ _builder_1.newLine();
+ Pair<String,String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
+ final Procedure1<CompilationUnitImpl> _function = new Procedure1<CompilationUnitImpl>() {
+ public void apply(final CompilationUnitImpl it) {
+ TypeLookupImpl _typeLookup = it.getTypeLookup();
+ final MutableClassDeclaration clazz = _typeLookup.findClass("myusercode.MyClass");
+ Iterable<? extends MutableAnnotationReference> _annotations = clazz.getAnnotations();
+ int _size = IterableExtensions.size(_annotations);
+ Assert.assertEquals(0, _size);
+ }
+ };
+ this.assertProcessing(_mappedTo, _mappedTo_1, _function);
+ }
+
+ @Test
public void testChangeJavaDoc() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
@@ -1375,7 +1439,8 @@ public abstract class AbstractReusableActiveAnnotationTests {
Assert.assertEquals("field_A_B_C", _simpleName);
}
};
- this.assertProcessing(this.THREE_ANNOTATIONS, _mappedTo, _function);
+ this.assertProcessing(
+ this.THREE_ANNOTATIONS, _mappedTo, _function);
}
@Test
@@ -1406,7 +1471,8 @@ public abstract class AbstractReusableActiveAnnotationTests {
Assert.assertEquals("field2_A_B_C", _simpleName_1);
}
};
- this.assertProcessing(this.THREE_ANNOTATIONS, _mappedTo, _function);
+ this.assertProcessing(
+ this.THREE_ANNOTATIONS, _mappedTo, _function);
}
@Test
@@ -1424,7 +1490,8 @@ public abstract class AbstractReusableActiveAnnotationTests {
Assert.assertNotNull(myClass);
}
};
- this.assertProcessing(this.THREE_ANNOTATIONS, _mappedTo, _function);
+ this.assertProcessing(
+ this.THREE_ANNOTATIONS, _mappedTo, _function);
}
public abstract void assertProcessing(final Pair<String,String> macroFile, final Pair<String,String> clientFile, final Procedure1<? super CompilationUnitImpl> expectations);