diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 1988de8c26b..959a8c6afbf 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -82,6 +82,45 @@ @SuppressWarnings({ "rawtypes", "unchecked" }) class CompilationUnitResolver extends Compiler { + + private static final class ECJCompilationUnitResolver implements ICompilationUnitResolver { + + @Override + public void resolve(String[] sourceFilePaths, String[] encodings, String[] bindingKeys, + FileASTRequestor requestor, int apiLevel, Map compilerOptions, List classpath, + int flags, IProgressMonitor monitor) { + CompilationUnitResolver.resolve(sourceFilePaths, encodings, bindingKeys, requestor, apiLevel, compilerOptions, classpath, flags, monitor); + } + + @Override + public void parse(ICompilationUnit[] compilationUnits, ASTRequestor requestor, int apiLevel, + Map compilerOptions, int flags, IProgressMonitor monitor) { + CompilationUnitResolver.parse(compilationUnits, requestor, apiLevel, compilerOptions, flags, monitor); + } + + @Override + public void parse(String[] sourceFilePaths, String[] encodings, FileASTRequestor requestor, int apiLevel, + Map compilerOptions, int flags, IProgressMonitor monitor) { + CompilationUnitResolver.parse(sourceFilePaths, encodings, requestor, apiLevel, compilerOptions, flags, monitor); + } + + @Override + public void resolve(ICompilationUnit[] compilationUnits, String[] bindingKeys, ASTRequestor requestor, + int apiLevel, Map compilerOptions, IJavaProject project, + WorkingCopyOwner workingCopyOwner, int flags, IProgressMonitor monitor) { + CompilationUnitResolver.resolve(compilationUnits, bindingKeys, requestor, apiLevel, compilerOptions, project, workingCopyOwner, flags, monitor); + } + + @Override + public CompilationUnit toCompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, final boolean initialNeedsToResolveBinding, IJavaProject project, List classpaths, NodeSearcher nodeSearcher, + int apiLevel, Map compilerOptions, WorkingCopyOwner parsedUnitWorkingCopyOwner, WorkingCopyOwner typeRootWorkingCopyOwner, int flags, IProgressMonitor monitor) { + return CompilationUnitResolver.toCompilationUnit(sourceUnit, initialNeedsToResolveBinding, project, + classpaths, nodeSearcher, apiLevel, compilerOptions, parsedUnitWorkingCopyOwner, typeRootWorkingCopyOwner, flags, monitor); + } + } + + public static final ECJCompilationUnitResolver FACADE = new ECJCompilationUnitResolver(); + public static final int RESOLVE_BINDING = 0x1; public static final int PARTIAL = 0x2; public static final int STATEMENT_RECOVERY = 0x4; @@ -1408,6 +1447,62 @@ public CompilationUnitDeclaration resolve( generateCode); } + public static CompilationUnit toCompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, final boolean initialNeedsToResolveBinding, IJavaProject project, List classpaths, NodeSearcher nodeSearcher, + int apiLevel, Map compilerOptions, WorkingCopyOwner parsedUnitWorkingCopyOwner, WorkingCopyOwner typeRootWorkingCopyOwner, int flags, IProgressMonitor monitor) { + // this -> astParser, pass as args + CompilationUnitDeclaration compilationUnitDeclaration = null; + boolean needsToResolveBindingsState = initialNeedsToResolveBinding; + try { + if (initialNeedsToResolveBinding) { + try { + // parse and resolve + compilationUnitDeclaration = + CompilationUnitResolver.resolve( + sourceUnit, + project, + classpaths, + nodeSearcher, + compilerOptions, + parsedUnitWorkingCopyOwner, + flags, + monitor); + } catch (JavaModelException e) { + flags &= ~ICompilationUnit.ENABLE_BINDINGS_RECOVERY; + compilationUnitDeclaration = CompilationUnitResolver.parse( + sourceUnit, + nodeSearcher, + compilerOptions, + flags); + needsToResolveBindingsState = false; + } + } else { + compilationUnitDeclaration = CompilationUnitResolver.parse( + sourceUnit, + nodeSearcher, + compilerOptions, + flags, + project); + needsToResolveBindingsState = false; + } + return CompilationUnitResolver.convert( + compilationUnitDeclaration, + sourceUnit.getContents(), + apiLevel, + compilerOptions, + needsToResolveBindingsState, + typeRootWorkingCopyOwner, + needsToResolveBindingsState ? new DefaultBindingResolver.BindingTables() : null, + flags, + monitor, + project != null, + project); + } finally { + if (compilationUnitDeclaration != null && initialNeedsToResolveBinding) { + compilationUnitDeclaration.cleanUp(); + } + } + } + private void worked(int work) { if (this.monitor != null) { if (this.monitor.isCanceled())