aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/bytecode/PoolConstantsApp.java
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2012-01-30 21:47:51 +0100
committerRoel Spilker <r.spilker@gmail.com>2012-01-30 21:47:51 +0100
commit42ea24a816832c3c7f2a8c43054d16158226c38f (patch)
treef0ec0a596dfd46665daeb943bc3c060ba84f0fb6 /src/core/lombok/bytecode/PoolConstantsApp.java
parent81f6149b08e46503ebe82407c09574d943295320 (diff)
downloadlombok-42ea24a816832c3c7f2a8c43054d16158226c38f.tar.gz
lombok-42ea24a816832c3c7f2a8c43054d16158226c38f.tar.bz2
lombok-42ea24a816832c3c7f2a8c43054d16158226c38f.zip
Added a tool to display the constant pool for a list of class files
Diffstat (limited to 'src/core/lombok/bytecode/PoolConstantsApp.java')
-rw-r--r--src/core/lombok/bytecode/PoolConstantsApp.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/core/lombok/bytecode/PoolConstantsApp.java b/src/core/lombok/bytecode/PoolConstantsApp.java
new file mode 100644
index 00000000..59c51a37
--- /dev/null
+++ b/src/core/lombok/bytecode/PoolConstantsApp.java
@@ -0,0 +1,81 @@
+package lombok.bytecode;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import lombok.core.LombokApp;
+
+import org.mangosdk.spi.ProviderFor;
+
+import com.zwitserloot.cmdreader.CmdReader;
+import com.zwitserloot.cmdreader.Description;
+import com.zwitserloot.cmdreader.InvalidCommandLineException;
+import com.zwitserloot.cmdreader.Mandatory;
+import com.zwitserloot.cmdreader.Sequential;
+import com.zwitserloot.cmdreader.Shorthand;
+
+@ProviderFor(LombokApp.class)
+public class PoolConstantsApp extends LombokApp {
+
+ @Override public String getAppName() {
+ return "Xprintpool";
+ }
+
+ @Override public List<String> getAppAliases() {
+ return Arrays.asList("Xprintpool");
+ }
+
+ @Override public String getAppDescription() {
+ return "Prints the content of the constant pool to standard out.";
+ }
+
+ @Override public boolean isDebugTool() {
+ return true;
+ }
+
+ public static class CmdArgs {
+ @Sequential
+ @Mandatory
+ @Description("paths to class files to be printed. If a directory is named, all files (recursively) in that directory will be printed.")
+ private List<String> classFiles = new ArrayList<String>();
+
+ @Shorthand({"h", "?"})
+ @Description("Shows this help text")
+ boolean help = false;
+ }
+
+ @Override public int runApp(List<String> raw) throws Exception {
+ CmdReader<CmdArgs> reader = CmdReader.of(CmdArgs.class);
+ CmdArgs args;
+ try {
+ args = reader.make(raw.toArray(new String[0]));
+ if (args.help) {
+ System.out.println(reader.generateCommandLineHelp("java -jar lombok.jar -printpool"));
+ return 0;
+ }
+ } catch (InvalidCommandLineException e) {
+ System.err.println(e.getMessage());
+ System.err.println(reader.generateCommandLineHelp("java -jar lombok.jar -printpool"));
+ return 1;
+ }
+
+ List<File> filesToProcess = PostCompilerApp.cmdArgsToFiles(args.classFiles);
+ int filesVisited = 0;
+ boolean moreThanOne = filesToProcess.size() > 1;
+ for (File file : filesToProcess) {
+ if (!file.exists() || !file.isFile()) {
+ System.out.printf("Cannot find file '%s'\n", file.getAbsolutePath());
+ continue;
+ }
+ filesVisited++;
+ if (moreThanOne) System.out.printf("Processing '%s'\n", file.getAbsolutePath());
+ System.out.println(new ClassFileMetaData(PostCompilerApp.readFile(file)).poolContent());
+ }
+
+ if (moreThanOne) System.out.printf("Total files visited: %d\n", filesVisited);
+
+ return filesVisited == 0 ? 1 : 0;
+ }
+}