Skip to content

Commit 99090b8

Browse files
committed
Implement fetching of inner classes in partial uri parser (#260)
1 parent 15d0854 commit 99090b8

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

core/src/main/java/eu/fasten/core/utils/FastenUriUtils.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package eu.fasten.core.utils;
22

3+
import eu.fasten.core.dbconnectors.PostgresConnector;
4+
import eu.fasten.core.maven.GraphMavenResolver;
5+
import eu.fasten.core.maven.data.Revision;
6+
37
import java.nio.charset.StandardCharsets;
48
import java.util.Arrays;
9+
import java.util.HashMap;
510
import java.util.List;
11+
import java.util.Set;
612
import java.util.regex.Matcher;
713
import java.util.regex.Pattern;
814
import java.util.stream.Collectors;
@@ -86,28 +92,29 @@ public static List<String> parsePartialFastenUri(String partialFastenUri) {
8692
throw new IllegalArgumentException(partialUriFormatException);
8793

8894
// Class: `/{class}.*(`
89-
Pattern classPattern = Pattern.compile("(?<=/)([^\\/]+)(?=\\.([^./]+)\\()");
95+
Pattern classPattern = Pattern.compile("(?<=/)([^,;./]+?)(?=(\\$|\\.)([^./]+)\\()");
9096
Matcher classMatcher = classPattern.matcher(partialFastenUri);
9197
if (!classMatcher.find() || classMatcher.group(0).isEmpty())
9298
throw new IllegalArgumentException(partialUriFormatException);
9399

94100

95101
// Method: `.{method}(`
96-
Pattern methodNamePattern = Pattern.compile("(?<=\\.)([^.]+)(?=\\()");
102+
Pattern methodNamePattern = Pattern.compile("(?<=\\.(\\$?))([^,;./$]+?)(?=\\()");
97103
Matcher methodNameMatcher = methodNamePattern.matcher(partialFastenUri);
98104
if (!methodNameMatcher.find() || methodNameMatcher.group(0).isEmpty())
99105
throw new IllegalArgumentException(partialUriFormatException);
100106

101107

102108
// Method Args: `({args})`
103-
Pattern methodArgsPattern = Pattern.compile("(?<=\\()(.*)(?=\\))");
109+
Pattern methodArgsPattern = Pattern.compile("(?<=" + methodNameMatcher.group(0) + "\\()(.*?)(?=\\))");
104110
Matcher methodArgsMatcher = methodArgsPattern.matcher(partialFastenUri);
105111
if (!methodArgsMatcher.find())
106112
throw new IllegalArgumentException(partialUriFormatException);
107113

108114

109115
// Method Return Type: `)/{type}`
110-
Pattern methodReturnPattern = Pattern.compile("(?<=\\))(.*)");
116+
Pattern methodReturnPattern = Pattern.compile(
117+
"(?<=" + methodNameMatcher.group(0) + "\\(" + methodArgsMatcher.group(0) + "\\))(.*)");
111118
Matcher methodReturnMatcher = methodReturnPattern.matcher(partialFastenUri);
112119
if (!methodReturnMatcher.find() || methodReturnMatcher.group(0).isEmpty())
113120
throw new IllegalArgumentException(partialUriFormatException);
@@ -121,4 +128,9 @@ public static List<String> parsePartialFastenUri(String partialFastenUri) {
121128

122129
return List.of(namespace, className, methodName, methodArgs, methodReturnType);
123130
}
131+
132+
public static void main(String[] args) {
133+
var partial = "/nl.tudelft.jpacman.ui/PacManUiBuilder$addStopButton%28Lnl$tudelft$jpacman$game$Game%3A%29V%3A30$Lambda.$newInstance(%2Fnl.tudelft.jpacman.game%2FGame)PacManUiBuilder$addStopButton%28Lnl$tudelft$jpacman$game$Game%3A%29V%3A30$Lambda";
134+
System.out.println(parsePartialFastenUri(partial));
135+
}
124136
}

core/src/test/java/eu/fasten/core/utils/FastenUriUtilsTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,22 @@ void testParsePartialFastenUriFailedMissingNamespace() {
186186
assertEquals(partialUriFormatException, actualMessage);
187187
}
188188

189+
@Test
190+
void testInnerClassesSuccess() {
191+
var partialUri = "/nl.tudelft.jpacman.ui/PacManUiBuilder$addStopButton(Lnl$tudelft$jpacman$game$Game:)V:30$Lambda.$newInstance(/nl.tudelft.jpacman.game/Game)PacManUiBuilder$addStopButton(Lnl$tudelft$jpacman$game$Game:)V:30$Lambda";
192+
var expectedNamespace = "nl.tudelft.jpacman.ui";
193+
var expectedClass = "PacManUiBuilder";
194+
var expectedMethod = "newInstance";
195+
var expectedArgs = "/nl.tudelft.jpacman.game/Game";
196+
var expectedReturnType = "PacManUiBuilder$addStopButton(Lnl$tudelft$jpacman$game$Game:)V:30$Lambda";
197+
198+
var actual = FastenUriUtils.parsePartialFastenUri(partialUri);
199+
200+
assertEquals(expectedNamespace, actual.get(0));
201+
assertEquals(expectedClass, actual.get(1));
202+
assertEquals(expectedMethod, actual.get(2));
203+
assertEquals(expectedArgs, actual.get(3));
204+
assertEquals(expectedReturnType, actual.get(4));
205+
}
206+
189207
}

0 commit comments

Comments
 (0)