Search in sources :

Example 51 with JavaFileObject

use of org.eclipse.ceylon.javax.tools.JavaFileObject 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 52 with JavaFileObject

use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.

the class CeylonModelLoader method loadClassInternal.

private boolean loadClassInternal(String quotedClassName) {
    try {
        Name name = names.fromString(quotedClassName);
        if (syms().classes.containsKey(name))
            return true;
        JavaFileObject fileObject = fileManager.getJavaFileForInput(PLATFORM_CLASS_PATH, quotedClassName, JavaFileObject.Kind.CLASS);
        if (fileObject == null) {
            fileObject = fileManager.getJavaFileForInput(CLASS_PATH, quotedClassName, JavaFileObject.Kind.CLASS);
        }
        if (fileObject != null) {
            reader.enterClass(name, fileObject);
            return true;
        }
        return false;
    } catch (IOException e) {
        // this is not normal, but will result in an error elsewhere, so just log it
        logVerbose("IOException loading class: " + e.getMessage());
        return false;
    }
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) IOException(java.io.IOException) Name(org.eclipse.ceylon.langtools.tools.javac.util.Name)

Example 53 with JavaFileObject

use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.

the class CeyloncFileManager method getJavaFileForInput.

@Override
public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException {
    nullCheck(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind " + kind);
    JavaFileObject file = getFileForInput(location, forClass(className, kind));
    if (file != null && file.getName().endsWith(".ceylon")) {
        return new CeylonFileObject(file);
    } else {
        return file;
    }
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)

Aggregations

JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)53 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)9 File (java.io.File)8 IOException (java.io.IOException)8 HashSet (java.util.HashSet)8 CeylonFileObject (org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)5 TaskEvent (org.eclipse.ceylon.langtools.source.util.TaskEvent)5 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)5 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)5 InputStream (java.io.InputStream)4 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)4 LinkedHashSet (java.util.LinkedHashSet)3 VirtualFile (org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)3 JavacFileManager (org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager)3 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)3 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 PrintWriter (java.io.PrintWriter)2 ByteBuffer (java.nio.ByteBuffer)2 CharBuffer (java.nio.CharBuffer)2