Search in sources :

Example 26 with TypedDeclaration

use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.

the class MethodOrValueReferenceVisitor method capture.

private void capture(Tree.Primary that, boolean methodSpecifier) {
    if (that instanceof Tree.MemberOrTypeExpression) {
        final Declaration decl = ((Tree.MemberOrTypeExpression) that).getDeclaration();
        if (!(decl instanceof TypedDeclaration)) {
            return;
        }
        TypedDeclaration d = (TypedDeclaration) decl;
        if (Decl.equal(d, declaration) || (d.isNativeHeader() && d.getOverloads().contains(declaration))) {
            d = declaration;
            if (Decl.isParameter(d)) {
                // a reference from a default argument 
                // expression of the same parameter 
                // list does not capture a parameter
                Scope s = that.getScope();
                boolean sameScope = d.getContainer().equals(s) || (s instanceof Declaration && (Decl.isParameter((Declaration) s) || (s instanceof Value && !((Value) s).isTransient())) && d.getContainer().equals(s.getScope()));
                if (!sameScope || methodSpecifier || inLazySpecifierExpression) {
                    ((FunctionOrValue) d).setCaptured(true);
                }
                // Accessing another instance's member passed to a class initializer
                if (that instanceof Tree.QualifiedMemberExpression) {
                    if (d instanceof TypedDeclaration && ((TypedDeclaration) d).getOtherInstanceAccess()) {
                        ((FunctionOrValue) d).setCaptured(true);
                    }
                }
                if (isCapturableMplParameter(d)) {
                    ((FunctionOrValue) d).setCaptured(true);
                }
            } else if (Decl.isValue(d) || Decl.isGetter(d)) {
                Value v = (Value) d;
                v.setCaptured(true);
                if (Decl.isObjectValue(d)) {
                    v.setSelfCaptured(isSelfCaptured(that, d));
                }
                if (v.getSetter() != null) {
                    v.getSetter().setCaptured(true);
                }
            } else if (d instanceof Function) {
                ((Function) d).setCaptured(true);
            }
        /*if (d.isVariable() && !d.isClassMember() && !d.isToplevel()) {
                    that.addError("access to variable local from capturing scope: " + declaration.getName());
                }*/
        }
    }
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Function(com.redhat.ceylon.model.typechecker.model.Function) Scope(com.redhat.ceylon.model.typechecker.model.Scope) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 27 with TypedDeclaration

use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.

the class ClassDoc method writeListOnSummary.

private void writeListOnSummary(String cssClass, String title, List<?> types) throws IOException {
    if (!isEmpty(types)) {
        open("div class='" + cssClass + " section'");
        around("span class='title'", title);
        boolean first = true;
        for (Object type : types) {
            if (!first) {
                write(", ");
            } else {
                first = false;
            }
            if (type instanceof TypedDeclaration) {
                TypedDeclaration decl = (TypedDeclaration) type;
                linkRenderer().to(decl).useScope(klass).write();
            } else if (type instanceof ClassOrInterface) {
                ClassOrInterface coi = (ClassOrInterface) type;
                linkRenderer().to(coi).useScope(klass).printAbbreviated(!isAbbreviatedType(coi)).write();
            } else {
                Type pt = (Type) type;
                linkRenderer().to(pt).useScope(klass).printAbbreviated(!isAbbreviatedType(pt.getDeclaration())).write();
            }
        }
        close("div");
    }
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Type(com.redhat.ceylon.model.typechecker.model.Type) Util.isAbbreviatedType(com.redhat.ceylon.ceylondoc.Util.isAbbreviatedType)

Example 28 with TypedDeclaration

use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.

the class Naming method getMethodNameInternal.

private static String getMethodNameInternal(TypedDeclaration decl) {
    String name;
    if (decl.isClassOrInterfaceMember() && decl instanceof Function) {
        Declaration refined = decl.getRefinedDeclaration();
        if (refined instanceof JavaMethod) {
            return ((JavaMethod) refined).getRealName();
        }
        name = quoteMethodNameIfProperty((Function) decl);
    } else {
        name = decl.getName();
    }
    if (decl.isClassMember() && "readResolve".equals(name) && Strategy.addReadResolve((Class) decl.getContainer())) {
        return quote(name);
    }
    if (decl.isClassMember() && "writeReplace".equals(name) && Strategy.useSerializationProxy((Class) decl.getContainer())) {
        return quote(name);
    }
    // ERASURE
    if (QUOTABLE_METHOD_NAMES.contains(name)) {
        return quote(name);
    } else {
        return quoteIfJavaKeyword(name);
    }
}
Also used : LazyFunction(com.redhat.ceylon.model.loader.model.LazyFunction) Function(com.redhat.ceylon.model.typechecker.model.Function) JavaMethod(com.redhat.ceylon.model.loader.model.JavaMethod) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 29 with TypedDeclaration

use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.

the class Naming method makeDefaultedParamMethod.

JCExpression makeDefaultedParamMethod(JCExpression qualifier, Parameter param) {
    // TODO Can we merge this into makeName(..., NA_DPM) ?
    if (!Strategy.hasDefaultParameterValueMethod(param)) {
        throw new BugException();
    }
    Declaration decl = param.getDeclaration();
    String methodName = getDefaultedParamMethodName(decl, param);
    if (Strategy.defaultParameterMethodOnSelf(param.getModel())) {
        // method not within interface
        Declaration container = param.getDeclaration().getRefinedDeclaration();
        if (!container.isToplevel()) {
            container = (Declaration) container.getContainer();
        }
        JCExpression className = makeTypeDeclarationExpression(qualifier, (TypeDeclaration) container, DeclNameFlag.COMPANION);
        return makeSelect(className, methodName);
    } else if (Strategy.defaultParameterMethodOnOuter(param.getModel())) {
        return makeQuotedQualIdent(qualifier, methodName);
    } else if (Strategy.defaultParameterMethodStatic(param.getModel())) {
        // top level method or class
        if (qualifier != null) {
            throw new BugException();
        }
        Declaration container = param.getDeclaration().getRefinedDeclaration();
        if (!container.isToplevel()) {
            container = (Declaration) container.getContainer();
        }
        if (container instanceof TypedDeclaration) {
            return makeSelect(makeName((TypedDeclaration) container, NA_FQ | NA_WRAPPER), methodName);
        } else {
            return makeSelect(gen().makeJavaType(((TypeDeclaration) container).getType(), AbstractTransformer.JT_RAW), methodName);
        }
    } else {
        // inner or local class or method, or method in an interface
        return makeQuotedQualIdent(qualifier, methodName);
    }
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 30 with TypedDeclaration

use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.

the class NamedArgumentInvocation method getParameterTypeForValueType.

protected Type getParameterTypeForValueType(Reference producedReference, Parameter param) {
    // we need to find the interface for this method
    Type paramType = param.getModel().getReference().getFullType().getType();
    Scope paramContainer = param.getModel().getContainer();
    if (paramContainer instanceof TypedDeclaration) {
        TypedDeclaration method = (TypedDeclaration) paramContainer;
        if (method.getContainer() instanceof TypeDeclaration && !(method.getContainer() instanceof Constructor)) {
            TypeDeclaration container = (TypeDeclaration) method.getContainer();
            Type qualifyingType = producedReference.getQualifyingType();
            Type supertype = qualifyingType.getSupertype(container);
            return paramType.substitute(supertype);
        }
    }
    return paramType;
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Type(com.redhat.ceylon.model.typechecker.model.Type) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)52 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)28 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)26 Type (com.redhat.ceylon.model.typechecker.model.Type)26 Function (com.redhat.ceylon.model.typechecker.model.Function)23 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)17 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)17 Class (com.redhat.ceylon.model.typechecker.model.Class)15 Value (com.redhat.ceylon.model.typechecker.model.Value)14 JCTree (com.sun.tools.javac.tree.JCTree)14 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)13 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)12 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)11 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)10 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)10 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)9 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)9 Interface (com.redhat.ceylon.model.typechecker.model.Interface)8 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)8 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)7