/** *Utilitytomanipulatecompiler.properties,andsuggestinfocommentsbased *oninformationderivedfromrunningexamples. * *Options: *-examplesdirlocationofexamplesdirectory *-ofileoutputfile *-checkjustcheckmessagefile *-ensureNewlinesensurenewlineaftereachentry *-fixIndentfixindentationofcontinuationlines *-sortsortmessages *-verboseverboseoutput *-replacereplacecommentsinsteadofmergingcomments *filejavaccompiler.propertiesfile *
*/ publicclass MessageInfo { publicstaticvoid main(String... args) throws Exception {
jtreg = (System.getProperty("test.src") != null);
File tmpDir; if (jtreg) { // use standard jtreg scratch directory: the current directory
tmpDir = new File(System.getProperty("user.dir"));
} else {
tmpDir = new File(System.getProperty("java.io.tmpdir"),
MessageInfo.class.getName()
+ (new SimpleDateFormat("yyMMddHHmmss")).format(new Date()));
}
Example.setTempDir(tmpDir);
Example.Compiler.factory = new ArgTypeCompilerFactory();
MessageInfo mi = new MessageInfo();
try { if (mi.run(args)) return;
} finally { /* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the *jtregscratchdirectory,whichisthecurrentdirectory. *Incasesomeoneisfakingjtregmode,makesuretoonly *cleantmpDirwhenitisreasonabletodoso.
*/ if (tmpDir.isDirectory() &&
tmpDir.getName().startsWith(MessageInfo.class.getName())) { if (clean(tmpDir))
tmpDir.delete();
}
}
for (int i = 0; i < args.length; i++) {
String arg = args[i]; if (arg.equals("-examples") && (i + 1) < args.length)
examplesDir = new File(args[++i]); elseif(arg.equals("-notyet") && (i + 1) < args.length)
notYetFile = new File(args[++i]); elseif (arg.equals("-ensureNewlines"))
ensureNewlines = true; elseif (arg.equals("-fixIndent"))
fixIndent = true; elseif (arg.equals("-sort"))
sort = true; elseif (arg.equals("-verbose"))
verbose = true; elseif (arg.equals("-replace"))
replace = true; elseif (arg.equals("-check"))
check = true; elseif (arg.equals("-o") && (i + 1) < args.length)
outFile = new File(args[++i]); elseif (arg.startsWith("-")) {
error("unknown option: " + arg); returnfalse;
} elseif (i == args.length - 1) {
msgFile = new File(arg);
} else {
error("unknown arg: " + arg); returnfalse;
}
}
if (!check && outFile == null) {
usage(); returntrue;
}
if ((ensureNewlines || fixIndent || sort) && outFile == null) {
error("must set output file for these options"); returnfalse;
}
if (notYetFile == null) {
notYetFile = new File(examplesDir.getParentFile(), "examples.not-yet.txt");
}
if (msgFile == null) { for (File d = testSrc; d != null; d = d.getParentFile()) { if (new File(d, "TEST.ROOT").exists()) {
d = d.getParentFile();
File f = new File(d, "src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties"); if (f.exists()) {
msgFile = f; break;
}
}
} if (msgFile == null) { if (jtreg) {
System.err.println("Warning: no message file available, test skipped"); returntrue;
}
error("no message file available"); returnfalse;
}
}
for (Map.Entry<String, Set<String>> e: msgInfo.entrySet()) {
String k = e.getKey();
Set<String> suggestions = e.getValue();
MessageFile.Message m = mf.messages.get(k); if (m == null) {
error("Can't find message for " + k + " in message file"); continue;
}
MessageFile.Info info = m.getInfo();
Set<Integer> placeholders = m.getPlaceholders();
MessageFile.Info suggestedInfo = new MessageFile.Info(suggestions);
suggestedInfo.markUnused(placeholders);
if (!info.isEmpty()) { if (info.contains(suggestedInfo)) continue; if (!replace) { if (info.fields.size() != suggestedInfo.fields.size())
error("Cannot merge info for " + k); else
suggestedInfo.merge(info);
}
}
if (outFile == null) {
System.err.println("suggest for " + k);
System.err.println(suggestedInfo.toComment());
} else
m.setInfo(suggestedInfo);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.