Java Code Examples for com.sun.tools.javac.code.Source#instance()

The following examples show how to use com.sun.tools.javac.code.Source#instance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected Flow(Context context) {
    context.put(flowKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    types = Types.instance(context);
    chk = Check.instance(context);
    lint = Lint.instance(context);
    rs = Resolve.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    Source source = Source.instance(context);
    allowImprovedRethrowAnalysis = source.allowImprovedRethrowAnalysis();
    allowImprovedCatchAnalysis = source.allowImprovedCatchAnalysis();
    allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses();
    enforceThisDotInit = source.enforceThisDotInit();
}
 
Example 2
Source File: ToolEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected ToolEnvironment(Context context) {
    context.put(ToolEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    finder = JavadocClassFinder.instance(context);
    enter = JavadocEnter.instance(context);
    names = Names.instance(context);
    externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = com.sun.tools.javac.code.Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }
    docTrees = JavacTrees.instance(context);
    source = Source.instance(context);
    elements =  JavacElements.instance(context);
    typeutils = JavacTypes.instance(context);
    elementToTreePath = new HashMap<>();
}
 
Example 3
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected TypeEnter(Context context) {
    context.put(typeEnterKey, this);
    names = Names.instance(context);
    enter = Enter.instance(context);
    memberEnter = MemberEnter.instance(context);
    log = Log.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    syms = Symtab.instance(context);
    make = TreeMaker.instance(context);
    todo = Todo.instance(context);
    annotate = Annotate.instance(context);
    typeAnnotations = TypeAnnotations.instance(context);
    types = Types.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);
    lint = Lint.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    dependencies = Dependencies.instance(context);
    Source source = Source.instance(context);
    allowTypeAnnos = source.allowTypeAnnotations();
    allowDeprecationOnImport = source.allowDeprecationOnImport();
}
 
Example 4
Source File: ParserFactory.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
protected ParserFactory(Context context) {
    super();
    context.put(parserFactoryKey, this);
    this.F = TreeMaker.instance(context);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.keywords = Keywords.instance(context);
    this.source = Source.instance(context);
    this.options = Options.instance(context);
    this.scannerFactory = ScannerFactory.instance(context);
}
 
Example 5
Source File: ElementsTable.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the table to manage included and excluded elements.
 *
 * @param context the context to locate commonly used objects
 * @param location the location used to locate source files
 */
ElementsTable(Context context, Map<ToolOption, Object> opts) {
    this.toolEnv = ToolEnvironment.instance(context);
    this.syms = Symtab.instance(context);
    this.names = Names.instance(context);
    this.fm = toolEnv.fileManager;
    this.modules = Modules.instance(context);
    this.opts = opts;
    this.messager = Messager.instance0(context);
    this.compiler = JavaCompiler.instance(context);
    Source source = Source.instance(context);

    List<Location> locs = new ArrayList<>();
    if (modules.multiModuleMode) {
        locs.add(StandardLocation.MODULE_SOURCE_PATH);
    } else {
        if (toolEnv.fileManager.hasLocation(StandardLocation.SOURCE_PATH))
            locs.add(StandardLocation.SOURCE_PATH);
        else
            locs.add(StandardLocation.CLASS_PATH);
    }
    if (source.allowModules() && toolEnv.fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH))
        locs.add(StandardLocation.PATCH_MODULE_PATH);
    this.locations = Collections.unmodifiableList(locs);

    getEntry("").excluded = false;

    accessFilter = new ModifierFilter(opts);
    xclasses = (boolean)opts.getOrDefault(ToolOption.XCLASSES, false);
    expandRequires = (AccessKind)opts.get(ToolOption.EXPAND_REQUIRES);
}
 
Example 6
Source File: ScannerFactory.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new scanner factory.
 */
protected ScannerFactory(Context context) {
    context.put(scannerFactoryKey, this);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.source = Source.instance(context);
    this.keywords = Keywords.instance(context);
}
 
Example 7
Source File: ParserFactory.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected ParserFactory(Context context) {
    super();
    context.put(parserFactoryKey, this);
    this.F = TreeMaker.instance(context);
    this.docTreeMaker = DocTreeMaker.instance(context);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.tokens = Tokens.instance(context);
    this.source = Source.instance(context);
    this.options = Options.instance(context);
    this.scannerFactory = ScannerFactory.instance(context);
    this.locale = context.get(Locale.class);
}
 
Example 8
Source File: JavacElements.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected JavacElements(Context context) {
    context.put(JavacElements.class, this);
    javaCompiler = JavaCompiler.instance(context);
    syms = Symtab.instance(context);
    modules = Modules.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);
    enter = Enter.instance(context);
    resolve = Resolve.instance(context);
    JavacTask t = context.get(JavacTask.class);
    javacTaskImpl = t instanceof JavacTaskImpl ? (JavacTaskImpl) t : null;
    log = Log.instance(context);
    Source source = Source.instance(context);
    allowModules = source.allowModules();
}
 
