diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java index 64c5051d1a..1d00f27be2 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java @@ -584,4 +584,10 @@ public void addSuppressWarnings(JAnnotatable generatedElement, String annotation generatedElement.annotate(SuppressWarnings.class).param("value", annotationValue); } + + public void addTrimmedDocComment(JMethod method, String docComment) { + if (docComment != null) { + method.javadoc().append(docComment.replaceAll("\r", "").trim()); + } + } } diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ExtraHandler.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ExtraHandler.java index b30e31340a..8baa6d3916 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ExtraHandler.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ExtraHandler.java @@ -75,7 +75,8 @@ public void process(Element element, HasExtras holder) { injectExtraInComponent(element, holder, extraKeyStaticField, fieldName); if (holder instanceof HasIntentBuilder) { - createIntentInjectionMethod(element, (HasIntentBuilder) holder, extraKeyStaticField, fieldName); + String docComment = getProcessingEnvironment().getElementUtils().getDocComment(element); + createIntentInjectionMethod(element, (HasIntentBuilder) holder, extraKeyStaticField, fieldName, docComment); } } @@ -105,7 +106,7 @@ private void injectExtraInComponent(Element element, HasExtras hasExtras, JField ifContainsKey.assign(extraField, restoreMethodCall); } - private void createIntentInjectionMethod(Element element, HasIntentBuilder holder, JFieldVar extraKeyStaticField, String fieldName) { - holder.getIntentBuilder().getPutExtraMethod(element.asType(), fieldName, extraKeyStaticField); + private void createIntentInjectionMethod(Element element, HasIntentBuilder holder, JFieldVar extraKeyStaticField, String fieldName, String docComment) { + holder.getIntentBuilder().getPutExtraMethod(element.asType(), fieldName, extraKeyStaticField, docComment); } } diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/FragmentArgHandler.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/FragmentArgHandler.java index e4599e1585..c9965371a0 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/FragmentArgHandler.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/FragmentArgHandler.java @@ -109,5 +109,10 @@ private void createBuilderInjectionMethod(Element element, EFragmentHolder holde JVar arg = method.param(paramClass, fieldName); method.body().invoke(builderArgsField, bundleHelper.getMethodNameToSave()).arg(argKeyStaticField).arg(arg); method.body()._return(_this()); + + String docComment = getProcessingEnvironment().getElementUtils().getDocComment(element); + codeModelHelper.addTrimmedDocComment(method, docComment); + method.javadoc().addParam(fieldName).append("the Fragment argument"); + method.javadoc().addReturn().append("the FragmentBuilder to chain calls"); } } diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ServiceActionHandler.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ServiceActionHandler.java index cd3065014d..400f25e061 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ServiceActionHandler.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ServiceActionHandler.java @@ -122,6 +122,10 @@ private void addActionToIntentBuilder(EIntentServiceHolder holder, ExecutableEle JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), methodName); JBlock body = method.body(); + String docComment = getProcessingEnvironment().getElementUtils().getDocComment(executableElement); + codeModelHelper.addTrimmedDocComment(method, docComment); + method.javadoc().addReturn().append("the IntentBuilder to chain calls"); + // setAction body.invoke("action").arg(actionKeyField); @@ -132,8 +136,8 @@ private void addActionToIntentBuilder(EIntentServiceHolder holder, ExecutableEle JFieldVar paramVar = getStaticExtraField(holder, paramName); JVar methodParam = method.param(parameterClass, paramName); - JMethod putExtraMethod = holder.getIntentBuilder().getPutExtraMethod(param.asType(), paramName, paramVar); - body.invoke(putExtraMethod).arg(methodParam); + JInvocation putExtraInvocation = holder.getIntentBuilder().getSuperPutExtraInvocation(param.asType(), methodParam, paramVar); + body.add(putExtraInvocation); } body._return(JExpr._this()); } diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/helper/IntentBuilder.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/helper/IntentBuilder.java index e342515dee..606e31b4b5 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/helper/IntentBuilder.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/helper/IntentBuilder.java @@ -107,22 +107,25 @@ private void createIntentMethod() { method.body()._return(_new(holder.getIntentBuilderClass()).arg(contextParam)); } - public JMethod getPutExtraMethod(TypeMirror elementType, String parameterName, JFieldVar extraKeyField) { + public JMethod getPutExtraMethod(TypeMirror elementType, String parameterName, JFieldVar extraKeyField, String docComment) { Pair signature = new Pair<>(elementType, parameterName); JMethod putExtraMethod = putExtraMethods.get(signature); if (putExtraMethod == null) { - putExtraMethod = addPutExtraMethod(elementType, parameterName, extraKeyField); + putExtraMethod = addPutExtraMethod(elementType, parameterName, extraKeyField, docComment); putExtraMethods.put(signature, putExtraMethod); } return putExtraMethod; } - private JMethod addPutExtraMethod(TypeMirror elementType, String parameterName, JFieldVar extraKeyField) { + private JMethod addPutExtraMethod(TypeMirror elementType, String parameterName, JFieldVar extraKeyField, String docComment) { JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), parameterName); JClass parameterClass = codeModelHelper.typeMirrorToJClass(elementType); JVar extraParameterVar = method.param(parameterClass, parameterName); JInvocation superCall = getSuperPutExtraInvocation(elementType, extraParameterVar, extraKeyField); method.body()._return(superCall); + codeModelHelper.addTrimmedDocComment(method, docComment); + method.javadoc().addParam(parameterName).append("the extra value"); + method.javadoc().addReturn().append("the IntentBuilder to chain calls"); return method; } diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/ActivityWithExtras.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/ActivityWithExtras.java new file mode 100644 index 0000000000..3e83229a8a --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/ActivityWithExtras.java @@ -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.generation; + +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.Extra; + +import android.app.Activity; + +@EActivity +public class ActivityWithExtras extends Activity { + + /** + * this is a javadoc comment + */ + @Extra + public String testExtra; +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/FragmentWithArg.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/FragmentWithArg.java new file mode 100644 index 0000000000..b94b5856b9 --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/FragmentWithArg.java @@ -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.generation; + +import org.androidannotations.annotations.EFragment; +import org.androidannotations.annotations.FragmentArg; + +import android.app.Fragment; + +@EFragment +public class FragmentWithArg extends Fragment { + + /** + * this is a javadoc comment + */ + @FragmentArg + public String testArg; +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/GenerateJavaDocTest.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/GenerateJavaDocTest.java new file mode 100644 index 0000000000..e0c451a576 --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/GenerateJavaDocTest.java @@ -0,0 +1,70 @@ +/** + * 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.generation; + +import java.io.File; +import java.io.IOException; + +import org.androidannotations.internal.AndroidAnnotationProcessor; +import org.androidannotations.testutils.AAProcessorTestHelper; +import org.junit.Before; +import org.junit.Test; + +public class GenerateJavaDocTest extends AAProcessorTestHelper { + + @Before + public void setUp() { + addManifestProcessorParameter(ActivityInManifest.class); + addProcessor(AndroidAnnotationProcessor.class); + ensureOutputDirectoryIsEmpty(); + } + + @Test + public void generateJavaDocForActivityExtra() throws IOException { + CompileResult result = compileFiles(ActivityWithExtras.class); + File generatedFile = toGeneratedFile(ActivityWithExtras.class); + + assertCompilationSuccessful(result); + + assertGeneratedClassMatches(generatedFile, ".*\\* this is a javadoc comment"); + assertGeneratedClassMatches(generatedFile, ".*\\* @param testExtra"); + assertGeneratedClassMatches(generatedFile, ".*\\* @return"); + } + + @Test + public void generateJavaDocForFragementArg() throws IOException { + CompileResult result = compileFiles(FragmentWithArg.class); + File generatedFile = toGeneratedFile(FragmentWithArg.class); + + assertCompilationSuccessful(result); + + assertGeneratedClassMatches(generatedFile, ".*\\* this is a javadoc comment"); + assertGeneratedClassMatches(generatedFile, ".*\\* @param testArg"); + assertGeneratedClassMatches(generatedFile, ".*\\* @return"); + } + + @Test + public void generateJavaDocForServiceAction() throws IOException { + CompileResult result = compileFiles(ServiceWithServiceAction.class); + File generatedFile = toGeneratedFile(ServiceWithServiceAction.class); + + assertCompilationSuccessful(result); + + assertGeneratedClassMatches(generatedFile, ".*\\* this is a javadoc comment"); + assertGeneratedClassMatches(generatedFile, ".*\\* @param param this is a param"); + assertGeneratedClassMatches(generatedFile, ".*\\* @return"); + } +} diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/ServiceWithServiceAction.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/ServiceWithServiceAction.java new file mode 100644 index 0000000000..631f11c88e --- /dev/null +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/generation/ServiceWithServiceAction.java @@ -0,0 +1,37 @@ +/** + * 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.generation; + +import org.androidannotations.annotations.EIntentService; +import org.androidannotations.annotations.ServiceAction; +import org.androidannotations.api.support.app.AbstractIntentService; + +@EIntentService +public class ServiceWithServiceAction extends AbstractIntentService { + + public ServiceWithServiceAction() { + super(ServiceWithServiceAction.class.getSimpleName()); + } + + /** + * this is a javadoc comment + * + * @param param this is a param + */ + @ServiceAction + void action(String param) { + } +}