Search in sources :

Example 1 with Options

use of com.sun.tools.javac.util.Options in project lombok by rzwitserloot.

the class Processor method listOptions.

private void listOptions(StringBuilder message, ProcessingEnvironment procEnv) {
    try {
        JavacProcessingEnvironment environment = (JavacProcessingEnvironment) procEnv;
        Options instance = Options.instance(environment.getContext());
        Field field = Options.class.getDeclaredField("values");
        field.setAccessible(true);
        @SuppressWarnings("unchecked") Map<String, String> values = (Map<String, String>) field.get(instance);
        if (values.isEmpty()) {
            message.append("Options: empty\n\n");
            return;
        }
        message.append("Compiler Options:\n");
        for (Map.Entry<String, String> value : values.entrySet()) {
            message.append("- ");
            string(message, value.getKey());
            message.append(" = ");
            string(message, value.getValue());
            message.append("\n");
        }
        message.append("\n");
    } catch (Exception e) {
        message.append("No options available\n\n");
    }
}
Also used : Options(com.sun.tools.javac.util.Options) Field(java.lang.reflect.Field) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment) Map(java.util.Map) IOException(java.io.IOException)

Example 2 with Options

use of com.sun.tools.javac.util.Options in project lombok by rzwitserloot.

the class LombokOptionsFactory method getDelombokOptions.

public static LombokOptions getDelombokOptions(Context context) {
    Options rawOptions = Options.instance(context);
    if (rawOptions instanceof LombokOptions)
        return (LombokOptions) rawOptions;
    LombokOptions options;
    if (Javac.getJavaCompilerVersion() < 8) {
        options = LombokOptionCompilerVersion.JDK7_AND_LOWER.createAndRegisterOptions(context);
    } else {
        options = LombokOptionCompilerVersion.JDK8.createAndRegisterOptions(context);
    }
    return options;
}
Also used : LombokOptions(lombok.javac.LombokOptions) Javac6BasedLombokOptions(lombok.javac.Javac6BasedLombokOptions) Javac8BasedLombokOptions(lombok.javac.Javac8BasedLombokOptions) Options(com.sun.tools.javac.util.Options) LombokOptions(lombok.javac.LombokOptions) Javac6BasedLombokOptions(lombok.javac.Javac6BasedLombokOptions) Javac8BasedLombokOptions(lombok.javac.Javac8BasedLombokOptions)

Example 3 with Options

use of com.sun.tools.javac.util.Options in project jangaroo-tools by CoreMedia.

the class Start method parseAndExecute.

