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 @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeMirror, String> 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;
}

Expand Down
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.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;
}
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.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;
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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) {
}
}
X Tutup