Skip to content

Commit

Permalink
feature #64: Track doc changes (Ydocchange)
Browse files Browse the repository at this point in the history
- Add a new change type Ydocchange which extends Ysignaturechange
- Rename everywhere reference of *javaDoc* -> Doc to keep things consistent with python
  and typescript implementation
TODO list:
- Implement `getInitialDoc` in `com/felixgrund/codeshovel/parser/impl/PythonFunction.java`
- Implement `getInitialDoc` in `com/felixgrund/codeshovel/parser/impl/TypeScriptFunction.java`
- Handle `Ydocchange` in `src/main/java/com/felixgrund/codeshovel/parser/impl/TypeScriptParser.java`
- Handle `Ydocchange` in `src/main/java/com/felixgrund/codeshovel/parser/impl/PythonParser.java`
- Get the diff for doc changes
  • Loading branch information
ishtiaque05 committed Feb 23, 2021
1 parent 3ce998e commit 0d642eb
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public JsonObject toJsonObject() {
obj.addProperty("functionStartLine", newFunction.getNameLineNumber());
obj.addProperty("functionName", newFunction.getName());
obj.addProperty("functionAnnotation", newFunction.getAnnotation());
obj.addProperty("functionJavaDoc", newFunction.getJavaDoc());
obj.addProperty("functionDoc", newFunction.getFunctionDoc());
obj.addProperty("diff", getDiffAsString());
obj.add("extendedDetails", getExtendedDetailsJsonObject());
return obj;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/felixgrund/codeshovel/changes/Ydocchange.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.felixgrund.codeshovel.changes;

import com.felixgrund.codeshovel.parser.Yfunction;
import com.felixgrund.codeshovel.wrappers.StartEnvironment;

public class Ydocchange extends Ysignaturechange{

public Ydocchange(StartEnvironment startEnv, Yfunction newFunction, Yfunction oldFunction) {
super(startEnv, newFunction, oldFunction);
}

@Override
protected Object getOldValue() {
return oldFunction.getFunctionDoc();
}

@Override
protected Object getNewValue() {
return newFunction.getFunctionDoc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public JsonObject toJsonObject() {
obj.addProperty("functionStartLine", newFunction.getNameLineNumber());
obj.addProperty("functionName", newFunction.getName());
obj.addProperty("functionAnnotation", newFunction.getAnnotation());
obj.addProperty("functionJavaDoc", newFunction.getJavaDoc());
obj.addProperty("functionDoc", newFunction.getFunctionDoc());
return obj;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static Yresult runForMethod(StartEnvironment startEnv, String filePath,
task.setFunctionName(name);
task.setFunctionStartLine(lineNumber);
task.setFunctionAnnotation(method.getAnnotation());
task.setFunctionJavaDoc(method.getJavaDoc());
task.setFunctionDoc(method.getFunctionDoc());

RecursiveAnalysisTask recursiveAnalysisTask = new RecursiveAnalysisTask(startEnv, task);
recursiveAnalysisTask.run();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/felixgrund/codeshovel/json/JsonResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class JsonResult {
private String functionId;
private String sourceFilePath;
private String functionAnnotation;
private String functionJavaDoc;
private String functionDoc;
private int functionStartLine;
private int functionEndLine;
private int numCommitsSeen;
Expand All @@ -47,7 +47,7 @@ public JsonResult(String origin, AnalysisTask startTask, List<String> changeHist
this.functionName = startTask.getFunctionName();
this.functionStartLine = startTask.getFunctionStartLine();
this.functionAnnotation = startTask.getFunctionAnnotation();
this.functionJavaDoc = startTask.getFunctionJavaDoc();
this.functionDoc = startTask.getFunctionDoc();
this.functionEndLine = startTask.getFunctionEndLine();
this.functionId = startTask.getStartFunction().getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public abstract class AbstractFunction<E> implements Yfunction {
private String annotation;
protected abstract String getInitialAnnotation(E rawMethod);
private String sourceFragment;
private String javaDoc;
protected abstract String getInitialJavaDoc(E rawMethod);
private String functionDoc;
protected abstract String getInitialDoc(E rawMethod);

public AbstractFunction(E rawMethod, Commit commit, String sourceFilePath, String sourceFileContent) {
this.commit = commit;
Expand All @@ -72,7 +72,7 @@ public AbstractFunction(E rawMethod, Commit commit, String sourceFilePath, Strin
this.returnStmt = getInitialReturnStmt(rawMethod); // Must be called after getInitialType
this.annotation = getInitialAnnotation(rawMethod);
this.sourceFragment = getInitialSourceFragment(rawMethod); // Must be called after begin/endLine
this.javaDoc = getInitialJavaDoc(rawMethod);
this.functionDoc = getInitialDoc(rawMethod);
}

protected String getIdParameterString() {
Expand Down Expand Up @@ -205,7 +205,7 @@ public String getAnnotation() {
}

@Override
public String getJavaDoc() {
return this.javaDoc;
public String getFunctionDoc() {
return this.functionDoc;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/felixgrund/codeshovel/parser/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public AbstractParser(StartEnvironment startEnv, String filePath, String fileCon

protected abstract List<Yfunction> parseMethods() throws ParseException;

protected Ydocchange getDocChange(Ycommit commit, Yfunction compareFunction) {
Ydocchange ret = null;
String docA = compareFunction.getFunctionDoc();
String docB = commit.getMatchedFunction().getFunctionDoc();
if(!docA.equals(docB)) {
ret = new Ydocchange(this.startEnv, commit.getMatchedFunction(), compareFunction);
}
return ret;
}

protected Yannotationchange getAnnotationChange(Ycommit commit, Yfunction compareFunction) {
Yannotationchange ret = null;
String annotationA = compareFunction.getAnnotation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ public interface Yfunction {
/**
* @return java documentation of a method if present
* */
String getJavaDoc();
String getFunctionDoc();

}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private boolean isNestedMethod(MethodDeclaration method) {
}

@Override
protected String getInitialJavaDoc(MethodDeclaration method) {
return method.hasJavaDocComment() ? method.getJavadoc().get().toText() : null ;
protected String getInitialDoc(MethodDeclaration method) {
return method.hasJavaDocComment() ? method.getJavadoc().get().toText() : "" ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public List<Ychange> getMinorChanges(Ycommit commit, Yfunction compareFunction)
Ybodychange ybodychange = getBodyChange(commit, compareFunction);
Yparametermetachange yparametermetachange = getParametersMetaChange(commit, compareFunction);
Yannotationchange yannotationchange = getAnnotationChange(commit, compareFunction);
Ydocchange ydocchange = getDocChange(commit, compareFunction);

if (yreturntypechange != null) {
changes.add(yreturntypechange);
}
Expand All @@ -91,6 +93,9 @@ public List<Ychange> getMinorChanges(Ycommit commit, Yfunction compareFunction)
if (yannotationchange != null) {
changes.add(yannotationchange);
}
if (ydocchange != null) {
changes.add(ydocchange);
}
return changes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected String getInitialAnnotation(PythonParser.FuncdefContext rawMethod) {
}

@Override
protected String getInitialJavaDoc(PythonParser.FuncdefContext rawMethod) {
protected String getInitialDoc(PythonParser.FuncdefContext rawMethod) {
// TODO: implement function for python
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public List<Ychange> getMinorChanges(Ycommit commit, Yfunction compareFunction)
Ybodychange ybodychange = getBodyChange(commit, compareFunction);
Ymodifierchange ymodifierchange = getModifiersChange(commit, compareFunction);
Yannotationchange yannotationchange = getAnnotationChange(commit, compareFunction);
// TODO handle Ydocchange

if (yparametermetachange != null) {
changes.add(yparametermetachange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected String getInitialAnnotation(V8Object rawMethod) {
}

@Override
protected String getInitialJavaDoc(V8Object rawMethod) {
protected String getInitialDoc(V8Object rawMethod) {
// TODO: implement function for typescript
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public List<Ychange> getMinorChanges(Ycommit commit, Yfunction compareFunction)
Ymodifierchange ymodifierchange = getModifiersChange(commit, compareFunction);
Ybodychange ybodychange = getBodyChange(commit, compareFunction);
Yannotationchange yannotationchange = getAnnotationChange(commit, compareFunction);
// TODO: handle Ydocchange
if (yreturntypechange != null) {
changes.add(yreturntypechange);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/felixgrund/codeshovel/tasks/AnalysisTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AnalysisTask {
private String functionAnnotation;
private int functionStartLine;
private int functionEndLine;
private String functionJavaDoc;
private String functionDoc;

private boolean wasBuilt;

Expand Down Expand Up @@ -84,7 +84,7 @@ public AnalysisTask(StartEnvironment startEnv, Yfunction oldFunction) throws Exc
this.setFunctionStartLine(oldFunction.getNameLineNumber());
this.setFunctionEndLine(oldFunction.getEndLineNumber());
this.setFunctionAnnotation(oldFunction.getAnnotation());
this.setFunctionJavaDoc(oldFunction.getJavaDoc());
this.setFunctionDoc(oldFunction.getFunctionDoc());
this.buildAndValidate();
}

Expand Down Expand Up @@ -342,11 +342,11 @@ public String getFunctionAnnotation() {
return functionAnnotation;
}

public String getFunctionJavaDoc() {
return functionJavaDoc;
public String getFunctionDoc() {
return functionDoc;
}

public void setFunctionJavaDoc(String functionJavaDoc) {
this.functionJavaDoc = functionJavaDoc;
public void setFunctionDoc(String functionDoc) {
this.functionDoc = functionDoc;
}
}

0 comments on commit 0d642eb

Please sign in to comment.