private boolean parseAndExecute(String[] as) {
    long l = System.currentTimeMillis();
    ListBuffer listbuffer = new ListBuffer();
    try {
        as = CommandLine.parse(as);
    } catch (FileNotFoundException filenotfoundexception) {
        messager.error(null, "main.cant.read", filenotfoundexception.getMessage());
        exit();
    } catch (IOException ioexception) {
        ioexception.printStackTrace();
        exit();
    }
    setDocletInvoker(as);
    ListBuffer listbuffer1 = new ListBuffer();
    ListBuffer listbuffer2 = new ListBuffer();
    Options options1 = Options.instance(context);
    boolean flag = false;
    for (int i = 0; i < as.length; i++) {
        String s = as[i];
        if (s.equals("-subpackages")) {
            oneArg(as, i++);
            addToList(listbuffer1, as[i]);
            continue;
        }
        if (s.equals("-exclude")) {
            oneArg(as, i++);
            addToList(listbuffer2, as[i]);
            continue;
        }
        if (s.equals("-verbose")) {
            setOption(s);
            options1.put("-verbose", "");
            continue;
        }
        if (s.equals("-encoding")) {
            oneArg(as, i++);
            encoding = as[i];
            options1.put("-encoding", as[i]);
            continue;
        }
        if (s.equals("-breakiterator")) {
            breakiterator = true;
            setOption("-breakiterator");
            continue;
        }
        if (s.equals("-help")) {
            usage();
            exit();
            continue;
        }
        if (s.equals("-Xclasses")) {
            setOption(s);
            flag = true;
            continue;
        }
        if (s.equals("-Xwerror")) {
            setOption(s);
            rejectWarnings = true;
            continue;
        }
        if (s.equals("-private")) {
            setOption(s);
            setFilter(-9223372036854775801L);
            continue;
        }
        if (s.equals("-package")) {
            setOption(s);
            setFilter(-9223372036854775803L);
            continue;
        }
        if (s.equals("-protected")) {
            setOption(s);
            setFilter(5L);
            continue;
        }
        if (s.equals("-public")) {
            setOption(s);
            setFilter(1L);
            continue;
        }
        if (s.equals("-source")) {
            oneArg(as, i++);
            if (options1.get("-source") != null)
                usageError("main.option.already.seen", s);
            options1.put("-source", as[i]);
            continue;
        }
        if (s.equals("-gj")) {
            options1.put("-gj", "-gj");
            continue;
        }
        if (s.equals("-prompt")) {
            options1.put("-prompt", "-prompt");
            messager.promptOnError = true;
            continue;
        }
        if (s.equals("-sourcepath")) {
            oneArg(as, i++);
            if (options1.get("-sourcepath") != null)
                usageError("main.option.already.seen", s);
            options1.put("-sourcepath", as[i]);
            continue;
        }
        if (s.equals("-classpath")) {
            oneArg(as, i++);
            if (options1.get("-classpath") != null)
                usageError("main.option.already.seen", s);
            options1.put("-classpath", as[i]);
            continue;
        }
        if (s.equals("-sysclasspath")) {
            oneArg(as, i++);
            if (options1.get("-bootclasspath") != null)
                usageError("main.option.already.seen", s);
            options1.put("-bootclasspath", as[i]);
            continue;
        }
        if (s.equals("-bootclasspath")) {
            oneArg(as, i++);
            if (options1.get("-bootclasspath") != null)
                usageError("main.option.already.seen", s);
            options1.put("-bootclasspath", as[i]);
            continue;
        }
        if (s.equals("-extdirs")) {
            oneArg(as, i++);
            if (options1.get("-extdirs") != null)
                usageError("main.option.already.seen", s);
            options1.put("-extdirs", as[i]);
            continue;
        }
        if (s.equals("-overview")) {
            oneArg(as, i++);
            continue;
        }
        if (s.equals("-doclet")) {
            i++;
            continue;
        }
        if (s.equals("-docletpath")) {
            i++;
            continue;
        }
        if (s.equals("-locale")) {
            if (i != 0)
                usageError("main.locale_first");
            oneArg(as, i++);
            docLocale = as[i];
            continue;
        }
        if (s.startsWith("-XD")) {
            String s1 = s.substring("-XD".length());
            int k = s1.indexOf('=');
            String s2 = k >= 0 ? s1.substring(0, k) : s1;
            String s3 = k >= 0 ? s1.substring(k + 1) : s1;
            options1.put(s2, s3);
            continue;
        }
        if (s.startsWith("-")) {
            int j = docletInvoker.optionLength(s);
            if (j < 0) {
                exit();
                continue;
            }
            if (j == 0) {
                usageError("main.invalid_flag", s);
                continue;
            }
            if (i + j > as.length)
                usageError("main.requires_argument", s);
            ListBuffer listbuffer3 = new ListBuffer();
            for (int i1 = 0; i1 < j - 1; i1++) listbuffer3.append(as[++i]);
            setOption(s, listbuffer3.toList());
        } else {
            listbuffer.append(s);
        }
    }
    if (listbuffer.isEmpty() && listbuffer1.isEmpty())
        usageError("main.No_packages_or_classes_specified");
    if (!docletInvoker.validOptions(options.toList()))
        exit();
    JoodocTool joodocTool = new JoodocTool(messager);
    if (joodocTool == null)
        return false;
    if (showAccess == null)
        setFilter(defaultFilter);
    net.jangaroo.joodoc.RootDocImpl rootdocimpl = joodocTool.getRootDocImpl(docLocale, encoding, showAccess, listbuffer.toList(), options.toList(), breakiterator, listbuffer1.toList(), listbuffer2.toList(), flag);
    boolean flag1 = rootdocimpl != null;
    if (flag1)
        flag1 = docletInvoker.start(rootdocimpl);
    if (options1.get("-verbose") != null) {
        l = System.currentTimeMillis() - l;
        messager.notice("main.done_in", Long.toString(l));
    }
    return flag1;
}
Also used : Options(com.sun.tools.javac.util.Options) ListBuffer(com.sun.tools.javac.util.ListBuffer) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 4 with Options

