From a3286cea9bcdbcfaa5541b51cf910ded933b3328 Mon Sep 17 00:00:00 2001 From: Rodrigo Brito Date: Thu, 15 Apr 2021 23:14:40 -0300 Subject: [PATCH] fix(parser): include params in function signature --- .../java/refdiff/parsers/python/Node.java | 21 ------------------- .../refdiff/parsers/python/PythonPlugin.java | 6 ++---- .../parsers/python/TestCstPythonParser.java | 12 +++++++---- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/main/java/refdiff/parsers/python/Node.java b/src/main/java/refdiff/parsers/python/Node.java index 465e783..c24de06 100644 --- a/src/main/java/refdiff/parsers/python/Node.java +++ b/src/main/java/refdiff/parsers/python/Node.java @@ -187,33 +187,12 @@ public ArrayList getTokenPositions(String content) { return positions; } -// Map 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)); } diff --git a/src/main/java/refdiff/parsers/python/PythonPlugin.java b/src/main/java/refdiff/parsers/python/PythonPlugin.java index 27a1850..a00d054 100644 --- a/src/main/java/refdiff/parsers/python/PythonPlugin.java +++ b/src/main/java/refdiff/parsers/python/PythonPlugin.java @@ -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 @@ -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); } @@ -296,11 +296,9 @@ private CstNode toCSTNode(Node node, String filePath) { @Override public FilePathFilter getAllowedFilesFilter() { - List ignoreFiles = Arrays.asList(""); return new FilePathFilter(Arrays.asList(".py")); } - @Override public void close() {} } diff --git a/src/test/java/refdiff/parsers/python/TestCstPythonParser.java b/src/test/java/refdiff/parsers/python/TestCstPythonParser.java index 31987a7..7420874 100644 --- a/src/test/java/refdiff/parsers/python/TestCstPythonParser.java +++ b/src/test/java/refdiff/parsers/python/TestCstPythonParser.java @@ -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 { @@ -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