This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We copy all non-AA annotations when we override a method. This can help Otto, because it does not read annotations from parent classes. But if a method is only annotated with Otto annotation, so we do not override it, the annotation will not be read Otto and the methods will not be called. To help that case, we re-add Otto handlers, which override (and annotate) Otto annotated methods in the generated subclass.
- Loading branch information
1 parent
2465468
commit 7d7213f
Showing
7 changed files
with
284 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...tions/androidannotations/src/main/java/org/androidannotations/handler/ProduceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (C) 2010-2014 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.handler; | ||
|
||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.ExecutableElement; | ||
|
||
import org.androidannotations.helper.APTCodeModelHelper; | ||
import org.androidannotations.helper.CanonicalNameConstants; | ||
import org.androidannotations.helper.TargetAnnotationHelper; | ||
import org.androidannotations.holder.EComponentHolder; | ||
import org.androidannotations.model.AnnotationElements; | ||
import org.androidannotations.process.IsValid; | ||
|
||
public class ProduceHandler extends BaseAnnotationHandler<EComponentHolder> { | ||
|
||
private final TargetAnnotationHelper annotationHelper; | ||
private final APTCodeModelHelper codeModelHelper = new APTCodeModelHelper(); | ||
|
||
public ProduceHandler(ProcessingEnvironment processingEnvironment) { | ||
super(CanonicalNameConstants.PRODUCE, processingEnvironment); | ||
annotationHelper = new TargetAnnotationHelper(processingEnv, getTarget()); | ||
} | ||
|
||
@Override | ||
public void validate(Element element, AnnotationElements validatedElements, IsValid valid) { | ||
if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) { | ||
valid.invalidate(); | ||
return; | ||
} | ||
|
||
ExecutableElement executableElement = (ExecutableElement) element; | ||
|
||
/* | ||
* We check that twice to skip invalid annotated elements | ||
*/ | ||
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(executableElement, validatedElements, valid); | ||
|
||
validatorHelper.returnTypeIsNotVoid(executableElement, valid); | ||
|
||
validatorHelper.isPublic(element, valid); | ||
|
||
validatorHelper.doesntThrowException(executableElement, valid); | ||
|
||
validatorHelper.isNotFinal(element, valid); | ||
|
||
validatorHelper.param.zeroParameter(executableElement, valid); | ||
} | ||
|
||
@Override | ||
public void process(Element element, EComponentHolder holder) throws Exception { | ||
ExecutableElement executableElement = (ExecutableElement) element; | ||
|
||
codeModelHelper.overrideAnnotatedMethod(executableElement, holder); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...ons/androidannotations/src/main/java/org/androidannotations/handler/SubscribeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (C) 2010-2014 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.handler; | ||
|
||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.ExecutableElement; | ||
|
||
import org.androidannotations.helper.APTCodeModelHelper; | ||
import org.androidannotations.helper.CanonicalNameConstants; | ||
import org.androidannotations.helper.TargetAnnotationHelper; | ||
import org.androidannotations.holder.EComponentHolder; | ||
import org.androidannotations.model.AnnotationElements; | ||
import org.androidannotations.process.IsValid; | ||
|
||
public class SubscribeHandler extends BaseAnnotationHandler<EComponentHolder> { | ||
|
||
private final TargetAnnotationHelper annotationHelper; | ||
private final APTCodeModelHelper codeModelHelper = new APTCodeModelHelper(); | ||
|
||
public SubscribeHandler(ProcessingEnvironment processingEnvironment) { | ||
super(CanonicalNameConstants.SUBSCRIBE, processingEnvironment); | ||
annotationHelper = new TargetAnnotationHelper(processingEnv, getTarget()); | ||
} | ||
|
||
@Override | ||
public void validate(Element element, AnnotationElements validatedElements, IsValid valid) { | ||
if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) { | ||
valid.invalidate(); | ||
return; | ||
} | ||
|
||
ExecutableElement executableElement = (ExecutableElement) element; | ||
|
||
/* | ||
* We check that twice to skip invalid annotated elements | ||
*/ | ||
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(executableElement, validatedElements, valid); | ||
|
||
validatorHelper.returnTypeIsVoid(executableElement, valid); | ||
|
||
validatorHelper.isPublic(element, valid); | ||
|
||
validatorHelper.doesntThrowException(executableElement, valid); | ||
|
||
validatorHelper.isNotFinal(element, valid); | ||
|
||
validatorHelper.param.hasExactlyOneParameter(executableElement, valid); | ||
} | ||
|
||
@Override | ||
public void process(Element element, EComponentHolder holder) throws Exception { | ||
ExecutableElement executableElement = (ExecutableElement) element; | ||
|
||
codeModelHelper.overrideAnnotatedMethod(executableElement, holder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...nal-test-1-5-tests/src/test/java/org/androidannotations/test15/otto/OttoActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (C) 2010-2014 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.test15.otto; | ||
|
||
import static org.fest.assertions.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.Robolectric; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class OttoActivityTest { | ||
|
||
@Test | ||
public void testOttoMethodsCalled() { | ||
OttoActivity activity = Robolectric.setupActivity(OttoActivity_.class); | ||
|
||
assertThat(activity.lastEvent).isNotNull(); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...notations/functional-test-1-5/src/main/java/org/androidannotations/test15/otto/Event.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (C) 2010-2014 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.test15.otto; | ||
|
||
public class Event { | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...ns/functional-test-1-5/src/main/java/org/androidannotations/test15/otto/OttoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (C) 2010-2014 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.test15.otto; | ||
|
||
import org.androidannotations.annotations.EActivity; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
|
||
import com.squareup.otto.Bus; | ||
import com.squareup.otto.Produce; | ||
import com.squareup.otto.Subscribe; | ||
|
||
@EActivity | ||
public class OttoActivity extends Activity { | ||
|
||
Event lastEvent; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
Bus bus = new Bus(); | ||
bus.register(this); | ||
} | ||
|
||
@Subscribe | ||
public void onEvent(Event event) { | ||
lastEvent = event; | ||
} | ||
|
||
@Produce | ||
public Event produceEvent() { | ||
return new Event(); | ||
} | ||
} |