Search in sources :

Example 1 with CategorizedProblem

use of org.eclipse.jdt.core.compiler.CategorizedProblem in project che by eclipse.

the class ReconcileWorkingCopyOperation method reportProblems.

/**
     * Report working copy problems to a given requestor.
     *
     * @param workingCopy
     * @param problemRequestor
     */
private void reportProblems(CompilationUnit workingCopy, IProblemRequestor problemRequestor) {
    try {
        problemRequestor.beginReporting();
        for (Iterator iteraror = this.problems.values().iterator(); iteraror.hasNext(); ) {
            CategorizedProblem[] categorizedProblems = (CategorizedProblem[]) iteraror.next();
            if (categorizedProblems == null)
                continue;
            for (int i = 0, length = categorizedProblems.length; i < length; i++) {
                CategorizedProblem problem = categorizedProblems[i];
                if (JavaModelManager.VERBOSE) {
                    //$NON-NLS-1$
                    System.out.println("PROBLEM FOUND while reconciling : " + problem.getMessage());
                }
                if (this.progressMonitor != null && this.progressMonitor.isCanceled())
                    break;
                problemRequestor.acceptProblem(problem);
            }
        }
    } finally {
        problemRequestor.endReporting();
    }
}
Also used : CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) Iterator(java.util.Iterator)

Example 2 with CategorizedProblem

use of org.eclipse.jdt.core.compiler.CategorizedProblem in project che by eclipse.

the class CheCompilationUnitResolver method resolve.

public static CompilationUnitDeclaration resolve(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, IJavaProject javaProject, List classpaths, NodeSearcher nodeSearcher, Map options, WorkingCopyOwner owner, int flags, IProgressMonitor monitor) throws JavaModelException {
    CompilationUnitDeclaration unit = null;
    INameEnvironmentWithProgress environment = null;
    CancelableProblemFactory problemFactory = null;
    CheCompilationUnitResolver resolver = null;
    try {
        if (javaProject == null) {
            FileSystem.Classpath[] allEntries = new FileSystem.Classpath[classpaths.size()];
            classpaths.toArray(allEntries);
            environment = new NameEnvironmentWithProgress(allEntries, null, monitor);
        } else {
            environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor);
        }
        problemFactory = new CancelableProblemFactory(monitor);
        CompilerOptions compilerOptions = CompilationUnitResolver.getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
        boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
        resolver = new CheCompilationUnitResolver(environment, CompilationUnitResolver.getHandlingPolicy(), compilerOptions, CompilationUnitResolver.getRequestor(), problemFactory, monitor, javaProject != null);
        boolean analyzeAndGenerateCode = !ignoreMethodBodies;
        unit = resolver.resolve(// no existing compilation unit declaration
        null, sourceUnit, nodeSearcher, // method verification
        true, // analyze code
        analyzeAndGenerateCode, // generate code
        analyzeAndGenerateCode);
        if (resolver.hasCompilationAborted) {
            // the bindings could not be resolved due to missing types in name environment
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
            CompilationUnitDeclaration unitDeclaration = CompilationUnitResolver.parse(sourceUnit, nodeSearcher, options, flags);
            if (unit != null) {
                final int problemCount = unit.compilationResult.problemCount;
                if (problemCount != 0) {
                    unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount];
                    System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems, 0, problemCount);
                    unitDeclaration.compilationResult.problemCount = problemCount;
                }
            } else if (resolver.abortProblem != null) {
                unitDeclaration.compilationResult.problemCount = 1;
                unitDeclaration.compilationResult.problems = new CategorizedProblem[] { resolver.abortProblem };
            }
            return unitDeclaration;
        }
        if (NameLookup.VERBOSE && environment instanceof CancelableNameEnvironment) {
            CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment;
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms");
        }
        return unit;
    } finally {
        if (environment != null) {
            // don't hold a reference to this external object
            environment.setMonitor(null);
        }
        if (problemFactory != null) {
            // don't hold a reference to this external object
            problemFactory.monitor = null;
        }
    }
}
Also used : JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) INameEnvironmentWithProgress(org.eclipse.jdt.internal.core.INameEnvironmentWithProgress) INameEnvironmentWithProgress(org.eclipse.jdt.internal.core.INameEnvironmentWithProgress) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) CancelableProblemFactory(org.eclipse.jdt.internal.core.CancelableProblemFactory) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) CancelableNameEnvironment(org.eclipse.jdt.internal.core.CancelableNameEnvironment)

