forked from eclipse-jdt/eclipse.jdt.core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force the DOM parser to continue with errors (#808)
* Force the DOM parser to continue with compilation errors
- Loading branch information
1 parent
c4d1f11
commit cb3c54f
Showing
3 changed files
with
79 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/TolerantJavaCompiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Microsoft Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Microsoft Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.internal.javac; | ||
|
||
import java.util.Queue; | ||
|
||
import javax.tools.JavaFileObject; | ||
|
||
import com.sun.tools.javac.comp.AttrContext; | ||
import com.sun.tools.javac.comp.CompileStates.CompileState; | ||
import com.sun.tools.javac.comp.Env; | ||
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 TolerantJavaCompiler extends JavaCompiler { | ||
boolean isInGeneration = false; | ||
|
||
public TolerantJavaCompiler(Context context) { | ||
super(context); | ||
} | ||
|
||
@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(); | ||
} | ||
|
||
public static JavaCompiler configureCompilerInstance(Context context) { | ||
TolerantJavaCompiler javacCompiler = new TolerantJavaCompiler(context); | ||
context.put(JavaCompiler.compilerKey, javacCompiler); | ||
return javacCompiler; | ||
} | ||
} |