Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/framework/org.eclipse.papyrus.tests.framework.annotations/src/org/eclipse/papyrus/tests/framework/xtend/annotations/TestPackageRule.xtend')
-rw-r--r--tests/framework/org.eclipse.papyrus.tests.framework.annotations/src/org/eclipse/papyrus/tests/framework/xtend/annotations/TestPackageRule.xtend53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/framework/org.eclipse.papyrus.tests.framework.annotations/src/org/eclipse/papyrus/tests/framework/xtend/annotations/TestPackageRule.xtend b/tests/framework/org.eclipse.papyrus.tests.framework.annotations/src/org/eclipse/papyrus/tests/framework/xtend/annotations/TestPackageRule.xtend
new file mode 100644
index 00000000000..d159c2a5f13
--- /dev/null
+++ b/tests/framework/org.eclipse.papyrus.tests.framework.annotations/src/org/eclipse/papyrus/tests/framework/xtend/annotations/TestPackageRule.xtend
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.tests.framework.xtend.annotations
+
+import java.lang.annotation.Target
+import org.eclipse.xtend.lib.macro.AbstractFieldProcessor
+import org.eclipse.xtend.lib.macro.Active
+import org.eclipse.xtend.lib.macro.TransformationContext
+import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1
+import org.eclipse.xtend.lib.macro.declaration.Visibility
+
+/**
+ * An active annotation for test-package rules. Such rules are blocks that
+ * define a {@link TestPackageBuilder} as the only input (the implicit <b>{@code it}</b> variable).
+ * The field declaration may omit the type. It may be declared as either {@code var} or {@code val}
+ * but it will be generated as a {@code val}.
+ */
+@Target(FIELD)
+@Active(TestPackageRuleProcessor)
+annotation TestPackageRule {}
+
+class TestPackageRuleProcessor extends AbstractFieldProcessor {
+
+ override doTransform(MutableFieldDeclaration field, extension TransformationContext context) {
+ field.type = findTypeGlobally(Procedure1).newTypeReference(
+ findTypeGlobally("org.eclipse.papyrus.tests.framework.gmfgenuml2utp.TransformationUtilities.TestPackageBuilder").newTypeReference.newWildcardTypeReferenceWithLowerBound
+ )
+ field.final = true
+ field.visibility = Visibility.PRIVATE
+
+ field.declaringType.addMethod('get' + field.simpleName.toFirstUpper) [
+ field.markAsRead
+ returnType = field.type
+ body = ['''
+ return Ā«field.simpleNameĀ»;
+ ''']
+ primarySourceElement = field
+ ]
+ }
+
+} \ No newline at end of file

Back to the top