Example 3 with CategorizedProblem

use of org.eclipse.jdt.core.compiler.CategorizedProblem in project che by eclipse.

the class CodenvyCompilationUnitResolver method resolve.

public static CompilationUnitDeclaration resolve(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, IJavaProject javaProject, INameEnvironment environment, Map options, int flags, IProgressMonitor monitor) throws JavaModelException {
    CompilationUnitDeclaration unit = null;
    //        INameEnvironmentWithProgress environment = null;
    CancelableProblemFactory problemFactory = null;
    CodenvyCompilationUnitResolver resolver = null;
    try {
        //            if (javaProject == null) {
        //                FileSystem.Classpath[] allEntries = new FileSystem.Classpath[classpaths.size()];
        //                classpaths.toArray(allEntries);
        //                environment = new NameEnvironmentWithProgress(allEntries, null, monitor);
        //            } else {
        //                environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor);
        //            }
        problemFactory = new CancelableProblemFactory(monitor);
        CompilerOptions compilerOptions = CompilationUnitResolver.getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
        boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
        resolver = new CodenvyCompilationUnitResolver(environment, CompilationUnitResolver.getHandlingPolicy(), compilerOptions, CompilationUnitResolver.getRequestor(), problemFactory, monitor, javaProject != null);
        boolean analyzeAndGenerateCode = !ignoreMethodBodies;
        unit = resolver.resolve(// no existing compilation unit declaration
        null, sourceUnit, null, // method verification
        true, // analyze code
        analyzeAndGenerateCode, // generate code
        analyzeAndGenerateCode);
        if (resolver.hasCompilationAborted) {
            // the bindings could not be resolved due to missing types in name environment
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
            CompilationUnitDeclaration unitDeclaration = CompilationUnitResolver.parse(sourceUnit, null, options, flags);
            if (unit != null) {
                final int problemCount = unit.compilationResult.problemCount;
                if (problemCount != 0) {
                    unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount];
                    System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems, 0, problemCount);
                    unitDeclaration.compilationResult.problemCount = problemCount;
                }
            } else if (resolver.abortProblem != null) {
                unitDeclaration.compilationResult.problemCount = 1;
                unitDeclaration.compilationResult.problems = new CategorizedProblem[] { resolver.abortProblem };
            }
            return unitDeclaration;
        }
        if (NameLookup.VERBOSE && environment instanceof CancelableNameEnvironment) {
            CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment;
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms");
        }
        return unit;
    } finally {
        if (environment != null) {
        // don't hold a reference to this external object
        //                environment.setMonitor(null);
        }
        if (problemFactory != null) {
            // don't hold a reference to this external object
            problemFactory.monitor = null;
        }
    }
}
Also used : CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) CancelableProblemFactory(org.eclipse.jdt.internal.core.CancelableProblemFactory) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) CancelableNameEnvironment(org.eclipse.jdt.internal.core.CancelableNameEnvironment)

Example 4 with CategorizedProblem

use of org.eclipse.jdt.core.compiler.CategorizedProblem in project che by eclipse.

the class Java50Fix method hasFatalError.

