Package com.redhat.ceylon.compiler.typechecker.model

Examples of com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface


        throw (RuntimeException)e;
    }

    @Override
    public void visit(Tree.ClassOrInterface that){
        ClassOrInterface model = that.getDeclarationModel();
        // stop at aliases, do not collect them since we can never create any instance of them
        // and they are useless at runtime
        if(!model.isAlias())
            throw new HasTypeException();
    }
View Full Code Here


                thisType = gen.naming.makeName((TypedDeclaration)getPrimaryDeclaration(), Naming.NA_WRAPPER);
                defaultedParameterInstance = gen.naming.makeName((TypedDeclaration)getPrimaryDeclaration(), Naming.NA_MEMBER);
            }
        } else if (getPrimary() instanceof Tree.BaseTypeExpression
                || getPrimary() instanceof Tree.QualifiedTypeExpression) {
            ClassOrInterface declaration = (ClassOrInterface)((Tree.MemberOrTypeExpression) getPrimary()).getDeclaration();
            thisType = gen.makeJavaType(declaration.getType(), JT_COMPANION);
            defaultedParameterInstance = gen.make().NewClass(
                    null,
                    null,
                    gen.makeJavaType(declaration.getType(), JT_COMPANION),
                    List.<JCExpression>nil(), null);
        } else {
            if (isOnValueType()) {
                thisType = gen.makeJavaType(target.getQualifyingType());
            } else {
View Full Code Here

        // and they are useless at runtime
    }

    @Override
    public void visit(Tree.ClassOrInterface that){
        ClassOrInterface model = that.getDeclarationModel();
        // stop at aliases, do not collect them since we can never create any instance of them
        // and they are useless at runtime
        if(!model.isAlias()){
            // we never need to collect other local declaration names since only interfaces compete in the $impl name range
            if(model instanceof Interface)
                collect(that, (Interface) model);

            Set<String> old = localCompanionClasses;
View Full Code Here

            ((LazyElement)d).setLocal(true);
        }else if(d instanceof ClassOrInterface || d instanceof TypeAlias){
            // do overloads later, since their container is their abstract superclass's container and
            // we have to set that one first
            if(d instanceof Class == false || !((Class)d).isOverloaded()){
                ClassOrInterface container = getContainer(pkg.getModule(), classMirror);
                d.setContainer(container);
                d.setScope(container);
                if(d instanceof LazyInterface && ((LazyInterface) d).isCeylon()){
                    setInterfaceCompanionClass(d, container, pkg);
                }
View Full Code Here

                javaClassName = javaClassName.substring(0, javaClassName.length() - 5);
           
            // find the enclosing declaration
            Declaration enclosingClassDeclaration = convertToDeclaration(pkg.getModule(), javaClassName, DeclarationType.TYPE);
            if(enclosingClassDeclaration instanceof ClassOrInterface){
                ClassOrInterface containerDecl = (ClassOrInterface) enclosingClassDeclaration;
                // now find the method's declaration
                // FIXME: find the proper overload if any
                if(method.isConstructor()){
                    methodDecl = (LocalDeclarationContainer) containerDecl;
                }else{
                    String name = method.getName();
                    // this is only for error messages
                    String type;
                    // lots of special cases
                    if(isStringAttribute(method)){
                        name = "string";
                        type = "attribute";
                    }else if(isHashAttribute(method)){
                        name = "hash";
                        type = "attribute";
                    }else if(isGetter(method)) {
                        // simple attribute
                        name = getJavaAttributeName(name);
                        type = "attribute";
                    }else if(isSetter(method)) {
                        // simple attribute
                        name = getJavaAttributeName(name);
                        type = "attribute setter";
                        isSetter = true;
                    }else{
                        type = "method";
                    }
                    // strip any escaping or private suffix
                    // it can be foo$priv$canonical so get rid of that one first
                    if (name.endsWith(Naming.Suffix.$canonical$.toString())) {
                        name = name.substring(0, name.length()-11);
                    }
                    name = Util.strip(name, true, method.isPublic() || method.isProtected() || method.isDefaultAccess());

                    methodDecl = (LocalDeclarationContainer) containerDecl.getDirectMember(name, null, false);

                    if(methodDecl == null)
                        throw new ModelResolutionException("Failed to load outer "+type+" " + name
                                + " for local type " + classMirror.getQualifiedName().toString());
View Full Code Here

    private ClassOrInterface getContainer(Module module, ClassMirror classMirror) {
        AnnotationMirror containerAnnotation = classMirror.getAnnotation(CEYLON_CONTAINER_ANNOTATION);
        if(containerAnnotation != null){
            TypeMirror javaClassMirror = (TypeMirror)containerAnnotation.getValue("klass");
            String javaClassName = javaClassMirror.getQualifiedName();
            ClassOrInterface containerDecl = (ClassOrInterface) convertToDeclaration(module, javaClassName, DeclarationType.TYPE);
            if(containerDecl == null)
                throw new ModelResolutionException("Failed to load outer type " + javaClassName
                        + " for inner type " + classMirror.getQualifiedName().toString());
            return containerDecl;
        }else{
View Full Code Here

    @Override
    public void completeActual(Declaration decl){
        Scope container = decl.getContainer();

        if(container instanceof ClassOrInterface){
            ClassOrInterface klass = (ClassOrInterface) container;
           
            decl.setRefinedDeclaration(decl);
            // we never consider Interface and other stuff, since we never register the actualCompleter for them
            if(decl instanceof Class){
                // Java member classes are never actual
                if(!Decl.isCeylon((Class)decl))
                    return;
                // we already set the actual bit for member classes, we just need the refined decl
                if(decl.isActual()){
                    Declaration refined = klass.getRefinedMember(decl.getName(), getSignature(decl), false);
                    decl.setRefinedDeclaration(refined);
                }
            }else{ // Method or Value
                MethodMirror methodMirror;
                if(decl instanceof JavaBeanValue)
                    methodMirror = ((JavaBeanValue) decl).mirror;
                else if(decl instanceof JavaMethod)
                    methodMirror = ((JavaMethod) decl).mirror;
                else
                    throw new ModelResolutionException("Unknown type of declaration: "+decl+": "+decl.getClass().getName());
               
                decl.setRefinedDeclaration(decl);
                // For Ceylon interfaces we rely on annotation
                if(klass instanceof LazyInterface
                        && ((LazyInterface)klass).isCeylon()){
                    boolean actual = methodMirror.getAnnotation(CEYLON_LANGUAGE_ACTUAL_ANNOTATION) != null;
                    decl.setActual(actual);
                    if(actual){
                        Declaration refined = klass.getRefinedMember(decl.getName(), getSignature(decl), false);
                        decl.setRefinedDeclaration(refined);
                    }
                }else{
                    if(isOverridingMethod(methodMirror)){
                        decl.setActual(true);
                        Declaration refined = klass.getRefinedMember(decl.getName(), getSignature(decl), false);
                        decl.setRefinedDeclaration(refined);
                    }
                }
               
                // now that we know the refined declaration, we can check for reified type param support
View Full Code Here

                return null;
            // only try to find better if we're erasing to Object and we're not returning a type param
            if(willEraseToObject(typedReference.getType())
                        || isWideningTypeArguments(decl.getType(), modelRefinedDecl.getType(), true)
                    && !isTypeParameter(typedReference.getType())){
                ClassOrInterface declaringType = (ClassOrInterface) qualifyingDeclaration;
                Set<TypedDeclaration> refinedMembers = getRefinedMembers(declaringType, decl.getName(),
                        com.redhat.ceylon.compiler.typechecker.model.Util.getSignature(decl), false);
                // now we must select a different refined declaration if we refine it more than once
                if(refinedMembers.size() > (forMixinMethod ? 0 : 1)){
                    // first case
                    for(TypedDeclaration refinedDecl : refinedMembers){
                        // get the type reference to see if any eventual type param is instantiated in our inheritance of this type/method
                        ProducedTypedReference refinedTypedReference = getRefinedTypedReference(typedReference, refinedDecl);
                        // if it is not instantiated, that's the one we're looking for
                        if(isTypeParameter(refinedTypedReference.getType()))
                            return refinedTypedReference;
                    }
                    // second case
                    for(TypedDeclaration refinedDecl : refinedMembers){
                        // get the type reference to see if any eventual type param is instantiated in our inheritance of this type/method
                        ProducedTypedReference refinedTypedReference = getRefinedTypedReference(typedReference, refinedDecl);
                        // if we're not erasing this one to Object let's select it
                        if(!willEraseToObject(refinedTypedReference.getType()) && !isWideningTypeArguments(refinedDecl.getType(), modelRefinedDecl.getType(), true))
                            return refinedTypedReference;
                    }
                    // third case
                    if(isTypeParameter(modelRefinedDecl.getType())){
                        // it can happen that we have inherited a method twice from a single refined declaration
                        // via different supertype instantiations, without having ever refined them in supertypes
                        // so we try each super type to see if we already have a matching typed reference
                        // first super type
                        ProducedType extendedType = declaringType.getExtendedType();
                        if(extendedType != null){
                            ProducedTypedReference refinedTypedReference = getRefinedTypedReference(extendedType, modelRefinedDecl);
                            ProducedType refinedType = refinedTypedReference.getType();
                            if(!isTypeParameter(refinedType)
                                    && !willEraseToObject(refinedType))
                                return refinedTypedReference;
                        }
                        // then satisfied interfaces
                        for(ProducedType satisfiedType : declaringType.getSatisfiedTypes()){
                            ProducedTypedReference refinedTypedReference = getRefinedTypedReference(satisfiedType, modelRefinedDecl);
                            ProducedType refinedType = refinedTypedReference.getType();
                            if(!isTypeParameter(refinedType)
                                    && !willEraseToObject(refinedType))
                                return refinedTypedReference;
View Full Code Here

    private TypedDeclaration getFirstRefinedDeclaration(TypedDeclaration decl) {
        if(decl.getContainer() instanceof ClassOrInterface == false)
            return decl;
        java.util.List<ProducedType> signature = com.redhat.ceylon.compiler.typechecker.model.Util.getSignature(decl);
        ClassOrInterface container = (ClassOrInterface) decl.getContainer();
        HashSet<TypeDeclaration> visited = new HashSet<TypeDeclaration>();
        // start looking for it, but skip this type, only lookup upwards of it
        TypedDeclaration firstRefinedDeclaration = getFirstRefinedDeclaration(container, decl, signature, visited, true);
        // only keep the first refined decl if its type can be trusted: if it is not itself widening
        if(firstRefinedDeclaration != null){
View Full Code Here

            // local interfaces that are pulled to the toplevel need to cross containing methods to find
            // all the containing type parameters that it captures
            if(Decl.isLocal(typeDeclaration)
                    && needsQualifyingTypeArgumentsFromLocalContainers
                    && typeDeclaration instanceof ClassOrInterface){
                ClassOrInterface container = Decl.getClassOrInterfaceContainer(typeDeclaration, false);
                qType = container == null ? null : container.getType();
            }else{
                qType = qType.getQualifyingType();
                if(qType != null && qType.getDeclaration() instanceof ClassOrInterface == false){
                    // sometimes the typechecker throws qualifying intersections at us and
                    // we can't make anything of them, since some members may be unrelated to
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.