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..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 @@ -8,10 +8,11 @@ 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. - * + * * @author Kenji Fujiwara * */ @@ -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. */ @@ -61,7 +72,7 @@ protected ASTMethod() { /** * Factory method of ASTMethod from MethodDeclaration of Eclipse AST. - * + * * @param node * MethodDeclaration of Eclipse AST */ @@ -72,11 +83,16 @@ protected ASTMethod(MethodDeclaration node) { isConstructor = node.isConstructor(); setBody(node); setParameters(node.parameters()); + + Type returnType = node.getReturnType2(); + if (returnType != null) { + setReturnType(returnType); + } } /** * Return root tree name. - * + * * @param node * MethodDeclaration of Eclipse AST * @return name of root tree @@ -104,7 +120,7 @@ private String getTreeName(MethodDeclaration node) { /** * Read and set method body to the Blob. - * + * * @param node * MethodDeclaration of Eclipse AST */ @@ -121,7 +137,7 @@ private void setBody(MethodDeclaration node) { /** * Read and set method parameters to the Blob. - * + * * @param parametersList * list of parameters */ @@ -142,9 +158,22 @@ 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. - * + * * @return directory name of the method */ public String getName() { @@ -153,7 +182,7 @@ public String getName() { /** * avoid conflicting blob name. - * + * * @param number * unique number of conflicted method */ @@ -167,7 +196,7 @@ public void conflict(int number) { /** * Return True if method is constructor. - * + * * @return method is constructor or not. */ public boolean isConstructor() { @@ -176,7 +205,7 @@ public boolean isConstructor() { /** * Factory method of ASTMethod. - * + * * @param node * MethodDeclaration of Eclipse AST * @return ASTMethod instance created from MethodDeclaration