com.sun.tools.javac.code.Source Java Examples

The following examples show how to use com.sun.tools.javac.code.Source. 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: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected Annotate(Context context) {
    context.put(annotateKey, this);

    attr = Attr.instance(context);
    chk = Check.instance(context);
    cfolder = ConstFold.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);
    enter = Enter.instance(context);
    log = Log.instance(context);
    lint = Lint.instance(context);
    make = TreeMaker.instance(context);
    names = Names.instance(context);
    resolve = Resolve.instance(context);
    syms = Symtab.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    types = Types.instance(context);

    theUnfinishedDefaultValue =  new Attribute.Error(syms.errType);

    Source source = Source.instance(context);
    allowRepeatedAnnos = source.allowRepeatedAnnotations();
    sourceName = source.name;

    blockCount = 1;
}
 
Example #2
Source File: ModuleFileManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ModuleFileManager(
        @NonNull final CachingArchiveProvider cap,
        @NonNull final ClassPath modulePath,
        @NonNull final Function<URL,Collection<? extends URL>> peers,
        @NullAllowed final Source sourceLevel,
        @NonNull final Location forLocation,
        final boolean cacheFile) {
    assert cap != null;
    assert modulePath != null;
    assert peers != null;
    assert forLocation != null;
    this.cap = cap;
    this.modulePath = modulePath;
    this.peers = peers;
    this.sourceLevel = sourceLevel;
    this.forLocation = forLocation;
    this.cacheFile = cacheFile;
}
 
Example #3
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected TransTypes(Context context) {
    context.put(transTypesKey, this);
    compileStates = CompileStates.instance(context);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    enter = Enter.instance(context);
    bridgeSpans = new HashMap<>();
    types = Types.instance(context);
    make = TreeMaker.instance(context);
    resolve = Resolve.instance(context);
    Source source = Source.instance(context);
    allowInterfaceBridges = source.allowDefaultMethods();
    allowGraphInference = source.allowGraphInference();
    annotate = Annotate.instance(context);
    attr = Attr.instance(context);
}
 
Example #4
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 #5
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected Analyzer(Context context) {
    context.put(analyzerKey, this);
    types = Types.instance(context);
    log = Log.instance(context);
    attr = Attr.instance(context);
    deferredAttr = DeferredAttr.instance(context);
    argumentAttr = ArgumentAttr.instance(context);
    make = TreeMaker.instance(context);
    names = Names.instance(context);
    Options options = Options.instance(context);
    String findOpt = options.get("find");
    //parse modes
    Source source = Source.instance(context);
    allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation();
    analyzerModes = AnalyzerMode.getAnalyzerModes(findOpt, source);
}
 
Example #6
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method is used to parse the {@code find} option.
 * Possible modes are separated by colon; a mode can be excluded by
 * prepending '-' to its name. Finally, the special mode 'all' can be used to
 * add all modes to the resulting enum.
 */
static EnumSet<AnalyzerMode> getAnalyzerModes(String opt, Source source) {
    if (opt == null) {
        return EnumSet.noneOf(AnalyzerMode.class);
    }
    List<String> modes = List.from(opt.split(","));
    EnumSet<AnalyzerMode> res = EnumSet.noneOf(AnalyzerMode.class);
    if (modes.contains("all")) {
        res = EnumSet.allOf(AnalyzerMode.class);
    }
    for (AnalyzerMode mode : values()) {
        if (modes.contains(mode.opt)) {
            res.add(mode);
        } else if (modes.contains("-" + mode.opt) || !mode.sourceFilter.test(source)) {
            res.remove(mode);
        }
    }
    return res;
}
 
Example #7
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected Infer(Context context) {
    context.put(inferKey, this);

    rs = Resolve.instance(context);
    chk = Check.instance(context);
    syms = Symtab.instance(context);
    types = Types.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    inferenceException = new InferenceException(diags);
    Options options = Options.instance(context);
    allowGraphInference = Source.instance(context).allowGraphInference()
            && options.isUnset("useLegacyInference");
    dependenciesFolder = options.get("debug.dumpInferenceGraphsTo");
    pendingGraphs = List.nil();

    emptyContext = new InferenceContext(this, List.nil());
}
 
