Returned CANCELLED rewrite if CompilerProvider.findTypeDeclaration returns NOT_FOUND (fixes #323)

This commit is contained in:
Akash Yadav
2022-07-23 08:37:49 +05:30
parent a77418a495
commit 3927313ffb
4 changed files with 21 additions and 0 deletions
@@ -60,6 +60,12 @@ public class GenerateRecordConstructor extends Rewrite {
LOG.info("Generate default constructor for " + className + "...");
// TODO this needs to fall back on looking for inner classes and package-private classes
Path file = compiler.findTypeDeclaration(className);
if (file == CompilerProvider.NOT_FOUND) {
LOG.warn("Unable to find source file for class:", this.className);
return CANCELLED;
}
SynchronizedTask synchronizedTask = compiler.compile(file);
return synchronizedTask.get(
task -> {
@@ -84,6 +84,11 @@ public class ImplementAbstractMethods extends Rewrite {
@Override
public Map<Path, TextEdit[]> rewrite(@NonNull CompilerProvider compiler) {
final Path file = compiler.findTypeDeclaration(this.classFile);
if (file == CompilerProvider.NOT_FOUND) {
LOG.warn("Unable to find source file for class:", this.className, "classFile=", this.classFile);
return CANCELLED;
}
final SynchronizedTask synchronizedTask = compiler.compile(file);
return synchronizedTask.get(
task -> {
@@ -23,6 +23,7 @@ import com.itsaky.androidide.lsp.java.utils.FindHelper;
import com.itsaky.androidide.models.Position;
import com.itsaky.androidide.models.Range;
import com.itsaky.androidide.lsp.models.TextEdit;
import com.itsaky.androidide.utils.ILogger;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.LineMap;
@@ -49,6 +50,8 @@ public class RemoveException extends Rewrite {
final String className, methodName;
final String[] erasedParameterTypes;
final String exceptionType;
private static final ILogger LOG = ILogger.newInstance("RemoveException");
public RemoveException(
String className, String methodName, String[] erasedParameterTypes, String exceptionType) {
@@ -61,6 +64,12 @@ public class RemoveException extends Rewrite {
@Override
public Map<Path, TextEdit[]> rewrite(CompilerProvider compiler) {
Path file = compiler.findTypeDeclaration(className);
if (file == CompilerProvider.NOT_FOUND) {
LOG.warn("Unable to find source file for class:", this.className);
return CANCELLED;
}
SynchronizedTask synchronizedTask = compiler.compile(file);
return synchronizedTask.get(
task -> {
@@ -46,6 +46,7 @@ public class RemoveMethod extends Rewrite {
if (file == CompilerProvider.NOT_FOUND) {
return CANCELLED;
}
return compiler
.compile(file)
.get(