Java Code Examples for com.sun.tools.javac.jvm.Profile#values()

The following examples show how to use com.sun.tools.javac.jvm.Profile#values() . 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: ProfileOptionTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
void testClassesInProfiles() throws Exception {
    for (Profile p: Profile.values()) {
        for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
            for (JavaFileObject fo: e.getValue()) {
                DiagnosticCollector<JavaFileObject> dl =
                        new DiagnosticCollector<JavaFileObject>();
                List<String> opts = (p == Profile.DEFAULT)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("-profile", p.name);
                JavacTask task = (JavacTask) javac.getTask(null, fm, dl, opts, null,
                        Arrays.asList(fo));
                task.analyze();

                List<String> expectDiagCodes = (p.value >= e.getKey().value)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("compiler.err.not.in.profile");

                checkDiags(opts + " " + fo.getName(), dl.getDiagnostics(), expectDiagCodes);
            }
        }
    }
}
 
Example 2
Source File: ProfileOptionTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Test
void testClassesInProfiles() throws Exception {
    for (Profile p: Profile.values()) {
        for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
            for (JavaFileObject fo: e.getValue()) {
                DiagnosticCollector<JavaFileObject> dl =
                        new DiagnosticCollector<JavaFileObject>();
                List<String> opts = (p == Profile.DEFAULT)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("-profile", p.name);
                JavacTask task = (JavacTask) javac.getTask(null, fm, dl, opts, null,
                        Arrays.asList(fo));
                task.analyze();

                List<String> expectDiagCodes = (p.value >= e.getKey().value)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("compiler.err.not.in.profile");

                checkDiags(opts + " " + fo.getName(), dl.getDiagnostics(), expectDiagCodes);
            }
        }
    }
}
 
Example 3
Source File: ProfileOptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test
void testClassesInProfiles() throws Exception {
    for (Profile p: Profile.values()) {
        for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
            for (JavaFileObject fo: e.getValue()) {
                DiagnosticCollector<JavaFileObject> dl =
                        new DiagnosticCollector<JavaFileObject>();
                List<String> opts = (p == Profile.DEFAULT)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("-profile", p.name);
                JavacTask task = (JavacTask) javac.getTask(null, fm, dl, opts, null,
                        Arrays.asList(fo));
                task.analyze();

                List<String> expectDiagCodes = (p.value >= e.getKey().value)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("compiler.err.not.in.profile");

                checkDiags(opts + " " + fo.getName(), dl.getDiagnostics(), expectDiagCodes);
            }
        }
    }
}
 
Example 4
Source File: ProfileOptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
void testClassesInProfiles() throws Exception {
    for (Profile p: Profile.values()) {
        for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
            for (JavaFileObject fo: e.getValue()) {
                DiagnosticCollector<JavaFileObject> dl =
                        new DiagnosticCollector<JavaFileObject>();
                List<String> opts = (p == Profile.DEFAULT)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("-profile", p.name);
                JavacTask task = (JavacTask) javac.getTask(null, fm, dl, opts, null,
                        Arrays.asList(fo));
                task.analyze();

                List<String> expectDiagCodes = (p.value >= e.getKey().value)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("compiler.err.not.in.profile");

                checkDiags(opts + " " + fo.getName(), dl.getDiagnostics(), expectDiagCodes);
            }
        }
    }
}
 
Example 5
Source File: ProfileOptionTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Test
void testClassesInProfiles() throws Exception {
    for (Profile p: Profile.values()) {
        for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
            for (JavaFileObject fo: e.getValue()) {
                DiagnosticCollector<JavaFileObject> dl =
                        new DiagnosticCollector<JavaFileObject>();
                List<String> opts = (p == Profile.DEFAULT)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("-profile", p.name);
                JavacTask task = (JavacTask) javac.getTask(null, fm, dl, opts, null,
                        Arrays.asList(fo));
                task.analyze();

                List<String> expectDiagCodes = (p.value >= e.getKey().value)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("compiler.err.not.in.profile");

                checkDiags(opts + " " + fo.getName(), dl.getDiagnostics(), expectDiagCodes);
            }
        }
    }
}
 
