com.sun.tools.javac.file.JavacFileManager Java Examples

The following examples show how to use com.sun.tools.javac.file.JavacFileManager. 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 Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #2
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #3
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an empty processor iterator if no processors are on the
 * relevant path, otherwise if processors are present, logs an
 * error.  Called when a service loader is unavailable for some
 * reason, either because a service loader class cannot be found
 * or because a security policy prevents class loaders from being
 * created.
 *
 * @param key The resource key to use to log an error message
 * @param e   If non-null, pass this exception to Abort
 */
private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
    JavaFileManager fileManager = context.get(JavaFileManager.class);

    if (fileManager instanceof JavacFileManager) {
        StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
        Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
            ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
            : standardFileManager.getLocation(CLASS_PATH);

        if (needClassLoader(options.get(PROCESSOR), workingPath) )
            handleException(key, e);

    } else {
        handleException(key, e);
    }

    java.util.List<Processor> pl = Collections.emptyList();
    return pl.iterator();
}
 
Example #4
Source Project: openjdk-8-source   Author: keerath   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Throwable {

        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
        JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java");

        try {
            // first, test case with no annotation processing
            testNoAnnotationProcessing(fm, f);

            // now, test case with annotation processing
            testAnnotationProcessing(fm, f);
        }
        catch (Throwable t) {
            AssertionError e = new AssertionError();
            e.initCause(t);
            throw e;
        }
    }
 
Example #5
Source Project: openjdk-8   Author: bpupadhyaya   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #6
Source Project: TencentKona-8   Author: Tencent   File: JavadocTaskImplTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDirectAccess1() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    StandardJavaFileManager fm = new JavacFileManager(c, true, null);
    File outDir = getOutDir();
    fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
    if (t.call()) {
        System.err.println("task succeeded");
    } else {
        throw new Exception("task failed");
    }
}
 
Example #7
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JavadocTaskImplTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDirectAccess1() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    StandardJavaFileManager fm = new JavacFileManager(c, true, null);
    File outDir = getOutDir();
    fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
    if (t.call()) {
        System.err.println("task succeeded");
    } else {
        throw new Exception("task failed");
    }
}
 
Example #8
Source Project: TencentKona-8   Author: Tencent   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: StarImportTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Setup env by creating pseudo-random collection of names, packages and classes.
 */
void setup() {
    log ("setup");
    context = new Context();
    JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab
    make = TreeMaker.instance(context);
    names = Names.instance(context);       // Name.Table impls tied to an instance of Names
    symtab = Symtab.instance(context);
    types = Types.instance(context);
    int setupCount = rgen.nextInt(MAX_SETUP_COUNT);
    for (int i = 0; i < setupCount; i++) {
        switch (random(SetupKind.values())) {
            case NAMES:
                setupNames();
                break;
            case PACKAGE:
                setupPackage();
                break;
            case CLASS:
                setupClass();
                break;
        }
    }
}
 
Example #10
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Throwable {

        JavacFileManager fm = new JavacFileManager(new Context(), false, null);
        JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java");

        try {
            // first, test case with no annotation processing
            testNoAnnotationProcessing(fm, f);

            // now, test case with annotation processing
            testAnnotationProcessing(fm, f);
        }
        catch (Throwable t) {
            AssertionError e = new AssertionError();
            e.initCause(t);
            throw e;
        }
    }
 
Example #11
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: JavacTool.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override @DefinedBy(Api.COMPILER)
public JavacFileManager getStandardFileManager(
    DiagnosticListener<? super JavaFileObject> diagnosticListener,
    Locale locale,
    Charset charset) {
    Context context = new Context();
    context.put(Locale.class, locale);
    if (diagnosticListener != null)
        context.put(DiagnosticListener.class, diagnosticListener);
    PrintWriter pw = (charset == null)
            ? new PrintWriter(System.err, true)
            : new PrintWriter(new OutputStreamWriter(System.err, charset), true);
    context.put(Log.errKey, pw);
    CacheFSInfo.preRegister(context);
    return new JavacFileManager(context, true, charset);
}
 
Example #12
Source Project: openjdk-8-source   Author: keerath   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an empty processor iterator if no processors are on the
 * relevant path, otherwise if processors are present, logs an
 * error.  Called when a service loader is unavailable for some
 * reason, either because a service loader class cannot be found
 * or because a security policy prevents class loaders from being
 * created.
 *
 * @param key The resource key to use to log an error message
 * @param e   If non-null, pass this exception to Abort
 */
