Search in sources :

Example 6 with VirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.VirtualFile in project ceylon by eclipse.

the class JsCompiler method findFile.

VirtualFile findFile(File path) {
    for (VirtualFile root : srcDirectories) {
        String p = path.getPath().replace(File.separator, "/");
        String r = root.getPath();
        if (p.startsWith(r)) {
            File relPath = new File(p.substring(r.length() + 1));
            VirtualFile f = findFile(root, relPath);
            if (f != null) {
                return f;
            }
        }
    }
    return null;
}
Also used : VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 7 with VirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.VirtualFile in project ceylon by eclipse.

the class JsCompiler method getStitchedFile.

VirtualFile getStitchedFile(final Declaration d, final String suffix) {
    String fqn = d.getQualifiedNameString();
    String name = d.getName();
    if (name == null && d instanceof Constructor) {
        name = "default$constructor";
        if (fqn.endsWith(".null")) {
            fqn = fqn.substring(0, fqn.length() - 4);
        }
        fqn = fqn + name;
    }
    if (fqn.startsWith("ceylon.language")) {
        fqn = fqn.substring(15);
    }
    if (fqn.startsWith("::")) {
        fqn = fqn.substring(2);
    }
    fqn = fqn.replace('.', '/').replace("::", "/");
    File path;
    if (isCompilingLanguageModule()) {
        path = new File(Stitcher.LANGMOD_JS_SRC, fqn + suffix);
    } else {
        PhasedUnit pu = tc.getPhasedUnitFromRelativePath(d.getUnit().getRelativePath());
        path = new File(getFullPath(pu).getParentFile(), name + suffix);
    }
    return findFile(path);
}
Also used : Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 8 with VirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.VirtualFile in project ceylon by eclipse.

the class JsCompiler method findFile.

private VirtualFile findFile(VirtualFile root, File path) {
    VirtualFile result = root;
    String[] parts = path.getPath().split(Pattern.quote(File.separator));
    outer: for (String p : parts) {
        if (p.equals("."))
            continue;
        for (VirtualFile f : result.getChildren()) {
            if (f.getName().equals(p)) {
                result = f;
                continue outer;
            }
        }
        return null;
    }
    return result;
}
Also used : VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)

Example 9 with VirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.VirtualFile in project ceylon by eclipse.

the class PhasedUnits method parseUnits.

public void parseUnits(List<VirtualFile> srcDirectories) {
    this.srcDirectories = srcDirectories;
    for (VirtualFile file : srcDirectories) {
        parseUnit(file, file);
    }
    this.srcDirectories = null;
}
Also used : VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)

Example 10 with VirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.VirtualFile in project ceylon by eclipse.

the class LanguageCompiler method ceylonParse.