Example #8
Source File: CachingFileManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private CachingFileManager(
        @NonNull final CachingArchiveProvider provider,
        @NonNull final ClassPath cp,
        @NullAllowed final JavaFileFilterImplementation filter,
        @NullAllowed final Source sourceLevel,
        final boolean allowOutput,
        final boolean cacheFile,
        final boolean ignoreExcludes) {
    assert provider != null;
    assert cp != null;
    this.provider = provider;
    this.cp = cp;
    if (CacheClassPath.KEEP_JARS) {
        cp.addPropertyChangeListener(WeakListeners.propertyChange(this, cp));
    }
    this.filter = filter;
    this.sourceLevel = sourceLevel;
    this.allowOutput = allowOutput;
    this.cacheFile = cacheFile;
    this.ignoreExcludes = ignoreExcludes;
}
 
Example #9
Source File: SourceTargetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void run() throws Exception {
    try (FileWriter out = new FileWriter("C.java")) {
        out.write("class C { }");
    }

    for (Source s: Source.values()) {
        test(s, null, "source", getKind(s, Source.MIN));
    }

    for (Target t: Target.values()) {
        test(Source.values()[0], t, "target", getKind(t, Target.MIN));
    }

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
Example #10
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method is used to parse the {@code find} option.
 * Possible modes are separated by colon; a mode can be excluded by
 * prepending '-' to its name. Finally, the special mode 'all' can be used to
 * add all modes to the resulting enum.
 */
static EnumSet<AnalyzerMode> getAnalyzerModes(String opt, Source source) {
    if (opt == null) {
        return EnumSet.noneOf(AnalyzerMode.class);
    }
    List<String> modes = List.from(opt.split(","));
    EnumSet<AnalyzerMode> res = EnumSet.noneOf(AnalyzerMode.class);
    if (modes.contains("all")) {
        res = EnumSet.allOf(AnalyzerMode.class);
    }
    for (AnalyzerMode mode : values()) {
        if (modes.contains(mode.opt)) {
            res.add(mode);
        } else if (modes.contains("-" + mode.opt) || !mode.sourceFilter.test(source)) {
            res.remove(mode);
        }
    }
    return res;
}
 
Example #11
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 #12
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 #13
Source File: JavacParserTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testValidateCompilerOptions() {
    List<String> input = Arrays.asList("--add-exports", "foo/bar=foobar",
                                       "--add-exports=foo2/bar=foobar",
                                       "--limit-modules", "foo",
                                       "--add-modules", "foo",
                                       "--add-reads", "foo=foo2");
    assertEquals(Collections.emptyList(), JavacParser.validateCompilerOptions(input, com.sun.tools.javac.code.Source.lookup("1.8")));
    assertEquals(input, JavacParser.validateCompilerOptions(input, com.sun.tools.javac.code.Source.lookup("9")));
    assertEquals(input, JavacParser.validateCompilerOptions(input, com.sun.tools.javac.code.Source.lookup("10")));
}
 
Example #14
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 #15
Source File: CachingFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of CachingFileManager */
public CachingFileManager(
        @NonNull final CachingArchiveProvider provider,
        @NonNull final ClassPath cp,
        @NullAllowed final JavaFileFilterImplementation filter,
        @NullAllowed final Source sourceLevel,
        final boolean cacheFile,
        final boolean ignoreExcludes) {
    this (provider, cp, filter, sourceLevel, true, cacheFile, ignoreExcludes);
}
 
Example #16
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected Modules(Context context) {
    context.put(Modules.class, this);
    log = Log.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    attr = Attr.instance(context);
    chk = Check.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    moduleFinder = ModuleFinder.instance(context);
    types = Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    source = Source.instance(context);
    allowModules = source.allowModules();
    Options options = Options.instance(context);

    allowAccessIntoSystem = options.isUnset(Option.RELEASE);
    lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);

    multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
    ClassWriter classWriter = ClassWriter.instance(context);
    classWriter.multiModuleMode = multiModuleMode;
    JNIWriter jniWriter = JNIWriter.instance(context);
    jniWriter.multiModuleMode = multiModuleMode;

    java_se = names.fromString("java.se");
    java_ = names.fromString("java.");

    addExportsOpt = options.get(Option.ADD_EXPORTS);
    addReadsOpt = options.get(Option.ADD_READS);
    addModsOpt = options.get(Option.ADD_MODULES);
    limitModsOpt = options.get(Option.LIMIT_MODULES);
    moduleVersionOpt = options.get(Option.MODULE_VERSION);
}
 