private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
    JavaFileManager fileManager = context.get(JavaFileManager.class);

    if (fileManager instanceof JavacFileManager) {
        StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
        Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
            ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
            : standardFileManager.getLocation(CLASS_PATH);

        if (needClassLoader(options.get(PROCESSOR), workingPath) )
            handleException(key, e);

    } else {
        handleException(key, e);
    }

    java.util.List<Processor> pl = Collections.emptyList();
    return pl.iterator();
}
 
Example #13
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: MakeLiteralTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);

    test("abc",                     CLASS,      syms.stringType,    "abc");
    test(Boolean.FALSE,             BOOLEAN,    syms.booleanType,   Integer.valueOf(0));
    test(Boolean.TRUE,              BOOLEAN,    syms.booleanType,   Integer.valueOf(1));
    test(Byte.valueOf((byte) 1),    BYTE,       syms.byteType,      Byte.valueOf((byte) 1));
    test(Character.valueOf('a'),    CHAR,       syms.charType,      Integer.valueOf('a'));
    test(Double.valueOf(1d),        DOUBLE,     syms.doubleType,    Double.valueOf(1d));
    test(Float.valueOf(1f),         FLOAT,      syms.floatType,     Float.valueOf(1f));
    test(Integer.valueOf(1),        INT,        syms.intType,       Integer.valueOf(1));
    test(Long.valueOf(1),           LONG,       syms.longType,      Long.valueOf(1));
    test(Short.valueOf((short) 1),  SHORT,      syms.shortType,     Short.valueOf((short) 1));

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
Example #14
Source Project: openjdk-8-source   Author: keerath   File: StarImportTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Setup env by creating pseudo-random collection of names, packages and classes.
 */
void setup() {
    log ("setup");
    context = new Context();
    JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab
    names = Names.instance(context);       // Name.Table impls tied to an instance of Names
    symtab = Symtab.instance(context);
    int setupCount = rgen.nextInt(MAX_SETUP_COUNT);
    for (int i = 0; i < setupCount; i++) {
        switch (random(SetupKind.values())) {
            case NAMES:
                setupNames();
                break;
            case PACKAGE:
                setupPackage();
                break;
            case CLASS:
                setupClass();
                break;
        }
    }
}
 
Example #15
Source Project: jdk8u60   Author: chenghanpeng   File: JavadocTaskImplTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDirectAccess2() throws Exception {
    JavaFileObject srcFile = null; // error, provokes NPE
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    Context c = new Context();
    Messager.preRegister(c, "javadoc");
    StandardJavaFileManager fm = new JavacFileManager(c, true, null);
    File outDir = getOutDir();
    fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    try {
        DocumentationTask t = new JavadocTaskImpl(c, null, null, files);;
        error("getTask succeeded, no exception thrown");
    } catch (NullPointerException e) {
        System.err.println("exception caught as expected: " + e);
    }
}
 
Example #16
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: T6725036.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class");

    File testJar = createJar("test.jar", "java.lang.*");

    try (JarFile j = new JarFile(testJar)) {
        JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath());
        long jarEntryTime = je.getTime();

        Context context = new Context();
        JavacFileManager fm = new JavacFileManager(context, false, null);
        fm.setLocation(StandardLocation.CLASS_PATH, Collections.singletonList(testJar));
        FileObject fo =
            fm.getFileForInput(StandardLocation.CLASS_PATH, "", TEST_ENTRY_NAME.getPath());
        long jfoTime = fo.getLastModified();

        check(je, jarEntryTime, fo, jfoTime);

        if (errors > 0)
            throw new Exception(errors + " occurred");
    }
}
 
Example #17
Source Project: hottub   Author: dsrg-uoft   File: T6358166.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example #18
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: InferenceRegressionTest02.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Trees trees = JavacTrees.instance(context);
    StringWriter strOut = new StringWriter();
    PrintWriter pw = new PrintWriter(strOut);
    DPrinter dprinter = new DPrinter(pw, trees);
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource()));
    Iterable<? extends CompilationUnitTree> elements = ct.parse();
    ct.analyze();
    Assert.check(elements.iterator().hasNext());
    dprinter.treeTypes(true).printTree("", (JCTree)elements.iterator().next());
    String output = strOut.toString();
    Assert.check(!output.contains("java.lang.Object"), "there shouldn't be any type instantiated to Object");
}
 
