use of org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter in project omegaide by omegaui.
the class JavaSyntaxParser method parse.
@Override
public void parse() {
if (parsing || packingCodes)
return;
new Thread(() -> {
errorCount = 0;
warningCount = 0;
parsing = true;
DiagnosticCollector<JavaFileObject> diagnostics = compileSilently();
parsing = false;
LinkedList<Highlight> highlights = new LinkedList<>();
if (diagnostics == null || diagnostics.getDiagnostics() == null)
return;
List<Diagnostic<? extends JavaFileObject>> diagnosticList = diagnostics.getDiagnostics();
for (Diagnostic d : diagnosticList) {
if (d.getKind() != Kind.ERROR && d.getKind() != Kind.WARNING && d.getKind() != Kind.MANDATORY_WARNING)
continue;
int start = (int) d.getStartPosition();
int end = (int) d.getEndPosition();
if (start == end) {
start--;
end++;
}
JavaFileObject fileObject = (JavaFileObject) d.getSource();
String filePath = fileObject.toUri().getPath();
String srcDir = BUILDSPACE_DIR.getAbsolutePath();
filePath = Screen.getProjectFile().getProjectPath() + filePath.substring(srcDir.length() + (Screen.onWindows() ? 1 : 0));
Editor editor = Screen.getScreen().getEditor(new File(filePath));
if (editor == null) {
editor = Screen.getScreen().loadFile(new File(filePath));
}
SquiggleUnderlineHighlightPainter painter = new SquiggleUnderlineHighlightPainter(getSuitableColor(d.getKind()));
painter.setUseFlatLine(d.getKind() == Kind.WARNING);
Highlight h = new Highlight(editor, painter, start, end, d.getKind() != Kind.ERROR);
h.setDiagnosticData(d);
h.setGutterIconInfo(new JavaSyntaxParserGutterIconInfo(editor, d));
highlights.add(huntHighlight(h));
}
LinkedList<Highlight> removableHighlights = new LinkedList<>();
mainx: for (Highlight hx : this.highlights) {
for (Highlight hy : highlights) {
if (hx.equals(hy))
continue mainx;
}
removableHighlights.add(hx);
}
resetHighlights(removableHighlights);
this.highlights = highlights;
this.highlights.forEach(hx -> {
hx.applyLineColor((int) hx.getDiagnosticData().getLineNumber() - 1, TOOLMENU_COLOR2_SHADE);
hx.apply();
});
datas.forEach(data -> data.resetData());
datas.clear();
main: for (Highlight h : highlights) {
for (JavaErrorData data : datas) {
if (data.editor == h.editor)
continue main;
}
JavaErrorData data = new JavaErrorData();
data.editor = h.editor;
datas.add(data);
}
for (Highlight h : highlights) {
for (JavaErrorData data : datas) {
data.add(h);
}
}
datas.forEach(data -> {
data.setData();
});
int totalErrors = 0;
int totalWarnings = 0;
for (JavaErrorData data : datas) {
totalErrors += data.errorCount;
totalErrors += data.warningCount;
}
if (totalErrors > 0 || totalWarnings > 0)
omega.Screen.getScreen().getToolMenu().setTask(totalErrors + " Error(s), " + totalWarnings + " Warning(s)", totalErrors + "", totalWarnings + "");
else
omega.Screen.getScreen().getToolMenu().setTask("Currently Opened Codes are Error Free!", "Currently Opened Codes are Error Free!");
}).start();
}
use of org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter in project omegaide by omegaui.
the class PythonErrorHighlighter method loadErrors.
/*
File "entry.py", line 43
hbox.pack_start(self.icon, True, True, 0).
^
SyntaxError: invalid syntax
*/
@Override
public void loadErrors(String errorLog) {
removeAllHighlights();
StringTokenizer tokenizer = new StringTokenizer(errorLog, "\n");
boolean canRecord = false;
String path = "";
String code = "";
String message = "";
int line = 0;
try {
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (token.trim().startsWith("Traceback (most recent call last):"))
continue;
if (!canRecord && token.contains(", line")) {
int index;
path = token.substring(index = token.indexOf('\"') + 1, index = token.indexOf('\"', index + 1)).trim();
String lineString = token.substring(token.indexOf(", line") + ", line".length() + 1).trim();
if (lineString.contains(","))
lineString = lineString.substring(0, lineString.indexOf(',')).trim();
line = Integer.parseInt(lineString);
canRecord = true;
} else if (canRecord) {
code = token.trim();
message = token = tokenizer.nextToken().trim();
if (token.equals("^"))
message = token = tokenizer.nextToken().trim();
if (!path.contains(File.separator)) {
path = Screen.getProjectFile().getArgumentManager().compileDir + File.separator + path;
}
File file = new File(path);
if (file.exists()) {
Editor e = Screen.getProjectFile().getScreen().loadFile(file);
try {
ImageIcon icon = new ImageIcon(IconManager.fluenterrorImage);
int size = e.getGraphics().getFontMetrics().getHeight();
icon = new ImageIcon(icon.getImage().getScaledInstance(size, size, Image.SCALE_SMOOTH));
gutterIconInfos.add(new JavaSyntaxParserGutterIconInfo(e.getAttachment().getGutter().addLineTrackingIcon(line - 1, icon, message), e));
} catch (Exception ex) {
ex.printStackTrace();
}
Highlighter h = e.getHighlighter();
SquiggleUnderlineHighlightPainter painter = new SquiggleUnderlineHighlightPainter(Color.RED);
String text = e.getText();
int index = 0;
int times = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '\n' && times < line - 1) {
index = i;
times++;
}
}
int start = text.indexOf(code, line == 1 ? 0 : index + 1);
int end = start + code.length();
h.addHighlight(start, end, painter);
highlights.add(new Highlight(e, painter, start, end, false));
}
canRecord = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
int count = 0;
for (Highlight h : highlights) {
count = 0;
for (Highlight hx : highlights) {
if (h.editor.equals(hx.editor))
count++;
}
h.editor.javaErrorPanel.setDiagnosticData(count, 0);
}
}
use of org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter in project omegaide by omegaui.
the class CErrorHighlighter method loadErrors.
/*
c_test.c: In function ‘main’:
c_test.c:6:2: error: expected ‘,’ or ‘;’ before ‘return’
6 | return 2;
| ^~~~~~
main.c:3:10: fatal error: utils.c: No such file or directory
3 | #include <utils.c>
| ^~~~~~~~~
*/
@Override
public void loadErrors(String errorLog) {
removeAllHighlights();
StringTokenizer tokenizer = new StringTokenizer(errorLog, "\n");
boolean canRecord = false;
String path = "";
String code = "";
String message = "";
int line = 0;
try {
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (!canRecord && CodeFramework.count(token, ':') >= 4 && !token.startsWith(" ")) {
int index;
path = token.substring(0, index = token.indexOf(':')).trim();
line = Integer.parseInt(token.substring(index + 1, index = token.indexOf(':', index + 1)).trim());
index = token.indexOf(':', index + 1);
message = token.substring(index + 1).trim();
canRecord = true;
} else if (canRecord && token.contains("|")) {
code = token.substring(token.indexOf('|') + 1).trim();
if (!path.contains(File.separator)) {
path = Screen.getProjectFile().getArgumentManager().compileDir + File.separator + path;
}
File file = new File(path);
if (file.exists()) {
Editor e = Screen.getProjectFile().getScreen().loadFile(file);
try {
ImageIcon icon = new ImageIcon(message.startsWith("warning") ? IconManager.fluentwarningImage : IconManager.fluenterrorImage);
int size = e.getGraphics().getFontMetrics().getHeight();
icon = new ImageIcon(icon.getImage().getScaledInstance(size, size, Image.SCALE_SMOOTH));
gutterIconInfos.add(new JavaSyntaxParserGutterIconInfo(e.getAttachment().getGutter().addLineTrackingIcon(line - 1, icon, message), e));
} catch (Exception ex) {
ex.printStackTrace();
}
Highlighter h = e.getHighlighter();
SquiggleUnderlineHighlightPainter painter = new SquiggleUnderlineHighlightPainter(message.startsWith("warning") ? Color.YELLOW : Color.RED);
String text = e.getText();
int index = 0;
int times = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '\n' && times < line - 1) {
index = i;
times++;
}
}
int start = text.indexOf(code, line == 1 ? 0 : index + 1);
int end = start + code.length();
h.addHighlight(start, end, painter);
highlights.add(new Highlight(e, painter, start, end, message.startsWith("warning")));
}
canRecord = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
int warningCount = 0;
int errorCount = 0;
for (Highlight h : highlights) {
warningCount = 0;
errorCount = 0;
for (Highlight hx : highlights) {
if (h.editor.equals(hx.editor)) {
if (hx.warning)
warningCount++;
else
errorCount++;
}
}
h.editor.javaErrorPanel.setDiagnosticData(errorCount, warningCount);
}
}
use of org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter in project omegaide by omegaui.
the class KotlinErrorHighlighter method loadErrors.
/*
testDir/src/kode/Main.kt:5:17: error: unresolved reference: getTitle
println(screen.getTitle())
^
testDir/src/kode/Screen.kt:9:20: error: import must be placed on a single line
import javax.swing.
^
*/
@Override
public void loadErrors(String errorLog) {
removeAllHighlights();
StringTokenizer tokenizer = new StringTokenizer(errorLog, "\n");
boolean canRecord = false;
String path = "";
String code = "";
String message = "";
int line = 0;
try {
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (!canRecord && CodeFramework.count(token, ':') >= 4 && !token.startsWith(" ")) {
int index;
path = token.substring(0, index = token.indexOf(':')).trim();
path = Screen.getProjectFile().getArgumentManager().compileDir + File.separator + path;
line = Integer.parseInt(token.substring(index + 1, index = token.indexOf(':', index + 1)).trim());
index = token.indexOf(':', index + 1);
message = token.substring(index + 1).trim();
canRecord = true;
} else if (canRecord) {
code = token.trim();
if (!path.contains(File.separator)) {
path = Screen.getProjectFile().getArgumentManager().compileDir + File.separator + path;
}
File file = new File(path);
if (file.exists()) {
Editor e = Screen.getProjectFile().getScreen().loadFile(file);
try {
ImageIcon icon = new ImageIcon(IconManager.fluenterrorImage);
int size = e.getGraphics().getFontMetrics().getHeight();
icon = new ImageIcon(icon.getImage().getScaledInstance(size, size, Image.SCALE_SMOOTH));
gutterIconInfos.add(new JavaSyntaxParserGutterIconInfo(e.getAttachment().getGutter().addLineTrackingIcon(line - 1, icon, message), e));
} catch (Exception ex) {
ex.printStackTrace();
}
Highlighter h = e.getHighlighter();
SquiggleUnderlineHighlightPainter painter = new SquiggleUnderlineHighlightPainter(Color.RED);
String text = e.getText();
int index = 0;
int times = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '\n' && times < line - 1) {
index = i;
times++;
}
}
int start = text.indexOf(code, line == 1 ? 0 : index + 1);
int end = start + code.length();
h.addHighlight(start, end, painter);
highlights.add(new Highlight(e, painter, start, end, false));
}
canRecord = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
int count = 0;
for (Highlight h : highlights) {
count = 0;
for (Highlight hx : highlights) {
if (h.editor.equals(hx.editor))
count++;
}
h.editor.javaErrorPanel.setDiagnosticData(count, 0);
}
}
Aggregations