com.sun.tools.javac.jvm.Target Java Examples

The following examples show how to use com.sun.tools.javac.jvm.Target. 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: Lower.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #2
Source File: BadClassfile.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #3
Source File: Lower.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #4
Source File: BadClassfile.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #5
Source File: Lower.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #6
Source File: BadClassfile.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #7
Source File: Lower.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #8
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 #9
Source File: Lower.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #10
Source File: BadClassfile.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #11
Source File: Lower.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #12
Source File: BadClassfile.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #13
Source File: BadClassfile.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #14
Source File: BadClassfile.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #15
Source File: Lower.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #16
Source File: Lower.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #17
Source File: Lower.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    reader = ClassReader.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    allowEnums = source.allowEnums();
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #18
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 #19
Source File: ReleaseOptionUnsupported.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testUnsafeUnnamed(Path base) throws IOException {
    Path src = base.resolve("src");
    tb.writeJavaFiles(src,
                      "package test; public class Test { sun.misc.Unsafe unsafe; } ");
    Path classes = base.resolve("classes");
    tb.createDirectories(classes);

    List<String> log;
    List<String> expected = Arrays.asList(
            "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe",
            "1 warning"
    );

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics")
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.SUCCESS)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    if (!expected.equals(log)) {
        throw new AssertionError("Unexpected output: " + log);
    }

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics",
                     "--release", Target.DEFAULT.multiReleaseValue())
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.SUCCESS)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    if (!expected.equals(log)) {
        throw new AssertionError("Unexpected output: " + log);
    }
}
 
Example #20
Source File: ReleaseOptionUnsupported.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testUnsafe(Path base) throws IOException {
    Path src = base.resolve("src");
    tb.writeJavaFiles(src,
                      "module m { requires jdk.unsupported; }",
                      "package test; public class Test { sun.misc.Unsafe unsafe; } ");
    Path classes = base.resolve("classes");
    tb.createDirectories(classes);

    List<String> log;
    List<String> expected = Arrays.asList(
            "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe",
            "1 warning"
    );

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics")
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.SUCCESS)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    if (!expected.equals(log)) {
        throw new AssertionError("Unexpected output: " + log);
    }

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics",
                     "--release", Target.DEFAULT.multiReleaseValue())
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.SUCCESS)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    if (!expected.equals(log)) {
        throw new AssertionError("Unexpected output: " + log);
    }
}
 
Example #21
Source File: Lower.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    operators = Operators.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());
    dollarCloseResource = names.
        fromString(target.syntheticNameChar() + "closeResource");

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #22
Source File: Attr.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
protected Attr(Context context) {
    context.put(attrKey, this);

    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    memberEnter = MemberEnter.instance(context);
    make = TreeMaker.instance(context);
    enter = Enter.instance(context);
    infer = Infer.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    types = Types.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    annotate = Annotate.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);

    Options options = Options.instance(context);

    Source source = Source.instance(context);
    allowGenerics = source.allowGenerics();
    allowVarargs = source.allowVarargs();
    allowEnums = source.allowEnums();
    allowBoxing = source.allowBoxing();
    allowCovariantReturns = source.allowCovariantReturns();
    allowAnonOuterThis = source.allowAnonOuterThis();
    allowStringsInSwitch = source.allowStringsInSwitch();
    sourceName = source.name;
    relax = (options.isSet("-retrofit") ||
             options.isSet("-relax"));
    findDiamonds = options.get("findDiamond") != null &&
             source.allowDiamond();
    useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
}
 
Example #23
Source File: Attr.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
protected Attr(Context context) {
    context.put(attrKey, this);

    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    chk = Check.instance(context);
    memberEnter = MemberEnter.instance(context);
    make = TreeMaker.instance(context);
    enter = Enter.instance(context);
    infer = Infer.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    types = Types.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    annotate = Annotate.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);

    Options options = Options.instance(context);

    Source source = Source.instance(context);
    allowGenerics = source.allowGenerics();
    allowVarargs = source.allowVarargs();
    allowEnums = source.allowEnums();
    allowBoxing = source.allowBoxing();
    allowCovariantReturns = source.allowCovariantReturns();
    allowAnonOuterThis = source.allowAnonOuterThis();
    allowStringsInSwitch = source.allowStringsInSwitch();
    sourceName = source.name;
    relax = (options.isSet("-retrofit") ||
             options.isSet("-relax"));
    findDiamonds = options.get("findDiamond") != null &&
             source.allowDiamond();
    useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
}
 