use of com.sun.tools.javac.util.Options in project ceylon-compiler by ceylon.

the class TestLog method test.

static void test(boolean genEndPos) throws IOException {
    Context context = new Context();
    Options options = Options.instance(context);
    options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m");
    Log log = Log.instance(context);
    log.multipleErrors = true;
    JavacFileManager.preRegister(context);
    ParserFactory pfac = ParserFactory.instance(context);
    final String text = "public class Foo {\n" + "  public static void main(String[] args) {\n" + "    if (args.length == 0)\n" + "      System.out.println(\"no args\");\n" + "    else\n" + "      System.out.println(args.length + \" args\");\n" + "  }\n" + "}\n";
    JavaFileObject fo = new StringJavaFileObject("Foo", text);
    log.useSource(fo);
    CharSequence cs = fo.getCharContent(true);
    Parser parser = pfac.newParser(cs, false, genEndPos, false);
    JCTree.JCCompilationUnit tree = parser.parseCompilationUnit();
    log.setEndPosTable(fo, tree.endPositions);
    TreeScanner ts = new LogTester(log, tree.endPositions);
    ts.scan(tree);
    check(log.nerrors, 4, "errors");
    check(log.nwarnings, 4, "warnings");
}
Also used : Context(com.sun.tools.javac.util.Context) Options(com.sun.tools.javac.util.Options) Log(com.sun.tools.javac.util.Log) JCTree(com.sun.tools.javac.tree.JCTree) ParserFactory(com.sun.tools.javac.parser.ParserFactory) Parser(com.sun.tools.javac.parser.Parser) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) JavaFileObject(javax.tools.JavaFileObject) TreeScanner(com.sun.tools.javac.tree.TreeScanner)

Example 5 with Options

use of com.sun.tools.javac.util.Options in project ceylon-compiler by ceylon.

the class A method getFileManager.

JavaFileManager getFileManager(String classpathProperty, boolean symFileKind, boolean zipFileIndexKind) throws IOException {
    Context ctx = new Context();
    Options options = Options.instance(ctx);
    options.put("useOptimizedZip", Boolean.toString(zipFileIndexKind == USE_ZIP_FILE_INDEX));
    if (symFileKind == IGNORE_SYMBOL_FILE)
        options.put("ignore.symbol.file", "true");
    JavacFileManager fm = new JavacFileManager(ctx, false, null);
    List<File> path = getPath(System.getProperty(classpathProperty));
    fm.setLocation(CLASS_PATH, path);
    return fm;
}
Also used : Context(com.sun.tools.javac.util.Context) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) Options(com.sun.tools.javac.util.Options)

Aggregations

Options (com.sun.tools.javac.util.Options)19 Context (com.sun.tools.javac.util.Context)8 JavacFileManager (com.sun.tools.javac.file.JavacFileManager)4 DefaultToolOptions (com.redhat.ceylon.common.config.DefaultToolOptions)3 JavacOption (com.sun.tools.javac.main.JavacOption)3 RecognizedOptions (com.sun.tools.javac.main.RecognizedOptions)3 File (java.io.File)3 IOException (java.io.IOException)3 ListBuffer (com.sun.tools.javac.util.ListBuffer)2 FileNotFoundException (java.io.FileNotFoundException)2 CeylonConfig (com.redhat.ceylon.common.config.CeylonConfig)1 ToolUsageError (com.redhat.ceylon.common.tool.ToolUsageError)1 Main (com.redhat.ceylon.compiler.java.launcher.Main)1 Lint (com.sun.tools.javac.code.Lint)1 Source (com.sun.tools.javac.code.Source)1 Target (com.sun.tools.javac.jvm.Target)1 JavaCompiler (com.sun.tools.javac.main.JavaCompiler)1 COption (com.sun.tools.javac.main.JavacOption.COption)1 HiddenOption (com.sun.tools.javac.main.JavacOption.HiddenOption)1 Option (com.sun.tools.javac.main.JavacOption.Option)1