Java Code Examples for com.sun.tools.javac.util.ClientCodeException#getCause()

The following examples show how to use com.sun.tools.javac.util.ClientCodeException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavadocTaskImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Boolean call() {
    if (!used.getAndSet(true)) {
        initContext();
        Start jdoc = new Start(context);
        try {
            return jdoc.begin(docletClass, options, fileObjects);
        } catch (ClientCodeException e) {
            throw new RuntimeException(e.getCause());
        }
    } else {
        throw new IllegalStateException("multiple calls to method 'call'");
    }
}
 
Example 2
Source File: JavadocTaskImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Boolean call() {
    if (!used.getAndSet(true)) {
        initContext();
        Start jdoc = new Start(context);
        try {
            return jdoc.begin(docletClass, options, fileObjects);
        } catch (ClientCodeException e) {
            throw new RuntimeException(e.getCause());
        }
    } else {
        throw new IllegalStateException("multiple calls to method 'call'");
    }
}
 
Example 3
Source File: JavadocTaskImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Boolean call() {
    if (!used.getAndSet(true)) {
        initContext();
        Start jdoc = new Start(context);
        try {
            return jdoc.begin(docletClass, options, fileObjects);
        } catch (ClientCodeException e) {
            throw new RuntimeException(e.getCause());
        }
    } else {
        throw new IllegalStateException("multiple calls to method 'call'");
    }
}
 
Example 4
Source File: JavadocTaskImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Boolean call() {
    if (!used.getAndSet(true)) {
        initContext();
        Start jdoc = new Start(context);
        try {
            return jdoc.begin(docletClass, options, fileObjects);
        } catch (ClientCodeException e) {
            throw new RuntimeException(e.getCause());
        }
    } else {
        throw new IllegalStateException("multiple calls to method 'call'");
    }
}
 
Example 5
Source File: JavadocTaskImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Boolean call() {
    if (!used.getAndSet(true)) {
        initContext();
        Start jdoc = new Start(context);
        try {
            return jdoc.begin(docletClass, options, fileObjects);
        } catch (ClientCodeException e) {
            throw new RuntimeException(e.getCause());
        }
    } else {
        throw new IllegalStateException("multiple calls to method 'call'");
    }
}
 
Example 6
Source File: JavadocTaskImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Boolean call() {
    if (!used.getAndSet(true)) {
        initContext();
        Start jdoc = new Start(context);
        try {
            return jdoc.begin(docletClass, options, fileObjects);
        } catch (ClientCodeException e) {
            throw new RuntimeException(e.getCause());
        }
    } else {
        throw new IllegalStateException("multiple calls to method 'call'");
    }
}
 
Example 7
Source File: JavadocTaskImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Boolean call() {
    if (!used.getAndSet(true)) {
        initContext();
        Start jdoc = new Start(context);
        try {
            return jdoc.begin(docletClass, options, fileObjects);
        } catch (ClientCodeException e) {
            throw new RuntimeException(e.getCause());
        }
    } else {
        throw new IllegalStateException("multiple calls to method 'call'");
    }
}
 
