示例#1
0
  private static boolean setOptions(String[] lcommand) {

    Options loptions = new Options();
    loptions.addOption(new Option("d", "debug", false, "print debug information (highly verbose)"));
    loptions.addOption(new Option("o", "stdout", false, "print output files to standard output"));
    loptions.addOption(new Option("w", "warning", false, "print warning messages"));

    CommandLineParser clparser = new PosixParser();
    try {
      cmd = clparser.parse(loptions, lcommand);
    } catch (org.apache.commons.cli.ParseException e) {
      String mytoolcmd = "java -jar stave.jar";
      String myoptlist = " <options> <source files>";
      String myheader = "Convert JavaParser's AST to OpenJDK's AST";
      String myfooter = "More info: https://github.com/pcgomes/javaparser2jctree";

      HelpFormatter formatter = new HelpFormatter();
      // formatter.printUsage( new PrintWriter(System.out,true), 100, "java -jar synctask.jar",
      // loptions );
      // formatter.printHelp( mytoolcmd + myoptlist, myheader, loptions, myfooter, false);
      formatter.printHelp(mytoolcmd + myoptlist, loptions, false);
      return (false);
    }

    return (true);
  }
 @SuppressWarnings("fallthrough")
 public SimpleConfiguration(Options options, Set<DiagnosticPart> parts) {
   this(parts);
   String showSource = null;
   if ((showSource = options.get("showSource")) != null) {
     if (showSource.equals("true")) setVisiblePart(DiagnosticPart.SOURCE, true);
     else if (showSource.equals("false")) setVisiblePart(DiagnosticPart.SOURCE, false);
   }
   String diagOpts = options.get("diags");
   if (diagOpts != null) { // override -XDshowSource
     Collection<String> args = Arrays.asList(diagOpts.split(","));
     if (args.contains("short")) {
       setVisiblePart(DiagnosticPart.DETAILS, false);
       setVisiblePart(DiagnosticPart.SUBDIAGNOSTICS, false);
     }
     if (args.contains("source")) setVisiblePart(DiagnosticPart.SOURCE, true);
     if (args.contains("-source")) setVisiblePart(DiagnosticPart.SOURCE, false);
   }
   String multiPolicy = null;
   if ((multiPolicy = options.get("multilinePolicy")) != null) {
     if (multiPolicy.equals("disabled")) setVisiblePart(DiagnosticPart.SUBDIAGNOSTICS, false);
     else if (multiPolicy.startsWith("limit:")) {
       String limitString = multiPolicy.substring("limit:".length());
       String[] limits = limitString.split(":");
       try {
         switch (limits.length) {
           case 2:
             {
               if (!limits[1].equals("*"))
                 setMultilineLimit(MultilineLimit.DEPTH, Integer.parseInt(limits[1]));
             }
           case 1:
             {
               if (!limits[0].equals("*"))
                 setMultilineLimit(MultilineLimit.LENGTH, Integer.parseInt(limits[0]));
             }
         }
       } catch (NumberFormatException ex) {
         setMultilineLimit(MultilineLimit.DEPTH, -1);
         setMultilineLimit(MultilineLimit.LENGTH, -1);
       }
     }
   }
   String showCaret = null;
   if (((showCaret = options.get("showCaret")) != null) && showCaret.equals("false"))
     setCaretEnabled(false);
   else setCaretEnabled(true);
 }
  /** Construct a new compiler from a shared context. */
  public AptJavaCompiler(Context context) {
    super(preRegister(context));

    context.put(compilerKey, this);
    apt = Apt.instance(context);

    ClassReader classReader = ClassReader.instance(context);
    classReader.preferSource = true;

    // TEMPORARY NOTE: bark==log, but while refactoring, we maintain their
    // original identities, to remember the original intent.
    log = Log.instance(context);
    bark = Bark.instance(context);

    Options options = Options.instance(context);
    classOutput = options.get("-retrofit") == null;
    nocompile = options.get("-nocompile") != null;
    print = options.get("-print") != null;
    classesAsDecls = options.get("-XclassesAsDecls") != null;

    genSourceFileNames = new java.util.LinkedHashSet<String>();
    genClassFileNames = new java.util.LinkedHashSet<String>();

    // this forces a copy of the line map to be kept in the tree,
    // for use by com.sun.mirror.util.SourcePosition.
    lineDebugInfo = true;
  }