1111import java .util .Map ;
1212import java .util .logging .Level ;
1313import java .util .logging .Logger ;
14+ import java .util .stream .Collectors ;
1415
1516import javax .swing .*;
1617import javax .swing .border .*;
@@ -195,9 +196,7 @@ public void mouseReleased(MouseEvent evt) {
195196
196197 for (SketchCode code : getSketch ().getCode ()) {
197198 Document document = code .getDocument ();
198- if (document != null ) {
199- addDocumentListener (document );
200- }
199+ addDocumentListener (document );
201200 }
202201 }
203202
@@ -2513,7 +2512,7 @@ public List<Problem> getProblems() {
25132512 * line or not
25142513 */
25152514 public void updateEditorStatus () {
2516- Problem problem = findError (textarea .getCaretLine ());
2515+ Problem problem = findProblem (textarea .getCaretLine ());
25172516 if (problem != null ) {
25182517 int type = problem .isError () ?
25192518 EditorStatus .CURSOR_LINE_ERROR : EditorStatus .CURSOR_LINE_WARNING ;
@@ -2530,21 +2529,36 @@ public void updateEditorStatus() {
25302529
25312530
25322531 /**
2533- * @return the LineMarker for the first error or warning on 'line'
2532+ * @return the Problem for the first error or warning on 'line'
25342533 */
2535- public Problem findError (int line ) {
2534+ public Problem findProblem (int line ) {
25362535 JavaTextArea textArea = getJavaTextArea ();
25372536 int currentTab = getSketch ().getCurrentCodeIndex ();
2538- for (Problem p : problems ) {
2539- if (p .getTabIndex () != currentTab ) continue ;
2540- int pStartLine = p .getLineNumber ();
2541- int pEndOffset = p .getStopOffset ();
2542- int pEndLine = textArea .getLineOfOffset (pEndOffset );
2543- if (line >= pStartLine && line <= pEndLine ) {
2544- return p ;
2545- }
2546- }
2547- return null ;
2537+ return problems .stream ()
2538+ .filter (p -> p .getTabIndex () == currentTab )
2539+ .filter (p -> {
2540+ int pStartLine = p .getLineNumber ();
2541+ int pEndOffset = p .getStopOffset ();
2542+ int pEndLine = textArea .getLineOfOffset (pEndOffset );
2543+ return line >= pStartLine && line <= pEndLine ;
2544+ })
2545+ .findFirst ()
2546+ .orElse (null );
2547+ }
2548+
2549+
2550+ public List <Problem > findProblems (int line ) {
2551+ JavaTextArea textArea = getJavaTextArea ();
2552+ int currentTab = getSketch ().getCurrentCodeIndex ();
2553+ return problems .stream ()
2554+ .filter (p -> p .getTabIndex () == currentTab )
2555+ .filter (p -> {
2556+ int pStartLine = p .getLineNumber ();
2557+ int pEndOffset = p .getStopOffset ();
2558+ int pEndLine = textArea .getLineOfOffset (pEndOffset );
2559+ return line >= pStartLine && line <= pEndLine ;
2560+ })
2561+ .collect (Collectors .toList ());
25482562 }
25492563
25502564
0 commit comments