Search in sources :

Example 56 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class LanguageCompiler method loadCompiledModules.

private List<JCCompilationUnit> loadCompiledModules(List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
    compilerDelegate.visitModules(phasedUnits);
    Modules modules = ceylonContext.getModules();
    // now make sure the phase units have their modules and packages set correctly
    for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
        Package pkg = pu.getPackage();
        loadModuleFromSource(pkg, modules, moduleTrees, trees);
    }
    // also make sure we have packages and modules set up for every Java file we compile
    for (JCCompilationUnit cu : trees) {
        // skip Ceylon CUs
        if (cu instanceof CeylonCompilationUnit)
            continue;
        String packageName = "";
        if (cu.pid != null)
            packageName = TreeInfo.fullName(cu.pid).toString();
        /*
             * Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
             */
        Package pkg = modelLoader.findOrCreateModulelessPackage(packageName);
        loadModuleFromSource(pkg, modules, moduleTrees, trees);
    }
    for (PhasedUnit phasedUnit : phasedUnits.getPhasedUnits()) {
        if (!phasedUnit.getCompilationUnit().getModuleDescriptors().isEmpty()) {
            String name = phasedUnit.getPackage().getNameAsString();
            CeylonPhasedUnit cpu = (CeylonPhasedUnit) phasedUnit;
            CeylonFileObject cfo = (CeylonFileObject) cpu.getFileObject();
            moduleNamesToFileObjects.put(name, cfo);
        }
    }
    if (addModuleTrees) {
        for (JCCompilationUnit moduleTree : moduleTrees) {
            trees = trees.append(moduleTree);
        }
    }
    return trees;
}
Also used : JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) Modules(org.eclipse.ceylon.model.typechecker.model.Modules) Package(org.eclipse.ceylon.model.typechecker.model.Package) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 57 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package 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)

Example 58 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class RuntimeModuleManager method createPackage.

@Override
public Package createPackage(String pkgName, Module module) {
    final Package pkg = new LazyPackage(getModelLoader());
    List<String> name = pkgName.isEmpty() ? Collections.<String>emptyList() : splitModuleName(pkgName);
    pkg.setName(name);
    if (module != null) {
        module.getPackages().add(pkg);
        pkg.setModule(module);
    }
    return pkg;
}
Also used : LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 59 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class ImportScanner method importPackage.

private void importPackage(JCFieldAccess selected) {
    String importedPkg = selected.toString();
    if (importedPkg.isEmpty())
        return;
    // Also work with Ceylon qualified types
    if (importedPkg.startsWith("."))
        importedPkg = importedPkg.substring(1);
    Package importedPackage = importingModule.getPackage(importedPkg);
    if (importedPackage == null) {
        // try one level up to skip potential types
        if (selected.selected instanceof JCFieldAccess) {
            importPackage((JCFieldAccess) selected.selected);
        }
    }
}
Also used : JCFieldAccess(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCFieldAccess) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 60 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class Naming method getTypeArgumentDescriptorName.

public String getTypeArgumentDescriptorName(TypeParameter tp) {
    String name;
    if (tp.isCaptured()) {
        // must build unique name
        StringBuilder sb = new StringBuilder();
        LinkedList<Declaration> decls = new LinkedList<Declaration>();
        Scope scope = tp;
        while (scope != null && scope instanceof Package == false) {
            if (scope instanceof Declaration)
                decls.add((Declaration) scope);
            scope = scope.getContainer();
        }
        Iterator<Declaration> iterator = decls.descendingIterator();
        while (iterator.hasNext()) {
            sb.append(iterator.next().getName());
            if (iterator.hasNext())
                sb.append("$");
        }
        name = sb.toString();
    } else {
        name = tp.getName();
    }
    return prefixName(Prefix.$reified$, name);
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package) LinkedList(java.util.LinkedList)

Aggregations

Package (org.eclipse.ceylon.model.typechecker.model.Package)84 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)31 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)31 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)27 Module (org.eclipse.ceylon.model.typechecker.model.Module)26 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)21 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)14 ArrayList (java.util.ArrayList)13 LazyPackage (org.eclipse.ceylon.model.loader.model.LazyPackage)11 Class (org.eclipse.ceylon.model.typechecker.model.Class)11 Function (org.eclipse.ceylon.model.typechecker.model.Function)9 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)9 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)8 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)8 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)8 HashSet (java.util.HashSet)7 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)7 Type (org.eclipse.ceylon.model.typechecker.model.Type)7