mirror of
https://github.com/processing/processing4.git
synced 2026-01-28 10:51:07 +01:00
Closes #714.
Depending on how the Problem is made, the error may be given relative to start of line or start of tab. Flag indicates to users of Problems which one they are working with.
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
|
||||
|
||||
@@ -29,6 +28,7 @@ public interface Problem {
|
||||
public int getLineNumber(); // 0-indexed
|
||||
public String getMessage();
|
||||
|
||||
public boolean isLineOffset();
|
||||
public int getStartOffset();
|
||||
public int getStopOffset();
|
||||
}
|
||||
|
||||
@@ -152,6 +152,11 @@ public class PdeTextAreaPainter extends TextAreaPainter {
|
||||
|
||||
int lineOffset = textArea.getLineStartOffset(line);
|
||||
|
||||
if (problem.isLineOffset()) {
|
||||
startOffset += lineOffset;
|
||||
stopOffset += lineOffset;
|
||||
}
|
||||
|
||||
int wiggleStart = Math.max(startOffset, lineOffset);
|
||||
int wiggleStop = Math.min(stopOffset, textArea.getLineStopOffset(line));
|
||||
|
||||
|
||||
@@ -2624,7 +2624,15 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
.filter(p -> {
|
||||
int pStartLine = p.getLineNumber();
|
||||
int pEndOffset = p.getStopOffset();
|
||||
int pEndLine = textarea.getLineOfOffset(pEndOffset);
|
||||
|
||||
int pEndLine;
|
||||
if (p.isLineOffset()) {
|
||||
int lineGlobalOffset = textarea.getLineStartOffset(pStartLine);
|
||||
pEndLine = textarea.getLineOfOffset(pEndOffset + lineGlobalOffset);
|
||||
} else {
|
||||
pEndLine = textarea.getLineOfOffset(pEndOffset);
|
||||
}
|
||||
|
||||
return line >= pStartLine && line <= pEndLine;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -82,7 +82,7 @@ public class JavaProblem implements Problem {
|
||||
}
|
||||
|
||||
|
||||
public void setPDEOffsets(int startOffset, int stopOffset){
|
||||
public void setPDEOffsets(int startOffset, int stopOffset) {
|
||||
this.startOffset = startOffset;
|
||||
this.stopOffset = stopOffset;
|
||||
}
|
||||
@@ -139,6 +139,9 @@ public class JavaProblem implements Problem {
|
||||
importSuggestions = a;
|
||||
}
|
||||
|
||||
public boolean isLineOffset() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -53,7 +53,8 @@ public class ProblemFactory {
|
||||
localLine,
|
||||
message,
|
||||
lineStart,
|
||||
lineStop
|
||||
lineStop,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -83,8 +84,9 @@ public class ProblemFactory {
|
||||
tab,
|
||||
localLine,
|
||||
message,
|
||||
localLine,
|
||||
localLine + col
|
||||
0,
|
||||
col,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ public class SyntaxProblem extends JavaProblem {
|
||||
private final String message;
|
||||
private final int startOffset;
|
||||
private final int stopOffset;
|
||||
private final boolean lineFlag;
|
||||
|
||||
/**
|
||||
* Create a new syntax problem.
|
||||
@@ -18,12 +19,14 @@ public class SyntaxProblem extends JavaProblem {
|
||||
* @param newLineNumber The line number within the tab at which the offending code can be found.
|
||||
* @param newMessage Human readable message describing the issue.
|
||||
* @param newStartOffset The character index at which the issue starts. This is relative to start
|
||||
* of tab / file not relative to start of line.
|
||||
* of tab / file not relative to start of line if newIsLineOffset is true else it is line
|
||||
* offset.
|
||||
* @param newStopOffset The character index at which the issue ends. This is relative to start
|
||||
* * of tab / file not relative to start of line.
|
||||
* of tab / file not relative to start of line if newIsLineOffset is true else it is line
|
||||
* offset.
|
||||
*/
|
||||
public SyntaxProblem(int newTabIndex, int newLineNumber, String newMessage, int newStartOffset,
|
||||
int newStopOffset) {
|
||||
int newStopOffset, boolean newIsLineOffset) {
|
||||
|
||||
super(newMessage, JavaProblem.ERROR, newLineNumber, newLineNumber);
|
||||
|
||||
@@ -32,6 +35,7 @@ public class SyntaxProblem extends JavaProblem {
|
||||
message = newMessage;
|
||||
startOffset = newStartOffset;
|
||||
stopOffset = newStopOffset;
|
||||
lineFlag = newIsLineOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,4 +73,8 @@ public class SyntaxProblem extends JavaProblem {
|
||||
return stopOffset;
|
||||
}
|
||||
|
||||
public boolean isLineOffset() {
|
||||
return lineFlag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user