diff --git a/AndroidAnnotations/androidannotations-otto/otto-test/pom.xml b/AndroidAnnotations/androidannotations-otto/otto-test/pom.xml
index f2d66c59e4..6ec652a635 100644
--- a/AndroidAnnotations/androidannotations-otto/otto-test/pom.xml
+++ b/AndroidAnnotations/androidannotations-otto/otto-test/pom.xml
@@ -58,7 +58,6 @@
com.squareup
otto
- 1.3.8
org.robolectric
diff --git a/AndroidAnnotations/androidannotations-otto/otto/pom.xml b/AndroidAnnotations/androidannotations-otto/otto/pom.xml
index 65bd2f6511..d73edd4265 100644
--- a/AndroidAnnotations/androidannotations-otto/otto/pom.xml
+++ b/AndroidAnnotations/androidannotations-otto/otto/pom.xml
@@ -38,6 +38,16 @@
org.androidannotations
androidannotations
+
+ org.androidannotations
+ androidannotations-testutils
+ test
+
+
+ com.squareup
+ otto
+ test
+
com.helger
jcodemodel
diff --git a/AndroidAnnotations/androidannotations-otto/otto/src/main/java/org/androidannotations/otto/handler/AbstractOttoHandler.java b/AndroidAnnotations/androidannotations-otto/otto/src/main/java/org/androidannotations/otto/handler/AbstractOttoHandler.java
index ef58d04ef8..86abf598be 100644
--- a/AndroidAnnotations/androidannotations-otto/otto/src/main/java/org/androidannotations/otto/handler/AbstractOttoHandler.java
+++ b/AndroidAnnotations/androidannotations-otto/otto/src/main/java/org/androidannotations/otto/handler/AbstractOttoHandler.java
@@ -36,17 +36,12 @@ public AbstractOttoHandler(String target, AndroidAnnotationsEnvironment environm
@Override
public void validate(Element element, ElementValidation valid) {
if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
- valid.invalidate();
+ // do nothing when otto annotations are used in non-enhanced classes
return;
}
ExecutableElement executableElement = (ExecutableElement) element;
- /*
- * We check that twice to skip invalid annotated elements
- */
- validatorHelper.enclosingElementHasEnhancedComponentAnnotation(executableElement, valid);
-
validateReturnType(executableElement, valid);
validatorHelper.isPublic(element, valid);
@@ -64,6 +59,10 @@ public void validate(Element element, ElementValidation valid) {
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
+ if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
+ // do nothing when otto annotations are used in non-enhanced classes
+ return;
+ }
ExecutableElement executableElement = (ExecutableElement) element;
JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
diff --git a/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/EnhancedBean.java b/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/EnhancedBean.java
new file mode 100644
index 0000000000..d421b38372
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/EnhancedBean.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.otto;
+
+import org.androidannotations.annotations.EBean;
+
+import com.squareup.otto.Produce;
+import com.squareup.otto.Subscribe;
+
+@EBean
+public class EnhancedBean {
+
+ @Subscribe
+ public void subscriber(String fakeEvent) {
+ }
+
+ @Produce
+ public String producer() {
+ return "";
+ }
+}
diff --git a/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/NonEnhancedBean.java b/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/NonEnhancedBean.java
new file mode 100644
index 0000000000..90ddaef45c
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/NonEnhancedBean.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.otto;
+
+import com.squareup.otto.Produce;
+import com.squareup.otto.Subscribe;
+
+public class NonEnhancedBean {
+
+ @Subscribe
+ public void subscriber(String fakeEvent) {
+ }
+
+ @Produce
+ public String producer() {
+ return "";
+ }
+}
diff --git a/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/OttoGenerationTest.java b/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/OttoGenerationTest.java
new file mode 100644
index 0000000000..6b595ed753
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/OttoGenerationTest.java
@@ -0,0 +1,65 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.otto;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.androidannotations.internal.AndroidAnnotationProcessor;
+import org.androidannotations.testutils.AAProcessorTestHelper;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OttoGenerationTest extends AAProcessorTestHelper {
+
+ @Before
+ public void setUp() {
+ addManifestProcessorParameter(OttoGenerationTest.class);
+ addProcessor(AndroidAnnotationProcessor.class);
+ }
+
+ @Test
+ public void enhancedClassCompilesSuccessfully() {
+ assertCompilationSuccessful(compileFiles(EnhancedBean.class));
+ }
+
+ @Test
+ public void nonEnhancedClassCompilesSuccessfully() {
+ assertCompilationSuccessful(compileFiles(NonEnhancedBean.class));
+ }
+
+ @Test
+ public void enhancedClassGeneratesCode() {
+ CompileResult result = compileFiles(EnhancedBean.class);
+ File generatedFile = toGeneratedFile(EnhancedBean.class);
+
+ assertCompilationSuccessful(result);
+
+ assertTrue(generatedFile.exists());
+ }
+
+ @Test
+ public void nonEnhancedClassDoesNotGenerateCode() {
+ CompileResult result = compileFiles(NonEnhancedBean.class);
+ File generatedFile = toGeneratedFile(NonEnhancedBean.class);
+
+ assertCompilationSuccessful(result);
+
+ assertFalse(generatedFile.exists());
+ }
+}
diff --git a/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/R.java b/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/R.java
new file mode 100644
index 0000000000..8a10d44e61
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-otto/otto/src/test/java/org/androidannotations/otto/R.java
@@ -0,0 +1,19 @@
+/**
+ * Copyright (C) 2010-2015 eBusiness Information, Excilys Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed To in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.androidannotations.otto;
+
+public class R {
+}
diff --git a/AndroidAnnotations/androidannotations-otto/otto/src/test/resources/org/androidannotations/otto/AndroidManifest.xml b/AndroidAnnotations/androidannotations-otto/otto/src/test/resources/org/androidannotations/otto/AndroidManifest.xml
new file mode 100644
index 0000000000..b6d0d69717
--- /dev/null
+++ b/AndroidAnnotations/androidannotations-otto/otto/src/test/resources/org/androidannotations/otto/AndroidManifest.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
diff --git a/AndroidAnnotations/androidannotations-otto/pom.xml b/AndroidAnnotations/androidannotations-otto/pom.xml
index 7fc2aae1a7..1931cacdd1 100644
--- a/AndroidAnnotations/androidannotations-otto/pom.xml
+++ b/AndroidAnnotations/androidannotations-otto/pom.xml
@@ -46,6 +46,11 @@
otto
${project.version}
+
+ com.squareup
+ otto
+ 1.3.8
+