Search in sources :

Example 41 with Package

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

the class AbstractModelLoader method addLocalDeclarations.

private void addLocalDeclarations(LocalDeclarationContainer container, ClassMirror classContainerMirror, AnnotatedMirror annotatedMirror) {
    if (!needsLocalDeclarations())
        return;
    AnnotationMirror annotation = annotatedMirror.getAnnotation(CEYLON_LOCAL_DECLARATIONS_ANNOTATION);
    if (annotation == null)
        return;
    List<String> values = getAnnotationStringValues(annotation, "value");
    String parentClassName = classContainerMirror.getQualifiedName();
    Package pkg = ModelUtil.getPackageContainer(container);
    Module module = pkg.getModule();
    for (String scope : values) {
        // assemble the name with the parent
        String name;
        if (scope.startsWith("::")) {
            // interface pulled to toplevel
            name = pkg.getNameAsString() + "." + scope.substring(2);
        } else {
            name = parentClassName;
            name += "$" + scope;
        }
        Declaration innerDecl = convertToDeclaration(module, (Declaration) container, name, DeclarationType.TYPE);
        if (innerDecl == null)
            throw new ModelResolutionException("Failed to load local type " + name + " for outer type " + container.getQualifiedNameString());
    }
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 42 with Package

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

the class AbstractModelLoader method findLanguageModuleDeclarationForBootstrap.

private Declaration findLanguageModuleDeclarationForBootstrap(String name) {
    // make sure we don't return anything for ceylon.language
    if (name.equals(CEYLON_LANGUAGE))
        return null;
    // we're bootstrapping ceylon.language so we need to return the ProducedTypes straight from the model we're compiling
    Module languageModule = modules.getLanguageModule();
    int lastDot = name.lastIndexOf(".");
    if (lastDot == -1)
        return null;
    String pkgName = name.substring(0, lastDot);
    String simpleName = name.substring(lastDot + 1);
    // Nothing is a special case with no real decl
    if (name.equals("ceylon.language.Nothing"))
        return typeFactory.getNothingDeclaration();
    // find the right package
    Package pkg = languageModule.getDirectPackage(pkgName);
    if (pkg != null) {
        Declaration member = pkg.getDirectMember(simpleName, null, false);
        // if we get a value, we want its type
        if (JvmBackendUtil.isValue(member) && ((Value) member).getTypeDeclaration().getName().equals(simpleName)) {
            member = ((Value) member).getTypeDeclaration();
        }
        if (member != null)
            return member;
    }
    throw new ModelResolutionException("Failed to look up given type in language module while bootstrapping: " + name);
}
Also used : LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 43 with Package

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

the class AbstractModelLoader method makeInteropAnnotationConstructor.

public AnnotationProxyMethod makeInteropAnnotationConstructor(LazyInterface iface, AnnotationProxyClass klass, OutputElement oe, Scope scope) {
    String ctorName = oe == null ? NamingBase.getJavaBeanName(iface.getName()) : NamingBase.getDisambigAnnoCtorName(iface, oe);
    AnnotationProxyMethod ctor = new AnnotationProxyMethod(this, klass, oe);
    ctor.setAnnotationTarget(oe);
    ctor.setContainer(scope);
    ctor.setScope(scope);
    if (!(scope instanceof Package)) {
        ctor.setStatic(true);
    }
    ctor.setAnnotation(true);
    ctor.setName(ctorName);
    ctor.setShared(iface.isShared());
    Annotation annotationAnnotation2 = new Annotation();
    annotationAnnotation2.setName("annotation");
    ctor.getAnnotations().add(annotationAnnotation2);
    ctor.setType(((TypeDeclaration) iface).getType());
    ctor.setUnit(iface.getUnit());
    return ctor;
}
Also used : AnnotationProxyMethod(org.eclipse.ceylon.model.loader.model.AnnotationProxyMethod) 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 44 with Package

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

the class AbstractModelLoader method getDirectMember.

/**
 * Looks for a direct member of type ClassOrInterface. We're not using Class.getDirectMember()
 * because it skips object types and we want them.
 */
public static Declaration getDirectMember(Scope container, String name) {
    if (name.isEmpty())
        return null;
    boolean wantsSetter = false;
    if (name.startsWith(NamingBase.Suffix.$setter$.name())) {
        wantsSetter = true;
        name = name.substring(8);
    }
    if (Character.isDigit(name.charAt(0))) {
        // this is a local type we have a different accessor for it
        return ((LocalDeclarationContainer) container).getLocalDeclaration(name);
    }
    // which is too late
    if (container instanceof Package) {
        // don't use Package.getMembers() as it loads the whole package
        Declaration result = container.getDirectMember(name, null, false);
        return selectTypeOrSetter(result, wantsSetter);
    } else {
        // must be a Declaration
        for (Declaration member : container.getMembers()) {
            // avoid constructors with no name
            if (member.getName() == null)
                continue;
            if (!member.getName().equals(name))
                continue;
            Declaration result = selectTypeOrSetter(member, wantsSetter);
            if (result != null)
                return result;
        }
    }
    // not found
    return null;
}
Also used : LocalDeclarationContainer(org.eclipse.ceylon.model.loader.model.LocalDeclarationContainer) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 45 with Package

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

the class AbstractModelLoader method inspectForStats.

private int inspectForStats(Map<String, Declaration> cache, Map<Package, Stats> loadedByPackage) {
    int loaded = 0;
    for (Declaration decl : cache.values()) {
        if (decl instanceof LazyElement) {
            Package pkg = getPackage(decl);
            if (pkg == null) {
                logVerbose("[Model loader stats: declaration " + decl.getName() + " has no package. Skipping.]");
                continue;
            }
            Stats stats = loadedByPackage.get(pkg);
            if (stats == null) {
                stats = new Stats();
                loadedByPackage.put(pkg, stats);
            }
            stats.total++;
            if (((LazyElement) decl).isLoaded()) {
                loaded++;
                stats.loaded++;
            }
        }
    }
    return loaded;
}
Also used : LazyElement(org.eclipse.ceylon.model.loader.model.LazyElement) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package)

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