From 67b83b944682373b7a7e7257db5b3a030105bd7b Mon Sep 17 00:00:00 2001 From: Junichi Hayashi Date: Tue, 26 Sep 2017 14:44:39 +0900 Subject: [PATCH 1/2] add a return type of method --- .../sd/kenja/factextractor/ast/ASTMethod.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/jp/naist/sd/kenja/factextractor/ast/ASTMethod.java b/src/main/java/jp/naist/sd/kenja/factextractor/ast/ASTMethod.java index 6236c3d..dd86f94 100644 --- a/src/main/java/jp/naist/sd/kenja/factextractor/ast/ASTMethod.java +++ b/src/main/java/jp/naist/sd/kenja/factextractor/ast/ASTMethod.java @@ -8,6 +8,7 @@ import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jdt.core.dom.Type; /** * A class which represents Method of Java for Historage. @@ -27,6 +28,11 @@ public class ASTMethod implements Treeable { */ private Blob parameters; + /** + * A Blob instance corresponding to method return type. + */ + private Blob returns; + /** * root Tree of a Method. */ @@ -42,6 +48,11 @@ public class ASTMethod implements Treeable { */ private static final String PARAMETERS_BLOB_NAME = "parameters"; + /** + * file name of method return type. + */ + private static final String RETURN_BLOB_NAME = "return"; + /** * True if method is a constructor. */ @@ -72,6 +83,10 @@ protected ASTMethod(MethodDeclaration node) { isConstructor = node.isConstructor(); setBody(node); setParameters(node.parameters()); + + if (!isConstructor) { + setReturnType(node.getReturnType2()); + } } /** @@ -142,6 +157,19 @@ private void setParameters(List parametersList) { parameters.setBody(parameterBody); } + /** + * Read and set method return type to the Blob. + * + * @param returnType + * type of return value + */ + private void setReturnType(Type returnType) { + returns = new Blob(RETURN_BLOB_NAME); + root.append(returns); + + returns.setBody(returnType.toString() + "\n"); + } + /** * return directory name of the method. * From 017ad4da81ca2119734fed2554e8f41a884d0b52 Mon Sep 17 00:00:00 2001 From: Junichi Hayashi Date: Thu, 12 Oct 2017 15:09:16 +0900 Subject: [PATCH 2/2] add a null check for getReturnType2 --- .../sd/kenja/factextractor/ast/ASTMethod.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/jp/naist/sd/kenja/factextractor/ast/ASTMethod.java b/src/main/java/jp/naist/sd/kenja/factextractor/ast/ASTMethod.java index dd86f94..30b3c49 100644 --- a/src/main/java/jp/naist/sd/kenja/factextractor/ast/ASTMethod.java +++ b/src/main/java/jp/naist/sd/kenja/factextractor/ast/ASTMethod.java @@ -12,7 +12,7 @@ /** * A class which represents Method of Java for Historage. - * + * * @author Kenji Fujiwara * */ @@ -72,7 +72,7 @@ protected ASTMethod() { /** * Factory method of ASTMethod from MethodDeclaration of Eclipse AST. - * + * * @param node * MethodDeclaration of Eclipse AST */ @@ -84,14 +84,15 @@ protected ASTMethod(MethodDeclaration node) { setBody(node); setParameters(node.parameters()); - if (!isConstructor) { - setReturnType(node.getReturnType2()); + Type returnType = node.getReturnType2(); + if (returnType != null) { + setReturnType(returnType); } } /** * Return root tree name. - * + * * @param node * MethodDeclaration of Eclipse AST * @return name of root tree @@ -119,7 +120,7 @@ private String getTreeName(MethodDeclaration node) { /** * Read and set method body to the Blob. - * + * * @param node * MethodDeclaration of Eclipse AST */ @@ -136,7 +137,7 @@ private void setBody(MethodDeclaration node) { /** * Read and set method parameters to the Blob. - * + * * @param parametersList * list of parameters */ @@ -172,7 +173,7 @@ private void setReturnType(Type returnType) { /** * return directory name of the method. - * + * * @return directory name of the method */ public String getName() { @@ -181,7 +182,7 @@ public String getName() { /** * avoid conflicting blob name. - * + * * @param number * unique number of conflicted method */ @@ -195,7 +196,7 @@ public void conflict(int number) { /** * Return True if method is constructor. - * + * * @return method is constructor or not. */ public boolean isConstructor() { @@ -204,7 +205,7 @@ public boolean isConstructor() { /** * Factory method of ASTMethod. - * + * * @param node * MethodDeclaration of Eclipse AST * @return ASTMethod instance created from MethodDeclaration