Example 6
Source File: ProfileOptionTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Test
void testClassesInProfiles() throws Exception {
    for (Profile p: Profile.values()) {
        for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
            for (JavaFileObject fo: e.getValue()) {
                DiagnosticCollector<JavaFileObject> dl =
                        new DiagnosticCollector<JavaFileObject>();
                List<String> opts = (p == Profile.DEFAULT)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("-profile", p.name);
                JavacTask task = (JavacTask) javac.getTask(null, fm, dl, opts, null,
                        Arrays.asList(fo));
                task.analyze();

                List<String> expectDiagCodes = (p.value >= e.getKey().value)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("compiler.err.not.in.profile");

                checkDiags(opts + " " + fo.getName(), dl.getDiagnostics(), expectDiagCodes);
            }
        }
    }
}
 
Example 7
Source File: ProfileOptionTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
void testClassesInProfiles() throws Exception {
    for (Profile p: Profile.values()) {
        for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
            for (JavaFileObject fo: e.getValue()) {
                DiagnosticCollector<JavaFileObject> dl =
                        new DiagnosticCollector<JavaFileObject>();
                List<String> opts = (p == Profile.DEFAULT)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("-profile", p.name);
                JavacTask task = (JavacTask) javac.getTask(null, fm, dl, opts, null,
                        Arrays.asList(fo));
                task.analyze();

                List<String> expectDiagCodes = (p.value >= e.getKey().value)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("compiler.err.not.in.profile");

                checkDiags(opts + " " + fo.getName(), dl.getDiagnostics(), expectDiagCodes);
            }
        }
    }
}
 
Example 8
Source File: ProfileOptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
void testClassesInProfiles() throws Exception {
    for (Profile p: Profile.values()) {
        for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
            for (JavaFileObject fo: e.getValue()) {
                DiagnosticCollector<JavaFileObject> dl =
                        new DiagnosticCollector<JavaFileObject>();
                List<String> opts = (p == Profile.DEFAULT)
                        ? Collections.<String>emptyList()
                        : Arrays.asList("--release", "8", "-profile", p.name);
                JavacTask task = (JavacTask) javac.getTask(null, fm, dl, opts, null,
                        Arrays.asList(fo));
                task.analyze();

                List<String> expectDiagCodes = new ArrayList<>();
                if (fo.getName().equals("TPolicyFile.java")) {
                    expectDiagCodes.add("compiler.warn.has.been.deprecated.for.removal");
                }

                if (p.value < e.getKey().value) {
                    expectDiagCodes.add("compiler.err.not.in.profile");
                }

                checkDiags(opts + " " + fo.getName(), dl.getDiagnostics(), expectDiagCodes);
            }
        }
    }
}
 
Example 9
Source File: ProfileOptionTest.java    From TencentKona-8 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 10
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 11
Source File: ProfileOptionTest.java    From openjdk-jdk8u 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 12
Source File: ProfileOptionTest.java    From openjdk-jdk8u-backup 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 13
Source File: ProfileOptionTest.java    From openjdk-jdk9 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:
            case JDK1_3:
            case JDK1_4:
            case JDK1_5: // not supported
                continue;
        }

        for (Profile p: Profile.values()) {
            List<String> opts = new ArrayList<>();
            opts.addAll(Arrays.asList("-source", t.name, "-target", t.name));
            opts.add("-Xlint:-options"); // don't warn about no -bootclasspath
            if (p != Profile.DEFAULT)
                opts.addAll(Arrays.asList("-profile", p.name));

            IllegalStateException ise;
            StringWriter sw = new StringWriter();
            try {
                JavacTask task = (JavacTask) javac.getTask(sw, fm, null, opts, null,
                        Arrays.asList(fo));
                task.analyze();
                ise = null;
            } catch (IllegalStateException e) {
                ise = e;
            }

            // 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 (ise != null)
                        error("unexpected exception from compiler: " + ise);
                    break;
                case JDK1_9:
                    if (p == Profile.DEFAULT)
                        break;
                    if (ise == null)
                        error("IllegalStateException not thrown as expected");
                    else if (!ise.getMessage().contains("option -profile " +
                            "not allowed with target " + t.name)) {
                        error("exception not thrown as expected: " + ise);
                    }
                    break;
                default:
                    if (p == Profile.DEFAULT)
                        break;
                    if (ise == null)
                        error("IllegalStateException not thrown as expected");
                    else if (!ise.getMessage().contains("profile " + p.name
                                + " is not valid for target release " + t.name)) {
                        error("exception not thrown as expected: " + ise);
                    }
                    break;
            }
        }
    }
}
 
Example 14
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 15
Source File: ProfileOptionTest.java    From openjdk-8-source 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 16
Source File: ProfileOptionTest.java    From openjdk-8 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");
                    }
            }
        }
    }
}