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
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016 the AndroidAnnotations project
*
* 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
Expand Down Expand Up @@ -35,6 +36,7 @@
import org.androidannotations.api.sharedpreferences.LongPrefEditorField;
import org.androidannotations.api.sharedpreferences.SharedPreferencesHelper;
import org.androidannotations.api.sharedpreferences.StringPrefEditorField;
import org.androidannotations.api.sharedpreferences.StringPrefField;
import org.androidannotations.api.sharedpreferences.StringSetPrefEditorField;
import org.androidannotations.helper.CanonicalNameConstants;

Expand Down Expand Up @@ -118,8 +120,18 @@ private void createEditMethod() {
public void createFieldMethod(Class<?> prefFieldHelperClass, IJExpression keyExpression, String fieldName, String fieldHelperMethodName, IJExpression defaultValue,
String docComment, String defaultValueStr) {
JMethod fieldMethod = generatedClass.method(PUBLIC, prefFieldHelperClass, fieldName);

if (defaultValueStr != null) {
fieldMethod.javadoc().append("<p><b>Defaults to</b>: " + defaultValueStr + "</p>\n");
boolean isStringPrefField = StringPrefField.class == prefFieldHelperClass;

final String defaultValueJavaDoc;
if (isStringPrefField) {
defaultValueJavaDoc = "\"" + defaultValueStr + "\"";
} else {
defaultValueJavaDoc = defaultValueStr;
}

fieldMethod.javadoc().append("<p><b>Defaults to</b>: " + defaultValueJavaDoc + "</p>\n");
}
codeModelHelper.addTrimmedDocComment(fieldMethod, docComment);
fieldMethod.body()._return(JExpr.invoke(fieldHelperMethodName).arg(keyExpression).arg(defaultValue));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016 the AndroidAnnotations project
*
* 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
Expand Down Expand Up @@ -95,4 +96,42 @@ public void generateJavaDocForSharedPref() throws IOException {
assertGeneratedClassContains(generatedFile, fieldDoc);
assertGeneratedClassContains(generatedFile, editorDoc);
}

@Test
public void generateJavaDocForEmptySharedPrefStringFields() throws IOException {
CompileResult result = compileFiles(SharedPrefWithJavaDoc.class);
File generatedFile = toGeneratedFile(SharedPrefWithJavaDoc.class);

assertCompilationSuccessful(result);

// CHECKSTYLE:OFF
String[] fieldDoc = { //
" * <p><b>Defaults to</b>: \"\"</p>", //
" * ", //
" */", //
" public StringPrefField title() {", //
};
// CHECKSTYLE:ON
assertGeneratedClassContains(generatedFile, fieldDoc);
}


@Test
public void generateJavaDocForNonEmptySharedPrefStringFields() throws IOException {
CompileResult result = compileFiles(SharedPrefWithJavaDoc.class);
File generatedFile = toGeneratedFile(SharedPrefWithJavaDoc.class);

assertCompilationSuccessful(result);

// CHECKSTYLE:OFF
String[] fieldDoc = { //
" * <p><b>Defaults to</b>: \"something\"</p>", //
" * ", //
" */", //
" public StringPrefField something() {", //
};
// CHECKSTYLE:ON
assertGeneratedClassContains(generatedFile, fieldDoc);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016 the AndroidAnnotations project
*
* 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
Expand Down Expand Up @@ -38,4 +39,9 @@ public interface SharedPrefWithJavaDoc {

@DefaultLong(42L)
long ageLong();

String title();

@DefaultString("something")
String something();
}