Skip to content
Open
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
21 changes: 0 additions & 21 deletions src/main/java/refdiff/parsers/python/Node.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,33 +187,12 @@ public ArrayList<TokenPosition> getTokenPositions(String content) {
return positions;
}

// Map<Integer, Integer> linePositionOffset = new HashMap<>();
// linePositionOffset.put(0, 0);
// int lineNumber = 1;
// String[] lines = content.split(System.lineSeparator());
// for (String line: lines) {
// linePositionOffset.put(lineNumber, linePositionOffset.get(lineNumber-1) + line.length() + System.lineSeparator().length());
// lineNumber++;
// }


for(String token: this.tokens) {
String[] parts = token.split("-");

int start = Integer.parseInt(parts[0]);
int end = Integer.parseInt(parts[1]);

// int line = Integer.parseInt(parts[0]);
// int column = Integer.parseInt(parts[1]);
// int size = Integer.parseInt(parts[2]);
//
// if (line >= lines.length){
// System.out.println("eita!");
// }
//
// int startPosition = linePositionOffset.get(line) + column;
// int endPosition = startPosition + size;

positions.add(new TokenPosition(start, end));
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/refdiff/parsers/python/PythonPlugin.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -189,7 +189,7 @@ public CstRoot parse(SourceFileSet sources) throws Exception {
if (node.getParent() != null) {
node.setNamespace(null);
// initialize if key not present
childrenByAddress= AddtoArraylist(childrenByAddress, temp1, node);
childrenByAddress= AddtoArraylist(childrenByAddress, temp1, node);
}

// save call graph information
Expand DownExpand Up@@ -282,7 +282,7 @@ private CstNode toCSTNode(Node node, String filePath) {
}

if (node.getType().equals(NodeType.FUNCTION)) {
String localName = String.format("%s(%s)", node.getName(), String.join(",", node.getParameterTypes()));
String localName = String.format("%s(%s)", node.getName(), String.join(",", node.getParametersNames()));
if (node.getReceiver() != null && !node.getReceiver().isEmpty()) {
localName = String.format("%s.%s", node.getReceiver(), localName);
}
Expand All@@ -296,11 +296,9 @@ private CstNode toCSTNode(Node node, String filePath) {

@Override
public FilePathFilter getAllowedFilesFilter() {
List<String> ignoreFiles = Arrays.asList("");
return new FilePathFilter(Arrays.asList(".py"));
}


@Override
public void close() {}
}
12 changes: 8 additions & 4 deletions src/test/java/refdiff/parsers/python/TestCstPythonParser.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,6 @@
import refdiff.core.cst.CstRoot;
import refdiff.core.diff.CstRootHelper;
import refdiff.core.io.SourceFolder;
import refdiff.parsers.python.NodeType;
import refdiff.parsers.python.PythonPlugin;
import refdiff.test.util.PythonParserSingleton;

public class TestCstPythonParser {
Expand DownExpand Up@@ -46,12 +44,18 @@ public void shouldMatchNodes() throws Exception {
CstNode sumFunctionNode = classNode.getNodes().get(0);
assertThat(sumFunctionNode.getType(), is(NodeType.FUNCTION));
assertThat(sumFunctionNode.getSimpleName(), is("sum"));
assertThat(sumFunctionNode.getParent(), is(classNode));
assertThat(sumFunctionNode.getLocalName(), is("sum(a,b)"));
assertThat(sumFunctionNode.getParameters().get(0).getName(), is("a"));
assertThat(sumFunctionNode.getParameters().get(1).getName(), is("b"));
assertThat(sumFunctionNode.getParent().get().getLocalName(), is(classNode.getLocalName()));

CstNode multiFunctionNode = classNode.getNodes().get(1);
assertThat(multiFunctionNode.getType(), is(NodeType.FUNCTION));
assertThat(multiFunctionNode.getSimpleName(), is("multi"));
assertThat(multiFunctionNode.getParent(), is(classNode));
assertThat(multiFunctionNode.getLocalName(), is("multi(q,w)"));
assertThat(multiFunctionNode.getParameters().get(0).getName(), is("q"));
assertThat(multiFunctionNode.getParameters().get(1).getName(), is("w"));
assertThat(multiFunctionNode.getParent().get().getLocalName(), is(classNode.getLocalName()));
}

@Test
Expand Down