/** Construct a log with given I/O redirections. */ protected Log( Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) { super(JCDiagnostic.Factory.instance(context)); context.put(logKey, this); this.errWriter = errWriter; this.warnWriter = warnWriter; this.noticeWriter = noticeWriter; @SuppressWarnings("unchecked") // FIXME DiagnosticListener<? super JavaFileObject> dl = context.get(DiagnosticListener.class); this.diagListener = dl; diagnosticHandler = new DefaultDiagnosticHandler(); messages = JavacMessages.instance(context); messages.add(Main.javacBundleName); final Options options = Options.instance(context); initOptions(options); options.addListener( new Runnable() { public void run() { initOptions(options); } }); }
// @ non_null public static Nowarns instance(Context context) { Nowarns instance = context.get(nowarnsKey); if (instance == null) { instance = new Nowarns(context); context.put(nowarnsKey, instance); } return instance; }
private Context prepareContext(Context baseContext, JCCompilationUnit compilationUnit) { Context context = new SubContext(baseContext); if (context.get(JavaFileManager.class) == null) { JavacFileManager.preRegister(context); } context.put(JCCompilationUnit.class, compilationUnit); context.put(PackageSymbol.class, compilationUnit.packge); context.put(RULE_TYPE_VARS, typeVariables()); return context; }
/** Construct a new module finder. */ protected ModuleFinder(Context context) { context.put(moduleFinderKey, this); names = Names.instance(context); syms = Symtab.instance(context); fileManager = context.get(JavaFileManager.class); log = Log.instance(context); classFinder = ClassFinder.instance(context); diags = JCDiagnostic.Factory.instance(context); }
/** Get the Ceylon context instance for this context. */ public static com.redhat.ceylon.compiler.typechecker.context.Context getCeylonContextInstance( Context context) { com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext = context.get(ceylonContextKey); if (ceylonContext == null) { CeyloncFileManager fileManager = (CeyloncFileManager) context.get(JavaFileManager.class); VFS vfs = new VFS(); ceylonContext = new com.redhat.ceylon.compiler.typechecker.context.Context( fileManager.getRepositoryManager(), vfs); context.put(ceylonContextKey, ceylonContext); } return ceylonContext; }
public static DPrinter instance(Context context) { DPrinter dp = context.get(DPrinter.class); if (dp == null) { dp = new DPrinter(context); } return dp; }
/** Construct a new compiler from a shared context. */ public AptJavaCompiler(Context context) { super(preRegister(context)); context.put(compilerKey, this); apt = Apt.instance(context); ClassReader classReader = ClassReader.instance(context); classReader.preferSource = true; // TEMPORARY NOTE: bark==log, but while refactoring, we maintain their // original identities, to remember the original intent. log = Log.instance(context); bark = Bark.instance(context); Options options = Options.instance(context); classOutput = options.get("-retrofit") == null; nocompile = options.get("-nocompile") != null; print = options.get("-print") != null; classesAsDecls = options.get("-XclassesAsDecls") != null; genSourceFileNames = new java.util.LinkedHashSet<String>(); genClassFileNames = new java.util.LinkedHashSet<String>(); // this forces a copy of the line map to be kept in the tree, // for use by com.sun.mirror.util.SourcePosition. lineDebugInfo = true; }
public static CompilerDelegate getCompilerDelegate(final Context context) { CompilerDelegate compilerDelegate = context.get(compilerDelegateKey); if (compilerDelegate == null) { return new CeyloncCompilerDelegate(context); } return compilerDelegate; }
/** Run a processing round. */ void run(boolean lastRound, boolean errorStatus) { printRoundInfo(lastRound); TaskListener taskListener = context.get(TaskListener.class); if (taskListener != null) taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); try { if (lastRound) { filer.setLastRound(true); Set<Element> emptyRootElements = Collections.emptySet(); // immutable RoundEnvironment renv = new JavacRoundEnvironment( true, errorStatus, emptyRootElements, JavacProcessingEnvironment.this); discoveredProcs.iterator().runContributingProcs(renv); } else { discoverAndRunProcs(context, annotationsPresent, topLevelClasses, packageInfoFiles); } } finally { if (taskListener != null) taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); } nMessagerErrors = messager.errorCount(); }
private static Context preRegister(Context context) { Bark.preRegister(context); if (context.get(JavaFileManager.class) == null) JavacFileManager.preRegister(context); return context; }
public static void preRegister(Context context) { context.put( enterKey, new Context.Factory<Enter>() { public Enter make(Context c) { return new JavadocEnter(c); } }); }
public static void preRegister(final Context context) { context.put( memberEnterKey, new Context.Factory<MemberEnter>() { public MemberEnter make() { return new JavadocMemberEnter(context); } }); }
public static void preRegister(Context context, final String programName) { context.put( logKey, new Context.Factory<Log>() { public Log make(Context c) { return new Messager(c, programName); } }); }
/** Get the PhasedUnits instance for this context. */ public static PhasedUnits getPhasedUnitsInstance(final Context context) { PhasedUnits phasedUnits = context.get(phasedUnitsKey); if (phasedUnits == null) { com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext = getCeylonContextInstance(context); phasedUnits = new PhasedUnits( ceylonContext, new ModuleManagerFactory() { @Override public ModuleManager createModuleManager( com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext) { return new CompilerModuleManager(ceylonContext, context); } }); context.put(phasedUnitsKey, phasedUnits); } return phasedUnits; }
protected Enter(Context context) { context.put(enterKey, this); log = Log.instance(context); reader = ClassReader.instance(context); make = TreeMaker.instance(context); syms = Symtab.instance(context); chk = Check.instance(context); memberEnter = MemberEnter.instance(context); types = Types.instance(context); annotate = Annotate.instance(context); lint = Lint.instance(context); predefClassDef = make.ClassDef(make.Modifiers(PUBLIC), syms.predefClass.name, null, null, null, null); predefClassDef.sym = syms.predefClass; todo = Todo.instance(context); fileManager = context.get(JavaFileManager.class); }
protected Operators(Context context) { context.put(operatorsKey, this); syms = Symtab.instance(context); names = Names.instance(context); log = Log.instance(context); types = Types.instance(context); initOperatorNames(); initUnaryOperators(); initBinaryOperators(); }
/** Get the JavaCompiler instance for this context. */ public static JavaCompiler instance(Context context) { Options options = Options.instance(context); options.put("-Xprefer", "source"); // make sure it's registered CeylonLog.instance(context); CeylonEnter.instance(context); CeylonClassWriter.instance(context); JavaCompiler instance = context.get(compilerKey); if (instance == null) instance = new LanguageCompiler(context); return instance; }
public static void preRegister(Context context) { context.put( resolveKey, new Context.Factory<Resolve>() { public Resolve make(Context c) { Resolve instance = new ResolveWithDeps(c); c.put(Resolve.class, instance); return instance; } }); }
public static void preRegister(Context context) { context.put( attrKey, new Context.Factory<Attr>() { public Attr make(Context c) { Attr instance = new AttrWithDeps(c); c.put(Attr.class, instance); return instance; } }); }
protected Annotate(Context context) { context.put(annotateKey, this); attr = Attr.instance(context); make = TreeMaker.instance(context); log = Log.instance(context); syms = Symtab.instance(context); names = Names.instance(context); rs = Resolve.instance(context); types = Types.instance(context); cfolder = ConstFold.instance(context); chk = Check.instance(context); }
/** 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); } }); }
public static void preRegister( Context context, final String programName, final PrintWriter errWriter, final PrintWriter warnWriter, final PrintWriter noticeWriter) { context.put( logKey, new Context.Factory<Log>() { public Log make(Context c) { return new Messager(c, programName, errWriter, warnWriter, noticeWriter); } }); }
private void initProcessorIterator(Context context, Iterable<? extends Processor> processors) { Log log = Log.instance(context); Iterator<? extends Processor> processorIterator; if (options.isSet(XPRINT)) { try { Processor processor = PrintingProcessor.class.newInstance(); processorIterator = List.of(processor).iterator(); } catch (Throwable t) { AssertionError assertError = new AssertionError("Problem instantiating PrintingProcessor."); assertError.initCause(t); throw assertError; } } else if (processors != null) { processorIterator = processors.iterator(); } else { String processorNames = options.get(PROCESSOR); JavaFileManager fileManager = context.get(JavaFileManager.class); try { // If processorpath is not explicitly set, use the classpath. processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH) ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH) : fileManager.getClassLoader(CLASS_PATH); /* * If the "-processor" option is used, search the appropriate * path for the named class. Otherwise, use a service * provider mechanism to create the processor iterator. */ if (processorNames != null) { processorIterator = new NameProcessIterator(processorNames, processorClassLoader, log); } else { processorIterator = new ServiceIterator(processorClassLoader, log); } } catch (SecurityException e) { /* * A security exception will occur if we can't create a classloader. * Ignore the exception if, with hindsight, we didn't need it anyway * (i.e. no processor was specified either explicitly, or implicitly, * in service configuration file.) Otherwise, we cannot continue. */ processorIterator = handleServiceLoaderUnavailability("proc.cant.create.loader", e); } } discoveredProcs = new DiscoveredProcessors(processorIterator); }
/** * Returns an empty processor iterator if no processors are on the relevant path, otherwise if * processors are present, logs an error. Called when a service loader is unavailable for some * reason, either because a service loader class cannot be found or because a security policy * prevents class loaders from being created. * * @param key The resource key to use to log an error message * @param e If non-null, pass this exception to Abort */ private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) { JavaFileManager fileManager = context.get(JavaFileManager.class); if (fileManager instanceof JavacFileManager) { StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager; Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH) ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH) : standardFileManager.getLocation(CLASS_PATH); if (needClassLoader(options.get(PROCESSOR), workingPath)) handleException(key, e); } else { handleException(key, e); } java.util.List<Processor> pl = Collections.emptyList(); return pl.iterator(); }
/** Get the current messager, which is also the compiler log. */ public static Messager instance0(Context context) { Log instance = context.get(logKey); if (instance == null || !(instance instanceof Messager)) throw new InternalError("no messager instance!"); return (Messager) instance; }
public static JavadocEnter instance0(Context context) { Enter instance = context.get(enterKey); if (instance == null) instance = new JavadocEnter(context); return (JavadocEnter) instance; }
/** Get the ModuleFinder instance for this invocation. */ public static ModuleFinder instance(Context context) { ModuleFinder instance = context.get(moduleFinderKey); if (instance == null) instance = new ModuleFinder(context); return instance; }
public Delombok() { context.put(DeleteLombokAnnotations.class, new DeleteLombokAnnotations(true)); }
protected Paths(Context context) { context.put(pathsKey, this); pathsForLocation = new HashMap<Location, Path>(16); setContext(context); }
/** * Get the Paths instance for this context. * * @param context the context * @return the Paths instance for this context */ public static Paths instance(Context context) { Paths instance = context.get(pathsKey); if (instance == null) instance = new Paths(context); return instance; }