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();
}
}
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;
}
}
}
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;
}
}
}
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;
}
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;
}
Aggregations