List of usage examples for org.eclipse.jdt.internal.core.builder ProblemFactory getProblemFactory
public static ProblemFactory getProblemFactory(Locale locale)
From source file:br.com.objectos.code.JdtCompilerBuilderPojo.java
License:Apache License
@Override public JdtCompiler build() { NameEnvironment environment = new NameEnvironment(); IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitAfterAllProblems(); CompilerOptions options = new CompilerOptions(); options.set(optionMap.build());/*from ww w. j a va 2s .co m*/ IProblemFactory problemFactory = ProblemFactory.getProblemFactory(Locale.getDefault()); Compiler delegate = new Compiler(environment, policy, options, requestor, problemFactory); annotationProcessorManager.set(delegate); return new JdtCompiler(delegate); }
From source file:io.takari.maven.plugins.compile.jdt.CompilerJdt.java
License:Open Source License
@Override public int compile() throws MojoExecutionException, IOException { Map<String, String> args = new HashMap<String, String>(); // XXX figure out how to reuse source/target check from jdt // org.eclipse.jdt.internal.compiler.batch.Main.validateOptions(boolean) args.put(CompilerOptions.OPTION_TargetPlatform, getTarget()); // support 5/6/7 aliases args.put(CompilerOptions.OPTION_Compliance, getTarget()); // support 5/6/7 aliases args.put(CompilerOptions.OPTION_Source, getSource()); // support 5/6/7 aliases args.put(CompilerOptions.OPTION_ReportForbiddenReference, CompilerOptions.ERROR); Set<Debug> debug = getDebug(); if (debug == null || debug.contains(Debug.all)) { args.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); args.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE); args.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE); } else if (debug.contains(Debug.none)) { args.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); args.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); args.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE); } else {//from w w w . ja va2 s . c o m args.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); args.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); args.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE); for (Debug keyword : debug) { switch (keyword) { case lines: args.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE); break; case source: args.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE); break; case vars: args.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); break; default: throw new IllegalArgumentException(); } } } class _CompilerOptions extends CompilerOptions { public void setShowWarnings(boolean showWarnings) { if (showWarnings) { warningThreshold = IrritantSet.COMPILER_DEFAULT_WARNINGS; } else { warningThreshold = new IrritantSet(0); } } } _CompilerOptions compilerOptions = new _CompilerOptions(); compilerOptions.set(args); compilerOptions.performMethodsFullRecovery = false; compilerOptions.performStatementsRecovery = false; compilerOptions.verbose = isVerbose(); compilerOptions.suppressWarnings = true; compilerOptions.setShowWarnings(isShowWarnings()); compilerOptions.docCommentSupport = true; if (isProcEscalate() && strategy instanceof IncrementalCompilationStrategy) { strategy.enqueueAllSources(); strategy = new FullCompilationStrategy(); } Classpath namingEnvironment = strategy.createClasspath(); IErrorHandlingPolicy errorHandlingPolicy = DefaultErrorHandlingPolicies.exitAfterAllProblems(); IProblemFactory problemFactory = ProblemFactory.getProblemFactory(Locale.getDefault()); Compiler compiler = new Compiler(namingEnvironment, errorHandlingPolicy, compilerOptions, this, problemFactory); compiler.options.produceReferenceInfo = true; EclipseFileManager fileManager = null; try { if (!isProcNone()) { fileManager = new EclipseFileManager(null, getSourceEncoding()); fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, dependencies); fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(getOutputDirectory())); fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(getGeneratedSourcesDirectory())); ProcessingEnvImpl processingEnv = new ProcessingEnvImpl(context, fileManager, getAnnotationProcessorOptions(), compiler, this); compiler.annotationProcessorManager = new AnnotationProcessorManager(processingEnv, fileManager, getAnnotationProcessors()); compiler.options.storeAnnotations = true; } return strategy.compile(namingEnvironment, compiler); } finally { if (fileManager != null) { fileManager.flush(); fileManager.close(); } } }
From source file:org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.java
License:Open Source License
protected Compiler newCompiler() { // disable entire javadoc support if not interested in diagnostics Map projectOptions = this.javaBuilder.javaProject.getOptions(true); String option = (String) projectOptions.get(JavaCore.COMPILER_PB_INVALID_JAVADOC); if (option == null || option.equals(JavaCore.IGNORE)) { // TODO (frederic) see why option is null sometimes while running model tests!? option = (String) projectOptions.get(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS); if (option == null || option.equals(JavaCore.IGNORE)) { option = (String) projectOptions.get(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS); if (option == null || option.equals(JavaCore.IGNORE)) { option = (String) projectOptions.get(JavaCore.COMPILER_PB_UNUSED_IMPORT); if (option == null || option.equals(JavaCore.IGNORE)) { // Unused import need also to look inside javadoc comment projectOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED); }//from w w w . j a v a 2 s . c o m } } } // called once when the builder is initialized... can override if needed CompilerOptions compilerOptions = new CompilerOptions(projectOptions); compilerOptions.performMethodsFullRecovery = true; compilerOptions.performStatementsRecovery = true; // GROOVY start: make it behave in a groovier way if this project has the right nature CompilerUtils.configureOptionsBasedOnNature(compilerOptions, this.javaBuilder.javaProject); // GROOVY end Compiler newCompiler = new Compiler(this.nameEnvironment, DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, this, ProblemFactory.getProblemFactory(Locale.getDefault())); CompilerOptions options = newCompiler.options; // temporary code to allow the compiler to revert to a single thread String setting = System.getProperty("jdt.compiler.useSingleThread"); //$NON-NLS-1$ newCompiler.useSingleThread = setting != null && setting.equals("true"); //$NON-NLS-1$ // enable the compiler reference info support options.produceReferenceInfo = true; if (options.complianceLevel >= ClassFileConstants.JDK1_6 && options.processAnnotations) { // support for Java 6 annotation processors initializeAnnotationProcessorManager(newCompiler); } return newCompiler; }
From source file:org.eclipse.zest.dot.GraphCreatorViaInternalJdtCompiler.java
License:Open Source License
private URL compileWithInternalJdtCompiler(final File zestFile, final String graphName) { /*// w ww .j a v a2 s .co m * TODO we need to set up the environment here. Here, we basically hit * the same issue as when running with the Java compiler API: we need * the classpath */ INameEnvironment nameEnvironment = new FileSystem(new String[0], new String[0], "UTF-8"); CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.generateClassFiles = true; compilerOptions.verbose = true; org.eclipse.jdt.internal.compiler.Compiler compiler = new org.eclipse.jdt.internal.compiler.Compiler( nameEnvironment, DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new ICompilerRequestor() { public void acceptResult(final CompilationResult result) { CategorizedProblem[] errors = result.getErrors(); for (CategorizedProblem categorizedProblem : errors) { System.out.println(String.format("%s: '%s' (%s, line %s)", categorizedProblem.getMarkerType(), categorizedProblem.getMessage(), new String(categorizedProblem.getOriginatingFileName()), categorizedProblem.getSourceLineNumber())); } } }, ProblemFactory.getProblemFactory(Locale.getDefault())); compiler.compile(new ICompilationUnit[] { new ICompilationUnit() { public char[] getFileName() { return zestFile.getAbsolutePath().toCharArray(); } public char[][] getPackageName() { return null; } public char[] getMainTypeName() { return graphName.toCharArray(); } public char[] getContents() { return read(zestFile).toCharArray(); } } }); try { URL url = zestFile.getParentFile().toURI().toURL(); return url; } catch (MalformedURLException e) { e.printStackTrace(); } return null; }
From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianCompilationParticipant.java
License:Open Source License
protected Compiler newCompiler(IJavaProject javaProject) { Map projectOptions = javaProject.getOptions(true); String option = (String) projectOptions.get(JavaCore.COMPILER_PB_INVALID_JAVADOC); if (option == null || option.equals(JavaCore.IGNORE)) { option = (String) projectOptions.get(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS); if (option == null || option.equals(JavaCore.IGNORE)) { option = (String) projectOptions.get(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS); if (option == null || option.equals(JavaCore.IGNORE)) { option = (String) projectOptions.get(JavaCore.COMPILER_PB_UNUSED_IMPORT); if (option == null || option.equals(JavaCore.IGNORE)) { projectOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED); }/*from w w w . j a v a2 s . com*/ } } } CompilerOptions compilerOptions = new CompilerOptions(projectOptions); compilerOptions.performMethodsFullRecovery = true; compilerOptions.performStatementsRecovery = true; nameEnvironment = new ArquillianNameEnvironment(javaProject); Compiler newCompiler = new Compiler(nameEnvironment, DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, this, ProblemFactory.getProblemFactory(Locale.getDefault())); CompilerOptions options = newCompiler.options; // temporary code to allow the compiler to revert to a single thread String setting = System.getProperty("jdt.compiler.useSingleThread"); //$NON-NLS-1$ newCompiler.useSingleThread = setting != null && setting.equals("true"); //$NON-NLS-1$ // enable the compiler reference info support options.produceReferenceInfo = true; return newCompiler; }