Repository navigation
572 enhanced service #601
572 enhanced service #601
Changes from 6 commits
be954c9
0e05794
c9a53d3
a8686e6
883af2e
9d1b3ca
5b97589
c1d25d3
84130ab
d4dbebe
2a60e05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Copyright (C) 2010-2013 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.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Use this annotation to enhance an Android Service | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.TYPE) | ||
| public @interface EIntentService { | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * Copyright (C) 2010-2013 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.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Use this annotation to enhance an Android Service | ||
|
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. Copy and Paste programming ? :p
Contributor
Author
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. Haha. Damn copy&paste x) |
||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.METHOD) | ||
| public @interface ServiceAction { | ||
|
|
||
| String value() default ""; | ||
|
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. On this field too |
||
|
|
||
| } | ||
| 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); | ||
|
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. parameterizedClass or parameterClass ? |
||
| 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; | ||
| } | ||
| } | ||
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.
To enhance
Android ServiceorAndroid IntentServices ?