@Override public void init(JavacTask javacTask, String... args) { Context context = ((BasicJavacTask) javacTask).getContext(); BaseErrorProneJavaCompiler.checkCompilePolicy(Options.instance(context).get("compilePolicy")); BaseErrorProneJavaCompiler.setupMessageBundle(context); RefactoringCollection[] refactoringCollection = {null}; javacTask.addTaskListener( BaseErrorProneJavaCompiler.createAnalyzer( BuiltInCheckerSuppliers.defaultChecks(), ErrorProneOptions.processArgs(args), context, refactoringCollection)); if (refactoringCollection[0] != null) { javacTask.addTaskListener(new RefactoringTask(context, refactoringCollection[0])); } } }
/** Returns true if the compilation is targeting Android. */ public boolean isAndroidCompatible() { return Options.instance(context).getBoolean("androidCompatible"); } }
/** * Creates a new compilation environment with the given options and * classpath. */ public static JavaCompilationEnvironment create(JSweetOptions jsweetOptions, String classPath) { JSweetContext context = new JSweetContext(jsweetOptions); Options options = Options.instance(context); options.put(Option.CLASSPATH, classPath); options.put(Option.XLINT, "path"); context.put(Log.outKey, new PrintWriter(System.out)); // options.put(Option.XLINT_CUSTOM.text + "-" + // LintCategory.OPTIONS.option, "true"); // options.remove(Option.XLINT_CUSTOM.text + // LintCategory.OPTIONS.option); options.put(Option.XLINT_CUSTOM.text + "-" + LintCategory.OVERRIDES.option, "true"); JavacFileManager.preRegister(context); JavaFileManager fileManager = context.get(JavaFileManager.class); Log log = Log.instance(context); log.emitWarnings = false; log.suppressNotes = true; Types javacTypes = Types.instance(context); JavaCompiler compiler = JavaCompiler.instance(context); compiler.attrParseOnly = true; compiler.verbose = false; compiler.genEndPos = true; compiler.keepComments = true; Names names = Names.instance(context); Symtab symtab = Symtab.instance(context); return new JavaCompilationEnvironment(fileManager, compiler, options, context, log, javacTypes, names, symtab); }
public boolean process(Options options, String option) { options.put("-Xlint:deprecation", option); return false; } },
protected Lint(Context context) { // initialize values according to the lint options Options options = Options.instance(context); values = EnumSet.noneOf(LintCategory.class); for (Map.Entry<String, LintCategory> e: map.entrySet()) { if (options.lint(e.getKey())) values.add(e.getValue()); } suppressedValues = EnumSet.noneOf(LintCategory.class); context.put(lintKey, this); augmentor = new AugmentVisitor(context); }
private Map<String, String> initProcessorOptions(Context context) { Options options = Options.instance(context); Set<String> keySet = options.keySet(); Map<String, String> tempOptions = new LinkedHashMap<String, String>(); for(String key : keySet) { if (key.startsWith("-A") && key.length() > 2) { int sepIndex = key.indexOf('='); String candidateKey = null; String candidateValue = null; if (sepIndex == -1) candidateKey = key.substring(2); else if (sepIndex >= 3) { candidateKey = key.substring(2, sepIndex); candidateValue = (sepIndex < key.length()-1)? key.substring(sepIndex+1) : null; } tempOptions.put(candidateKey, candidateValue); } } return Collections.unmodifiableMap(tempOptions); }
public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) { options = Options.instance(context); this.context = context; log = Log.instance(context); source = Source.instance(context); printProcessorInfo = options.get("-XprintProcessorInfo") != null; printRounds = options.get("-XprintRounds") != null; verbose = options.get("-verbose") != null; lint = options.lint("processing"); procOnly = options.get("-proc:only") != null || options.get("-Xprint") != null; fatalErrors = options.get("fatalEnterError") != null; platformAnnotations = initPlatformAnnotations(); // Initialize services before any processors are initialzied // in case processors use them. filer = new JavacFiler(context); messager = new JavacMessager(context, this); elementUtils = new JavacElements(context); typeUtils = new JavacTypes(context); processorOptions = initProcessorOptions(context); unmatchedProcessorOptions = initUnmatchedProcessorOptions(); initProcessorIterator(context, processors); }
private void listOptions(StringBuilder message, ProcessingEnvironment procEnv) { try { JavacProcessingEnvironment environment = (JavacProcessingEnvironment) procEnv; Options instance = Options.instance(environment.getContext()); Field field = Permit.getField(Options.class, "values"); @SuppressWarnings("unchecked") Map<String, String> values = (Map<String, String>) field.get(instance); if (values.isEmpty()) { message.append("Options: empty\n\n"); return; } message.append("Compiler Options:\n"); for (Map.Entry<String, String> value : values.entrySet()) { message.append("- "); string(message, value.getKey()); message.append(" = "); string(message, value.getValue()); message.append("\n"); } message.append("\n"); } catch (Exception e) { message.append("No options available\n\n"); } }
: (candiesProcessor == null ? false : candiesProcessor.isUsingJavaRuntime())); adapter = factory.createAdapter(context); options = Options.instance(context); if (classPath != null) { options.put(Option.CLASSPATH, classPath); for (String s : classPath.split(File.pathSeparator)) { if (s.contains(JSweetConfig.MAVEN_JAVA_OVERRIDE_ARTIFACT)) { context.strictMode = true; options.put(Option.BOOTCLASSPATH, s); options.put(Option.ENCODING, encoding); logger.debug("encoding: " + options.get(Option.ENCODING)); options.put(Option.XLINT, "path"); JavacFileManager.preRegister(context); fileManager = context.get(JavaFileManager.class);
/** Check for a lint suboption. */ public boolean lint(String s) { // return true if either the specific option is enabled, or // they are all enabled without the specific one being // disabled return get(LINT + ":" + s)!=null || (get(LINT)!=null || get(LINT + ":all")!=null) && get(LINT+":-"+s)==null; } }
/** Create a new diagnostic factory. */ protected Factory(Context context) { this(JavacMessages.instance(context), "compiler"); context.put(diagnosticFactoryKey, this); final Options options = Options.instance(context); initOptions(options); options.addListener(new Runnable() { public void run() { initOptions(options); } }); }
@Override public void remove(String name) { options.remove(name); } };
/** Get the Options instance for this context. */ public static Options instance(Context context) { Options instance = context.get(optionsKey); if (instance == null) instance = new Options(context); return instance; }
public EvaluationResult performEval(SourceFile[] sourceFiles) throws Exception { Options options = Options.instance(context); if (transpiler.getClassPath() != null) { options.put(Option.CLASSPATH, transpiler.getClassPath()); options.put(Option.XLINT, "path"); if (transpiler.getEncoding() != null) { options.put(Option.ENCODING, transpiler.getEncoding());
public boolean process(Options options, String option) { options.put("-Xlint:unchecked", option); return false; } },
protected Lint(Context context) { // initialize values according to the lint options Options options = Options.instance(context); values = EnumSet.noneOf(LintCategory.class); for (Map.Entry<String, LintCategory> e: map.entrySet()) { if (options.lint(e.getKey())) values.add(e.getValue()); } suppressedValues = EnumSet.noneOf(LintCategory.class); context.put(lintKey, this); augmentor = new AugmentVisitor(context); }
private Map<String, String> initProcessorOptions(Context context) { Options options = Options.instance(context); Set<String> keySet = options.keySet(); Map<String, String> tempOptions = new LinkedHashMap<String, String>(); for(String key : keySet) { if (key.startsWith("-A") && key.length() > 2) { int sepIndex = key.indexOf('='); String candidateKey = null; String candidateValue = null; if (sepIndex == -1) candidateKey = key.substring(2); else if (sepIndex >= 3) { candidateKey = key.substring(2, sepIndex); candidateValue = (sepIndex < key.length()-1)? key.substring(sepIndex+1) : null; } tempOptions.put(candidateKey, candidateValue); } } return Collections.unmodifiableMap(tempOptions); }