Example #24
Source File: ElementHandle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a qualified name of the {@link TypeElement} represented by this
 * {@link ElementHandle}. When the {@link ElementHandle} doesn't represent
 * a {@link TypeElement} it throws a {@link IllegalStateException}
 * @return the qualified name
 * @throws an {@link IllegalStateException} when this {@link ElementHandle} 
 * isn't creatred for the {@link TypeElement}.
 */
public @NonNull String getQualifiedName () throws IllegalStateException {
    if ((this.kind.isClass() && !isArray(signatures[0])) ||
            this.kind.isInterface() ||
            this.kind == ElementKind.MODULE ||
            this.kind == ElementKind.OTHER) {
        return this.signatures[0].replace (Target.DEFAULT.syntheticNameChar(),'.');    //NOI18N
    }
    else {
        throw new IllegalStateException ();
    }
}
 
Example #25
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Lower(Context context) {
    context.put(lowerKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    operators = Operators.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    cfolder = ConstFold.instance(context);
    target = Target.instance(context);
    source = Source.instance(context);
    typeEnvs = TypeEnvs.instance(context);
    dollarAssertionsDisabled = names.
        fromString(target.syntheticNameChar() + "assertionsDisabled");
    classDollar = names.
        fromString("class" + target.syntheticNameChar());
    dollarCloseResource = names.
        fromString(target.syntheticNameChar() + "closeResource");

    types = Types.instance(context);
    Options options = Options.instance(context);
    debugLower = options.isSet("debuglower");
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #26
Source File: BadClassfile.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);
    Symtab syms = Symtab.instance(task.getContext());

    task.ensureEntered();

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(syms.unnamedModule, classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #27
Source File: ProfileOptionTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
void testTargetProfileCombinations() throws Exception {
    JavaFileObject fo = new StringJavaFileObject("Test.java", "class Test { }");
    for (Target t: Target.values()) {
        switch (t) {
            case JDK1_1: case JDK1_2: // no equivalent -source
                continue;
        }

        for (Profile p: Profile.values()) {
            List<String> opts = new ArrayList<String>();
            opts.addAll(Arrays.asList("-source", t.name, "-target", t.name));
            opts.add("-Xlint:-options"); // dont warn about no -bootclasspath
            if (p != Profile.DEFAULT)
                opts.addAll(Arrays.asList("-profile", p.name));
            StringWriter sw = new StringWriter();
            JavacTask task = (JavacTask) javac.getTask(sw, fm, null, opts, null,
                    Arrays.asList(fo));
            task.analyze();

            // sadly, command line errors are not (yet?) reported to
            // the diag listener
            String out = sw.toString();
            if (!out.isEmpty())
                System.err.println(out.trim());

            switch (t) {
                case JDK1_8:
                    if (!out.isEmpty())
                        error("unexpected output from compiler");
                    break;
                default:
                    if (p != Profile.DEFAULT
                            && !out.contains("profile " + p.name
                                + " is not valid for target release " + t.name)) {
                        error("expected message not found");
                    }
            }
        }
    }
}
 
Example #28
Source File: Main.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public Collection<File> processArgs(String[] flags, String[] classNames) { // XXX sb protected
    int ac = 0;
    while (ac < flags.length) {
        String flag = flags[ac];
        ac++;

        Option option = null;

        if (flag.length() > 0) {
            // quick hack to speed up file processing:
            // if the option does not begin with '-', there is no need to check
            // most of the compiler options.
            int firstOptionToCheck = flag.charAt(0) == '-' ? 0 : recognizedOptions.length - 1;
            for (int j = firstOptionToCheck; j < recognizedOptions.length; j++) {
                if (recognizedOptions[j].matches(flag)) {
                    option = recognizedOptions[j];
                    break;
                }
            }
        }

        if (option == null) {
            error("err.invalid.flag", flag);
            return null;
        }

        if (option.hasArg()) {
            if (ac == flags.length) {
                error("err.req.arg", flag);
                return null;
            }
            String operand = flags[ac];
            ac++;
            if (option.process(options, flag, operand))
                return null;
        } else {
            if (option.process(options, flag))
                return null;
        }
    }

    if (this.classnames != null && classNames != null) {
        this.classnames.addAll(Arrays.asList(classNames));
    }

    if (!checkDirectory(D))
        return null;
    if (!checkDirectory(S))
        return null;

    String sourceString = options.get(SOURCE);
    Source source = (sourceString != null)
            ? Source.lookup(sourceString)
            : Source.DEFAULT;
    String targetString = options.get(TARGET);
    Target target = (targetString != null)
            ? Target.lookup(targetString)
            : Target.DEFAULT;
    // We don't check source/target consistency for CLDC, as J2ME
    // profiles are not aligned with J2SE targets; moreover, a
    // single CLDC target may have many profiles.  In addition,
    // this is needed for the continued functioning of the JSR14
    // prototype.
    if (Character.isDigit(target.name.charAt(0))) {
        if (target.compareTo(source.requiredTarget()) < 0) {
            if (targetString != null) {
                if (sourceString == null) {
                    warning("warn.target.default.source.conflict",
                            targetString,
                            source.requiredTarget().name);
                } else {
                    warning("warn.source.target.conflict",
                            sourceString,
                            source.requiredTarget().name);
                }
                return null;
            } else {
                target = source.requiredTarget();
                options.put("-target", target.name);
            }
        } else {
            if (targetString == null && !source.allowGenerics()) {
                target = Target.JDK1_4;
                options.put("-target", target.name);
            }
        }
    }

    // handle this here so it works even if no other options given
    String showClass = options.get("showClass");
    if (showClass != null) {
        if (showClass.equals("showClass")) // no value given for option
            showClass = "com.sun.tools.javac.Main";
        showClass(showClass);
    }

    return filenames;
}
 
Example #29
Source File: ProfileOptionTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
void testTargetProfileCombinations() throws Exception {
    JavaFileObject fo = new StringJavaFileObject("Test.java", "class Test { }");
    for (Target t: Target.values()) {
        switch (t) {
            case JDK1_1: case JDK1_2: // no equivalent -source
                continue;
        }

        for (Profile p: Profile.values()) {
            List<String> opts = new ArrayList<String>();
            opts.addAll(Arrays.asList("-source", t.name, "-target", t.name));
            opts.add("-Xlint:-options"); // dont warn about no -bootclasspath
            if (p != Profile.DEFAULT)
                opts.addAll(Arrays.asList("-profile", p.name));
            StringWriter sw = new StringWriter();
            JavacTask task = (JavacTask) javac.getTask(sw, fm, null, opts, null,
                    Arrays.asList(fo));
            task.analyze();

            // sadly, command line errors are not (yet?) reported to
            // the diag listener
            String out = sw.toString();
            if (!out.isEmpty())
                System.err.println(out.trim());

            switch (t) {
                case JDK1_8:
                    if (!out.isEmpty())
                        error("unexpected output from compiler");
                    break;
                default:
                    if (p != Profile.DEFAULT
                            && !out.contains("profile " + p.name
                                + " is not valid for target release " + t.name)) {
                        error("expected message not found");
                    }
            }
        }
    }
}
 
Example #30
Source File: ReleaseOptionUnsupported.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testAddExports(Path base) throws IOException {
    Path src = base.resolve("src");
    tb.writeJavaFiles(src,
                      "module m { }",
                      "package test; public class Test { jdk.internal.misc.Unsafe unsafe; } ");
    Path classes = base.resolve("classes");
    tb.createDirectories(classes);

    new JavacTask(tb)
            .options("-XDrawDiagnostics",
                     "--add-exports", "java.base/jdk.internal.misc=m")
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.SUCCESS)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    List<String> log;
    List<String> expected;

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics",
                     "--add-exports", "java.base/jdk.internal.misc=m",
                     "--release", Target.DEFAULT.multiReleaseValue())
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.FAIL)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    expected = Arrays.asList(
            "- compiler.err.add.exports.with.release: java.base",
            "1 error"
    );

    if (!expected.equals(log)) {
        throw new AssertionError("Unexpected output: " + log);
    }

    //OK to add exports a package of a non-system module:
    tb.writeJavaFiles(src,
                      "package test; public class Test { } ");
    tb.createDirectories(classes);

    new JavacTask(tb)
            .options("-XDrawDiagnostics",
                     "--add-exports", "m/test=ALL-UNNAMED",
                     "--release", Target.DEFAULT.multiReleaseValue())
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.SUCCESS)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);
}