Search in sources :

Example 96 with Function

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

the class DeclarationVisitor method checkForDuplicateDeclaration.

private static void checkForDuplicateDeclaration(Tree.Declaration that, Declaration model, Scope scope) {
    String name = model.getName();
    Unit unit = model.getUnit();
    if (name != null) {
        if (model instanceof Setter) {
            Setter setter = (Setter) model;
            checkGetterForSetter(that, setter, scope);
        } else {
            // this isn't the correct scope for declaration
            // which follow an assertion, since it misses
            // condition scopes, so use the argument scope
            // Scope scope = model.getContainer();
            boolean isControl;
            do {
                Declaration member = scope.getDirectMember(name, null, false);
                if (member != null && member != model) {
                    boolean dup = false;
                    boolean possibleOverloadedMethod = member instanceof Function && model instanceof Function && scope instanceof ClassOrInterface && !member.isNative() && member.isShared() && model.isShared();
                    boolean legalOverloadedMethod = possibleOverloadedMethod;
                    if (legalOverloadedMethod) {
                        // anticipate that it might be
                        // an overloaded method - then
                        // further checking happens in
                        // RefinementVisitor
                        initFunctionOverload((Function) model, (Function) member, scope, unit);
                    } else if (canBeNative(member) && canBeNative(model) && model.isNative()) {
                    // just to make sure no error
                    // gets reported
                    } else {
                        dup = true;
                        if (possibleOverloadedMethod) {
                            // it as overloading anyway
                            if (initFunctionOverload((Function) model, (Function) member, scope, unit)) {
                                that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
                            }
                        } else {
                            that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
                        }
                    }
                    if (dup) {
                        unit.getDuplicateDeclarations().add(member);
                    }
                }
                isControl = scope instanceof ControlBlock;
                scope = scope.getContainer();
            } while (isControl);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) ControlBlock(org.eclipse.ceylon.model.typechecker.model.ControlBlock) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) 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) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 97 with Function

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

the class ExpressionVisitor method createInferredParameter.

/**
 * Create a model for an inferred parameter of an
 * anonymous function.
 */
private boolean createInferredParameter(Tree.FunctionArgument anon, Declaration declaration, Tree.Parameter ap, Parameter parameter, Type type, FunctionOrValue original, boolean error) {
    if (isTypeUnknown(type)) {
        type = unit.getUnknownType();
        if (!dynamic) {
            if (error) {
                ap.addError("could not infer parameter type: '" + parameter.getName() + "' would have unknown type");
            } else {
                return false;
            }
        }
    } else if (involvesTypeParams(declaration, type)) {
        if (error) {
            type = unit.getUnknownType();
            ap.addError("could not infer parameter type: '" + parameter.getName() + "' would have type '" + type.asString(unit) + "' involving type parameters");
        } else {
            return false;
        }
    }
    Value model = (Value) parameter.getModel();
    if (model == null) {
        model = new Value();
        model.setUnit(unit);
        model.setName(parameter.getName());
        model.setOriginalParameterDeclaration(original);
        parameter.setModel(model);
        Function m = anon.getDeclarationModel();
        model.setContainer(m);
        model.setScope(m);
        m.addMember(model);
    }
    model.setType(type);
    model.setInferred(true);
    if (declaration != null && type != null && declaration.isJava() && !type.isUnknown() && type.isSubtypeOf(unit.getObjectType()) && canHaveUncheckedNulls(type)) {
        model.setUncheckedNullType(true);
    }
    model.setInitializerParameter(parameter);
    if (ap instanceof Tree.ValueParameterDeclaration) {
        Tree.ValueParameterDeclaration vpd = (Tree.ValueParameterDeclaration) ap;
        vpd.getTypedDeclaration().getType().setTypeModel(type);
    }
    return true;
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 98 with Function

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

the class TypeVisitor method visit.

@Override
public void visit(Tree.MethodDeclaration that) {
    super.visit(that);
    Tree.SpecifierExpression sie = that.getSpecifierExpression();
    Function dec = that.getDeclarationModel();
    if (isInitializerParameter(dec)) {
        if (sie != null) {
            sie.addError("function is an initializer parameter and may not have an initial value: '" + dec.getName() + "'");
        }
    }
// unnecessary, let definite assignment checking handle it!
// if (sie==null && isNativeImplementation(dec)) {
// that.addError("missing body for native function: '" +
// dec.getName() + "' must have a body");
// }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 99 with Function

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

the class TypeVisitor method visit.

@Override
public void visit(Tree.MethodDefinition that) {
    super.visit(that);
    Function dec = that.getDeclarationModel();
    if (isInitializerParameter(dec)) {
        that.getBlock().addError("function is an initializer parameter and may not have a body: '" + dec.getName() + "'");
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function)

Example 100 with Function

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

the class AnnotationVisitor method visit.

@Override
public void visit(Tree.AnyMethod that) {
    super.visit(that);
    Function a = that.getDeclarationModel();
    if (a.isAnnotation()) {
        checkAnnotationConstructor(that, a);
    }
    TypedDeclaration m = that.getDeclarationModel();
    Unit unit = that.getUnit();
    checkAnnotations(that.getAnnotationList(), unit.getFunctionDeclarationType(), unit.getFunctionMetatype(m.getTypedReference()), that);
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Aggregations

Function (org.eclipse.ceylon.model.typechecker.model.Function)167 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)71 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)70 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)69 Type (org.eclipse.ceylon.model.typechecker.model.Type)68 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)62 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)57 Value (org.eclipse.ceylon.model.typechecker.model.Value)50 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)46 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)43 Class (org.eclipse.ceylon.model.typechecker.model.Class)39 ArrayList (java.util.ArrayList)32 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)29 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)26 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)23 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)23 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)23 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)23 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)21