Skip to content

Commit

Permalink
Merge pull request #2393 from neilccbrown/fix-errors-not-shown
Browse files Browse the repository at this point in the history
Fix errors not being shown in Java editor
  • Loading branch information
PwtKCL authored Sep 10, 2024
2 parents 76a0d17 + f9e61f9 commit 0d48c84
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
30 changes: 19 additions & 11 deletions bluej/src/main/java/bluej/editor/flow/FlowErrorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ of the License, or (at your option) any later version.
import bluej.parser.nodes.*;
import bluej.parser.nodes.NodeTree.NodeAndPosition;
import bluej.pkgmgr.target.role.Kind;
import bluej.utility.BackgroundSupplier;
import bluej.utility.Debug;
import bluej.utility.Utility;
import bluej.utility.javafx.FXPlatformConsumer;
Expand Down Expand Up @@ -96,16 +97,10 @@ public void addErrorHighlight(int startPos, int endPos, String message, int iden

EditorFixesManager efm = editor.getEditorFixesManager();

// prepare for the next compilation (if imports not ready)
// or retrieve them (imports are ready)
Utility.runBackground(() -> {
Stream<AssistContentThreadSafe> imports = efm.getImportSuggestions().values().stream().
flatMap(Collection::stream);
Platform.runLater(() -> showErrors(editor, sourcePane, startPos, endPos, message, identifier, imports));
});
showErrors(editor, sourcePane, startPos, endPos, message, identifier, () -> efm.getImportSuggestions().values().stream().flatMap(Collection::stream));
}

private void showErrors(FlowEditor editor, FlowEditorPane sourcePane, int startPos, int endPos, String message, int identifier, Stream<AssistContentThreadSafe> imports)
private void showErrors(FlowEditor editor, FlowEditorPane sourcePane, int startPos, int endPos, String message, int identifier, BackgroundSupplier<Stream<AssistContentThreadSafe>> imports)
{
errorInfos.add(new FlowErrorManager.ErrorDetails(editor, startPos, endPos, message, identifier, imports));
editor.updateHeaderHasErrors(true);
Expand Down Expand Up @@ -207,21 +202,34 @@ public ObservableList<ErrorDetails> getObservableErrorList()

public static class ErrorDetails
{
// Several of these fields can be updated later while suggesting corrections, but all the
// access (both read and write) happens on the FX thread:
public final int startPos;
public final int endPos;
public final String message;
public String message;
private int italicMessageStartIndex;
private int italicMessageEndIndex;
public final int identifier;
public final List<FixSuggestion> corrections = new ArrayList<>();

private ErrorDetails(FlowEditor editor, int startPos, int endPos, String message, int identifier, Stream<AssistContentThreadSafe> possibleImports)
private ErrorDetails(FlowEditor editor, int startPos, int endPos, String message, int identifier, BackgroundSupplier<Stream<AssistContentThreadSafe>> possibleImports)
{
this.message = message;
this.startPos = startPos;
this.endPos = endPos;
this.identifier = identifier;
int italicMessageStartIndex = -1, italicMessageEndIndex = -1;
this.italicMessageStartIndex = -1;
this.italicMessageEndIndex = -1;
Utility.runBackground(() -> {
Stream<AssistContentThreadSafe> imports = possibleImports.get();
Platform.runLater(() -> calculateCorrections(editor, imports));
});
;
}

@OnThread(Tag.FXPlatform)
private void calculateCorrections(FlowEditor editor, Stream<AssistContentThreadSafe> possibleImports)
{
try
{
int errorLine = editor.getLineColumnFromOffset(startPos).getLine();
Expand Down
34 changes: 34 additions & 0 deletions bluej/src/main/java/bluej/utility/BackgroundSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
This file is part of the BlueJ program.
Copyright (C) 2024 Michael Kolling and John Rosenberg
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
This file is subject to the Classpath exception as provided in the
LICENSE.txt file that accompanied this code.
*/
package bluej.utility;

import threadchecker.OnThread;
import threadchecker.Tag;

/**
* Like supplier but must be run on background thread.
*/
@OnThread(Tag.Worker)
public interface BackgroundSupplier<T>
{
T get();
}
13 changes: 11 additions & 2 deletions bluej/src/main/java/bluej/utility/ImportScanner.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the BlueJ program.
Copyright (C) 2014,2015,2016,2017,2019,2020,2021 Michael Kolling and John Rosenberg
Copyright (C) 2014,2015,2016,2017,2019,2020,2021,2024 Michael Kolling and John Rosenberg
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -136,7 +136,16 @@ private AssistContentThreadSafe getType(String prefix, String name, JavadocResol
}
else
{
f.complete(new AssistContentThreadSafe(new ImportedTypeCompletion(c, javadocResolver)));
AssistContentThreadSafe ac = null;
try
{
ac = new AssistContentThreadSafe(new ImportedTypeCompletion(c, javadocResolver));
}
catch (Throwable t)
{
Debug.reportError(t);
}
f.complete(ac);
}
});
return f.get();
Expand Down

0 comments on commit 0d48c84

Please sign in to comment.