Example #17
Source File: CompletenessAnalyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
CompletenessAnalyzer(JShell proc) {
    this.proc = proc;
    Context context = new Context();
    Log log = CaLog.createLog(context);
    context.put(Log.class, log);
    context.put(Source.class, Source.JDK1_9);
    scannerFactory = ScannerFactory.instance(context);
}
 
Example #18
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 #19
Source File: SourceTargetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void test(Source s, Target t, String select, Kind kind) {
    System.err.println("Test: source:" + s + ", target:" + t + " " + select + " " + kind);
    List<String> args = new ArrayList<>();
    args.add("-XDrawDiagnostics");
    args.add("-source");
    args.add(s.name);
    if (t != null) {
        args.add("-target");
        args.add(t.name);
    }
    args.add("C.java");

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
    pw.close();
    String out = sw.toString();
    System.err.print(out);

    switch (kind) {
        case INVALID:
            check(out, "removed." + select, true);
            check(out, "obsolete." + select, false);
            break;

        case OBSOLETE:
            check(out, "removed." + select, false);
            check(out, "obsolete." + select, true);
            break;

        case VALID:
            check(out, "removed." + select, false);
            check(out, "obsolete." + select, false);
            break;
    }

    System.err.println();
}
 
Example #20
Source File: ScannerFactory.java    From hottub 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 #21
Source File: ParserFactory.java    From hottub 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 #22
Source File: BaseFileManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected Source getSource() {
    String sourceName = options.get(Option.SOURCE);
    Source source = null;
    if (sourceName != null)
        source = Source.lookup(sourceName);
    return (source != null ? source : Source.DEFAULT);
}
 
Example #23
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 #24
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 #25
Source File: ElementsService.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected ElementsService(Context context) {
    context.put(KEY, this);
    jctypes = com.sun.tools.javac.code.Types.instance(context);
    names = Names.instance(context);
    types = JavacTypes.instance(context);
    allowDefaultMethods = SourceLevelUtils.allowDefaultMethods(Source.instance(context));
}
 
Example #26
Source File: ModuleFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private List<? extends String> multiReleaseRelocations() {
    final List<String> prefixes = new ArrayList<>();
    prefixes.add("");   //NOI18N
    final Source[] sources = Source.values();
    for (int i=0; i< sources.length; i++) {
        if (sources[i].compareTo(SourceLevelUtils.JDK1_9) >=0 && sources[i].compareTo(sourceLevel) <=0) {
            prefixes.add(String.format(
                    "META-INF/versions/%s",    //NOI18N
                    normalizeSourceLevel(sources[i].name)));
        }
    }
    return prefixes;
}
 
Example #27
Source File: BaseFileManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected Source getSource() {
    String sourceName = options.get(Option.SOURCE);
    Source source = null;
    if (sourceName != null)
        source = Source.lookup(sourceName);
    return (source != null ? source : Source.DEFAULT);
}
 
Example #28
Source File: CachingFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private List<? extends String> multiReleaseRelocations() {
    final List<String> prefixes = new ArrayList<>();
    prefixes.add("");   //NOI18N
    final Source[] sources = Source.values();
    for (int i=0; i< sources.length; i++) {
        if (sources[i].compareTo(SourceLevelUtils.JDK1_9) >=0 && sources[i].compareTo(sourceLevel) <=0) {
            prefixes.add(String.format(
                    "META-INF/versions/%s",    //NOI18N
                    normalizeSourceLevel(sources[i].name)));
        }
    }
    return prefixes;
}
 
Example #29
Source File: CachingFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public CachingFileManager(
        @NonNull final CachingArchiveProvider provider,
        @NonNull final ClassPath cp,
        @NullAllowed final Source sourceLevel,
        final boolean cacheFile,
        final boolean ignoreExcludes) {
    this (provider, cp, null, sourceLevel, false, cacheFile, ignoreExcludes);
}
 
Example #30
Source File: ScannerFactory.java    From TencentKona-8 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);
}