Example #19
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: T6358166.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Throwable {
    String self = T6358166.class.getName();

    String testSrc = System.getProperty("test.src");

    JavacFileManager fm = new JavacFileManager(new Context(), false, null);
    JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + self + ".java");

    List<String> addExports = Arrays.asList(
            "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
            "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
            "--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
            "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED");

    test(fm, f, addExports, "-verbose", "-d", ".");

    test(fm, f, addExports, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self);
}
 
Example #20
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: JavaCompiler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Try to open input stream with given name.
 * Report an error if this fails.
 *
 * @param filename The file name of the input stream to be opened.
 */
public CharSequence readSource(JavaFileObject filename) {
    try {
        inputFiles.add(filename);
        return filename.getCharContent(false);
    } catch (IOException e) {
        log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
        return null;
    }
}
 
Example #21
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Example.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) {
    if (out != null && keys != null)
        throw new IllegalArgumentException();

    if (verbose)
        System.err.println("run_simple: " + opts + " " + files);

    List<String> args = new ArrayList<String>();

    if (out != null && raw)
        args.add("-XDrawDiagnostics");

    args.addAll(opts);
    for (File f: files)
        args.add(f.getPath());

    StringWriter sw = null;
    PrintWriter pw;
    if (keys != null) {
        sw = new StringWriter();
        pw = new PrintWriter(sw);
    } else
        pw = out;

    Context c = new Context();
    JavacFileManager.preRegister(c); // can't create it until Log has been set up
    MessageTracker.preRegister(c, keys);
    Main m = new Main("javac", pw);
    Main.Result rc = m.compile(args.toArray(new String[args.size()]), c);

    if (keys != null) {
        pw.close();
    }

    return rc.isOK();
}
 
Example #22
Source Project: TencentKona-8   Author: Tencent   File: Main.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Programmatic interface for main function.
 * @param args    The command line parameters.
 */
public Result compile(String[] args) {
    Context context = new Context();
    JavacFileManager.preRegister(context); // can't create it until Log has been set up
    Result result = compile(args, context);
    if (fileManager instanceof JavacFileManager) {
        // A fresh context was created above, so jfm must be a JavacFileManager
        ((JavacFileManager)fileManager).close();
    }
    return result;
}
 
Example #23
Source Project: lua-for-android   Author: qtiuto   File: DiagnosticSource.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected char[] initBuf(JavaFileObject fileObject) throws IOException {
    char[] buf;
    CharSequence cs = fileObject.getCharContent(true);
    if (cs instanceof CharBuffer) {
        CharBuffer cb = (CharBuffer) cs;
        buf = JavacFileManager.toArray(cb);
        bufLen = cb.limit();
    } else {
        buf = cs.toString().toCharArray();
        bufLen = buf.length;
    }
    refBuf = new SoftReference<>(buf);
    return buf;
}
 
Example #24
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TestName.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    final boolean PACKAGE = true;
    final boolean CLASS = true;
    JavacFileManager.testName("", PACKAGE, !CLASS);
    JavacFileManager.testName(".", !PACKAGE, !CLASS);
    JavacFileManager.testName("java.lang.", !PACKAGE, !CLASS);
    JavacFileManager.testName(".java.lang.", !PACKAGE, !CLASS);
    JavacFileManager.testName(".java.lang", !PACKAGE, !CLASS);
    JavacFileManager.testName("java.lang", PACKAGE, CLASS);
    JavacFileManager.testName("java.lang.Foo Bar", !PACKAGE, !CLASS);
    JavacFileManager.testName("java.lang.Foo+Bar", !PACKAGE, !CLASS);
    JavacFileManager.testName("java.lang.Foo$Bar", PACKAGE, CLASS);
    JavacFileManager.testName("Peter.von.der.Ah\u00e9", PACKAGE, CLASS);
}
 
