Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
This is a very small fork of lombok.ast as some Android tools needed a few modifications. The normal repository for lombok.ast is here https://github.com/rzwitserloot/lombok.ast and our changes for 0.2.3 are in this pull request: https://github.com/rzwitserloot/lombok.ast/pull/8
/*
* Copyright (C) 2011 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package lombok.ast.app;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.tools.SimpleJavaFileObject;
import lombok.AccessLevel;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.val;
import lombok.ast.Node;
import lombok.ast.Version;
import lombok.ast.ecj.EcjTreeBuilder;
import lombok.ast.ecj.EcjTreeConverter;
import lombok.ast.ecj.EcjTreeOperations;
import lombok.ast.ecj.EcjTreePrinter;
import lombok.ast.grammar.ParseProblem;
import lombok.ast.grammar.Source;
import lombok.ast.javac.JcTreeBuilder;
import lombok.ast.javac.JcTreeConverter;
import lombok.ast.javac.JcTreePrinter;
import lombok.ast.printer.HtmlFormatter;
import lombok.ast.printer.SourceFormatter;
import lombok.ast.printer.SourcePrinter;
import lombok.ast.printer.StructureFormatter;
import lombok.ast.printer.TextFormatter;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
import org.parboiled.google.collect.Lists;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.main.OptionName;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
import com.zwitserloot.cmdreader.CmdReader;
import com.zwitserloot.cmdreader.Description;
import com.zwitserloot.cmdreader.FullName;
import com.zwitserloot.cmdreader.InvalidCommandLineException;
import com.zwitserloot.cmdreader.Mandatory;
import com.zwitserloot.cmdreader.Sequential;
import com.zwitserloot.cmdreader.Shorthand;
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class Main {
private static class CmdArgs {
@Shorthand("v")
@Description("Print the name of each file as it is being converted.")
private boolean verbose;
@Description("Show version number and exit.")
private boolean version;
@Shorthand("h")
@Description("Show this help text and exit.")
private boolean help;
@Shorthand("e")
@Description("Sets the encoding of your source files. Defaults to the system default charset. Example: \"UTF-8\"")
private String encoding;
@Shorthand("p")
@Description("Print converted code to standard output instead of saving it in target directory")
private boolean print;
@Shorthand("d")
@Description("Directory to save converted files to")
@Mandatory(onlyIfNot={"print", "help", "version"})
private String target;
@Shorthand("i")
@Description("Save the result of each (intermediate) operation as 'text' representation. Do not use any text/source/html operations if you use this option.")
@FullName("save-intermediate")
private boolean saveIntermediate;
@Shorthand("z")
@Description("Normalize the way various different nodes are printed when using the structural printer ('text'), when these nodes are semantically identical")
private boolean normalize;
@Shorthand("n")
@Description("Omit printing the start and end position of nodes for structural output")
@FullName("no-positions")
private boolean noPositions;
@Mandatory(onlyIfNot={"help", "version"})
@Sequential
@Description("Operations to apply to each source file. Comma-separated (no spaces). Valid options: ecj/javac/lombok first to decide how the file is parsed initially, " +
"then any number of further ecj/javac/lombok keywords to convert ASTs, and finally text/source/html.")
private String program;
@Description("Files to convert. Provide either a file, or a directory. If you use a directory, all files in it (recursive) are converted")
@Mandatory(onlyIfNot={"help", "version"})
@Sequential
private List input = new ArrayList();
}
public static void main(String[] rawArgs) throws Exception {
CmdArgs args;
CmdReader reader = CmdReader.of(CmdArgs.class);
try {
args = reader.make(rawArgs);
} catch (InvalidCommandLineException e) {
System.err.println(e.getMessage());
System.err.println(reader.generateCommandLineHelp("java -jar lombok.ast.jar"));
System.exit(1);
return;
}
if (args.help) {
System.out.println("lombok.ast java AST tool " + Version.getVersion());
System.out.println(reader.generateCommandLineHelp("java -jar lombok.ast.jar"));
System.exit(0);
return;
}
if (args.version) {
System.out.println(Version.getVersion());
System.exit(0);
return;
}
try {
Charset charset = args.encoding == null ? Charset.defaultCharset() : Charset.forName(args.encoding);
Main main = new Main(charset, args.verbose, args.normalize, !args.noPositions, args.saveIntermediate);
main.compile(args.program);
if (!args.print) {
File targetDir = new File(args.target);
if (!targetDir.exists()) targetDir.mkdirs();
if (!targetDir.isDirectory()) {
System.err.printf("%s is not a directory or cannot be created\n", targetDir.getCanonicalPath());
System.exit(1);
return;
}
main.setOutputDir(targetDir);
}
for (String input : args.input) {
main.addToQueue(input);
}
main.go();
} catch (IllegalArgumentException e) {
System.err.println(e.getMessage());
System.exit(1);
return;
}
}
private void go() throws IOException {
for (Plan p : files) {
process(p.getFile(), outDir, p.getRelativeName());
}
if (errors > 0) {
System.err.printf("%d errors\n", errors);
}
System.exit(errors > 0 ? 2 : 0);
}
private void setOutputDir(File f) {
this.outDir = f;
}
private void addToQueue(String item) throws IOException {
addToQueue0(new File(item), "");
}
private void addToQueue0(File f, String pathSoFar) throws IOException {
pathSoFar += (pathSoFar.isEmpty() ? "" : "/") + f.getName();
if (f.isFile()) {
if (f.getName().endsWith(".java")) {
files.add(new Plan(f, pathSoFar));
}
} else if (f.isDirectory()) {
for (File inner : f.listFiles()) {
addToQueue0(inner, pathSoFar);
}
} else {
throw new IllegalArgumentException("Unknown file: " + f.getCanonicalPath());
}
}
@Data
private static class Plan {
final File file;
final String relativeName;
}
private void process(File in, File outDir, String relativeName) throws IOException {
File out = outDir == null ? null : new File(outDir, relativeName);
if (verbose && !saveIntermediate) {
System.out.printf("Processing: %s to %s\n", in.getCanonicalPath(), out == null ? "sysout" : out.getCanonicalPath());
}
Source source = new Source(Files.toString(in, charset), in.getCanonicalPath());
Object transfer = null;
String chain = "/";
try {
for (Operation