Example 9
Source File: ParserFactory.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected ParserFactory(Context context) {
    super();
    context.put(parserFactoryKey, this);
    this.F = TreeMaker.instance(context);
    this.docTreeMaker = DocTreeMaker.instance(context);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.tokens = Tokens.instance(context);
    this.source = Source.instance(context);
    this.options = Options.instance(context);
    this.scannerFactory = ScannerFactory.instance(context);
    this.locale = context.get(Locale.class);
}
 
Example 10
Source File: ScannerFactory.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Create a new scanner factory. */
protected ScannerFactory(Context context) {
    context.put(scannerFactoryKey, this);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.source = Source.instance(context);
    this.tokens = Tokens.instance(context);
}
 
Example 11
Source File: ClassReader.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Construct a new class reader. */
protected ClassReader(Context context) {
    context.put(classReaderKey, this);
    annotate = Annotate.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    types = Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager == null)
        throw new AssertionError("FileManager initialization error");
    diagFactory = JCDiagnostic.Factory.instance(context);

    log = Log.instance(context);

    Options options = Options.instance(context);
    verbose         = options.isSet(Option.VERBOSE);

    Source source = Source.instance(context);
    allowSimplifiedVarargs = source.allowSimplifiedVarargs();
    allowModules     = source.allowModules();

    saveParameterNames = options.isSet(PARAMETERS);

    profile = Profile.instance(context);

    typevars = WriteableScope.create(syms.noSymbol);

    lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE);

    initAttributeReaders();
}
 
Example 12
Source File: ParserFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected ParserFactory(Context context) {
    super();
    context.put(parserFactoryKey, this);
    this.F = TreeMaker.instance(context);
    this.docTreeMaker = DocTreeMaker.instance(context);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.tokens = Tokens.instance(context);
    this.source = Source.instance(context);
    this.options = Options.instance(context);
    this.scannerFactory = ScannerFactory.instance(context);
    this.locale = context.get(Locale.class);
}
 
Example 13
Source File: ParserFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected ParserFactory(Context context) {
    super();
    context.put(parserFactoryKey, this);
    this.F = TreeMaker.instance(context);
    this.docTreeMaker = DocTreeMaker.instance(context);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.tokens = Tokens.instance(context);
    this.source = Source.instance(context);
    this.options = Options.instance(context);
    this.scannerFactory = ScannerFactory.instance(context);
    this.locale = context.get(Locale.class);
}
 
Example 14
Source File: ParserFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected ParserFactory(Context context) {
    super();
    context.put(parserFactoryKey, this);
    this.F = TreeMaker.instance(context);
    this.docTreeMaker = DocTreeMaker.instance(context);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.tokens = Tokens.instance(context);
    this.source = Source.instance(context);
    this.options = Options.instance(context);
    this.scannerFactory = ScannerFactory.instance(context);
    this.locale = context.get(Locale.class);
}
 
Example 15
Source File: ScannerFactory.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new scanner factory.
 */
protected ScannerFactory(Context context) {
    context.put(scannerFactoryKey, this);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.source = Source.instance(context);
    this.keywords = Keywords.instance(context);
}
 
Example 16
Source File: ScannerFactory.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new scanner factory.
 */
protected ScannerFactory(Context context) {
    context.put(scannerFactoryKey, this);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.source = Source.instance(context);
    this.tokens = Tokens.instance(context);
}
 
Example 17
Source File: ScannerFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** Create a new scanner factory. */
protected ScannerFactory(Context context) {
    context.put(scannerFactoryKey, this);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.source = Source.instance(context);
    this.tokens = Tokens.instance(context);
}
 
Example 18
Source File: ParserFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected ParserFactory(Context context) {
    super();
    context.put(parserFactoryKey, this);
    this.F = TreeMaker.instance(context);
    this.docTreeMaker = DocTreeMaker.instance(context);
    this.log = Log.instance(context);
    this.names = Names.instance(context);
    this.tokens = Tokens.instance(context);
    this.source = Source.instance(context);
    this.options = Options.instance(context);
    this.scannerFactory = ScannerFactory.instance(context);
    this.locale = context.get(Locale.class);
}
 
Example 19
Source File: JavaCompiler.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a new compiler using a shared context.
 */
