Skip to content

Commit

Permalink
Fix error ranges and ids for "superclass lacks noargs constructor"
Browse files Browse the repository at this point in the history
eg.

```java
public class Superclass {
  public Superclass(int i) {
  }
}
```

```java
public class Subclass extends Superclass {
}
```

An error is issued; this PR ensures that the range covers the text `Subclass`,
which fixes the quickfix to add a constructor when it's invoked from the
beginning of the line.

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 authored and mickaelistria committed Jul 11, 2024
1 parent fadcd55 commit d2ad1b7
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ private org.eclipse.jface.text.Position getDiagnosticPosition(Diagnostic<? exten
return new org.eclipse.jface.text.Position(start, end - start);
}
}
} else if (problemId == IProblem.NotVisibleConstructorInDefaultConstructor || problemId == IProblem.UndefinedConstructorInDefaultConstructor) {
while (diagnosticPath != null && !(diagnosticPath.getLeaf() instanceof JCClassDecl)) {
diagnosticPath = diagnosticPath.getParentPath();
}
}
Tree element = diagnosticPath != null ? diagnosticPath.getLeaf() :
jcDiagnostic.getDiagnosticPosition() instanceof Tree tree ? tree :
Expand Down Expand Up @@ -437,7 +441,21 @@ public int toProblemId(Diagnostic<? extends JavaFileObject> diagnostic) {
case "compiler.err.cant.resolve.args.params" -> IProblem.UndefinedMethod;
case "compiler.err.cant.apply.symbols", "compiler.err.cant.apply.symbol" ->
switch (getDiagnosticArgumentByType(diagnostic, Kinds.KindName.class)) {
case CONSTRUCTOR -> IProblem.UndefinedConstructor;
case CONSTRUCTOR -> {
if (diagnostic instanceof JCDiagnostic.MultilineDiagnostic) {
yield IProblem.UndefinedConstructorInDefaultConstructor;
}
JCDiagnostic rootCause = getDiagnosticArgumentByType(diagnostic, JCDiagnostic.class);
if (rootCause == null) {
yield IProblem.UndefinedConstructor;
}
String rootCauseCode = rootCause.getCode();
yield switch (rootCauseCode) {
case "compiler.misc.report.access" -> convertNotVisibleAccess(diagnostic);
case "compiler.misc.arg.length.mismatch" -> IProblem.UndefinedConstructorInDefaultConstructor;
default -> IProblem.UndefinedConstructor;
};
}
case METHOD -> IProblem.ParameterMismatch;
default -> 0;
};
Expand Down

0 comments on commit d2ad1b7

Please sign in to comment.