mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 11:51:54 +01:00
clean up error/warning handling, differentiate errors/warnings in list (fixes #3406)
This commit is contained in:
@@ -1882,20 +1882,20 @@ public class JavaEditor extends Editor {
|
||||
* them.
|
||||
*/
|
||||
protected void downloadImports() {
|
||||
String importRegex = errorCheckerService.importRegexp;
|
||||
String tabCode;
|
||||
for (SketchCode sc : sketch.getCode()) {
|
||||
if (sc.isExtension("pde")) {
|
||||
tabCode = sc.getProgram();
|
||||
String tabCode = sc.getProgram();
|
||||
|
||||
String[][] pieces = PApplet.matchAll(tabCode, importRegex);
|
||||
String[][] pieces =
|
||||
PApplet.matchAll(tabCode, ErrorCheckerService.IMPORT_REGEX);
|
||||
|
||||
if (pieces != null) {
|
||||
ArrayList<String> importHeaders = new ArrayList<String>();
|
||||
for (String[] importStatement : pieces) {
|
||||
importHeaders.add(importStatement[2]);
|
||||
}
|
||||
List<AvailableContribution> installLibsHeaders = getNotInstalledAvailableLibs(importHeaders);
|
||||
List<AvailableContribution> installLibsHeaders =
|
||||
getNotInstalledAvailableLibs(importHeaders);
|
||||
if (!installLibsHeaders.isEmpty()) {
|
||||
StringBuilder libList = new StringBuilder("Would you like to install them now?");
|
||||
for (AvailableContribution ac : installLibsHeaders) {
|
||||
@@ -1907,8 +1907,7 @@ public class JavaEditor extends Editor {
|
||||
libList.toString());
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
ContributionManager.downloadAndInstallOnImport(base,
|
||||
installLibsHeaders);
|
||||
ContributionManager.downloadAndInstallOnImport(base, installLibsHeaders);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2403,10 +2402,21 @@ public class JavaEditor extends Editor {
|
||||
}
|
||||
|
||||
|
||||
public static final int STATUS_EMPTY = 100, STATUS_COMPILER_ERR = 200,
|
||||
STATUS_WARNING = 300, STATUS_INFO = 400, STATUS_ERR = 500;
|
||||
public int statusMessageType = STATUS_EMPTY;
|
||||
public String statusMessage;
|
||||
public void statusMessage(String message, int type) {
|
||||
status.message(message, type);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
static final int STATUS_EMPTY = 100;
|
||||
static final int STATUS_COMPILER_ERR = 200;
|
||||
static final int STATUS_WARNING = 300;
|
||||
static final int STATUS_INFO = 400;
|
||||
static final int STATUS_ERR = 500;
|
||||
|
||||
int statusMessageType = STATUS_EMPTY;
|
||||
String statusMessage;
|
||||
|
||||
public void statusMessage(final String what, int type){
|
||||
// Don't re-display the old message again
|
||||
if (type != STATUS_EMPTY) {
|
||||
@@ -2451,6 +2461,7 @@ public class JavaEditor extends Editor {
|
||||
statusMessageType = STATUS_EMPTY;
|
||||
super.statusEmpty();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// /**
|
||||
|
||||
@@ -22,6 +22,7 @@ package processing.mode.java.pdex;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -61,7 +62,6 @@ import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
@@ -110,6 +110,7 @@ import processing.app.Platform;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.Util;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
import processing.app.ui.EditorStatus;
|
||||
import processing.app.ui.Toolkit;
|
||||
import processing.data.StringList;
|
||||
import processing.mode.java.JavaEditor;
|
||||
@@ -1771,10 +1772,9 @@ public class ASTGenerator {
|
||||
(SimpleName) simpName);
|
||||
//retLabelString = getNodeAsString(decl);
|
||||
} else {
|
||||
// Base.loge("null");
|
||||
if (scrollOnly) {
|
||||
editor.statusMessage(simpName + " is not defined in this sketch",
|
||||
JavaEditor.STATUS_ERR);
|
||||
EditorStatus.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2059,7 +2059,7 @@ public class ASTGenerator {
|
||||
DefaultMutableTreeNode defCU = findAllOccurrences(); //TODO: Repetition here
|
||||
if(defCU == null){
|
||||
editor.statusMessage("Can't locate definition of " + selText,
|
||||
JavaEditor.STATUS_ERR);
|
||||
EditorStatus.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2156,14 +2156,14 @@ public class ASTGenerator {
|
||||
log("Last clicked word:" + lastClickedWord);
|
||||
if (lastClickedWord == null &&
|
||||
getSelectedText() == null) {
|
||||
editor.statusMessage("Highlight the class/function/variable name first"
|
||||
, JavaEditor.STATUS_INFO);
|
||||
editor.statusMessage("Highlight the class/function/variable name first",
|
||||
EditorStatus.NOTICE);
|
||||
return;
|
||||
}
|
||||
|
||||
if(errorCheckerService.hasSyntaxErrors()){
|
||||
editor.statusMessage("Can't perform action until syntax errors are " +
|
||||
"fixed :(", JavaEditor.STATUS_WARNING);
|
||||
if (errorCheckerService.hasSyntaxErrors()){
|
||||
editor.statusMessage("Can't perform action until errors are fixed",
|
||||
EditorStatus.WARNING);
|
||||
return;
|
||||
}
|
||||
DefaultMutableTreeNode defCU = findAllOccurrences();
|
||||
@@ -2171,7 +2171,7 @@ public class ASTGenerator {
|
||||
getSelectedText() : lastClickedWord;
|
||||
if (defCU == null) {
|
||||
editor.statusMessage("Can't locate definition of " + selText,
|
||||
JavaEditor.STATUS_ERR);
|
||||
EditorStatus.ERROR);
|
||||
return;
|
||||
}
|
||||
if(defCU.getChildCount() == 0)
|
||||
@@ -2499,13 +2499,13 @@ public class ASTGenerator {
|
||||
if (lastClickedWord == null &&
|
||||
getSelectedText() == null) {
|
||||
editor.statusMessage("Highlight the class/function/variable name first",
|
||||
JavaEditor.STATUS_INFO);
|
||||
EditorStatus.NOTICE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (errorCheckerService.hasSyntaxErrors()) {
|
||||
editor.statusMessage("Can't perform action until syntax errors are fixed :(",
|
||||
JavaEditor.STATUS_WARNING);
|
||||
EditorStatus.WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2513,8 +2513,8 @@ public class ASTGenerator {
|
||||
String selText = lastClickedWord == null ?
|
||||
getSelectedText() : lastClickedWord;
|
||||
if (defCU == null) {
|
||||
editor.statusMessage(selText + " isn't defined in this sketch, so it can't" +
|
||||
" be renamed", JavaEditor.STATUS_ERR);
|
||||
editor.statusMessage(selText + " isn't defined in this sketch, " +
|
||||
"so it cannot be renamed", EditorStatus.ERROR);
|
||||
return;
|
||||
}
|
||||
if (!frmRename.isVisible()){
|
||||
@@ -2524,7 +2524,7 @@ public class ASTGenerator {
|
||||
+ (editor.getHeight() - frmRename.getHeight())
|
||||
/ 2);
|
||||
frmRename.setVisible(true);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String selText = lastClickedWord == null ? getSelectedText()
|
||||
|
||||
@@ -181,7 +181,8 @@ public class ErrorCheckerService {
|
||||
/**
|
||||
* Regexp for import statements. (Used from Processing source)
|
||||
*/
|
||||
public static final String importRegexp = "(?:^|;)\\s*(import\\s+)((?:static\\s+)?\\S+)(\\s*;)";
|
||||
public static final String IMPORT_REGEX =
|
||||
"(?:^|;)\\s*(import\\s+)((?:static\\s+)?\\S+)(\\s*;)";
|
||||
|
||||
// /**
|
||||
// * Regexp for function declarations. (Used from Processing source)
|
||||
@@ -945,7 +946,7 @@ public class ErrorCheckerService {
|
||||
* line or not
|
||||
*/
|
||||
public void updateEditorStatus() {
|
||||
if (editor.getStatusMode() == EditorStatus.EDIT) return;
|
||||
// if (editor.getStatusMode() == EditorStatus.EDIT) return;
|
||||
|
||||
// editor.statusNotice("Position: " +
|
||||
// editor.getTextArea().getCaretLine());
|
||||
@@ -954,20 +955,20 @@ public class ErrorCheckerService {
|
||||
if (errorMarker != null) {
|
||||
if (errorMarker.getType() == LineMarker.WARNING) {
|
||||
editor.statusMessage(errorMarker.getProblem().getMessage(),
|
||||
JavaEditor.STATUS_INFO);
|
||||
EditorStatus.WARNING);
|
||||
} else {
|
||||
editor.statusMessage(errorMarker.getProblem().getMessage(),
|
||||
JavaEditor.STATUS_COMPILER_ERR);
|
||||
EditorStatus.COMPILER_ERROR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// This line isn't an error line anymore, so probably just clear it
|
||||
if (editor.statusMessageType == JavaEditor.STATUS_COMPILER_ERR) {
|
||||
editor.statusEmpty();
|
||||
return;
|
||||
}
|
||||
// // This line isn't an error line anymore, so probably just clear it
|
||||
// if (editor.statusMessageType == JavaEditor.STATUS_COMPILER_ERR) {
|
||||
// editor.statusEmpty();
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -1462,7 +1463,7 @@ public class ErrorCheckerService {
|
||||
String tabSource = tabProgram;
|
||||
do {
|
||||
// log("-->\n" + sourceAlt + "\n<--");
|
||||
String[] pieces = PApplet.match(tabSource, importRegexp);
|
||||
String[] pieces = PApplet.match(tabSource, IMPORT_REGEX);
|
||||
|
||||
// Stop the loop if we've removed all the import lines
|
||||
if (pieces == null) {
|
||||
|
||||
@@ -25,16 +25,14 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jdt.core.compiler.IProblem;
|
||||
|
||||
import processing.app.ui.ErrorTable;
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper class for IProblem.
|
||||
*
|
||||
* Stores the tabIndex and line number according to its tab, including the
|
||||
* original IProblem object
|
||||
*
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
*
|
||||
* Wrapper class for IProblem that stores the tabIndex and line number
|
||||
* according to its tab, including the original IProblem object
|
||||
*/
|
||||
public class Problem {
|
||||
public class Problem implements ErrorTable.Entry {
|
||||
/**
|
||||
* The IProblem which is being wrapped
|
||||
*/
|
||||
@@ -42,14 +40,14 @@ public class Problem {
|
||||
/**
|
||||
* The tab number to which the error belongs to
|
||||
*/
|
||||
private int tabIndex;
|
||||
private int tabIndex;
|
||||
/**
|
||||
* Line number(pde code) of the error
|
||||
*/
|
||||
private int lineNumber;
|
||||
|
||||
|
||||
private int lineStartOffset;
|
||||
|
||||
|
||||
private int lineStopOffset;
|
||||
|
||||
/**
|
||||
@@ -61,7 +59,7 @@ public class Problem {
|
||||
* The type of error - WARNING or ERROR.
|
||||
*/
|
||||
private int type;
|
||||
|
||||
|
||||
/**
|
||||
* If the error is a 'cannot find type' contains the list of suggested imports
|
||||
*/
|
||||
@@ -70,7 +68,7 @@ public class Problem {
|
||||
public static final int ERROR = 1, WARNING = 2;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param iProblem - The IProblem which is being wrapped
|
||||
* @param tabIndex - The tab number to which the error belongs to
|
||||
* @param lineNumber - Line number(pde code) of the error
|
||||
@@ -89,17 +87,17 @@ public class Problem {
|
||||
this.message = ErrorMessageSimplifier.getSimplifiedErrorMessage(this);
|
||||
//ErrorMessageSimplifier.getSimplifiedErrorMessage(this);
|
||||
}
|
||||
|
||||
|
||||
public void setPDEOffsets(int startOffset, int stopOffset){
|
||||
lineStartOffset = startOffset;
|
||||
lineStopOffset = stopOffset;
|
||||
}
|
||||
|
||||
public int getPDELineStartOffset(){
|
||||
|
||||
public int getPDELineStartOffset() {
|
||||
return lineStartOffset;
|
||||
}
|
||||
|
||||
public int getPDELineStopOffset(){
|
||||
|
||||
public int getPDELineStopOffset() {
|
||||
return lineStopOffset;
|
||||
}
|
||||
|
||||
@@ -109,37 +107,37 @@ public class Problem {
|
||||
+ message);
|
||||
}
|
||||
|
||||
public boolean isError(){
|
||||
public boolean isError() {
|
||||
return type == ERROR;
|
||||
}
|
||||
|
||||
public boolean isWarning(){
|
||||
public boolean isWarning() {
|
||||
return type == WARNING;
|
||||
}
|
||||
|
||||
public String getMessage(){
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public IProblem getIProblem(){
|
||||
public IProblem getIProblem() {
|
||||
return iProblem;
|
||||
}
|
||||
|
||||
public int getTabIndex(){
|
||||
|
||||
public int getTabIndex() {
|
||||
return tabIndex;
|
||||
}
|
||||
|
||||
public int getLineNumber(){
|
||||
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remember to subtract a -1 to line number because in compile check code an
|
||||
* extra package statement is added, so all line numbers are increased by 1
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getSourceLineNumber(){
|
||||
public int getSourceLineNumber() {
|
||||
return iProblem.getSourceLineNumber();
|
||||
}
|
||||
|
||||
@@ -150,11 +148,11 @@ public class Problem {
|
||||
type = WARNING;
|
||||
else throw new IllegalArgumentException("Illegal Problem type passed to Problem.setType(int)");
|
||||
}
|
||||
|
||||
|
||||
public String[] getImportSuggestions() {
|
||||
return importSuggestions;
|
||||
}
|
||||
|
||||
|
||||
public void setImportSuggestions(String[] a) {
|
||||
importSuggestions = a;
|
||||
}
|
||||
@@ -169,7 +167,7 @@ public class Problem {
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes error messages and attempts to make them a bit more english like.
|
||||
* Processes error messages and attempts to make them a bit more english like.
|
||||
* Currently performs:
|
||||
* <li>Remove all instances of token. "Syntax error on token 'blah', delete this token"
|
||||
* becomes "Syntax error on 'blah', delete this"
|
||||
@@ -179,7 +177,7 @@ public class Problem {
|
||||
public static String process(String message) {
|
||||
// Remove all instances of token
|
||||
// "Syntax error on token 'blah', delete this token"
|
||||
if(message == null) return null;
|
||||
if(message == null) return null;
|
||||
pattern = Pattern.compile(tokenRegExp);
|
||||
matcher = pattern.matcher(message);
|
||||
message = matcher.replaceAll("");
|
||||
@@ -187,7 +185,7 @@ public class Problem {
|
||||
return message;
|
||||
}
|
||||
|
||||
// Split camel case words into separate words.
|
||||
// Split camel case words into separate words.
|
||||
// "VaraibleDeclaration" becomes "Variable Declaration"
|
||||
// But sadly "PApplet" become "P Applet" and so on.
|
||||
public static String splitCamelCaseWord(String word) {
|
||||
|
||||
Reference in New Issue
Block a user