Search in sources :

Example 6 with JavacFileManager

use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.

the class LanguageCompiler method getSrcDir.

// FIXME: this function is terrible, possibly refactor it with getPackage?
private File getSrcDir(File sourceFile) throws IOException {
    Iterable<? extends File> prefixes = ((JavacFileManager) fileManager).getLocation(StandardLocation.SOURCE_PATH);
    File srcDirFile = FileUtil.selectPath(prefixes, sourceFile.getPath());
    if (srcDirFile != null) {
        return srcDirFile;
    } else {
        // This error should have been caught by the tool chain
        throw new RuntimeException(sourceFile.getPath() + " is not in the current source path");
    }
}
Also used : JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 7 with JavacFileManager

use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.

the class LanguageCompiler method addModuleDescriptors.

// This is a bit of a hack, but if we got passed a list of resources
// without any accompaning source files we'll not be able to determine
// 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);
        }
    }
    return result;
}
Also used : JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 8 with JavacFileManager

use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.

the class LanguageCompiler method findModuleDescriptorForFile.

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
        }
        dir = dir.getParentFile();
    }
    return null;
}
Also used : JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) IOException(java.io.IOException) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 9 with JavacFileManager

use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.

the class LanguageCompiler method isResource.

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;
        }
    }
    return false;
}
Also used : JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 10 with JavacFileManager

use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.

the class LanguageCompiler method getPackage.

private String getPackage(JavaFileObject file) throws IOException {
    Iterable<? extends File> prefixes = ((JavacFileManager) fileManager).getLocation(StandardLocation.SOURCE_PATH);
    // Figure out the package name by stripping the "-src" prefix and
    // extracting
    // the package part of the fullname.
    String filePath = file.toUri().getPath();
    // go absolute
    filePath = new File(filePath).getCanonicalPath();
    int srcDirLength = 0;
    for (File prefixFile : prefixes) {
        String prefix = prefixFile.getCanonicalPath();
        if (filePath.startsWith(prefix) && prefix.length() > srcDirLength) {
            srcDirLength = prefix.length();
        }
    }
    if (srcDirLength > 0) {
        String fullname = filePath.substring(srcDirLength);
        assert fullname.endsWith(".ceylon");
        fullname = fullname.substring(0, fullname.length() - ".ceylon".length());
        fullname = fullname.replace(File.separator, ".");
        if (fullname.startsWith("."))
            fullname = fullname.substring(1);
        String packageName = Convert.packagePart(fullname);
        if (!packageName.equals(""))
            return packageName;
    }
    return null;
}
Also used : JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Aggregations

JavacFileManager (org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager)12 File (java.io.File)7 VirtualFile (org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)5 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)4 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)3 JavaFileManager (org.eclipse.ceylon.javax.tools.JavaFileManager)3 CeyloncTool (org.eclipse.ceylon.compiler.java.tools.CeyloncTool)2 JavacTask (org.eclipse.ceylon.langtools.source.util.JavacTask)2 AnnotationProcessingError (org.eclipse.ceylon.langtools.tools.javac.processing.AnnotationProcessingError)2 Context (org.eclipse.ceylon.langtools.tools.javac.util.Context)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Overrides (org.eclipse.ceylon.cmr.api.Overrides)1 ExitState (org.eclipse.ceylon.compiler.java.launcher.Main.ExitState)1 CeyloncTaskImpl (org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl)1 org.eclipse.ceylon.javax.lang.model.util (org.eclipse.ceylon.javax.lang.model.util)1