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

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


                setInterfaceCompanionClass(d, null, pkg);
            }
            DeclarationVisitor.setVisibleScope(d);
        }else if(classMirror.isLocalClass()){
            // set its container to the package for now, but don't add it to the package as a member because it's not
            Scope localContainer = getLocalContainer(pkg, classMirror, d);
            if(localContainer != null){
                d.setContainer(localContainer);
                d.setScope(localContainer);
                // do not add it as member, it has already been registered by getLocalContainer
            }else{
View Full Code Here


   
    private Scope findLocalContainerFromAnnotationAndSetCompanionClass(Package pkg, Interface declaration, AnnotationMirror localContainerAnnotation) {
        @SuppressWarnings("unchecked")
        List<String> path = (List<String>) localContainerAnnotation.getValue("path");
        // we start at the package
        Scope scope = pkg;
        for(String name : path){
            scope = (Scope) getDirectMember(scope, name);
        }
        String companionClassName = (String) localContainerAnnotation.getValue("companionClassName");
        if(companionClassName == null || companionClassName.isEmpty()){
            declaration.setCompanionClassNeeded(false);
            return scope;
        }
        ClassMirror container;
        Scope javaClassScope;
        if(scope instanceof TypedDeclaration && ((TypedDeclaration) scope).isMember())
            javaClassScope = scope.getContainer();
        else
            javaClassScope = scope;
       
View Full Code Here

                if(klass == null)
                    return false;
            }
            if(!path.isEmpty() && klass.isLoadedFromSource()){
                // we need to find its model
                Scope scope = packagesByName.get(cacheKeyByModule(module, unquotedPkgName));
                if(scope == null)
                    return false;
                for(String name : path){
                    Declaration decl = scope.getDirectMember(name, null, false);
                    if(decl == null)
                        return false;
                    // if we get a value, we want its type
                    if(Decl.isValue(decl)
                            && ((Value)decl).getTypeDeclaration().getName().equals(name))
View Full Code Here

        decl.setActualCompleter(this);
    }
   
    @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
                // for Ceylon methods
                if(decl instanceof JavaMethod && Decl.isCeylon(klass)){
                    if(!methodMirror.getTypeParameters().isEmpty()
                            // because this requires the refined decl, we defer this check until we've set it, to not trigger
                            // lazy loading just to check.
                            && AbstractTransformer.supportsReified(decl)){
                        checkReifiedTypeDescriptors(methodMirror.getTypeParameters().size(),
                                container.getQualifiedNameString(), methodMirror, false);
                    }
                }
            }
        }
    }
View Full Code Here

                }
            }
            // add any container method TP
            TypeDeclaration declaration = qualifiedType.getDeclaration();
            if(Decl.isLocal(declaration)){
                Scope scope = declaration.getContainer();
                // collect every container method until the next type or package
                java.util.List<Method> methods = new LinkedList<Method>();
                while(scope != null
                        && scope instanceof ClassOrInterface == false
                        && scope instanceof Package == false){
                    if(scope instanceof Method){
                        methods.add((Method) scope);
                    }
                    scope = scope.getContainer();
                }
                // methods are sorted inner to outer, which is the order we're following here for types
                for(Method method : methods){
                    java.util.List<TypeParameter> methodTypeParameters = method.getTypeParameters();
                    if (methodTypeParameters != null) {
View Full Code Here

        } else if(declaration instanceof TypeParameter){
            TypeParameter tp = (TypeParameter) declaration;
            String name = naming.getTypeArgumentDescriptorName(tp);
            if(!qualified)
                return makeUnquotedIdent(name);
            Scope container = tp.getContainer();
            JCExpression qualifier = null;
            if(container instanceof Class){
                qualifier = naming.makeQualifiedThis(makeJavaType(((Class)container).getType(), JT_RAW));
            }else if(container instanceof Interface){
                qualifier = naming.makeQualifiedThis(makeJavaType(((Interface)container).getType(), JT_COMPANION | JT_RAW));
View Full Code Here

        return localVar;
    }
   
    protected Declaration getDeclarationContainer(Declaration declaration) {
        // Here we can use getContainer, we don't care about scopes
        Scope container = declaration.getContainer();
        while(container != null){
            if(container instanceof Package)
                return null;
            if(container instanceof Declaration
                    // skip anonymous methods
                    && (container instanceof Method == false || !((Declaration) container).isAnonymous()))
                return (Declaration) container;
            container = container.getContainer();
        }
        // did not find anything
        return null;
    }
View Full Code Here

   
    static protected class ModelComparison {
        private boolean isUltimatelyVisible(Declaration d) {
            if (d instanceof MethodOrValue &&
                    ((MethodOrValue)d).isParameter()) {
                Scope container = d.getContainer();
                if (container instanceof Declaration) {
                    return isUltimatelyVisible((Declaration)container);
                }
            }
            return d.isShared();
View Full Code Here

            }
        }
       
        protected void compareContainers(Declaration validDeclaration, Declaration modelDeclaration) {
            String name = validDeclaration.getQualifiedNameString();
            Scope validContainer = validDeclaration.getContainer();
            Scope modelContainer = modelDeclaration.getContainer();
            if(validContainer instanceof Declaration){
                Assert.assertTrue(name+" [Container is Declaration]", modelContainer instanceof Declaration);
                compareDeclarations(name+" [container]", (Declaration)validContainer, (Declaration)modelContainer);
            }else{
                Assert.assertTrue(name+" [Container is not Declaration]", modelContainer instanceof Declaration == false);
View Full Code Here

            }
        }
   
        protected void compareScopes(Declaration validDeclaration, Declaration modelDeclaration) {
            String name = validDeclaration.getQualifiedNameString();
            Scope validContainer = validDeclaration.getScope();
            Scope modelContainer = modelDeclaration.getScope();
            if(validContainer instanceof Declaration){
                Assert.assertTrue(name+" [Scope is Declaration]", modelContainer instanceof Declaration);
                compareDeclarations(name+" [scope]", (Declaration)validContainer, (Declaration)modelContainer);
            }else{
                Assert.assertTrue(name+" [Scope is not Declaration]", modelContainer instanceof Declaration == false);
View Full Code Here

TOP

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

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.