Search in sources :

Example 16 with TypedDeclaration

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

the class ClassOrPackageDoc method doc.

protected final void doc(String id, String name, Declaration d) throws IOException {
    String declarationName = Util.getDeclarationName(d);
    id = (id != null ? id : name);
    boolean alias = Util.nullSafeCompare(name, declarationName) != 0;
    // put the id on the td because IE8 doesn't support id attributes on tr (yeah right)
    open("tr");
    open("td id='" + id + "' nowrap");
    writeIcon(d);
    if (!(d instanceof Constructor)) {
        around("code class='decl-label'", name);
        close("td");
        open("td");
    }
    writeLinkOneSelf(id);
    if (alias) {
        writeTagged(d);
        writeAlias(d);
    } else {
        writeLinkSource(d);
        writeTagged(d);
        if (d instanceof Functional) {
            writeParameterLinksIfRequired((Functional) d);
        }
        open("code class='signature'");
        around("span class='modifiers'", getModifiers(d));
        write(" ");
        if (!ModelUtil.isConstructor(d)) {
            if (!Decl.isDynamic(d)) {
                if (d instanceof Functional && ((Functional) d).isDeclaredVoid()) {
                    around("span class='void'", "void");
                } else if (d instanceof TypedDeclaration) {
                    linkRenderer().to(((TypedDeclaration) d).getType()).useScope(d).write();
                } else {
                    linkRenderer().to(d).useScope(d).write();
                }
            } else {
                around("span class='dynamic'", "dynamic");
            }
        }
        write(" ");
        open("span class='identifier'");
        write(name);
        close("span");
        if (isConstantValue(d)) {
            writeConstantValue((Value) d);
        }
        if (d instanceof Generic) {
            writeTypeParameters(d.getTypeParameters(), d);
        }
        if (d instanceof Functional) {
            writeParameterList((Functional) d, d);
        }
        if (d instanceof Generic) {
            writeTypeParametersConstraints(d.getTypeParameters(), d);
        }
        if (d instanceof Value) {
            Setter setter = ((Value) d).getSetter();
            if (setter != null && Util.getAnnotation(setter.getUnit(), setter.getAnnotations(), "doc") != null) {
                tool.warningSetterDoc(d.getQualifiedNameString(), d);
            }
        }
        close("code");
        writeDescription(d);
    }
    close("td");
    close("tr");
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Setter(org.eclipse.ceylon.model.typechecker.model.Setter)

Example 17 with TypedDeclaration

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.Variable that) {
    super.visit(that);
    if (that instanceof CustomTree.GuardedVariable) {
        CustomTree.GuardedVariable gv = (CustomTree.GuardedVariable) that;
        setTypeForGuardedVariable(that, gv.getConditionList(), gv.isReversed());
        Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) that.getSpecifierExpression().getExpression().getTerm();
        Declaration original = bme.getDeclaration();
        if (original instanceof TypedDeclaration) {
            that.getDeclarationModel().setOriginalDeclaration((TypedDeclaration) original);
        }
    } else {
        Tree.SpecifierExpression se = that.getSpecifierExpression();
        if (se != null) {
            inferType(that, se);
            Tree.Type type = that.getType();
            if (type != null) {
                Type t = type.getTypeModel();
                if (!isTypeUnknown(t)) {
                    checkType(t, se);
                }
            }
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TreeUtil.isEffectivelyBaseMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.isEffectivelyBaseMemberExpression) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 18 with TypedDeclaration

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

the class ExpressionVisitor method setType.

private void setType(Tree.LocalModifier local, Tree.SpecifierOrInitializerExpression s, Tree.TypedDeclaration that) {
    Tree.Expression e = s.getExpression();
    if (e != null) {
        Type type = e.getTypeModel();
        if (type != null) {
            TypedDeclaration dec = that.getDeclarationModel();
            handleUncheckedNulls(local, e, dec);
            Type t = inferrableType(type);
            local.setTypeModel(t);
            dec.setType(t);
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 19 with TypedDeclaration

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

the class ExpressionVisitor method checkNamedArgument.

private void checkNamedArgument(Tree.NamedArgument arg, Reference reference, Parameter param) {
    arg.setParameter(param);
    Type argType = null;
    if (arg instanceof Tree.SpecifiedArgument) {
        Tree.SpecifiedArgument sa = (Tree.SpecifiedArgument) arg;
        Tree.Expression e = sa.getSpecifierExpression().getExpression();
        if (e != null) {
            argType = e.getTypeModel();
        }
    } else if (arg instanceof Tree.TypedArgument) {
        Tree.TypedArgument typedArg = (Tree.TypedArgument) arg;
        TypedDeclaration argDec = typedArg.getDeclarationModel();
        argType = argumentType(arg.getScope(), argDec);
        checkArgumentToVoidParameter(param, typedArg);
        if (!dynamic && isTypeUnknown(argType) && !hasError(arg)) {
            arg.addError("could not determine type of named argument: the type of '" + param.getName() + "' is not known");
        }
    }
    FunctionOrValue paramModel = param.getModel();
    if (paramModel != null) {
        TypedReference paramRef = reference.getTypedParameter(param);
        Type paramType = paramType(arg.getScope(), paramRef, paramModel);
        if (!isTypeUnknown(argType) && !isTypeUnknown(paramType)) {
            Node node;
            if (arg instanceof Tree.SpecifiedArgument) {
                Tree.SpecifiedArgument specifiedArg = (Tree.SpecifiedArgument) arg;
                node = specifiedArg.getSpecifierExpression();
            } else {
                node = arg;
            }
            checkAssignable(argType, paramType, node, "named argument must be assignable to parameter " + argdesc(param, reference), 2100);
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 20 with TypedDeclaration

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.MemberLiteral that) {
    if (that instanceof Tree.FunctionLiteral || that instanceof Tree.ValueLiteral) {
        declarationLiteral = true;
    } else {
        modelLiteral = true;
    }
    try {
        super.visit(that);
    } finally {
        declarationLiteral = false;
        modelLiteral = false;
    }
    Tree.Identifier id = that.getIdentifier();
    if (id != null) {
        String name = name(id);
        Tree.StaticType type = that.getType();
        if (type == null) {
            TypedDeclaration result;
            if (that.getPackageQualified()) {
                result = getPackageTypedDeclaration(name, null, false, unit);
            } else {
                result = getTypedDeclaration(that.getScope(), name, null, false, unit);
            }
            if (result != null) {
                checkBaseVisibility(that, result, name);
                setMemberMetatype(that, result);
            } else {
                that.addError("function or value is not defined: '" + name(id) + "'", 100);
                unit.setUnresolvedReferences();
            }
        } else {
            TypeDeclaration qtd = type.getTypeModel().getDeclaration();
            // checkNonlocalType(that.getType(), qtd);
            String container = "type '" + qtd.getName(unit) + "'";
            TypedDeclaration member = getTypedMember(qtd, name, null, false, unit, that.getScope());
            if (member == null) {
                if (qtd.isMemberAmbiguous(name, unit, null, false)) {
                    that.addError("method or attribute is ambiguous: '" + name + "' for " + container);
                } else {
                    that.addError("method or attribute is not defined: '" + name + "' in " + container);
                }
            } else {
                checkQualifiedVisibility(that, member, name, container, false);
                setMemberMetatype(that, member);
            }
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Aggregations

TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)110 Type (org.eclipse.ceylon.model.typechecker.model.Type)58 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)51 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)50 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)47 Function (org.eclipse.ceylon.model.typechecker.model.Function)34 Value (org.eclipse.ceylon.model.typechecker.model.Value)28 Class (org.eclipse.ceylon.model.typechecker.model.Class)26 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)26 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)25 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)21 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)21 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)20 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)19 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)18 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)17 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)17 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)16 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)15