Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigate to Scala classes in Analyze Stack Window #6640

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class StackLineAnalyser {
"at\\s" + // initial at // NOI18N
"("+IDENTIFIER+"(?:\\."+IDENTIFIER+")*/)?" + // optional module name // NOI18N
"(("+IDENTIFIER+"(\\."+IDENTIFIER+")*)\\.)?("+IDENTIFIER+")" + // class name // NOI18N
"\\.("+IDENTIFIER+"|\\<init\\>|\\<clinit\\>)\\((?:"+IDENTIFIER+"(?:\\."+IDENTIFIER+")*/)?" +IDENTIFIER+"\\.java" + // method and file name // NOI18N
"\\:([0-9]*)\\)"); // line number // NOI18N
"\\.("+IDENTIFIER+"|\\<init\\>|\\<clinit\\>)\\((?:"+IDENTIFIER+"(?:\\."+IDENTIFIER+")*/)?" +IDENTIFIER+"\\.?("+IDENTIFIER+ // method and file name // NOI18N
Copy link
Contributor

@dbalek dbalek Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\\.? - why is dot before file name extension optional in the new line pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some files may not have extension, was my thought.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In such case whole \\.?("+IDENTIFIER+") should be optional IMHO

")\\:([0-9]*)\\)"); // line number // NOI18N

static boolean matches(String line) {
Matcher matcher = LINE_PATTERN.matcher(line);
Expand All @@ -73,48 +73,51 @@ static Link analyse(String line) {
if (matcher.find()) {
int lineNumber = -1;
try {
lineNumber = Integer.parseInt(matcher.group(7));
lineNumber = Integer.parseInt(matcher.group(8));
} catch (NumberFormatException nfe) {
return null;
}
int moduleStart = -1;
if (matcher.group(1) != null) {
moduleStart = matcher.start(1);
}
String ext = "." + matcher.group(7);
if (matcher.group(2)==null ) {
return new Link(matcher.group(5),
lineNumber,
moduleStart != (-1) ? moduleStart : matcher.start(5),
matcher.end(7)+1
matcher.end(8)+1, ext
);

}
return new Link(matcher.group(2) + matcher.group(5),
lineNumber,
moduleStart != (-1) ? moduleStart : matcher.start(2),
matcher.end(7)+1
matcher.end(8)+1, ext
);
}
return null;
}

static class Link {

private String className;
private int lineNumber;
private int startOffset;
private int endOffset;

private Link (
String className,
int lineNumber,
int startOffset,
int endOffset
static final class Link {
private final String className;
private final int lineNumber;
private final int startOffset;
private final int endOffset;
private final String extension;

private Link(
String className,
int lineNumber,
int startOffset,
int endOffset,
String extension
) {
this.className = className;
this.lineNumber = lineNumber;
this.startOffset = startOffset;
this.endOffset = endOffset;
this.extension = extension;
}

int getStartOffset () {
Expand All @@ -125,13 +128,19 @@ int getEndOffset () {
return endOffset;
}

String getExtension() {
return extension;
}

void show () {
String name = className.replace('.', '/');
final List<String> resources = new ArrayList<>();
resources.add(name + getExtension()); //NOI18N
resources.add(name + ".java"); //NOI18N
int idx = name.lastIndexOf('$');
while (idx >= 0) {
name = name.substring(0, idx);
resources.add(name + getExtension()); //NOI18N
resources.add(name + ".java"); //NOI18N
idx = name.lastIndexOf('$');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public void testMatches() throws Exception {
assertTrue(StackLineAnalyser.matches(" at java.base/java.lang.String.lastIndexOf(String.java:1627)"));
}

@Test
public void testMatchesScalaLines() throws Exception {
assertTrue(StackLineAnalyser.matches("at org.enso.compiler.core.ir.MetadataStorage.$anonfun$getUnsafe$1(MetadataStorage.scala:80)"));
StackLineAnalyser.Link l = StackLineAnalyser.analyse("at org.enso.compiler.core.ir.MetadataStorage.$anonfun$getUnsafe$1(MetadataStorage.scala:80)");
assertEquals(3, l.getStartOffset());
assertEquals(91, l.getEndOffset());
assertEquals(".scala", l.getExtension());
}

@Test
public void testModuleStackTraceMatches() throws Exception {
assertTrue(StackLineAnalyser.matches("at library.Library.init(Utilities/Library.java:24)"));
Expand Down
Loading