Search in sources :

Example 1 with SquiggleUnderlineHighlightPainter

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();
}
Also used : Color(java.awt.Color) ProjectBuilder(omega.io.ProjectBuilder) AbstractSyntaxParser(omega.instant.support.AbstractSyntaxParser) Scanner(java.util.Scanner) Kind(javax.tools.Diagnostic.Kind) Locale(java.util.Locale) Diagnostic(javax.tools.Diagnostic) ImageIcon(javax.swing.ImageIcon) LinkedList(java.util.LinkedList) Screen(omega.Screen) DiagnosticCollector(javax.tools.DiagnosticCollector) BufferedImage(java.awt.image.BufferedImage) Image(java.awt.Image) JavaCompiler(javax.tools.JavaCompiler) Highlight(omega.instant.support.Highlight) LanguageTagView(omega.instant.support.LanguageTagView) IconManager(omega.io.IconManager) JavaErrorData(omega.instant.support.java.highlighter.JavaErrorData) File(java.io.File) JavaFileObject(javax.tools.JavaFileObject) StandardJavaFileManager(javax.tools.StandardJavaFileManager) Startup(omega.io.Startup) List(java.util.List) SquiggleUnderlineHighlightPainter(org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter) UIManager(omega.io.UIManager) Editor(omega.ui.component.Editor) NotificationPopup(omega.ui.popup.NotificationPopup) ToolProvider(javax.tools.ToolProvider) FileOperationManager(omega.io.FileOperationManager) Highlight(omega.instant.support.Highlight) Diagnostic(javax.tools.Diagnostic) JavaErrorData(omega.instant.support.java.highlighter.JavaErrorData) LinkedList(java.util.LinkedList) JavaFileObject(javax.tools.JavaFileObject) DiagnosticCollector(javax.tools.DiagnosticCollector) LinkedList(java.util.LinkedList) List(java.util.List) Editor(omega.ui.component.Editor) File(java.io.File) SquiggleUnderlineHighlightPainter(org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter)

Example 2 with SquiggleUnderlineHighlightPainter

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);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) StringTokenizer(java.util.StringTokenizer) Highlight(omega.instant.support.Highlight) Editor(omega.ui.component.Editor) File(java.io.File) SquiggleUnderlineHighlightPainter(org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter) JavaSyntaxParserGutterIconInfo(omega.instant.support.java.parser.JavaSyntaxParserGutterIconInfo) Highlighter(javax.swing.text.Highlighter) DefaultHighlighter(javax.swing.text.DefaultHighlighter) AbstractErrorHighlighter(omega.instant.support.AbstractErrorHighlighter)

Example 3 with SquiggleUnderlineHighlightPainter

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);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) StringTokenizer(java.util.StringTokenizer) Highlight(omega.instant.support.Highlight) Editor(omega.ui.component.Editor) File(java.io.File) SquiggleUnderlineHighlightPainter(org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter) JavaSyntaxParserGutterIconInfo(omega.instant.support.java.parser.JavaSyntaxParserGutterIconInfo) Highlighter(javax.swing.text.Highlighter) AbstractErrorHighlighter(omega.instant.support.AbstractErrorHighlighter)

Example 4 with SquiggleUnderlineHighlightPainter

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);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) StringTokenizer(java.util.StringTokenizer) Highlight(omega.instant.support.Highlight) Editor(omega.ui.component.Editor) File(java.io.File) SquiggleUnderlineHighlightPainter(org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter) JavaSyntaxParserGutterIconInfo(omega.instant.support.java.parser.JavaSyntaxParserGutterIconInfo) Highlighter(javax.swing.text.Highlighter) DefaultHighlighter(javax.swing.text.DefaultHighlighter) AbstractErrorHighlighter(omega.instant.support.AbstractErrorHighlighter)

Aggregations

File (java.io.File)4 ImageIcon (javax.swing.ImageIcon)4 Highlight (omega.instant.support.Highlight)4 Editor (omega.ui.component.Editor)4 SquiggleUnderlineHighlightPainter (org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter)4 StringTokenizer (java.util.StringTokenizer)3 Highlighter (javax.swing.text.Highlighter)3 AbstractErrorHighlighter (omega.instant.support.AbstractErrorHighlighter)3 JavaSyntaxParserGutterIconInfo (omega.instant.support.java.parser.JavaSyntaxParserGutterIconInfo)3 DefaultHighlighter (javax.swing.text.DefaultHighlighter)2 Color (java.awt.Color)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Locale (java.util.Locale)1 Scanner (java.util.Scanner)1 Diagnostic (javax.tools.Diagnostic)1 Kind (javax.tools.Diagnostic.Kind)1 DiagnosticCollector (javax.tools.DiagnosticCollector)1