environment = getLibraryAccess(); CompilerOptions compilerOptions = new CompilerOptions(this.options); compilerOptions.parseLiteralExpressionsAsConstants = false; new CommentRecorderParser( new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new DefaultProblemFactory(Locale.getDefault())), false);
private int indexForSourceLevel(String sourceLevel) { if (sourceLevel == null) return 0; int majVersion = (int) (CompilerOptions.versionToJdkLevel(sourceLevel) >>> 16); if (majVersion > ClassFileConstants.MAJOR_VERSION_1_2) { return (majVersion - ClassFileConstants.MAJOR_VERSION_1_1); } // all other cases including ClassFileConstants.MAJOR_VERSION_1_1 return 0; }
public InMemoryJavaCompiler(final ClassLoader parent, final CompilerOptions compilerOptions) { InMemoryJavaCompiler.ClassLoaderBasedNameEnvironment _classLoaderBasedNameEnvironment = new InMemoryJavaCompiler.ClassLoaderBasedNameEnvironment(parent); this.nameEnv = _classLoaderBasedNameEnvironment; this.parentClassLoader = parent; Map<String, String> _map = compilerOptions.getMap(); CompilerOptions _compilerOptions = new CompilerOptions(_map); this.compilerOptions = _compilerOptions; }
/** * Initializing the compiler options with external settings * @param settings */ public CompilerOptions(Map<String, String> settings){ resetDefaults(); if (settings != null) { set(settings); } }
public Engine(Map<String, String> settings){ this.options = new AssistOptions(settings); this.compilerOptions = new CompilerOptions(settings); this.forbiddenReferenceIsError = (this.compilerOptions.getSeverity(CompilerOptions.ForbiddenReference) & ProblemSeverities.Error) != 0; this.discouragedReferenceIsError = (this.compilerOptions.getSeverity(CompilerOptions.DiscouragedReference) & ProblemSeverities.Error) != 0; }
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; } /**
private Parser getParser() { Map<String,String> opts = new HashMap<String, String>(); opts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); return new Parser( new ProblemReporter(DefaultErrorHandlingPolicies.exitOnFirstError(), new CompilerOptions(opts), new DefaultProblemFactory(Locale.getDefault())), false); } @Override
public byte[] compileWithAttributes(IModuleDescription module, Map<String,String> classFileAttributes) throws JavaModelException { IJavaProject javaProject = module.getJavaProject(); NameEnvironment nameEnvironment = new NameEnvironment(javaProject, CompilationGroup.MAIN); addModuleUpdates(module, nameEnvironment.moduleUpdater, classFileAttributes); ClasspathMultiDirectory sourceLocation = getSourceLocation(javaProject, nameEnvironment, module); IFile file = (IFile) module.getCompilationUnit().getCorrespondingResource(); ICompilationUnit[] sourceUnits = { new SourceFile(file, sourceLocation) }; BytecodeCollector collector = new BytecodeCollector(); Compiler newCompiler = new Compiler( nameEnvironment, DefaultErrorHandlingPolicies.exitOnFirstError(), new CompilerOptions(javaProject.getOptions(true)), collector, ProblemFactory.getProblemFactory(Locale.getDefault())); newCompiler.compile(sourceUnits); return collector.bytes; }
private static Compiler newCompiler(ModuleAccumulatorEnvironment environment, IJavaProject javaProject) { Map<String, String> projectOptions = javaProject.getOptions(true); CompilerOptions compilerOptions = new CompilerOptions(projectOptions); compilerOptions.performMethodsFullRecovery = true; compilerOptions.performStatementsRecovery = true; ICompilerRequestor requestor = new ICompilerRequestor() { @Override public void acceptResult(CompilationResult result) { // Nothing to do here } }; Compiler newCompiler = new Compiler( environment, DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, requestor, ProblemFactory.getProblemFactory(Locale.getDefault())); return newCompiler; } public static String[] getReferencedModules(IJavaProject project) throws CoreException {
private Parser getParser() { if (this.parser == null) { this.compilerOptions = new CompilerOptions(JavaCore.getOptions()); ProblemReporter problemReporter = new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), this.compilerOptions, new DefaultProblemFactory()); this.parser = new Parser(problemReporter, true); } return this.parser; }
/** * Creates a new parser. */ protected DocumentElementParser getParser(Map settings) { return new DocumentElementParser(this, new DefaultProblemFactory(), new CompilerOptions(settings)); } /**
public HierarchyResolver(INameEnvironment nameEnvironment, Map settings, HierarchyBuilder builder, IProblemFactory problemFactory) { // create a problem handler with the 'exit after all problems' handling policy this.options = new CompilerOptions(settings); IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitAfterAllProblems(); ProblemReporter problemReporter = new ProblemReporter(policy, this.options, problemFactory); LookupEnvironment environment = new LookupEnvironment(this, this.options, problemReporter, nameEnvironment); environment.mayTolerateMissingType = true; setEnvironment(environment, builder); } public HierarchyResolver(LookupEnvironment lookupEnvironment, HierarchyBuilder builder) {
/** * @return the default set of compiler options. */ private CompilerOptions getDefaultOptions() { // Configure compiler options Map<String, String> settings = new HashMap<String, String>(); settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE); settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE); CompilerOptions options = new CompilerOptions(); options.set(settings); return options; } }
public void javadocHiddenReference(int sourceStart, int sourceEnd, Scope scope, int modifiers) { Scope currentScope = scope; while (currentScope.parent.kind != Scope.COMPILATION_UNIT_SCOPE ) { if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, currentScope.getDeclarationModifiers())) { return; } currentScope = currentScope.parent; } String[] arguments = new String[] { this.options.getVisibilityString(this.options.reportInvalidJavadocTagsVisibility), this.options.getVisibilityString(modifiers) }; this.handle(IProblem.JavadocHiddenReference, arguments, arguments, sourceStart, sourceEnd); } public void javadocInvalidConstructor(Statement statement, MethodBinding targetConstructor, int modifiers) {
public void initializeScanner() { this.scanner = new Scanner( false /*comment*/, false /*whitespace*/, this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/, this.options.sourceLevel /*sourceLevel*/, this.options.taskTags/*taskTags*/, this.options.taskPriorities/*taskPriorities*/, this.options.isTaskCaseSensitive/*taskCaseSensitive*/); }
private static boolean preventsUnlikelyTypeWarning(TypeBinding castedType, TypeBinding uncastedType, TypeBinding receiverType, MethodBinding binding, BlockScope scope) { if (!scope.compilerOptions().isAnyEnabled(IrritantSet.UNLIKELY_ARGUMENT_TYPE)) return false; if (binding.isStatic() || binding.parameters.length != 1) return false; // would using the uncastedType be considered as dangerous? UnlikelyArgumentCheck argumentChecks = UnlikelyArgumentCheck.determineCheckForNonStaticSingleArgumentMethod( uncastedType, scope, binding.selector, receiverType, binding.parameters); if (argumentChecks != null && argumentChecks.isDangerous(scope)) { // does the cast help? argumentChecks = UnlikelyArgumentCheck.determineCheckForNonStaticSingleArgumentMethod( castedType, scope, binding.selector, receiverType, binding.parameters); if (argumentChecks == null || !argumentChecks.isDangerous(scope)) return true; } return false; }
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; } /**
private Parser getParser() { Map<String,String> opts = new HashMap<String, String>(); opts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); return new Parser( new ProblemReporter(DefaultErrorHandlingPolicies.exitOnFirstError(), new CompilerOptions(opts), new DefaultProblemFactory(Locale.getDefault())), false); } @Override
public byte[] compileWithAttributes(IModuleDescription module, Map<String,String> classFileAttributes) throws JavaModelException { IJavaProject javaProject = module.getJavaProject(); NameEnvironment nameEnvironment = new NameEnvironment(javaProject); addModuleUpdates(module, nameEnvironment.moduleUpdater, classFileAttributes); ClasspathMultiDirectory sourceLocation = getSourceLocation(javaProject, nameEnvironment, module); IFile file = (IFile) module.getCompilationUnit().getCorrespondingResource(); ICompilationUnit[] sourceUnits = { new SourceFile(file, sourceLocation) }; BytecodeCollector collector = new BytecodeCollector(); Compiler newCompiler = new Compiler( nameEnvironment, DefaultErrorHandlingPolicies.exitOnFirstError(), new CompilerOptions(javaProject.getOptions(true)), collector, ProblemFactory.getProblemFactory(Locale.getDefault())); newCompiler.compile(sourceUnits); return collector.bytes; }
private Parser getParser() { if (this.parser == null) { this.compilerOptions = new CompilerOptions(JavaCore.getOptions()); ProblemReporter problemReporter = new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), this.compilerOptions, new DefaultProblemFactory()); this.parser = new Parser(problemReporter, true); } return this.parser; }