Skip to content

Commit

Permalink
Revert "Force the DOM parser to continue with errors (#808)"
Browse files Browse the repository at this point in the history
The commit has caused several regressions for which a fix is yet to
be found. Let's revert to keep the main branch as clean as possible
and work on TolerantParser in a different PR.

This reverts commit cb3c54f.
  • Loading branch information
mickaelistria committed Sep 10, 2024
1 parent cb3c54f commit 13a7ce9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import org.eclipse.jdt.internal.core.util.BindingKeyParser;
import org.eclipse.jdt.internal.javac.JavacProblemConverter;
import org.eclipse.jdt.internal.javac.JavacUtils;
import org.eclipse.jdt.internal.javac.TolerantJavaCompiler;
import org.eclipse.jdt.internal.javac.UnusedProblemFactory;
import org.eclipse.jdt.internal.javac.UnusedTreeScanner;

Expand Down Expand Up @@ -480,7 +479,6 @@ private Map<org.eclipse.jdt.internal.compiler.env.ICompilationUnit, CompilationU
}
var compiler = ToolProvider.getSystemJavaCompiler();
Context context = new Context();
TolerantJavaCompiler.configureCompilerInstance(context);
Map<org.eclipse.jdt.internal.compiler.env.ICompilationUnit, CompilationUnit> result = new HashMap<>(sourceUnits.length, 1.f);
Map<JavaFileObject, CompilationUnit> filesToUnits = new HashMap<>();
final UnusedProblemFactory unusedProblemFactory = new UnusedProblemFactory(new DefaultProblemFactory(), compilerOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -45,9 +46,12 @@
import org.eclipse.jdt.internal.core.builder.SourceFile;

import com.sun.tools.javac.api.MultiTaskListener;
import com.sun.tools.javac.comp.*;
import com.sun.tools.javac.comp.CompileStates.CompileState;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Pair;

public class JavacCompiler extends Compiler {
JavacConfig compilerConfig;
Expand Down Expand Up @@ -113,7 +117,46 @@ public void compile(ICompilationUnit[] sourceUnits) {
// Configure Javac to generate the class files in a mapped temporary location
var outputDir = JavacClassFile.getMappedTempOutput(outputSourceSet.getKey()).toFile();
JavacUtils.configureJavacContext(javacContext, this.compilerConfig, javaProject, outputDir, true);
JavaCompiler javac = TolerantJavaCompiler.configureCompilerInstance(javacContext);
JavaCompiler javac = new JavaCompiler(javacContext) {
boolean isInGeneration = false;

@Override
protected boolean shouldStop(CompileState cs) {
// Never stop
return false;
}

@Override
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) {
try {
this.isInGeneration = true;
super.generate(queue, results);
} catch (Throwable ex) {
// TODO error handling
} finally {
this.isInGeneration = false;
}
}

@Override
protected void desugar(Env<AttrContext> env, Queue<Pair<Env<AttrContext>, JCClassDecl>> results) {
try {
super.desugar(env, results);
} catch (Throwable ex) {
// TODO error handling
}
}

@Override
public int errorCount() {
// See JavaCompiler.genCode(Env<AttrContext> env, JCClassDecl cdef),
// it stops writeClass if errorCount is not zero.
// Force it to return 0 if we are in generation phase, and keeping
// generating class files for those files without errors.
return this.isInGeneration ? 0 : super.errorCount();
}
};
javacContext.put(JavaCompiler.compilerKey, javac);
javac.shouldStopPolicyIfError = CompileState.GENERATE;
try {
javac.compile(com.sun.tools.javac.util.List.from(outputSourceSet.getValue().stream()
Expand Down

This file was deleted.

0 comments on commit 13a7ce9

Please sign in to comment.