This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
572 enhanced service #601
Merged
Merged
572 enhanced service #601
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
be954c9
Implement onHandleIntent for @EIntentService according to issue #572
DayS 0e05794
Add @ServiceAction methods in IntentBuilder
DayS c9a53d3
Add functional tests
DayS a8686e6
Allow injection of bean and other AA annotations in @EIntentService
DayS 883af2e
Fix a bug with primitives and stop execution as soon as an action match
DayS 9d1b3ca
Refactoring common code between ServiceActionProcessor and ExtraProce…
DayS 5b97589
Fix javadocs and rename some variables
DayS c1d25d3
Add functional tests
DayS 84130ab
Check if there is duplicate method names
DayS d4dbebe
Merge branch 'develop' into 572_EnhancedService
DayS 2a60e05
Update unit test to make them more readable
DayS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactoring common code between ServiceActionProcessor and ExtraProce…
…ssor Refactoring three parts : addCastMethod, addIntentBuilderPutExtraMethod and camelCaseToUpperSnakeCase
- Loading branch information
commit 9d1b3ca03bcd794f60758b17f324172545e8f655
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -23,18 +23,25 @@ | |
| import static com.sun.codemodel.JMod.PUBLIC; | ||
| import static com.sun.codemodel.JMod.STATIC; | ||
| import static javax.lang.model.element.ElementKind.CONSTRUCTOR; | ||
| import static org.androidannotations.helper.CanonicalNameConstants.PARCELABLE; | ||
| import static org.androidannotations.helper.CanonicalNameConstants.SERIALIZABLE; | ||
| import static org.androidannotations.helper.CanonicalNameConstants.STRING; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import javax.annotation.processing.ProcessingEnvironment; | ||
| import javax.lang.model.element.Element; | ||
| import javax.lang.model.element.ExecutableElement; | ||
| import javax.lang.model.element.VariableElement; | ||
| import javax.lang.model.type.ArrayType; | ||
| import javax.lang.model.type.DeclaredType; | ||
| import javax.lang.model.type.TypeKind; | ||
| import javax.lang.model.type.TypeMirror; | ||
| import javax.lang.model.type.WildcardType; | ||
| import javax.lang.model.util.Elements; | ||
| import javax.lang.model.util.Types; | ||
|
|
||
| import org.androidannotations.processing.EBeanHolder; | ||
| import org.androidannotations.processing.EBeansHolder.Classes; | ||
|
|
@@ -56,6 +63,7 @@ | |
| import com.sun.codemodel.JStatement; | ||
| import com.sun.codemodel.JTryBlock; | ||
| import com.sun.codemodel.JType; | ||
| import com.sun.codemodel.JTypeVar; | ||
| import com.sun.codemodel.JVar; | ||
|
|
||
| public class APTCodeModelHelper { | ||
|
|
@@ -383,4 +391,47 @@ private void addIntentBuilder(JCodeModel codeModel, EBeanHolder holder, boolean | |
| } | ||
| } | ||
| } | ||
|
|
||
| public JInvocation addIntentBuilderPutExtraMethod(JCodeModel codeModel, EBeanHolder holder, APTCodeModelHelper helper, ProcessingEnvironment processingEnv, JMethod method, TypeMirror elementType, String paramName, String extraName) { | ||
| boolean castToSerializable = false; | ||
| boolean castToParcelable = false; | ||
| if (elementType.getKind() == TypeKind.DECLARED) { | ||
| Elements elementUtils = processingEnv.getElementUtils(); | ||
| Types typeUtils = processingEnv.getTypeUtils(); | ||
| TypeMirror parcelableType = elementUtils.getTypeElement(PARCELABLE).asType(); | ||
| if (!typeUtils.isSubtype(elementType, parcelableType)) { | ||
| TypeMirror stringType = elementUtils.getTypeElement(STRING).asType(); | ||
| if (!typeUtils.isSubtype(elementType, stringType)) { | ||
| castToSerializable = true; | ||
| } | ||
| } else { | ||
| TypeMirror serializableType = elementUtils.getTypeElement(SERIALIZABLE).asType(); | ||
| if (typeUtils.isSubtype(elementType, serializableType)) { | ||
| castToParcelable = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| JClass paramClass = helper.typeMirrorToJClass(elementType, holder); | ||
| JVar extraParam = method.param(paramClass, paramName); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| JBlock body = method.body(); | ||
| JInvocation invocation = body.invoke(holder.intentField, "putExtra").arg(extraName); | ||
| if (castToSerializable) { | ||
| return invocation.arg(cast(holder.classes().SERIALIZABLE, extraParam)); | ||
| } else if (castToParcelable) { | ||
| return invocation.arg(cast(holder.classes().PARCELABLE, extraParam)); | ||
| } | ||
| return invocation.arg(extraParam); | ||
| } | ||
|
|
||
| public void addCastMethod(JCodeModel codeModel, EBeanHolder holder) { | ||
| JType objectType = codeModel._ref(Object.class); | ||
| JMethod method = holder.generatedClass.method(JMod.PRIVATE, objectType, "cast_"); | ||
| JTypeVar genericType = method.generify("T"); | ||
| method.type(genericType); | ||
| JVar objectParam = method.param(objectType, "object"); | ||
| method.annotate(SuppressWarnings.class).param("value", "unchecked"); | ||
| method.body()._return(JExpr.cast(genericType, objectParam)); | ||
| holder.cast = method; | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
...ations/androidannotations/src/test/java/org/androidannotations/helper/CaseHelperTest.java
This file contains hidden or 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,26 @@ | ||
| package org.androidannotations.helper; | ||
|
|
||
| import junit.framework.Assert; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class CaseHelperTest { | ||
|
|
||
| @Test | ||
| public void testCamelCaseToUpperSnakeCaseString() throws Exception { | ||
| Assert.assertEquals("CAMEL_CASE", CaseHelper.camelCaseToUpperSnakeCase("camelCase")); | ||
| Assert.assertEquals("CAMEL_CASE", CaseHelper.camelCaseToUpperSnakeCase("camel_case")); | ||
| Assert.assertEquals("CAMEL_CASE", CaseHelper.camelCaseToUpperSnakeCase("Camel_Case")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCamelCaseToUpperSnakeCaseStringStringString() throws Exception { | ||
| Assert.assertEquals("CAMEL_CASE", CaseHelper.camelCaseToUpperSnakeCase(null, "camelCase", null)); | ||
| Assert.assertEquals("PREFIX_CAMEL_CASE", CaseHelper.camelCaseToUpperSnakeCase("prefix", "camelCase", null)); | ||
| Assert.assertEquals("PREFIX_CAMEL_CASE", CaseHelper.camelCaseToUpperSnakeCase("prefix", "prefixCamelCase", null)); | ||
| Assert.assertEquals("CAMEL_CASE_SUFFIX", CaseHelper.camelCaseToUpperSnakeCase(null, "camelCase", "suffix")); | ||
| Assert.assertEquals("CAMEL_CASE_SUFFIX", CaseHelper.camelCaseToUpperSnakeCase(null, "camelCaseSuffix", "suffix")); | ||
| Assert.assertEquals("PREFIX_CAMEL_CASE_SUFFIX", CaseHelper.camelCaseToUpperSnakeCase("prefix", "camelCase", "suffix")); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameterizedClass or parameterClass ?
Can you choose a more excplicit variable name ?