Skip to content

Commit

Permalink
Merge pull request #937 from e1dem/fix825
Browse files Browse the repository at this point in the history
Fix #825 - Showing wrong errors' line numbers for .java files
  • Loading branch information
Stefterv authored Jan 28, 2025
2 parents 4db8cfc + 826c206 commit e53ff13
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
25 changes: 20 additions & 5 deletions java/src/processing/mode/java/ErrorChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,29 @@ static private boolean isIgnorableProblem(IProblem iproblem) {


static private JavaProblem convertIProblem(IProblem iproblem, PreprocSketch ps) {
SketchInterval in = ps.mapJavaToSketch(iproblem);
if (in != SketchInterval.BEFORE_START) {
String badCode = ps.getPdeCode(in);
int line = ps.tabOffsetToTabLine(in.tabIndex, in.startTabOffset);
JavaProblem p = JavaProblem.fromIProblem(iproblem, in.tabIndex, line, badCode);
String originalFileName = new String(iproblem.getOriginatingFileName());
boolean isJavaTab = ps.isJavaTab(originalFileName);

// Java tabs' content isn't stored in a sketch's combined source code file,
// so they are processed differently
if (!isJavaTab) {
SketchInterval in = ps.mapJavaToSketch(iproblem);
if (in != SketchInterval.BEFORE_START) {
String badCode = ps.getPdeCode(in);
int line = ps.tabOffsetToTabLine(in.tabIndex, in.startTabOffset);
JavaProblem p = JavaProblem.fromIProblem(iproblem, in.tabIndex, line, badCode);
p.setPDEOffsets(0, -1);
return p;
}
} else {
int tabIndex = ps.getJavaTabIndex(originalFileName);
int line = iproblem.getSourceLineNumber() - 1;

JavaProblem p = JavaProblem.fromIProblem(iproblem, tabIndex, line, "");
p.setPDEOffsets(0, -1);
return p;
}

return null;
}

Expand Down
10 changes: 10 additions & 0 deletions java/src/processing/mode/java/PreprocSketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public SketchInterval mapJavaToSketch(ASTNode node) {
}


public boolean isJavaTab(String fileName) {
return javaFileMapping.containsKey(fileName);
}


public int getJavaTabIndex(String fileName) {
return javaFileMapping.get(fileName);
}


public SketchInterval mapJavaToSketch(IProblem iproblem) {
String originalFile = new String(iproblem.getOriginatingFileName());
boolean isJavaTab = javaFileMapping.containsKey(originalFile);
Expand Down

0 comments on commit e53ff13

Please sign in to comment.