本文整理汇总了Java中org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory类的典型用法代码示例。如果您正苦于以下问题:Java DefaultProblemFactory类的具体用法?Java DefaultProblemFactory怎么用?Java DefaultProblemFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultProblemFactory类属于org.eclipse.jdt.internal.compiler.problem包,在下文中一共展示了DefaultProblemFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
@Nullable
private static Node parse(String code) {
CompilerOptions options = new CompilerOptions();
options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_7;
options.parseLiteralExpressionsAsConstants = true;
ProblemReporter problemReporter = new ProblemReporter(
DefaultErrorHandlingPolicies.exitOnFirstError(), options, new DefaultProblemFactory());
Parser parser = new Parser(problemReporter, options.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = false;
EcjTreeConverter converter = new EcjTreeConverter();
org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit =
new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(code.toCharArray(), "unitTest", "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration unit = parser.parse(sourceUnit, compilationResult);
if (unit == null) {
return null;
}
converter.visit(code, unit);
List<? extends Node> nodes = converter.getAll();
for (lombok.ast.Node node : nodes) {
if (node instanceof lombok.ast.CompilationUnit) {
return node;
}
}
return null;
}
示例2: getSourceElementParser
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
public SourceElementParser getSourceElementParser(
IJavaProject project, ISourceElementRequestor requestor) {
// disable task tags to speed up parsing
Map options = project.getOptions(true);
options.put(JavaCore.COMPILER_TASK_TAGS, ""); // $NON-NLS-1$
try {
SourceElementParser parser =
new IndexingParser(
requestor,
new DefaultProblemFactory(Locale.getDefault()),
new CompilerOptions(options),
true, // index local declarations
true, // optimize string literals
false); // do not use source javadoc parser to speed up parsing
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;
}
}
示例3: process
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
@Override public ASTNode process(Source in, Void irrelevant) throws ConversionProblem {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(in.getRawInput().toCharArray(), in.getName(), charset.name());
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) {
throw new ConversionProblem(String.format("Can't read file %s due to parse error: %s", in.getName(), compilationResult.getErrors()[0]));
}
return cud;
}
示例4: createDefaultProblemReporter
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
private static ProblemReporter createDefaultProblemReporter(CompilerOptions options) {
return new ProblemReporter(new IErrorHandlingPolicy() {
public boolean proceedOnErrors() {
return true;
}
public boolean stopOnFirstError() {
return false;
}
@Override
public boolean ignoreAllErrors() {
return false;
}
}, options, new DefaultProblemFactory(Locale.ENGLISH));
}
示例5: parseWithLombok
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
@Override
protected ASTNode parseWithLombok(Source source) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) return null;
EcjTreeConverter converter = new EcjTreeConverter();
converter.visit(source.getRawInput(), cud);
Node lombokized = converter.get();
EcjTreeBuilder builder = new EcjTreeBuilder(source.getRawInput(), source.getName(), ecjCompilerOptions());
builder.visit(lombokized);
return builder.get();
}
示例6: parseWithTargetCompiler
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
@Override
protected ASTNode parseWithTargetCompiler(Source source) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) return null;
return cud;
}
示例7: parseWithTargetCompiler
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
@Override
protected ASTNode parseWithTargetCompiler(Source source) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) return null;
return cud;
}
示例8: parseWithTargetCompiler
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
protected Node parseWithTargetCompiler(Source source) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) return null;
EcjTreeConverter converter = new EcjTreeConverter();
converter.visit(source.getRawInput(), cud);
return converter.get();
}
示例9: getSourceElementParser
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
public SourceElementParser getSourceElementParser(IJavaProject project, ISourceElementRequestor requestor) {
// disable task tags to speed up parsing
Map options = project.getOptions(true);
options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
SourceElementParser parser = new IndexingParser(
requestor,
new DefaultProblemFactory(Locale.getDefault()),
new CompilerOptions(options),
true, // index local declarations
true, // optimize string literals
false); // do not use source javadoc parser to speed up parsing
parser.reportOnlyOneSyntaxError = true;
// Always check javadoc while indexing
parser.javadocParser.checkDocComment = true;
parser.javadocParser.reportProblems = false;
return parser;
}
示例10: compile
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
public void compile(Collection<Source> sources) {
Timer timer = metric.startTimer("act:classload:compile:_all");
int len = sources.size();
ICompilationUnit[] compilationUnits = new ICompilationUnit[len];
int i = 0;
for (Source source: sources) {
compilationUnits[i++] = source.compilationUnit();
}
IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitOnFirstError();
IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH);
org.eclipse.jdt.internal.compiler.Compiler jdtCompiler = new Compiler(
nameEnv, policy, compilerOptions, requestor, problemFactory) {
@Override
protected void handleInternalException(Throwable e, CompilationUnitDeclaration ud, CompilationResult result) {
}
};
jdtCompiler.compile(compilationUnits);
timer.stop();
}
示例11: compile
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
@Override
public CompilationResult compile(final Collection<String> sourceNames) {
final Map<String, byte[]> compiled = new HashMap<String, byte[]>();
final List<CompilationProblem> problems = new ArrayList<CompilationProblem>();
final List<ICompilationUnit> compilationUnits = collectCompilationUnits(sourceNames, problems);
// Exit if problems
if (! problems.isEmpty()) {
return new CompilationResult(problems);
}
// Setup compiler environment
final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
final INameEnvironment nameEnvironment = new NameEnvironment();
final ICompilerRequestor compilerRequestor = new CompilerRequestor(problems, compiled);
// Compile
final Compiler compiler = new Compiler(nameEnvironment, policy, new CompilerOptions(STANDARD_OPTIONS),
compilerRequestor, problemFactory);
compiler.compile(compilationUnits.toArray(new ICompilationUnit[0]));
return new CompilationResult(problems, compiled);
}
示例12: installStubs
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
public void installStubs(final Resource resource) {
boolean _isInfoFile = this.isInfoFile(resource);
if (_isInfoFile) {
return;
}
final CompilationUnit compilationUnit = this.getCompilationUnit(resource);
IErrorHandlingPolicy _proceedWithAllProblems = DefaultErrorHandlingPolicies.proceedWithAllProblems();
CompilerOptions _compilerOptions = this.getCompilerOptions(resource);
DefaultProblemFactory _defaultProblemFactory = new DefaultProblemFactory();
ProblemReporter _problemReporter = new ProblemReporter(_proceedWithAllProblems, _compilerOptions, _defaultProblemFactory);
final Parser parser = new Parser(_problemReporter, true);
final CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, (-1));
final CompilationUnitDeclaration result = parser.dietParse(compilationUnit, compilationResult);
if ((result.types != null)) {
for (final TypeDeclaration type : result.types) {
{
ImportReference _currentPackage = result.currentPackage;
char[][] _importName = null;
if (_currentPackage!=null) {
_importName=_currentPackage.getImportName();
}
List<String> _map = null;
if (((List<char[]>)Conversions.doWrapArray(_importName))!=null) {
final Function1<char[], String> _function = (char[] it) -> {
return String.valueOf(it);
};
_map=ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(_importName)), _function);
}
String _join = null;
if (_map!=null) {
_join=IterableExtensions.join(_map, ".");
}
final String packageName = _join;
final JvmDeclaredType jvmType = this.createType(type, packageName);
resource.getContents().add(jvmType);
}
}
}
}
示例13: compileUnits
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
@Override
protected String compileUnits(final JRCompilationUnit[] units, String classpath, File tempDirFile)
{
final INameEnvironment env = getNameEnvironment(units);
final IErrorHandlingPolicy policy =
DefaultErrorHandlingPolicies.proceedWithAllProblems();
final Map<String,String> settings = getJdtSettings();
final IProblemFactory problemFactory =
new DefaultProblemFactory(Locale.getDefault());
final CompilerRequestor requestor = getCompilerRequestor(units);
final Compiler compiler = new Compiler(env, policy, settings, requestor, problemFactory);
do
{
CompilationUnit[] compilationUnits = requestor.processCompilationUnits();
compiler.compile(compilationUnits);
}
while (requestor.hasMissingMethods());
requestor.processProblems();
return requestor.getFormattedProblems();
}
示例14: parseWithEcj
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
private void parseWithEcj(Source source) {
if (VERBOSE) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
parser.parse(sourceUnit, compilationResult);
}
}
示例15: resolveDocument
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //导入依赖的package包/类
public void resolveDocument() {
try {
IPath path = new Path(this.document.getPath());
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
JavaProject javaProject = (JavaProject) model.getJavaProject(project);
this.options = new CompilerOptions(javaProject.getOptions(true));
ProblemReporter problemReporter =
new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
this.options,
new DefaultProblemFactory());
// Re-parse using normal parser, IndexingParser swallows several nodes, see comment above class.
this.basicParser = new Parser(problemReporter, false);
this.basicParser.reportOnlyOneSyntaxError = true;
this.basicParser.scanner.taskTags = null;
this.cud = this.basicParser.parse(this.compilationUnit, new CompilationResult(this.compilationUnit, 0, 0, this.options.maxProblemsPerUnit));
// Use a non model name environment to avoid locks, monitors and such.
INameEnvironment nameEnvironment = new JavaSearchNameEnvironment(javaProject, JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, true/*add primary WCs*/));
this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, nameEnvironment);
reduceParseTree(this.cud);
this.lookupEnvironment.buildTypeBindings(this.cud, null);
this.lookupEnvironment.completeTypeBindings();
this.cud.scope.faultInTypes();
this.cud.resolve();
} catch (Exception e) {
if (JobManager.VERBOSE) {
e.printStackTrace();
}
}
}