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

Use offsets from .bgv file to select appropriate text #10510

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -246,6 +246,8 @@ public abstract static class Member implements LengthToString {
public final String name;

private Member(Klass holder, String name, int accessFlags) {
assert holder != null : "GraphElements.methodDeclaringClass must not return null!";
assert name != null;
this.holder = holder;
this.accessFlags = accessFlags;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String toString() {
String sep = "";
for (LocationStackFrame t = this; t != null; t = t.parent) {
sb.append(sep);
sb.append(methodHolderName(t)).append(".").append(t.method.name);
sb.append(methodHolderName(t)).append(".").append(methodName(t));
for (LocationStratum s : t.strata) {
if (s.file != null) {
sb.append("(").append(s.file).append(":").append(s.line).append(")");
Expand All @@ -63,6 +63,9 @@ public String toString() {
return sb.toString();
}

private static String methodName(LocationStackFrame t) {
return t != null && t.method != null ? t.method.name : null;
}
private static String methodHolderName(LocationStackFrame t) {
if (t != null && t.method != null && t.method.holder != null) {
return t.method.holder.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import javax.swing.SwingUtilities;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.openide.util.Mutex;

/**
*
Expand Down Expand Up @@ -65,22 +66,24 @@ private void openOrView(boolean focus) {
int line = location.getLine();
EditorCookie cake = toOpen.getLookup().lookup(EditorCookie.class);

Line l;
try {
l = cake.getLineSet().getOriginal(line - 1);
} catch (IndexOutOfBoundsException ex) {
// expected, the source has changed
return;
}
Line l = findLine(cake, line);
if (l == null) {
cake.open();
StatusDisplayer.getDefault().setStatusText(Bundle.ERR_LineNotFound());
return;
}
if (SwingUtilities.isEventDispatchThread()) {
Mutex.EVENT.readAccess(() -> {
l.show(Line.ShowOpenType.REUSE, focus ? Line.ShowVisibilityType.FRONT : Line.ShowVisibilityType.FRONT);
} else {
SwingUtilities.invokeLater(() -> l.show(Line.ShowOpenType.REUSE, focus ? Line.ShowVisibilityType.FRONT : Line.ShowVisibilityType.FRONT));
});
}

private Line findLine(EditorCookie cake, int line) {
try {
return cake.getLineSet().getOriginal(line - 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

} catch (IndexOutOfBoundsException ex) {
// expected, the source has changed
// just open the file
return null;
}
}

Expand Down