public JavaCompiler(Context context) {
    this.context = context;
    context.put(compilerKey, this);

    // if fileManager not already set, register the JavacFileManager to be used
    if (context.get(JavaFileManager.class) == null)
        JavacFileManager.preRegister(context);

    names = Names.instance(context);
    log = Log.instance(context);
    diagFactory = JCDiagnostic.Factory.instance(context);
    reader = ClassReader.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    enter = Enter.instance(context);
    todo = Todo.instance(context);

    fileManager = context.get(JavaFileManager.class);
    parserFactory = ParserFactory.instance(context);

    try {
        // catch completion problems with predefineds
        syms = Symtab.instance(context);
    } catch (CompletionFailure ex) {
        // inlined Check.completionError as it is not initialized yet
        log.error("cant.access", ex.sym, ex.getDetailValue());
        if (ex instanceof ClassReader.BadClassFile)
            throw new Abort();
    }
    source = Source.instance(context);
    attr = Attr.instance(context);
    chk = Check.instance(context);
    gen = Gen.instance(context);
    flow = Flow.instance(context);
    transTypes = TransTypes.instance(context);
    lower = Lower.instance(context);
    annotate = Annotate.instance(context);
    types = Types.instance(context);
    taskListener = context.get(TaskListener.class);

    reader.sourceCompleter = this;

    options = Options.instance(context);

    verbose = options.isSet(VERBOSE);
    sourceOutput = options.isSet(PRINTSOURCE); // used to be -s
    stubOutput = options.isSet("-stubs");
    relax = options.isSet("-relax");
    printFlat = options.isSet("-printflat");
    attrParseOnly = options.isSet("-attrparseonly");
    encoding = options.get(ENCODING);
    lineDebugInfo = options.isUnset(G_CUSTOM) ||
            options.isSet(G_CUSTOM, "lines");
    genEndPos = options.isSet(XJCOV) ||
            context.get(DiagnosticListener.class) != null;
    devVerbose = options.isSet("dev");
    processPcks = options.isSet("process.packages");
    werror = options.isSet(WERROR);

    if (source.compareTo(Source.DEFAULT) < 0) {
        if (options.isUnset(XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option)) {
            if (fileManager instanceof BaseFileManager) {
                if (((BaseFileManager) fileManager).isDefaultBootClassPath())
                    log.warning(LintCategory.OPTIONS, "source.no.bootclasspath", source.name);
            }
        }
    }

    verboseCompilePolicy = options.isSet("verboseCompilePolicy");

    if (attrParseOnly)
        compilePolicy = CompilePolicy.ATTR_ONLY;
    else
        compilePolicy = CompilePolicy.decode(options.get("compilePolicy"));

    implicitSourcePolicy = ImplicitSourcePolicy.decode(options.get("-implicit"));

    completionFailureName =
            options.isSet("failcomplete")
                    ? names.fromString(options.get("failcomplete"))
                    : null;

    shouldStopPolicy =
            options.isSet("shouldStopPolicy")
                    ? CompileState.valueOf(options.get("shouldStopPolicy"))
                    : null;
    if (options.isUnset("oldDiags"))
        log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
}
 
Example 20
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected JavacProcessingEnvironment(Context context) {
    this.context = context;
    context.put(JavacProcessingEnvironment.class, this);
    log = Log.instance(context);
    source = Source.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    options = Options.instance(context);
    printProcessorInfo = options.isSet(Option.XPRINTPROCESSORINFO);
    printRounds = options.isSet(Option.XPRINTROUNDS);
    verbose = options.isSet(Option.VERBOSE);
    lint = Lint.instance(context).isEnabled(PROCESSING);
    compiler = JavaCompiler.instance(context);
    if (options.isSet(Option.PROC, "only") || options.isSet(Option.XPRINT)) {
        compiler.shouldStopPolicyIfNoError = CompileState.PROCESS;
    }
    fatalErrors = options.isSet("fatalEnterError");
    showResolveErrors = options.isSet("showResolveErrors");
    werror = options.isSet(Option.WERROR);
    fileManager = context.get(JavaFileManager.class);
    platformAnnotations = initPlatformAnnotations();

    // Initialize services before any processors are initialized
    // in case processors use them.
    filer = new JavacFiler(context);
    messager = new JavacMessager(context, this);
    elementUtils = JavacElements.instance(context);
    typeUtils = JavacTypes.instance(context);
    modules = Modules.instance(context);
    types = Types.instance(context);
    annotate = Annotate.instance(context);
    processorOptions = initProcessorOptions();
    unmatchedProcessorOptions = initUnmatchedProcessorOptions();
    messages = JavacMessages.instance(context);
    taskListener = MultiTaskListener.instance(context);
    symtab = Symtab.instance(context);
    names = Names.instance(context);
    enter = Enter.instance(context);
    initialCompleter = ClassFinder.instance(context).getCompleter();
    chk = Check.instance(context);
    initProcessorLoader();

    allowModules = source.allowModules();
}