private JCCompilationUnit ceylonParse(JavaFileObject filename, CharSequence readSource) {
    if (ceylonEnter.hasRun())
        throw new RunTwiceException("Trying to load new source file after CeylonEnter has been called: " + filename);
    try {
        ModuleManager moduleManager = phasedUnits.getModuleManager();
        ModuleSourceMapper moduleSourceMapper = phasedUnits.getModuleSourceMapper();
        File sourceFile = new File(filename.getName());
        // FIXME: temporary solution
        VirtualFile file = vfs.getFromFile(sourceFile);
        VirtualFile srcDir = vfs.getFromFile(getSrcDir(sourceFile));
        String source = readSource.toString();
        char[] chars = source.toCharArray();
        LineMap map = Position.makeLineMap(chars, chars.length, false);
        PhasedUnit phasedUnit = null;
        PhasedUnit externalPhasedUnit = compilerDelegate.getExternalSourcePhasedUnit(srcDir, file);
        String suppressWarnings = options.get(Option.CEYLONSUPPRESSWARNINGS);
        final EnumSet<Warning> suppressedWarnings;
        if (suppressWarnings != null) {
            if (suppressWarnings.trim().isEmpty()) {
                suppressedWarnings = EnumSet.allOf(Warning.class);
            } else {
                suppressedWarnings = EnumSet.noneOf(Warning.class);
                for (String name : suppressWarnings.trim().split(" *, *")) {
                    suppressedWarnings.add(Warning.valueOf(name));
                }
            }
        } else {
            suppressedWarnings = EnumSet.noneOf(Warning.class);
        }
        if (externalPhasedUnit != null) {
            phasedUnit = new CeylonPhasedUnit(externalPhasedUnit, filename, map);
            phasedUnit.setSuppressedWarnings(suppressedWarnings);
            phasedUnits.addPhasedUnit(externalPhasedUnit.getUnitFile(), phasedUnit);
            gen.setMap(map);
            String pkgName = phasedUnit.getPackage().getQualifiedNameString();
            if ("".equals(pkgName)) {
                pkgName = null;
            }
            return gen.makeJCCompilationUnitPlaceholder(phasedUnit.getCompilationUnit(), filename, pkgName, phasedUnit);
        }
        if (phasedUnit == null) {
            ANTLRStringStream input = new NewlineFixingStringStream(source);
            CeylonLexer lexer = new CeylonLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(new CeylonInterpolatingLexer(lexer));
            CeylonParser parser = new CeylonParser(tokens);
            CompilationUnit cu = parser.compilationUnit();
            java.util.List<LexError> lexerErrors = lexer.getErrors();
            for (LexError le : lexerErrors) {
                printError(le, le.getMessage(), "ceylon.lexer", map);
            }
            java.util.List<ParseError> parserErrors = parser.getErrors();
            for (ParseError pe : parserErrors) {
                printError(pe, pe.getMessage(), "ceylon.parser", map);
            }
            // if we continue and it's not a descriptor, we don't care about errors
            if ((options.get(Option.CEYLONCONTINUE) != null && !ModuleManager.MODULE_FILE.equals(sourceFile.getName()) && !ModuleManager.PACKAGE_FILE.equals(sourceFile.getName())) || // otherwise we care about errors
            (lexerErrors.size() == 0 && parserErrors.size() == 0)) {
                // FIXME: this is bad in many ways
                String pkgName = getPackage(filename);
                // make a Package with no module yet, we will resolve them later
                /*
                     * Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
                     */
                Package p = modelLoader.findOrCreateModulelessPackage(pkgName == null ? "" : pkgName);
                phasedUnit = new CeylonPhasedUnit(file, srcDir, cu, p, moduleManager, moduleSourceMapper, ceylonContext, filename, map);
                phasedUnit.setSuppressedWarnings(suppressedWarnings);
                phasedUnits.addPhasedUnit(file, phasedUnit);
                gen.setMap(map);
                return gen.makeJCCompilationUnitPlaceholder(cu, filename, pkgName, phasedUnit);
            }
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    JCCompilationUnit result = make.TopLevel(List.<JCAnnotation>nil(), null, List.<JCTree>of(make.Erroneous()));
    result.sourcefile = filename;
    return result;
}
Also used : VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) Warning(org.eclipse.ceylon.compiler.typechecker.analyzer.Warning) ModuleManager(org.eclipse.ceylon.model.typechecker.util.ModuleManager) NewlineFixingStringStream(org.eclipse.ceylon.compiler.typechecker.util.NewlineFixingStringStream) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) ParseError(org.eclipse.ceylon.compiler.typechecker.parser.ParseError) ModuleSourceMapper(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper) CeylonParser(org.eclipse.ceylon.compiler.typechecker.parser.CeylonParser) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) CompilationUnit(org.eclipse.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) CommonTokenStream(org.antlr.runtime.CommonTokenStream) LineMap(org.eclipse.ceylon.langtools.tools.javac.util.Position.LineMap) CeylonLexer(org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer) IOException(java.io.IOException) CeylonInterpolatingLexer(org.eclipse.ceylon.compiler.typechecker.parser.CeylonInterpolatingLexer) Package(org.eclipse.ceylon.model.typechecker.model.Package) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File) LexError(org.eclipse.ceylon.compiler.typechecker.parser.LexError)

Aggregations

VirtualFile (org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)13 File (java.io.File)8 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Warning (org.eclipse.ceylon.compiler.typechecker.analyzer.Warning)2 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)2 Package (org.eclipse.ceylon.model.typechecker.model.Package)2 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 CommonTokenStream (org.antlr.runtime.CommonTokenStream)1 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1