X Tutup
Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<dependency>
<groupId>com.squareup</groupId>
<artifactId>otto</artifactId>
<version>1.3.8</version>
</dependency>
<dependency>
<groupId>org.robolectric</groupId>
Expand Down
10 changes: 10 additions & 0 deletions AndroidAnnotations/androidannotations-otto/otto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
</dependency>
<dependency>
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations-testutils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>otto</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.helger</groupId>
<artifactId>jcodemodel</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the next enclosingElementHasEnhancedComponentAnnotation() call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, i have not touched it as i was not sure why exaclty it was there...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i think, we can remove it.. double checking should not be necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a empty line? :D maybe because i already removed the check you were talking about? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExecutableElement executableElement = (ExecutableElement) element;

JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 "";
}
}
Original file line number Diff line number Diff line change
@@ -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 "";
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--

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.

-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.androidannotations.otto"
android:versionCode="1"
android:versionName="1.0" >

<application />

</manifest>
5 changes: 5 additions & 0 deletions AndroidAnnotations/androidannotations-otto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<artifactId>otto</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>otto</artifactId>
<version>1.3.8</version>
</dependency>
</dependencies>

</dependencyManagement>
Expand Down
X Tutup