You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2017/10/30 19:13:59 UTC
[isis] 02/02: ISIS-1632: fixes handling of annotations on fields
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch dev/2.0.0/ISIS-1632-meta-annotations
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 24adee1bbcef190680c2567fb413b13eafa703f2
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Mon Oct 30 19:13:50 2017 +0000
ISIS-1632: fixes handling of annotations on fields
---
.../isis/core/metamodel/facets/Annotations.java | 2 +-
.../Annotations_getAnnotations_on_Field_Test.java | 122 +++++++++++----------
2 files changed, 68 insertions(+), 56 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/Annotations.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/Annotations.java
index af966f3..95bd112 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/Annotations.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/Annotations.java
@@ -294,7 +294,7 @@ public final class Annotations {
// search for field
- if ( !shouldSearchForField(annotationClass) ) {
+ if ( shouldSearchForField(annotationClass) ) {
final List<String> fieldNameCandidates = fieldNameCandidatesFor(method.getName());
for (String fieldNameCandidate : fieldNameCandidates) {
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/Annotations_getAnnotations_on_Field_Test.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/Annotations_getAnnotations_on_Field_Test.java
index 1e6cade..2e767e3 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/Annotations_getAnnotations_on_Field_Test.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/Annotations_getAnnotations_on_Field_Test.java
@@ -12,36 +12,26 @@ import org.junit.Assert;
import org.junit.Test;
import org.apache.isis.applib.annotation.Meta;
+import org.apache.isis.applib.annotation.Property;
+import org.apache.isis.applib.annotation.Publishing;
import static org.hamcrest.CoreMatchers.is;
-public class Annotations_getAnnotations_on_Method_Test {
+public class Annotations_getAnnotations_on_Field_Test {
- @Inherited
- @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
- @Retention(RetentionPolicy.RUNTIME)
- public @interface DomainObj { // cf @DomainObject
- enum Publishng { // cf Publishing enum
- YES,
- NO,
- NOT_SPECIFIED
- }
- Publishng publishng() default Publishng.NOT_SPECIFIED;
- }
-
@Meta
- @DomainObj(publishng = DomainObj.Publishng.YES)
+ @Property(publishing = Publishing.ENABLED)
@Inherited
- @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
+ @Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@interface Published {
}
@Meta
- @DomainObj(publishng = DomainObj.Publishng.NO)
+ @Property(publishing = Publishing.DISABLED)
@Inherited
- @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
+ @Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@interface NotPublished {
}
@@ -49,7 +39,7 @@ public class Annotations_getAnnotations_on_Method_Test {
@Meta
@Published
@Inherited
- @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
+ @Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@interface MetaPublished {
}
@@ -58,16 +48,20 @@ public class Annotations_getAnnotations_on_Method_Test {
public void direct() throws Exception {
class SomeDomainObject {
- @DomainObj(publishng = DomainObj.Publishng.YES)
- public void updateName(String name) {}
+ @Property(publishing = Publishing.ENABLED)
+ private String name;
+
+ public String getName() {
+ return name;
+ }
}
- Method method = SomeDomainObject.class.getMethod("updateName", String.class);
- final List<DomainObj> annotations = Annotations.getAnnotations(method, DomainObj.class);
+ Method method = SomeDomainObject.class.getMethod("getName");
+ final List<Property> annotations = Annotations.getAnnotations(method, Property.class);
Assert.assertThat(annotations.size(), is(1));
- Assert.assertThat(annotations.get(0).publishng(), is(DomainObj.Publishng.YES));
+ Assert.assertThat(annotations.get(0).publishing(), is(Publishing.ENABLED));
}
@Test
@@ -75,15 +69,18 @@ public class Annotations_getAnnotations_on_Method_Test {
class SomeDomainObject {
@Published
- public void updateName(String name) {}
+ private String name;
+ public String getName() {
+ return name;
+ }
}
- Method method = SomeDomainObject.class.getMethod("updateName", String.class);
- final List<DomainObj> annotations = Annotations.getAnnotations(method, DomainObj.class);
+ Method method = SomeDomainObject.class.getMethod("getName");
+ final List<Property> annotations = Annotations.getAnnotations(method, Property.class);
Assert.assertThat(annotations.size(), is(1));
- Assert.assertThat(annotations.get(0).publishng(), is(DomainObj.Publishng.YES));
+ Assert.assertThat(annotations.get(0).publishing(), is(Publishing.ENABLED));
}
@Test
@@ -91,15 +88,18 @@ public class Annotations_getAnnotations_on_Method_Test {
class SomeDomainObject {
@MetaPublished
- public void updateName(String name) {}
+ private String name;
+ public String getName() {
+ return name;
+ }
}
- Method method = SomeDomainObject.class.getMethod("updateName", String.class);
- final List<DomainObj> annotations = Annotations.getAnnotations(method, DomainObj.class);
+ Method method = SomeDomainObject.class.getMethod("getName");
+ final List<Property> annotations = Annotations.getAnnotations(method, Property.class);
Assert.assertThat(annotations.size(), is(1));
- Assert.assertThat(annotations.get(0).publishng(), is(DomainObj.Publishng.YES));
+ Assert.assertThat(annotations.get(0).publishing(), is(Publishing.ENABLED));
}
@Test
@@ -108,16 +108,19 @@ public class Annotations_getAnnotations_on_Method_Test {
class SomeDomainObject {
@MetaPublished
@Published
- public void updateName(String name) {}
+ private String name;
+ public String getName() {
+ return name;
+ }
}
- Method method = SomeDomainObject.class.getMethod("updateName", String.class);
- final List<DomainObj> annotations = Annotations.getAnnotations(method, DomainObj.class);
+ Method method = SomeDomainObject.class.getMethod("getName");
+ final List<Property> annotations = Annotations.getAnnotations(method, Property.class);
Assert.assertThat(annotations.size(), is(2));
- Assert.assertThat(annotations.get(0).publishng(), is(DomainObj.Publishng.YES));
- Assert.assertThat(annotations.get(1).publishng(), is(DomainObj.Publishng.YES));
+ Assert.assertThat(annotations.get(0).publishing(), is(Publishing.ENABLED));
+ Assert.assertThat(annotations.get(1).publishing(), is(Publishing.ENABLED));
}
@Test
@@ -126,16 +129,19 @@ public class Annotations_getAnnotations_on_Method_Test {
class SomeDomainObject {
@MetaPublished
@NotPublished
- public void updateName(String name) {}
+ private String name;
+ public String getName() {
+ return name;
+ }
}
- Method method = SomeDomainObject.class.getMethod("updateName", String.class);
- final List<DomainObj> annotations = Annotations.getAnnotations(method, DomainObj.class);
+ Method method = SomeDomainObject.class.getMethod("getName");
+ final List<Property> annotations = Annotations.getAnnotations(method, Property.class);
Assert.assertThat(annotations.size(), is(2));
- Assert.assertThat(annotations.get(0).publishng(), is(DomainObj.Publishng.NO));
- Assert.assertThat(annotations.get(1).publishng(), is(DomainObj.Publishng.YES));
+ Assert.assertThat(annotations.get(0).publishing(), is(Publishing.DISABLED));
+ Assert.assertThat(annotations.get(1).publishing(), is(Publishing.ENABLED));
}
@Test
@@ -144,18 +150,21 @@ public class Annotations_getAnnotations_on_Method_Test {
class SomeDomainObject {
@MetaPublished
@Published
- @DomainObj(publishng = DomainObj.Publishng.NO)
- public void updateName(String name) {}
+ @Property(publishing = Publishing.DISABLED)
+ private String name;
+ public String getName() {
+ return name;
+ }
}
- Method method = SomeDomainObject.class.getMethod("updateName", String.class);
- final List<DomainObj> annotations = Annotations.getAnnotations(method, DomainObj.class);
+ Method method = SomeDomainObject.class.getMethod("getName");
+ final List<Property> annotations = Annotations.getAnnotations(method, Property.class);
Assert.assertThat(annotations.size(), is(3));
- Assert.assertThat(annotations.get(0).publishng(), is(DomainObj.Publishng.NO));
- Assert.assertThat(annotations.get(1).publishng(), is(DomainObj.Publishng.YES));
- Assert.assertThat(annotations.get(2).publishng(), is(DomainObj.Publishng.YES));
+ Assert.assertThat(annotations.get(0).publishing(), is(Publishing.DISABLED));
+ Assert.assertThat(annotations.get(1).publishing(), is(Publishing.ENABLED));
+ Assert.assertThat(annotations.get(2).publishing(), is(Publishing.ENABLED));
}
@@ -165,18 +174,21 @@ public class Annotations_getAnnotations_on_Method_Test {
class SomeDomainObject {
@MetaPublished
@NotPublished
- @DomainObj(publishng = DomainObj.Publishng.YES)
- public void updateName(String name) {}
+ @Property(publishing = Publishing.ENABLED)
+ private String name;
+ public String getName() {
+ return name;
+ }
}
- Method method = SomeDomainObject.class.getMethod("updateName", String.class);
- final List<DomainObj> annotations = Annotations.getAnnotations(method, DomainObj.class);
+ Method method = SomeDomainObject.class.getMethod("getName");
+ final List<Property> annotations = Annotations.getAnnotations(method, Property.class);
Assert.assertThat(annotations.size(), is(3));
- Assert.assertThat(annotations.get(0).publishng(), is(DomainObj.Publishng.YES));
- Assert.assertThat(annotations.get(1).publishng(), is(DomainObj.Publishng.NO));
- Assert.assertThat(annotations.get(2).publishng(), is(DomainObj.Publishng.YES));
+ Assert.assertThat(annotations.get(0).publishing(), is(Publishing.ENABLED));
+ Assert.assertThat(annotations.get(1).publishing(), is(Publishing.DISABLED));
+ Assert.assertThat(annotations.get(2).publishing(), is(Publishing.ENABLED));
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.