-
Notifications
You must be signed in to change notification settings - Fork 856
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
Stacktrace analyzer window fixes #6841
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,9 @@ | |
import javax.swing.text.StyledDocument; | ||
import org.netbeans.api.annotations.common.CheckForNull; | ||
import org.netbeans.api.annotations.common.NullAllowed; | ||
|
||
import org.netbeans.api.java.classpath.ClassPath; | ||
import org.netbeans.api.java.classpath.GlobalPathRegistry; | ||
import org.netbeans.api.progress.ProgressHandle; | ||
import org.netbeans.api.progress.ProgressHandleFactory; | ||
import org.netbeans.spi.java.classpath.support.ClassPathSupport; | ||
import org.openide.awt.StatusDisplayer; | ||
import org.openide.cookies.EditorCookie; | ||
|
@@ -57,11 +55,12 @@ class StackLineAnalyser { | |
private static final String IDENTIFIER = | ||
"\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*"; // NOI18N | ||
private static final Pattern LINE_PATTERN = Pattern.compile( | ||
"at\\s" + // initial at // NOI18N | ||
"at\\s+" + // initial at // NOI18N | ||
"("+IDENTIFIER+"(?:\\."+IDENTIFIER+")*/)?" + // optional module name // NOI18N | ||
"(("+IDENTIFIER+"(\\."+IDENTIFIER+")*)\\.)?("+IDENTIFIER+")" + // class name // NOI18N | ||
"\\.("+IDENTIFIER+"|\\<init\\>|\\<clinit\\>)\\((?:"+IDENTIFIER+"(?:\\."+IDENTIFIER+")*/)?" +IDENTIFIER+"\\.?("+IDENTIFIER+ // method and file name // NOI18N | ||
")\\:([0-9]*)\\)"); // line number // NOI18N | ||
"\\.("+IDENTIFIER+"|\\<init\\>|\\<clinit\\>)\\s*"+ // method name | ||
"\\((?:"+IDENTIFIER+"(?:\\."+IDENTIFIER+")*/)?"+IDENTIFIER+"(\\.(?:\\p{javaJavaIdentifierPart}+))?"+ // '(File.java' // NOI18N | ||
"\\:([0-9]*)\\)"); // ':123)' // NOI18N | ||
Comment on lines
57
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the original goal was to add a few optional The file extension group is now optional |
||
|
||
static boolean matches(String line) { | ||
Matcher matcher = LINE_PATTERN.matcher(line); | ||
|
@@ -71,7 +70,7 @@ static boolean matches(String line) { | |
static Link analyse(String line) { | ||
Matcher matcher = LINE_PATTERN.matcher(line); | ||
if (matcher.find()) { | ||
int lineNumber = -1; | ||
int lineNumber; | ||
try { | ||
lineNumber = Integer.parseInt(matcher.group(8)); | ||
} catch (NumberFormatException nfe) { | ||
|
@@ -81,7 +80,7 @@ static Link analyse(String line) { | |
if (matcher.group(1) != null) { | ||
moduleStart = matcher.start(1); | ||
} | ||
String ext = "." + matcher.group(7); | ||
String ext = matcher.group(7); | ||
if (matcher.group(2)==null ) { | ||
return new Link(matcher.group(5), | ||
lineNumber, | ||
|
@@ -144,75 +143,67 @@ void show () { | |
resources.add(name + ".java"); //NOI18N | ||
idx = name.lastIndexOf('$'); | ||
} | ||
final ProgressHandle handle = ProgressHandleFactory.createHandle( | ||
final ProgressHandle handle = ProgressHandle.createHandle( | ||
NbBundle.getMessage(StackLineAnalyser.class, "TXT_OpeningSource", resources.get(0))); | ||
handle.start(); | ||
RP.execute( | ||
new Runnable() { | ||
@Override | ||
public void run() { | ||
DataObject dobj = null; | ||
try { | ||
final ClassPath classPath = ClassPathSupport.createClassPath( | ||
RP.execute(() -> { | ||
DataObject dobj = null; | ||
try { | ||
final ClassPath classPath = ClassPathSupport.createClassPath( | ||
GlobalPathRegistry.getDefault().getSourceRoots().toArray(new FileObject[0])); | ||
for (String resource : resources) { | ||
dobj = findDataObject(classPath.findResource(resource)); | ||
if (dobj != null) | ||
break; | ||
for (String resource : resources) { | ||
dobj = findDataObject(classPath.findResource(resource)); | ||
if (dobj != null) | ||
break; | ||
} | ||
} finally { | ||
final DataObject dataObject = dobj; | ||
Mutex.EVENT.readAccess(() -> { | ||
try { | ||
if (dataObject == null) { | ||
StatusDisplayer.getDefault().setStatusText( | ||
NbBundle.getMessage(StackLineAnalyser.class, | ||
"AnalyzeStackTopComponent.sourceNotFound", | ||
new Object[]{resources.get(0)})); | ||
return; | ||
} | ||
} finally { | ||
final DataObject dataObject = dobj; | ||
Mutex.EVENT.readAccess(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
if (dataObject == null) { | ||
StatusDisplayer.getDefault().setStatusText( | ||
NbBundle.getMessage(StackLineAnalyser.class, | ||
"AnalyzeStackTopComponent.sourceNotFound", | ||
new Object[]{resources.get(0)})); | ||
return; | ||
} | ||
try { | ||
EditorCookie editorCookie = (EditorCookie) dataObject.getCookie(EditorCookie.class); | ||
LineCookie lineCookie = (LineCookie) dataObject.getCookie(LineCookie.class); | ||
if (editorCookie != null && lineCookie != null && lineNumber != -1) { | ||
StyledDocument doc = editorCookie.openDocument(); | ||
if (doc != null) { | ||
if (lineNumber != -1) { | ||
try { | ||
Line l = lineCookie.getLineSet().getCurrent(lineNumber - 1); | ||
|
||
if (l != null) { | ||
l.show(Line.SHOW_GOTO); | ||
return; | ||
} | ||
} catch (IndexOutOfBoundsException oob) { | ||
//line number is no more valid, do not report as an error | ||
StatusDisplayer.getDefault().setStatusText( | ||
NbBundle.getMessage(StackLineAnalyser.class, | ||
"AnalyzeStackTopComponent.lineNotFound", | ||
new Object[]{lineNumber})); | ||
} | ||
} | ||
try { | ||
EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class); | ||
LineCookie lineCookie = dataObject.getLookup().lookup(LineCookie.class); | ||
if (editorCookie != null && lineCookie != null && lineNumber != -1) { | ||
StyledDocument doc = editorCookie.openDocument(); | ||
if (doc != null) { | ||
if (lineNumber != -1) { | ||
try { | ||
Line l = lineCookie.getLineSet().getCurrent(lineNumber - 1); | ||
if (l != null) { | ||
l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FRONT); | ||
return; | ||
} | ||
} catch (IndexOutOfBoundsException oob) { | ||
//line number is no more valid, do not report as an error | ||
StatusDisplayer.getDefault().setStatusText( | ||
NbBundle.getMessage(StackLineAnalyser.class, | ||
"AnalyzeStackTopComponent.lineNotFound", | ||
new Object[]{lineNumber})); | ||
} | ||
OpenCookie openCookie = (OpenCookie) dataObject.getCookie(OpenCookie.class); | ||
if (openCookie != null) { | ||
openCookie.open(); | ||
return; | ||
} | ||
} catch (IOException e) { | ||
Exceptions.printStackTrace(e); | ||
} | ||
} finally { | ||
handle.finish(); | ||
} | ||
} | ||
}); | ||
OpenCookie openCookie = dataObject.getLookup().lookup(OpenCookie.class); | ||
if (openCookie != null) { | ||
openCookie.open(); | ||
return; | ||
} | ||
} catch (IOException e) { | ||
Exceptions.printStackTrace(e); | ||
} | ||
} finally { | ||
handle.finish(); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommend to enable ignore whitespace changes for reviewing this one - sorry about this