Example 8
Source File: JavadocTool.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public DocumentationTask getTask(
        Writer out,
        JavaFileManager fileManager,
        DiagnosticListener<? super JavaFileObject> diagnosticListener,
        Class<?> docletClass,
        Iterable<String> options,
        Iterable<? extends JavaFileObject> compilationUnits,
        Context context) {
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null) {
            for (String option : options)
                option.getClass(); // null check
        }

        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    final String kindMsg = "All compilation units must be of SOURCE kind";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else if (out instanceof PrintWriter)
            context.put(Log.outKey, ((PrintWriter) out));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);

        return new JavadocTaskImpl(context, docletClass, options, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 9
Source File: JavadocTool.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public DocumentationTask getTask(
        Writer out,
        JavaFileManager fileManager,
        DiagnosticListener<? super JavaFileObject> diagnosticListener,
        Class<?> docletClass,
        Iterable<String> options,
        Iterable<? extends JavaFileObject> compilationUnits,
        Context context) {
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null) {
            for (String option : options)
                option.getClass(); // null check
        }

        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    final String kindMsg = "All compilation units must be of SOURCE kind";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else if (out instanceof PrintWriter)
            context.put(Log.outKey, ((PrintWriter) out));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);

        return new JavadocTaskImpl(context, docletClass, options, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 10
Source File: JavadocTool.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public DocumentationTask getTask(
        Writer out,
        JavaFileManager fileManager,
        DiagnosticListener<? super JavaFileObject> diagnosticListener,
        Class<?> docletClass,
        Iterable<String> options,
        Iterable<? extends JavaFileObject> compilationUnits,
        Context context) {
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null) {
            for (String option : options)
                option.getClass(); // null check
        }

        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    final String kindMsg = "All compilation units must be of SOURCE kind";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else if (out instanceof PrintWriter)
            context.put(Log.outKey, ((PrintWriter) out));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);

        return new JavadocTaskImpl(context, docletClass, options, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 11
Source File: JavadocTool.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public DocumentationTask getTask(
        Writer out,
        JavaFileManager fileManager,
        DiagnosticListener<? super JavaFileObject> diagnosticListener,
        Class<?> docletClass,
        Iterable<String> options,
        Iterable<? extends JavaFileObject> compilationUnits,
        Context context) {
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null) {
            for (String option : options)
                option.getClass(); // null check
        }

        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    final String kindMsg = "All compilation units must be of SOURCE kind";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else if (out instanceof PrintWriter)
            context.put(Log.outKey, ((PrintWriter) out));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);

        return new JavadocTaskImpl(context, docletClass, options, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 12
Source File: JavacTool.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public JavacTask getTask(Writer out,
                         JavaFileManager fileManager,
                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
                         Iterable<String> options,
                         Iterable<String> classes,
                         Iterable<? extends JavaFileObject> compilationUnits)
{
    try {
        Context context = new Context();
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        final String kindMsg = "All compilation units must be of SOURCE kind";
        if (options != null)
            for (String option : options)
                option.getClass(); // null check
        if (classes != null) {
            for (String cls : classes)
                if (!SourceVersion.isName(cls)) // implicit null check
                    throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE)
                    throw new IllegalArgumentException(kindMsg);
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);
        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 13
Source File: JavacTool.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public JavacTask getTask(Writer out,
                         JavaFileManager fileManager,
                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
                         Iterable<String> options,
                         Iterable<String> classes,
                         Iterable<? extends JavaFileObject> compilationUnits,
                         Context context)
{
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null)
            for (String option : options)
                option.getClass(); // null check
        if (classes != null) {
            for (String cls : classes)
                if (!SourceVersion.isName(cls)) // implicit null check
                    throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    String kindMsg = "Compilation unit is not of SOURCE kind: "
                            + "\"" + cu.getName() + "\"";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);

        context.put(JavaFileManager.class, fileManager);

        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 14
Source File: JavacTool.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public JavacTask getTask(Writer out,
                         JavaFileManager fileManager,
                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
                         Iterable<String> options,
                         Iterable<String> classes,
                         Iterable<? extends JavaFileObject> compilationUnits,
                         Context context)
{
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null)
            for (String option : options)
                option.getClass(); // null check
        if (classes != null) {
            for (String cls : classes)
                if (!SourceVersion.isName(cls)) // implicit null check
                    throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    String kindMsg = "Compilation unit is not of SOURCE kind: "
                            + "\"" + cu.getName() + "\"";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);

        context.put(JavaFileManager.class, fileManager);

        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 15
Source File: JavadocTool.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public DocumentationTask getTask(
        Writer out,
        JavaFileManager fileManager,
        DiagnosticListener<? super JavaFileObject> diagnosticListener,
        Class<?> docletClass,
        Iterable<String> options,
        Iterable<? extends JavaFileObject> compilationUnits,
        Context context) {
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null) {
            for (String option : options)
                option.getClass(); // null check
        }

        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    final String kindMsg = "All compilation units must be of SOURCE kind";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else if (out instanceof PrintWriter)
            context.put(Log.outKey, ((PrintWriter) out));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);

        return new JavadocTaskImpl(context, docletClass, options, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 16
Source File: JavacTool.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public JavacTask getTask(Writer out,
                         JavaFileManager fileManager,
                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
                         Iterable<String> options,
                         Iterable<String> classes,
                         Iterable<? extends JavaFileObject> compilationUnits,
                         Context context)
{
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null)
            for (String option : options)
                option.getClass(); // null check
        if (classes != null) {
            for (String cls : classes)
                if (!SourceVersion.isName(cls)) // implicit null check
                    throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    String kindMsg = "Compilation unit is not of SOURCE kind: "
                            + "\"" + cu.getName() + "\"";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);

        context.put(JavaFileManager.class, fileManager);

        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 17
Source File: JavacTool.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public JavacTask getTask(Writer out,
                         JavaFileManager fileManager,
                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
                         Iterable<String> options,
                         Iterable<String> classes,
                         Iterable<? extends JavaFileObject> compilationUnits,
                         Context context)
{
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null)
            for (String option : options)
                option.getClass(); // null check
        if (classes != null) {
            for (String cls : classes)
                if (!SourceVersion.isName(cls)) // implicit null check
                    throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    String kindMsg = "Compilation unit is not of SOURCE kind: "
                            + "\"" + cu.getName() + "\"";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);

        context.put(JavaFileManager.class, fileManager);

        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 18
Source File: JavadocTool.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public DocumentationTask getTask(
        Writer out,
        JavaFileManager fileManager,
        DiagnosticListener<? super JavaFileObject> diagnosticListener,
        Class<?> docletClass,
        Iterable<String> options,
        Iterable<? extends JavaFileObject> compilationUnits,
        Context context) {
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null) {
            for (String option : options)
                option.getClass(); // null check
        }

        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    final String kindMsg = "All compilation units must be of SOURCE kind";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else if (out instanceof PrintWriter)
            context.put(Log.outKey, ((PrintWriter) out));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);

        return new JavadocTaskImpl(context, docletClass, options, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 19
Source File: JavacTool.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public JavacTask getTask(Writer out,
                         JavaFileManager fileManager,
                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
                         Iterable<String> options,
                         Iterable<String> classes,
                         Iterable<? extends JavaFileObject> compilationUnits,
                         Context context)
{
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null)
            for (String option : options)
                option.getClass(); // null check
        if (classes != null) {
            for (String cls : classes)
                if (!SourceVersion.isName(cls)) // implicit null check
                    throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    String kindMsg = "Compilation unit is not of SOURCE kind: "
                            + "\"" + cu.getName() + "\"";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);

        context.put(JavaFileManager.class, fileManager);

        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
 
Example 20
Source File: JavacTool.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public JavacTask getTask(Writer out,
                         JavaFileManager fileManager,
                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
                         Iterable<String> options,
                         Iterable<String> classes,
                         Iterable<? extends JavaFileObject> compilationUnits,
                         Context context)
{
    try {
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);

        if (options != null)
            for (String option : options)
                option.getClass(); // null check
        if (classes != null) {
            for (String cls : classes)
                if (!SourceVersion.isName(cls)) // implicit null check
                    throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE) {
                    String kindMsg = "Compilation unit is not of SOURCE kind: "
                            + "\"" + cu.getName() + "\"";
                    throw new IllegalArgumentException(kindMsg);
                }
            }
        }

        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));

        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));

        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);

        context.put(JavaFileManager.class, fileManager);

        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}