Search in sources :

Example 61 with Package

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

the class AbstractModelLoader method makeInteropAnnotationClass.

/**
 * <pre>
 *   annotation class Annotation$Proxy(...) satisfies Annotation {
 *       // a `shared` class parameter for each method of Annotation
 *   }
 * </pre>
 * @param iface The model of the annotation @interface
 * @return The annotation class for the given interface
 */
public AnnotationProxyClass makeInteropAnnotationClass(LazyInterface iface, Scope scope) {
    AnnotationProxyClass klass = new AnnotationProxyClass(this, iface);
    klass.setContainer(scope);
    klass.setScope(scope);
    if (!(scope instanceof Package)) {
        klass.setStatic(true);
    }
    klass.setName(iface.getName() + "$Proxy");
    klass.setShared(iface.isShared());
    klass.setAnnotation(true);
    Annotation annotationAnnotation = new Annotation();
    annotationAnnotation.setName("annotation");
    klass.getAnnotations().add(annotationAnnotation);
    klass.getSatisfiedTypes().add(iface.getType());
    klass.setUnit(iface.getUnit());
    klass.setScope(scope);
    return klass;
}
Also used : AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 62 with Package

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

the class AbstractModelLoader method getUnitForModule.

private Unit getUnitForModule(Module module) {
    List<Package> packages = module.getPackages();
    if (packages.isEmpty()) {
        System.err.println("No package for module " + module.getNameAsString());
        return null;
    }
    Package pkg = packages.get(0);
    if (pkg instanceof LazyPackage == false) {
        System.err.println("No lazy package for module " + module.getNameAsString());
        return null;
    }
    Unit unit = getCompiledUnit((LazyPackage) pkg, null);
    if (unit == null) {
        System.err.println("No unit for module " + module.getNameAsString());
        return null;
    }
    return unit;
}
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) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 63 with Package

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

the class AbstractModelLoader method loadLanguageModuleAndPackage.

protected Module loadLanguageModuleAndPackage() {
    Module languageModule = findOrCreateModule(CEYLON_LANGUAGE, null);
    addModuleToClassPath(languageModule, null);
    Package languagePackage = findOrCreatePackage(languageModule, CEYLON_LANGUAGE);
    typeFactory.setPackage(languagePackage);
    // make sure the language module has its real dependencies added, because we need them in the classpath
    // otherwise we will get errors on the Util and Metamodel calls we insert
    // WARNING! Make sure this list is always the same as the one in /ceylon-runtime/dist/repo/ceylon/language/_version_/module.xml
    // Note that we lie about the module exports: we pretend they're not imported at compile-time
    // while they are at run-time (in the module.xml file), so that users don't get these imports
    // visible in all their modules.
    languageModule.addImport(new ModuleImport(null, findOrCreateModule("org.eclipse.ceylon.common", Versions.CEYLON_VERSION_NUMBER), false, false, Backend.Java));
    languageModule.addImport(new ModuleImport(null, findOrCreateModule("org.eclipse.ceylon.model", Versions.CEYLON_VERSION_NUMBER), false, false, Backend.Java));
    return languageModule;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 64 with Package

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

the class AbstractModelLoader method setupWithNoStandardModules.

/**
 * This is meant to be called if your subclass doesn't call loadStandardModules for whatever reason
 */
public void setupWithNoStandardModules() {
    Module languageModule = modules.getLanguageModule();
    if (languageModule == null)
        throw new RuntimeException("Assertion failed: language module is null");
    Package languagePackage = languageModule.getPackage(CEYLON_LANGUAGE);
    if (languagePackage == null)
        throw new RuntimeException("Assertion failed: language package is null");
    typeFactory.setPackage(languagePackage);
}
Also used : LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 65 with Package

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

the class TypeParser method loadType.

private Type loadType(String pkg, String fullName, Part part, Type qualifyingType) {
    // try to find a qualified type
    try {
        Declaration newDeclaration;
        if (qualifyingType == null) {
            // FIXME: this only works for packages not contained in multiple modules
            Package foundPackage = moduleScope.getPackage(pkg);
            if (foundPackage != null)
                newDeclaration = loader.getDeclaration(foundPackage.getModule(), pkg, fullName, scope);
            else if (scope != null && !pkg.isEmpty() && loader.isDynamicMetamodel()) {
                // try the default module, damnit
                newDeclaration = loader.getDeclaration(loader.getLoadedModule(Module.DEFAULT_MODULE_NAME, null), pkg, fullName, scope);
            } else if (scope != null) {
                // if we did not find any package and the scope is null, chances are we're after a type variable
                // or a relative type, so use the module scope
                newDeclaration = loader.getDeclaration(moduleScope, pkg, fullName, scope);
            } else
                newDeclaration = null;
        } else {
            // look it up via its qualifying type or decl
            Declaration qualifyingDeclaration = qualifyingType.getDeclaration();
            if (qualifyingType.isUnion() || qualifyingType.isIntersection()) {
                newDeclaration = qualifyingDeclaration.getMember(part.name, null, false);
            } else {
                if (qualifyingDeclaration instanceof FunctionOrValueInterface)
                    qualifyingDeclaration = ((FunctionOrValueInterface) qualifyingDeclaration).getUnderlyingDeclaration();
                newDeclaration = AbstractModelLoader.getDirectMember((Scope) qualifyingDeclaration, part.name);
            }
            if (newDeclaration == null)
                throw new ModelResolutionException("Failed to resolve inner type or declaration " + part.name + " in " + qualifyingDeclaration.getQualifiedNameString());
        }
        if (newDeclaration == null)
            return null;
        TypeDeclaration newTypeDeclaration;
        if (newDeclaration instanceof TypeDeclaration)
            newTypeDeclaration = (TypeDeclaration) newDeclaration;
        else
            newTypeDeclaration = new FunctionOrValueInterface((TypedDeclaration) newDeclaration);
        Type ret = newTypeDeclaration.appliedType(qualifyingType, part.getParameters());
        // set the use-site variance if required, now that we know the TypeParameter declarations
        if (!part.getVariance().isEmpty()) {
            List<TypeParameter> tps = newTypeDeclaration.getTypeParameters();
            List<SiteVariance> variance = part.getVariance();
            for (int i = 0, l1 = tps.size(), l2 = variance.size(); i < l1 && i < l2; i++) {
                SiteVariance siteVariance = variance.get(i);
                if (siteVariance != null) {
                    ret.setVariance(tps.get(i), siteVariance);
                }
            }
        }
        return ret;
    } catch (ModelResolutionException x) {
        // - if we have type parameters we must have a type
        if (qualifyingType != null || (part.parameters != null && !part.parameters.isEmpty()))
            throw x;
        return null;
    }
}
Also used : FunctionOrValueInterface(org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface) Type(org.eclipse.ceylon.model.typechecker.model.Type) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) SiteVariance(org.eclipse.ceylon.model.typechecker.model.SiteVariance) 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) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

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