Example #25
Source Project: hottub   Author: dsrg-uoft   File: GetDeps.java    License: GNU General Public License v2.0 5 votes vote down vote up
void run(PrintWriter out, String... args) throws IOException, ClassFileNotFoundException {
    decodeArgs(args);

    final StandardJavaFileManager fm = new JavacFileManager(new Context(), false, null);
    if (classpath != null)
        fm.setLocation(StandardLocation.CLASS_PATH, classpath);

    ClassFileReader reader = new ClassFileReader(fm);

    Dependencies d = new Dependencies();

    if (regex != null)
        d.setFilter(Dependencies.getRegexFilter(Pattern.compile(regex)));

    if (packageNames.size() > 0)
        d.setFilter(Dependencies.getPackageFilter(packageNames, false));

    SortedRecorder r = new SortedRecorder(reverse);

    d.findAllDependencies(reader, rootClassNames, transitiveClosure, r);

    SortedMap<Location,SortedSet<Dependency>> deps = r.getMap();
    for (Map.Entry<Location, SortedSet<Dependency>> e: deps.entrySet()) {
        out.println(e.getKey());
        for (Dependency dep: e.getValue()) {
            out.println("    " + dep.getTarget());
        }
    }
}
 
Example #26
Source Project: javaide   Author: tranleduy2000   File: Main.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Programmatic interface for main function.
 *
 * @param args The command line parameters.
 */
public int compile(String[] args) {
    Context context = new Context();
    JavacFileManager.preRegister(context); // can't create it until Log has been set up
    int result = compile(args, context);
    if (fileManager instanceof JavacFileManager) {
        // A fresh context was created above, so jfm must be a JavacFileManager
        ((JavacFileManager) fileManager).close();
    }
    return result;
}
 
Example #27
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Arguments.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the files to be compiled.
 * @return the files to be compiled
 */
public Set<JavaFileObject> getFileObjects() {
    if (fileObjects == null) {
        fileObjects = new LinkedHashSet<>();
    }
    if (files != null) {
        JavacFileManager jfm = (JavacFileManager) getFileManager();
        for (JavaFileObject fo: jfm.getJavaFileObjectsFromPaths(files))
            fileObjects.add(fo);
    }
    return fileObjects;
}
 
Example #28
Source Project: hottub   Author: dsrg-uoft   File: TestName.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    final boolean PACKAGE = true;
    final boolean CLASS = true;
    JavacFileManager.testName("", PACKAGE, !CLASS);
    JavacFileManager.testName(".", !PACKAGE, !CLASS);
    JavacFileManager.testName("java.lang.", !PACKAGE, !CLASS);
    JavacFileManager.testName(".java.lang.", !PACKAGE, !CLASS);
    JavacFileManager.testName(".java.lang", !PACKAGE, !CLASS);
    JavacFileManager.testName("java.lang", PACKAGE, CLASS);
    JavacFileManager.testName("java.lang.Foo Bar", !PACKAGE, !CLASS);
    JavacFileManager.testName("java.lang.Foo+Bar", !PACKAGE, !CLASS);
    JavacFileManager.testName("java.lang.Foo$Bar", PACKAGE, CLASS);
    JavacFileManager.testName("Peter.von.der.Ah\u00e9", PACKAGE, CLASS);
}
 
Example #29
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JavadocTool.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public StandardJavaFileManager getStandardFileManager(
        DiagnosticListener<? super JavaFileObject> diagnosticListener,
        Locale locale,
        Charset charset) {
    Context context = new Context();
    context.put(Locale.class, locale);
    if (diagnosticListener != null)
        context.put(DiagnosticListener.class, diagnosticListener);
    PrintWriter pw = (charset == null)
            ? new PrintWriter(System.err, true)
            : new PrintWriter(new OutputStreamWriter(System.err, charset), true);
    context.put(Log.outKey, pw);
    return new JavacFileManager(context, true, charset);
}
 
Example #30
Source Project: openjdk-8-source   Author: keerath   File: T6625520.java    License: GNU General Public License v2.0 5 votes vote down vote up
void run() throws Exception {
    Context c = new Context();
    DiagnosticCollector<JavaFileObject> dc =
        new DiagnosticCollector<JavaFileObject>();
    c.put(DiagnosticListener.class, dc);
    StandardJavaFileManager fm = new JavacFileManager(c, false, null);
    fm.setLocation(StandardLocation.CLASS_PATH,
                   Arrays.asList(new File("DOES_NOT_EXIST.jar")));
    FileObject fo = fm.getFileForInput(StandardLocation.CLASS_PATH,
                                       "p", "C.java");
    System.err.println(fo + "\n" + dc.getDiagnostics());
    if (dc.getDiagnostics().size() > 0)
        throw new Exception("unexpected diagnostics found");
}