diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java index b2c0d26636..c99c7abc5f 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java @@ -23,6 +23,7 @@ import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; +import javax.lang.model.element.TypeParameterElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.ArrayType; import javax.lang.model.type.DeclaredType; @@ -109,7 +110,6 @@ public Parameter(String name, JClass jClass) { public JMethod overrideAnnotatedMethod(ExecutableElement executableElement, GeneratedClassHolder holder) { String methodName = executableElement.getSimpleName().toString(); - JClass returnType = typeMirrorToJClass(executableElement.getReturnType(), holder); List parameters = new ArrayList(); @@ -139,6 +139,21 @@ public JMethod overrideAnnotatedMethod(ExecutableElement executableElement, Gene method._throws(thrownType); } + for (TypeParameterElement typeParameter : executableElement.getTypeParameters()) { + List bounds = typeParameter.getBounds(); + + JClass jClassBounds; + if (bounds.isEmpty()) { + jClassBounds = holder.classes().OBJECT; + } else { + // Currently Codemodel can't generate generics with multiple + // classes like this . + // So we only take the first class + jClassBounds = typeMirrorToJClass(bounds.get(0), holder); + } + method.generify(typeParameter.toString(), jClassBounds); + } + callSuperMethod(method, holder, method.body()); return method; diff --git a/AndroidAnnotations/functional-test-1-5/AndroidManifest.xml b/AndroidAnnotations/functional-test-1-5/AndroidManifest.xml index 36eba61248..27824ec0e8 100644 --- a/AndroidAnnotations/functional-test-1-5/AndroidManifest.xml +++ b/AndroidAnnotations/functional-test-1-5/AndroidManifest.xml @@ -82,6 +82,7 @@ + diff --git a/AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/ActivityWithGenerics.java b/AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/ActivityWithGenerics.java new file mode 100644 index 0000000000..dde57ea81b --- /dev/null +++ b/AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/ActivityWithGenerics.java @@ -0,0 +1,49 @@ +/** + * 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.test15; + +import java.util.List; + +import org.androidannotations.annotations.Background; +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.UiThread; + +import android.app.Activity; + +@EActivity +public class ActivityWithGenerics extends Activity { + + // @UiThread + // > void emptyUiMethod(T param, S param2) { + // // Not possible due to Codemodel's constraints + // } + + @UiThread + void emptyUiMethod(T param) { + + } + + @Background + void emptyBackgroundMethod(T param) { + + } + + @Background + void emptyBackgroundMethod(T param, List param2) { + + } + +}