private static boolean hasFatalError(CompilationUnit compilationUnit) {
    try {
        if (!((ICompilationUnit) compilationUnit.getJavaElement()).isStructureKnown())
            return true;
    } catch (JavaModelException e) {
        JavaPlugin.log(e);
        return true;
    }
    IProblem[] problems = compilationUnit.getProblems();
    for (int i = 0; i < problems.length; i++) {
        if (problems[i].isError()) {
            if (!(problems[i] instanceof CategorizedProblem))
                return true;
            CategorizedProblem categorizedProblem = (CategorizedProblem) problems[i];
            int categoryID = categorizedProblem.getCategoryID();
            if (categoryID == CategorizedProblem.CAT_BUILDPATH)
                return true;
            if (categoryID == CategorizedProblem.CAT_SYNTAX)
                return true;
            if (categoryID == CategorizedProblem.CAT_IMPORT)
                return true;
            if (categoryID == CategorizedProblem.CAT_TYPE)
                return true;
            if (categoryID == CategorizedProblem.CAT_MEMBER)
                return true;
            if (categoryID == CategorizedProblem.CAT_INTERNAL)
                return true;
        }
    }
    return false;
}
Also used : CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) JavaModelException(org.eclipse.jdt.core.JavaModelException) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 5 with CategorizedProblem

use of org.eclipse.jdt.core.compiler.CategorizedProblem in project lombok by rzwitserloot.

the class RunTestsViaEcj method transformCode.

@Override
public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable {
    final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>();
    final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>();
    ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() {

        @Override
        public void acceptResult(CompilationResult result) {
            compilationResult_.set(result);
        }
    };
    String source = readFile(file);
    final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding);
    Compiler ecjCompiler = new Compiler(createFileSystem(file), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) {

        @Override
        protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) {
            if (inUnit == sourceUnit)
                compilationUnit_.set(parsedUnit);
            super.addCompilationUnit(inUnit, parsedUnit);
        }
    };
    ecjCompiler.compile(new ICompilationUnit[] { sourceUnit });
    CompilationResult compilationResult = compilationResult_.get();
    CategorizedProblem[] problems = compilationResult.getAllProblems();
    if (problems != null)
        for (CategorizedProblem p : problems) {
            messages.add(new CompilerMessage(p.getSourceLineNumber(), p.getSourceStart(), p.isError(), p.getMessage()));
        }
    CompilationUnitDeclaration cud = compilationUnit_.get();
    if (cud == null)
        result.append("---- NO CompilationUnit provided by ecj ----");
    else
        result.append(cud.toString());
    return true;
}
Also used : CompilationUnit(org.eclipse.jdt.internal.compiler.batch.CompilationUnit) ICompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) Compiler(org.eclipse.jdt.internal.compiler.Compiler) ICompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) CompilerMessage(lombok.javac.CapturingDiagnosticListener.CompilerMessage) ICompilerRequestor(org.eclipse.jdt.internal.compiler.ICompilerRequestor) AtomicReference(java.util.concurrent.atomic.AtomicReference) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory)

Aggregations

CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)9 IProblem (org.eclipse.jdt.core.compiler.IProblem)3 CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)3 ClassFile (org.eclipse.jdt.internal.compiler.ClassFile)2 CompilerOptions (org.eclipse.jdt.internal.compiler.impl.CompilerOptions)2 CancelableNameEnvironment (org.eclipse.jdt.internal.core.CancelableNameEnvironment)2 CancelableProblemFactory (org.eclipse.jdt.internal.core.CancelableProblemFactory)2 JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)1 JapidTemplateException (cn.bran.japid.exceptions.JapidTemplateException)1 JapidTemplate (cn.bran.japid.template.JapidTemplate)1 Iterator (java.util.Iterator)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CompilerMessage (lombok.javac.CapturingDiagnosticListener.CompilerMessage)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 CompilationResult (org.eclipse.jdt.internal.compiler.CompilationResult)1 Compiler (org.eclipse.jdt.internal.compiler.Compiler)1 ICompilerRequestor (org.eclipse.jdt.internal.compiler.ICompilerRequestor)1 ConstructorDeclaration (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration)1