com.sun.tools.javac.util.Log.PrefixKind Java Examples

The following examples show how to use com.sun.tools.javac.util.Log.PrefixKind. 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: VerifyLintDescriptions.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) {
    ModuleLayer boot = ModuleLayer.boot();
    Module jdk_compiler = boot.findModule("jdk.compiler").get();
    ResourceBundle b = ResourceBundle.getBundle("com.sun.tools.javac.resources.javac",
                                                Locale.US,
                                                jdk_compiler);

    List<String> missing = new ArrayList<>();

    for (LintCategory lc : LintCategory.values()) {
        try {
            b.getString(PrefixKind.JAVAC.key("opt.Xlint.desc." + lc.option));
        } catch (MissingResourceException ex) {
            missing.add(lc.option);
        }
    }

    if (!missing.isEmpty()) {
        throw new UnsupportedOperationException("Lints that are missing description: " + missing);
    }
}
 
Example #2
Source File: Option.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Composes the initial synopsis of one of the forms for this option.
 * @param name the name of this form of the option
 * @param log the log used to localize the description of the arguments
 * @return  the synopsis
 */
private String helpSynopsis(String name, Log log) {
    StringBuilder sb = new StringBuilder();
    sb.append(name);
    if (argsNameKey == null) {
        if (choices != null) {
            if (!name.endsWith(":"))
                sb.append(" ");
            String sep = "{";
            for (String choice : choices) {
                sb.append(sep);
                sb.append(choice);
                sep = ",";
            }
            sb.append("}");
        }
    } else {
        if (!name.matches(".*[=:]$") && argKind != ArgKind.ADJACENT)
            sb.append(" ");
        sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
    }

    return sb.toString();
}
 
Example #3
Source File: Option.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Composes the initial synopsis of one of the forms for this option.
 * @param name the name of this form of the option
 * @param log the log used to localize the description of the arguments
 * @return  the synopsis
 */
private String helpSynopsis(String name, Log log) {
    StringBuilder sb = new StringBuilder();
    sb.append(name);
    if (argsNameKey == null) {
        if (choices != null) {
            if (!name.endsWith(":"))
                sb.append(" ");
            String sep = "{";
            for (String choice : choices) {
                sb.append(sep);
                sb.append(choice);
                sep = ",";
            }
            sb.append("}");
        }
    } else {
        if (!name.matches(".*[=:]$") && argKind != ArgKind.ADJACENT)
            sb.append(" ");
        sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
    }

    return sb.toString();
}
 
Example #4
Source File: Main.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #5
Source File: Main.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #6
Source File: Arguments.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initializes this Args instance with a set of command line args.
 * The args will be processed in conjunction with the full set of
 * command line options, including -help, -version etc.
 * The args may also contain class names and filenames.
 * Any errors during this call, and later during validate, will be reported
 * to the log.
 * @param ownName the name of this tool; used to prefix messages
 * @param args the args to be processed
 */
public void init(String ownName, String... args) {
    this.ownName = ownName;
    errorMode = ErrorMode.LOG;
    files = new LinkedHashSet<>();
    deferredFileManagerOptions = new LinkedHashMap<>();
    fileObjects = null;
    classNames = new LinkedHashSet<>();
    processArgs(List.from(args), Option.getJavaCompilerOptions(), cmdLineHelper, true, false);
    if (errors) {
        log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
    }
}
 
Example #7
Source File: Main.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #8
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #9
Source File: Main.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #10
Source File: Main.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean twoClassLoadersInUse(IllegalAccessError iae) {
    String msg = iae.getMessage();
    Pattern pattern = Pattern.compile("(?i)(?<=tried to access class )([a-z_$][a-z\\d_$]*\\.)*[a-z_$][a-z\\d_$]*");
    Matcher matcher = pattern.matcher(msg);
    if (matcher.find()) {
        try {
            String otherClassName = matcher.group(0);
            Class<?> otherClass = Class.forName(otherClassName);
            ClassLoader otherClassLoader = otherClass.getClassLoader();
            ClassLoader javacClassLoader = this.getClass().getClassLoader();
            if (javacClassLoader != otherClassLoader) {
                CodeSource otherClassCodeSource = otherClass.getProtectionDomain().getCodeSource();
                CodeSource javacCodeSource = this.getClass().getProtectionDomain().getCodeSource();
                if (otherClassCodeSource != null && javacCodeSource != null) {
                    log.printLines(PrefixKind.JAVAC, "err.two.class.loaders.2",
                            otherClassCodeSource.getLocation(),
                            javacCodeSource.getLocation());
                } else {
                    log.printLines(PrefixKind.JAVAC, "err.two.class.loaders.1");
                }
                return true;
            }
        } catch (Throwable t) {
            return false;
        }
    }
    return false;
}
 
Example #11
Source File: Main.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #12
Source File: Arguments.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes this Args instance with a set of command line args.
 * The args will be processed in conjunction with the full set of
 * command line options, including -help, -version etc.
 * The args may also contain class names and filenames.
 * Any errors during this call, and later during validate, will be reported
 * to the log.
 * @param ownName the name of this tool; used to prefix messages
 * @param args the args to be processed
 */
