You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/01/15 21:42:27 UTC
[2/2] groovy git commit: Bug Fix for GROOVY-7259
Bug Fix for GROOVY-7259
Added the test file
Removing the unwanted instance declartion
Adding the code changes for boolean types and public only methods
Removing the syso
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c1516a81
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c1516a81
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c1516a81
Branch: refs/heads/master
Commit: c1516a8180a06c88be2fab18bea4d06062591790
Parents: a0c40f1
Author: Anto <an...@gmail.com>
Authored: Mon Apr 20 19:27:38 2015 +0530
Committer: pascalschumacher <pa...@gmx.net>
Committed: Fri Jan 15 21:42:04 2016 +0100
----------------------------------------------------------------------
.../SimpleGroovyClassDocAssembler.java | 61 +++++++++++++++++
.../tools/groovydoc/GroovyDocToolTest.java | 57 ++++++++++++++++
.../testfiles/GeneratePropertyFromGetSet.groovy | 69 ++++++++++++++++++++
3 files changed, 187 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/c1516a81/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
index 94a31ee..0cc994e 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyClassDocAssembler.java
@@ -266,6 +266,66 @@ public class SimpleGroovyClassDocAssembler extends VisitorAdapter implements Gro
}
}
+ //Fix for GROOVY-7259
+ private void processPropertiesFromGetterSetter(SimpleGroovyMethodDoc currentMethodDoc)
+ {
+ String methodName = currentMethodDoc.name();
+ SimpleGroovyClassDoc classDoc = getCurrentClassDoc();
+ GroovyMethodDoc methods[] = classDoc.methods();
+
+ String setOrGet = methodName.substring(0, Math.min(methodName.length(), 3));
+ if(setOrGet.equals("set") || setOrGet.equals("get") || setOrGet.contains("is")) {
+
+ //find the expectedMethod name
+ String expectedMethod = null ;
+ if(setOrGet.equals("set") && (currentMethodDoc.parameters().length >= 1 &&
+ !currentMethodDoc.parameters()[0].typeName().equals("boolean")))
+ expectedMethod = "get" + methodName.substring(3);
+ else if(setOrGet.equals("get") && !currentMethodDoc.returnType().typeName().equals("boolean"))
+ expectedMethod = "set" + methodName.substring(3);
+ else if(setOrGet.contains("is"))
+ expectedMethod = "set" + methodName.substring(2);
+ else
+ expectedMethod = "is" + methodName.substring(3);
+
+ for (GroovyMethodDoc methodDoc : methods) {
+ if (methodDoc.name().equals(expectedMethod)) {
+
+ //now extract the field name
+ String fieldName = null;
+ if(expectedMethod.contains("set") && methodName.substring(0,2).equals("is"))
+ fieldName = methodName.substring(2); //when we are finding for boolean types
+ else
+ fieldName = methodName.substring(3);
+
+ fieldName = fieldName.substring(0,1).toLowerCase() + fieldName.substring(1);
+ SimpleGroovyFieldDoc currentFieldDoc = new SimpleGroovyFieldDoc(fieldName, classDoc);
+
+ //Now find the type of the field
+ //If its setter, need to get the type from params
+ if(expectedMethod.contains("set") && methodDoc.parameters().length >= 1)
+ {
+ String typeName = methodDoc.parameters()[0].typeName();
+ currentFieldDoc.setType(new SimpleGroovyType(typeName));
+ }
+ else {
+ //If not setter, get the type info from return type of get* method.
+ currentFieldDoc.setType(methodDoc.returnType());
+ }
+
+ //interested only in public methods
+ if(methodDoc.isPublic() && currentMethodDoc.isPublic()) {
+ classDoc.addProperty(currentFieldDoc);
+ break;
+ }
+ else
+ continue;
+ }
+ }
+ }
+ }
+
+
private SimpleGroovyMethodDoc createMethod(GroovySourceAST t, SimpleGroovyClassDoc currentClassDoc) {
String methodName = getIdentFor(t);
SimpleGroovyMethodDoc currentMethodDoc = new SimpleGroovyMethodDoc(methodName, currentClassDoc);
@@ -274,6 +334,7 @@ public class SimpleGroovyClassDocAssembler extends VisitorAdapter implements Gro
currentMethodDoc.setReturnType(new SimpleGroovyType(getTypeOrDefault(t)));
addParametersTo(t, currentMethodDoc);
processAnnotations(t, currentMethodDoc);
+ processPropertiesFromGetterSetter(currentMethodDoc);
return currentMethodDoc;
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/c1516a81/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
index e4d8d00..8b5cf48 100644
--- a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
@@ -345,6 +345,63 @@ public class GroovyDocToolTest extends GroovyTestCase {
testVisibility(props, true, true, true, true);
}
+
+ public void testSinglePropertiesFromGetterSetter() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet","str properties should be there","<a href=\"#str\">str</a>",true);
+ }
+
+ public void testReOrderPropertiesFromGetterSetter() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet","str1 properties should be there","<a href=\"#str1\">str1</a>",true);
+ }
+
+ public void testCheckOtherTypesPropertiesFromGetterSetter() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet","int properties should be there","<a href=\"#int\">int</a>",true);
+ }
+
+ public void testPropertiesShouldNotBePresentForGetterAlone() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet","shouldNotBePresent properties shouldnt be there","<a href=\"#shouldNotBePresent\">shouldNotBePresent</a>",false);
+ }
+
+ public void testPropertiesPublicGetPrivateSet() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet", "_public_get_private_set shouldnt be present"
+ , "<a href=\"#_public_get_private_set\">_public_get_private_set</a>", false);
+ }
+
+ public void testPropertiesPrivateGetPublicSet() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet", "_private_get_public_set shouldnt be present",
+ "<a href=\"#_private_get_public_set\">_private_get_public_set</a>", false);
+ }
+
+ public void testPropertiesPrivateGetPrivateSet() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet", "_private_get_private_set shouldnt be present",
+ "<a href=\"#_private_get_private_set\">_private_get_private_set</a>", false);
+ }
+
+
+ public void testPropertiesShouldBePresentForSetIsBooleanType() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet","testBoolean properties should be there","<a href=\"#testBoolean\">testBoolean</a>",true);
+ }
+
+ public void testPropertiesShouldBePresentForIsSetBooleanType() throws Exception {
+ testPropertiesFromGetterSetter("GeneratePropertyFromGetSet","testBoolean2 properties should be there","<a href=\"#testBoolean2\">testBoolean2</a>",true);
+ }
+
+ private void testPropertiesFromGetterSetter(String fileName,String assertMessage,String expected,boolean isTrue) throws Exception
+ {
+ htmlTool = makeHtmltool(new ArrayList<LinkArgument>(), new Properties());
+ List<String> srcList = new ArrayList<String>();
+ String base = "org/codehaus/groovy/tools/groovydoc/testfiles/";
+ srcList.add(base + fileName + ".groovy");
+ htmlTool.add(srcList);
+ MockOutputTool output = new MockOutputTool();
+ htmlTool.renderToOutput(output, MOCK_DIR);
+ String exampleClass = output.getText(MOCK_DIR + "/" + base + fileName + ".html");
+ if(isTrue)
+ assertTrue(assertMessage, exampleClass.contains(expected));
+ else
+ assertFalse(assertMessage,exampleClass.contains(expected));
+ }
+
private void testVisibility(Properties props, boolean a, boolean b, boolean c, boolean d) throws Exception {
htmlTool = makeHtmltool(new ArrayList<LinkArgument>(), props);
List<String> srcList = new ArrayList<String>();
http://git-wip-us.apache.org/repos/asf/groovy/blob/c1516a81/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/GeneratePropertyFromGetSet.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/GeneratePropertyFromGetSet.groovy b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/GeneratePropertyFromGetSet.groovy
new file mode 100644
index 0000000..9ec1fb3
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/GeneratePropertyFromGetSet.groovy
@@ -0,0 +1,69 @@
+package org.codehaus.groovy.tools.groovydoc.testfiles;
+
+public class GeneratePropertyFromGetSet {
+
+ public void setStr(String str) {
+ }
+
+ public String getStr() {
+ return "";
+ }
+
+ public String getStr1() {
+ return "";
+ }
+
+ public void setStr1(String str) {
+ }
+
+ public int getInt() {
+ return 0;
+ }
+
+ public void setInt(int integer) {
+ }
+
+ public void setShouldNotBePresent(int str) {
+ }
+
+ private void set_public_get_private_set(String public_get_private_set) {
+ }
+
+ public String get_public_get_private_set() {
+ return "";
+ }
+
+ public void set_private_get_public_set(String private_get_public_set) {
+ }
+
+ private String get_private_get_public_set() {
+ return "";
+ }
+
+ private void set_private_get_private_set(String private_get_private_set) {
+ }
+
+ private String get_private_get_private_set() {
+ }
+
+ public void setTestBoolean(boolean a)
+ {
+
+ }
+
+ public boolean isTestBoolean()
+ {
+
+ }
+
+ public boolean isTestBoolean2()
+ {
+
+ }
+
+ public void setTestBoolean2(boolean a)
+ {
+
+ }
+
+}