use of org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory in project che by eclipse.
the class IndexManager method getSourceElementParser.
public SourceElementParser getSourceElementParser(IJavaProject project, ISourceElementRequestor requestor) {
// disable task tags to speed up parsing
Map options = project.getOptions(true);
//$NON-NLS-1$
options.put(JavaCore.COMPILER_TASK_TAGS, "");
try {
SourceElementParser parser = new IndexingParser(requestor, new DefaultProblemFactory(Locale.getDefault()), new CompilerOptions(options), // index local declarations
true, // optimize string literals
true, // do not use source javadoc parser to speed up parsing
false);
parser.reportOnlyOneSyntaxError = true;
// Always check javadoc while indexing
parser.javadocParser.checkDocComment = true;
parser.javadocParser.reportProblems = false;
return parser;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory in project jetbrick-template-1x by subchen.
the class JdtCompiler method generateJavaClass.
@Override
protected void generateJavaClass(JavaSource source) throws IOException {
INameEnvironment env = new NameEnvironment(source);
IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
CompilerOptions options = getCompilerOptions();
CompilerRequestor requestor = new CompilerRequestor();
IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
Compiler compiler = new Compiler(env, policy, options, requestor, problemFactory);
compiler.compile(new ICompilationUnit[] { new CompilationUnit(source) });
if (requestor.hasErrors()) {
String sourceCode = source.getSourceCode();
String[] sourceCodeLines = sourceCode.split("(\r\n|\r|\n)", -1);
StringBuilder sb = new StringBuilder();
sb.append("Compilation failed.");
sb.append('\n');
for (IProblem p : requestor.getErrors()) {
sb.append(p.getMessage()).append('\n');
int start = p.getSourceStart();
// default
int column = start;
for (int i = start; i >= 0; i--) {
char c = sourceCode.charAt(i);
if (c == '\n' || c == '\r') {
column = start - i;
break;
}
}
sb.append(StringUtils.getPrettyError(sourceCodeLines, p.getSourceLineNumber(), column, p.getSourceStart(), p.getSourceEnd(), 3));
}
sb.append(requestor.getErrors().length);
sb.append(" error(s)\n");
throw new CompileErrorException(sb.toString());
}
requestor.save(source.getOutputdir());
}
use of org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory in project opennms by OpenNMS.
the class CustomJRJdtCompiler method compileUnits.
@Override
protected String compileUnits(final JRCompilationUnit[] units, String classpath, File tempDirFile) {
final INameEnvironment env = getNameEnvironment(units);
final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
final CompilerOptions options = getJdtSettings();
final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
final CompilerRequestor requestor = getCompilerRequestor(units);
final Compiler compiler = new Compiler(env, policy, options, requestor, problemFactory);
do {
CompilationUnit[] compilationUnits = requestor.processCompilationUnits();
compiler.compile(compilationUnits);
} while (requestor.hasMissingMethods());
requestor.processProblems();
return requestor.getFormattedProblems();
}
use of org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory in project webpieces by deanhiller.
the class CompilerWrapper method compile.
/**
* Please compile this className
*/
@SuppressWarnings("deprecation")
public void compile(String[] classNames, ClassDefinitionLoader loader) {
ICompilationUnit[] compilationUnits = new CompilationUnit[classNames.length];
for (int i = 0; i < classNames.length; i++) {
compilationUnits[i] = new CompilationUnit(classNames[i]);
}
IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitOnFirstError();
IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH);
/**
* To find types ...
*/
INameEnvironment nameEnvironment = new INameEnvironmentImpl(loader);
/**
* Compilation result
*/
ICompilerRequestor compilerRequestor = new ICompilerRequestorImpl();
/**
* The JDT compiler
*/
Compiler jdtCompiler = new Compiler(nameEnvironment, policy, settings, compilerRequestor, problemFactory) {
@Override
protected void handleInternalException(Throwable e, CompilationUnitDeclaration ud, CompilationResult result) {
}
};
// Go !
jdtCompiler.compile(compilationUnits);
}
Aggregations