public void init(String ownName, String... args) {
    this.ownName = ownName;
    errorMode = ErrorMode.LOG;
    files = new LinkedHashSet<>();
    deferredFileManagerOptions = new LinkedHashMap<>();
    fileObjects = null;
    classNames = new LinkedHashSet<>();
    processArgs(List.from(args), Option.getJavaCompilerOptions(), cmdLineHelper, true, false);
    if (errors) {
        log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
    }
}
 
Example #13
Source File: Main.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #14
Source File: Main.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #15
Source File: Main.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Report a usage error.
 */
void error(String key, Object... args) {
    if (apiMode) {
        String msg = log.localize(PrefixKind.JAVAC, key, args);
        throw new PropagatedException(new IllegalStateException(msg));
    }
    warning(key, args);
    log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
}
 
Example #16
Source File: Main.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/** Print a message reporting an out-of-resources error.
 */
void resourceMessage(Throwable ex) {
    log.printLines(PrefixKind.JAVAC, "msg.resource");
    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}
 
Example #17
Source File: Main.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Print a message reporting an uncaught exception from an
 * annotation processor.
 */
void apMessage(AnnotationProcessingError ex) {
    log.printLines(PrefixKind.JAVAC, "msg.proc.annotation.uncaught.exception");
    ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
}
 
Example #18
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Print a message reporting an input/output error.
 */
void ioMessage(Throwable ex) {
    log.printLines(PrefixKind.JAVAC, "msg.io");
    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}
 
Example #19
Source File: OptionHelper.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
void error(String key, Object... args) {
    throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
}
 
Example #20
Source File: Main.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/** Print a message reporting an uncaught exception from an
 * annotation processor.
 */
void apMessage(AnnotationProcessingError ex) {
    log.printLines(PrefixKind.JAVAC, "msg.proc.annotation.uncaught.exception");
    ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
}
 
Example #21
Source File: OptionHelper.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
void error(String key, Object... args) {
    throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
}
 
Example #22
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Print a message reporting an uncaught exception from an
 * annotation processor.
 */
void apMessage(AnnotationProcessingError ex) {
    log.printLines(PrefixKind.JAVAC, "msg.proc.annotation.uncaught.exception");
    ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
}
 
Example #23
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Print a message reporting an out-of-resources error.
 */
void resourceMessage(Throwable ex) {
    log.printLines(PrefixKind.JAVAC, "msg.resource");
    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}
 
Example #24
Source File: Main.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/** Report a warning.
 */
void warning(String key, Object... args) {
    log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
}
 
Example #25
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Print a message reporting an internal error.
 */
void bugMessage(Throwable ex) {
    log.printLines(PrefixKind.JAVAC, "msg.bug", JavaCompiler.version());
    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}
 
Example #26
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Report a warning.
 */
void warning(String key, Object... args) {
    log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
}
 
Example #27
Source File: Arguments.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void report(String key, Object... args) {
    // Would be good to have support for -XDrawDiagnostics here
    log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
}
 
Example #28
Source File: Arguments.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Handles the {@code --release} option.
 *
 * @param additionalOptions a predicate to handle additional options implied by the
 * {@code --release} option. The predicate should return true if all the additional
 * options were processed successfully.
 * @return true if successful, false otherwise
 */
public boolean handleReleaseOptions(Predicate<Iterable<String>> additionalOptions) {
    String platformString = options.get(Option.RELEASE);

    checkOptionAllowed(platformString == null,
            option -> error("err.release.bootclasspath.conflict", option.getPrimaryName()),
            Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
            Option.XBOOTCLASSPATH_PREPEND,
            Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
            Option.EXTDIRS, Option.DJAVA_EXT_DIRS,
            Option.SOURCE, Option.TARGET,
            Option.SYSTEM, Option.UPGRADE_MODULE_PATH);

    if (platformString != null) {
        PlatformDescription platformDescription = PlatformUtils.lookupPlatformDescription(platformString);

        if (platformDescription == null) {
            error("err.unsupported.release.version", platformString);
            return false;
        }

        options.put(Option.SOURCE, platformDescription.getSourceVersion());
        options.put(Option.TARGET, platformDescription.getTargetVersion());

        context.put(PlatformDescription.class, platformDescription);

        if (!additionalOptions.test(platformDescription.getAdditionalOptions()))
            return false;

        Collection<Path> platformCP = platformDescription.getPlatformPath();

        if (platformCP != null) {
            JavaFileManager fm = getFileManager();

            if (!(fm instanceof StandardJavaFileManager)) {
                error("err.release.not.standard.file.manager");
                return false;
            }

            try {
                StandardJavaFileManager sfm = (StandardJavaFileManager) fm;

                if (Source.instance(context).allowModules()) {
                    sfm.handleOption("--system", Arrays.asList("none").iterator());
                    sfm.setLocationFromPaths(StandardLocation.UPGRADE_MODULE_PATH, platformCP);
                } else {
                    sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
                }
            } catch (IOException ex) {
                log.printLines(PrefixKind.JAVAC, "msg.io");
                ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
                return false;
            }
        }
    }

    return true;
}
 
Example #29
Source File: OptionHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
void error(String key, Object... args) {
    throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
}
 
Example #30
Source File: Main.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/** Print a message reporting an uncaught exception from an
 * annotation processor.
 */
void pluginMessage(Throwable ex) {
    log.printLines(PrefixKind.JAVAC, "msg.plugin.uncaught.exception");
    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
}