Package com.sun.tools.javac.file

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


import java.util.Set;
import java.util.HashSet;

public class T6589361 {
    public static void main(String [] args) throws Exception {
        JavacFileManager fm = null;
        try {
            fm = new JavacFileManager(new Context(), false, null);
            Set<JavaFileObject.Kind> set = new HashSet<JavaFileObject.Kind>();
            set.add(JavaFileObject.Kind.CLASS);
            Iterable<JavaFileObject> files = fm.list(StandardLocation.PLATFORM_CLASS_PATH, "java.lang", set, false);
            for (JavaFileObject file : files) {
                // Note: Zip/Jar entry names use '/', not File.separator, but just to be sure,
                // we normalize the filename as well.
                if (file.getName().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
                    String str = fm.inferBinaryName(StandardLocation.CLASS_PATH, file);
                    if (!str.equals("java.lang.Object")) {
                        throw new AssertionError("Error in JavacFileManager.inferBinaryName method!");
                    }
                    else {
                        return;
                    }
                }
            }
        }
        finally {
            if (fm != null) {
                fm.close();
            }
        }
        throw new AssertionError("Could not find java/lang/Object.class while compiling");
    }
View Full Code Here


            }
           
            if (!filenames.isEmpty()) {
                // add filenames to fileObjects
                List<JavaFileObject> otherFiles = List.nil();
                JavacFileManager dfm = (JavacFileManager) fileManager;
                for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(filenames)) {
                    otherFiles = otherFiles.append(fo);
                }
                fileObjects = fileObjects.prependList(otherFiles);
            }
            if(fileObjects.isEmpty()){
View Full Code Here

    }

    private void compileJavaModule(String pathname, String... fileNames) throws Exception {
        CeyloncTool compiler = new CeyloncTool();
        List<String> options = Arrays.asList("-src", pathname, "-out", "build/ceylon-cars", "-cp", CompilerTest.getClassPathAsPath());
        JavacFileManager fileManager = compiler.getStandardFileManager(null, null, null);
        List<String> qualifiedNames = new ArrayList<String>(fileNames.length);
        for(String name : fileNames){
            qualifiedNames.add(pathname + File.separator + name);
        }
        Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromStrings(qualifiedNames);
        JavacTask task = compiler.getTask(null, null, null, options, null, fileObjects);
        Boolean ret = task.call();
        Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
    }
View Full Code Here

    private boolean isResource(JavaFileObject fo) {
        // make sure we get a proper normalized abslute path
        String fileName = FileUtil.absoluteFile(new File(fo.toUri().getPath())).getPath();
        // now see if it's in any of the resource paths
        JavacFileManager dfm = (JavacFileManager) fileManager;
        for (File dir : dfm.getLocation(CeylonLocation.RESOURCE_PATH)) {
            String prefix = FileUtil.absoluteFile(dir).getPath();
            if (fileName.startsWith(prefix)) {
                return true;
            }
        }
View Full Code Here

    // the module to which the resource files belong. So to try to fix that
    // we see if a module file exists in the source folders and add it to
    // the list of source files
    private List<JavaFileObject> addModuleDescriptors(List<JavaFileObject> sourceFiles, List<JavaFileObject> resourceFiles) {
        List<JavaFileObject> result = sourceFiles;
        JavacFileManager dfm = (JavacFileManager) fileManager;
        for (JavaFileObject fo : resourceFiles) {
            String resName = JarUtils.toPlatformIndependentPath(dfm.getLocation(CeylonLocation.RESOURCE_PATH), fo.getName());
            JavaFileObject moduleFile = findModuleDescriptorForFile(new File(resName));
            if (moduleFile != null && !result.contains(moduleFile)) {
                result = result.append(moduleFile);
            }
        }
View Full Code Here

        }
        return result;
    }

    private JavaFileObject findModuleDescriptorForFile(File file) {
        JavacFileManager dfm = (JavacFileManager) fileManager;
        File dir = file.getParentFile();
        while (dir != null) {
            try {
                String name = dir.getPath() + "/module";
                JavaFileObject fo = dfm.getJavaFileForInput(StandardLocation.SOURCE_PATH, name, Kind.SOURCE);
                if (fo != null) {
                    return fo;
                }
            } catch (IOException e) {
                // Ignore
View Full Code Here

        long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME);

        check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime);

        Context context = new Context();
        JavacFileManager fm = new JavacFileManager(context, false, null);
        ZipFileIndexArchive zfia = new ZipFileIndexArchive(fm, zfi);
        JavaFileObject jfo =
            zfia.getFileObject(TEST_ENTRY_NAME.dirname(),
                                   TEST_ENTRY_NAME.basename());
        long jfoTime = jfo.getLastModified();
View Full Code Here

    public static void main(String... args) throws Throwable {
        String self = T6358024.class.getName();

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

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

        test(fm, f,
             new Option[] { new Option("-d", ".")},
             7);
View Full Code Here

    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.getFileForInput(testSrc + File.separatorChar + self + ".java");

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

        test(fm, f, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self);
    }
View Full Code Here

        Charset charset) {
        Context context = new Context();
        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, diagnosticListener);
        context.put(Log.outKey, new PrintWriter(System.err, true)); // FIXME
        return new JavacFileManager(context, true, charset);
    }
View Full Code Here

TOP

Related Classes of com.sun.tools.javac.file.JavacFileManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.