X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnitProblemFinder.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnitProblemFinder.java index e511719..5ebd54c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnitProblemFinder.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnitProblemFinder.java @@ -15,11 +15,13 @@ import java.util.Map; import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.IJavaElement; +import net.sourceforge.phpdt.core.IJavaModelStatusConstants; import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.IPackageFragment; import net.sourceforge.phpdt.core.IProblemRequestor; import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.core.JavaModelException; +import net.sourceforge.phpdt.core.WorkingCopyOwner; import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.core.compiler.IProblem; import net.sourceforge.phpdt.internal.compiler.CompilationResult; @@ -32,10 +34,13 @@ import net.sourceforge.phpdt.internal.compiler.env.INameEnvironment; import net.sourceforge.phpdt.internal.compiler.env.ISourceType; import net.sourceforge.phpdt.internal.compiler.lookup.PackageBinding; import net.sourceforge.phpdt.internal.compiler.parser.SourceTypeConverter; +import net.sourceforge.phpdt.internal.compiler.parser.UnitParser; import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilation; import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory; +import net.sourceforge.phpdt.internal.core.util.Util; import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; /** @@ -127,7 +132,7 @@ public class CompilationUnitProblemFinder extends Compiler { throws JavaModelException { return (SearchableEnvironment) ((JavaProject) sourceUnit.getJavaProject()) .getSearchableNameEnvironment(); - } + } /* * Answer the component to which will be handed back compilation results from the compiler @@ -186,6 +191,81 @@ public class CompilationUnitProblemFinder extends Compiler { } public static CompilationUnitDeclaration process( + CompilationUnitDeclaration unit, + ICompilationUnit unitElement, + char[] contents, + UnitParser parser, + WorkingCopyOwner workingCopyOwner, + IProblemRequestor problemRequestor, + IProblemFactory problemFactory, + boolean cleanupCU, + IProgressMonitor monitor) + throws JavaModelException { + + char[] fileName = unitElement.getElementName().toCharArray(); + + JavaProject project = (JavaProject) unitElement.getJavaProject(); + CompilationUnitProblemFinder problemFinder = + new CompilationUnitProblemFinder( + project.newSearchableNameEnvironment(workingCopyOwner), + getHandlingPolicy(), + project.getOptions(true), + getRequestor(), + problemFactory); + if (parser != null) { + problemFinder.parser = parser; + } + + try { + + IPackageFragment packageFragment = (IPackageFragment)unitElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT); + char[][] expectedPackageName = null; + if (packageFragment != null){ + expectedPackageName = CharOperation.splitOn('.', packageFragment.getElementName().toCharArray()); + } + if (unit == null) { + unit = problemFinder.resolve( + new BasicCompilationUnit( + contents, + expectedPackageName, + new String(fileName), + unitElement), + true, // verify methods + true); //, // analyze code + //true); // generate code + } else { + problemFinder.resolve( + unit, + null, // no need for source + true, // verify methods + true); //, // analyze code + // true); // generate code + } + reportProblems(unit, problemRequestor, monitor); + return unit; + } catch(RuntimeException e) { + // avoid breaking other tools due to internal compiler failure (40334) + Util.log(e, "Exception occurred during problem detection: "); //$NON-NLS-1$ + throw new JavaModelException(e, IJavaModelStatusConstants.COMPILER_FAILURE); + } finally { + if (cleanupCU && unit != null) { + unit.cleanUp(); + } + problemFinder.lookupEnvironment.reset(); + } + } + public static CompilationUnitDeclaration process( + ICompilationUnit unitElement, + char[] contents, + WorkingCopyOwner workingCopyOwner, + IProblemRequestor problemRequestor, + boolean cleanupCU, + IProgressMonitor monitor) + throws JavaModelException { + + return process(null/*no CompilationUnitDeclaration*/, unitElement, contents, null/*use default Parser*/, workingCopyOwner, problemRequestor, new DefaultProblemFactory(), cleanupCU, monitor); + } + public static CompilationUnitDeclaration process( ICompilationUnit unitElement, IProblemRequestor problemRequestor, IProgressMonitor monitor) @@ -228,5 +308,16 @@ public class CompilationUnitProblemFinder extends Compiler { problemFinder.lookupEnvironment.reset(); } } + private static void reportProblems(CompilationUnitDeclaration unit, IProblemRequestor problemRequestor, IProgressMonitor monitor) { + CompilationResult unitResult = unit.compilationResult; + IProblem[] problems = unitResult.getAllProblems(); + for (int i = 0, problemLength = problems == null ? 0 : problems.length; i < problemLength; i++) { + if (JavaModelManager.VERBOSE){ + System.out.println("PROBLEM FOUND while reconciling : "+problems[i].getMessage());//$NON-NLS-1$ + } + if (monitor != null && monitor.isCanceled()) break; + problemRequestor.acceptProblem(problems[i]); + } + } }