Search in sources :

Example 86 with Value

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

the class MethodOrValueReferenceVisitor method visit.

@Override
public void visit(Tree.AttributeDeclaration that) {
    final SpecifierOrInitializerExpression specifier = that.getSpecifierOrInitializerExpression();
    Value model = that.getDeclarationModel();
    boolean lse = inLazySpecifierExpression;
    if (specifier != null && model.isLate() && model.isClassMember()) {
        model.setCaptured(true);
        inLazySpecifierExpression = true;
    }
    super.visit(that);
    inLazySpecifierExpression = lse;
}
Also used : FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) SpecifierOrInitializerExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.SpecifierOrInitializerExpression)

Example 87 with Value

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

the class DeclarationErrorVisitor method planAccordingToErrors.

/**
 * Update the plan according to the errors on the node
 */
private void planAccordingToErrors(Node that) {
    List<Message> errors = that.getErrors();
    for (Message message : errors) {
        if (isError(that, message)) {
            TransformationPlan plan;
            /*if (message.getCode() == MEMBER_HAS_WRONG_NUMBER_OF_PARAMETERS
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if (message.getCode() == TYPE_OF_PARAMETER_IS_DIFFERENT_TO_CORRESPONDING_PARAMETER
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if (message.getCode() == COULD_NOT_DETERMINE_PARAMETER_TYPE_SAME_AS_CORRESPONDING_PARAMETER
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if ((message.getCode() == REFINED_MEMBER_WRONG_NUM_PL
                                || message.getCode() == MISSING_PL_FUNCTION_DECL)
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else*/
            if (message.getCode() == FORMAL_MEMBER_UNIMPLEMENTED_IN_CLASS_HIERARCHY && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
                plan = new ThrowerMethod(that, message);
            } else if ((message.getCode() == PL_AND_CONSTRUCTORS || message.getCode() == NO_CONSTRUCTORS) && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
                if (message.getCode() == NO_CONSTRUCTORS) {
                    plan = new PrivateConstructorOnly(that, message);
                } else {
                    plan = new ThrowerCatchallConstructor(that, message);
                }
            } else if (message.getCode() == FORWARD_DECL_NOT_IN_DECL_SECTION) {
                plan = Errors.GENERATE;
            } else {
                plan = new Drop(that, message);
            }
            newplan(plan);
        }
    }
}
Also used : Message(org.eclipse.ceylon.compiler.typechecker.tree.Message) Value(org.eclipse.ceylon.model.typechecker.model.Value) Class(org.eclipse.ceylon.model.typechecker.model.Class) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass)

Example 88 with Value

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

the class AbstractModelLoader method addConstructorMethorOrValue.

protected FunctionOrValue addConstructorMethorOrValue(Class klass, ClassMirror classMirror, MethodMirror ctor, Constructor constructor, boolean isNativeHeader) {
    boolean isCeylon = classMirror.getAnnotation(CEYLON_CEYLON_ANNOTATION) != null;
    if (ctor.getAnnotation(CEYLON_ENUMERATED_ANNOTATION) != null) {
        klass.setEnumerated(true);
        Value v = new Value();
        v.setName(constructor.getName());
        v.setType(constructor.getType());
        v.setContainer(klass);
        v.setScope(klass);
        v.setUnit(klass.getUnit());
        v.setVisibleScope(constructor.getVisibleScope());
        // read annotations from the getter method
        setNonLazyDeclarationProperties(v, ctor, ctor, classMirror, isCeylon);
        setAnnotations(v, ctor, isNativeHeader);
        klass.addMember(v);
        return v;
    } else {
        setParameters(constructor, classMirror, ctor, true, klass, false);
        klass.setConstructors(true);
        Function f = new Function();
        f.setName(constructor.getName());
        f.setType(constructor.getType());
        f.addParameterList(constructor.getParameterList());
        f.setContainer(klass);
        f.setScope(klass);
        f.setUnit(klass.getUnit());
        f.setVisibleScope(constructor.getVisibleScope());
        // read annotations from the constructor
        setNonLazyDeclarationProperties(f, ctor, ctor, classMirror, isCeylon);
        setAnnotations(f, ctor, isNativeHeader);
        klass.addMember(f);
        return f;
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) JavaParameterValue(org.eclipse.ceylon.model.loader.model.JavaParameterValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue)

Example 89 with Value

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

the class AbstractModelLoader method isRaw.

private boolean isRaw(Module module, TypeMirror type) {
    // See https://github.com/ceylon/ceylon-compiler/issues/1085
    switch(type.getKind()) {
        // arrays are never raw
        case ARRAY:
        case BOOLEAN:
        case BYTE:
        case CHAR:
        case DOUBLE:
        case ERROR:
        case FLOAT:
        case INT:
        case LONG:
        case NULL:
        case SHORT:
        case TYPEVAR:
        case VOID:
        case WILDCARD:
            return false;
        case DECLARED:
            ClassMirror klass = type.getDeclaredClass();
            if (klass.isJavaSource()) {
                // I suppose this should work
                return type.isRaw();
            }
            List<String> path = new LinkedList<String>();
            String pkgName = klass.getPackage().getQualifiedName();
            String unquotedPkgName = unquotePackageName(klass.getPackage());
            String qualifiedName = klass.getQualifiedName();
            String relativeName = pkgName.isEmpty() ? qualifiedName : qualifiedName.substring(pkgName.length() + 1);
            for (String name : relativeName.split("[\\$\\.]")) {
                if (!name.isEmpty()) {
                    path.add(name);
                }
            }
            if (path.size() > 1) {
                // find the proper class mirror for the container
                klass = loadClass(module, pkgName, new StringBuilder(pkgName).append('.').append(path.get(0)).toString());
                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 (JvmBackendUtil.isValue(decl) && ((Value) decl).getTypeDeclaration().getName().equals(name))
                        decl = ((Value) decl).getTypeDeclaration();
                    if (decl instanceof TypeDeclaration == false)
                        return false;
                    scope = (TypeDeclaration) decl;
                }
                TypeDeclaration typeDecl = (TypeDeclaration) scope;
                return typeDecl.isParameterized() && type.getTypeArguments().isEmpty();
            }
            try {
                return type.isRaw();
            } catch (Exception x) {
                // it will be logged somewhere else
                return false;
            }
        default:
            return false;
    }
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) JavaParameterValue(org.eclipse.ceylon.model.loader.model.JavaParameterValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) LinkedList(java.util.LinkedList) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException)

Example 90 with Value

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

the class AbstractModelLoader method makeSetter.

private SetterWithLocalDeclarations makeSetter(Value value, ClassMirror classMirror) {
    SetterWithLocalDeclarations setter = new SetterWithLocalDeclarations(classMirror);
    Scope scope = value.getContainer();
    setter.setContainer(scope);
    setter.setScope(scope);
    setter.setType(value.getType());
    setter.setName(value.getName());
    Parameter p = new Parameter();
    p.setHidden(true);
    Value v = new Value();
    v.setType(value.getType());
    v.setUnboxed(value.getUnboxed());
    v.setInitializerParameter(p);
    v.setContainer(setter);
    v.setScope(setter);
    p.setModel(v);
    v.setName(setter.getName());
    p.setName(setter.getName());
    p.setDeclaration(setter);
    setter.setParameter(p);
    value.setSetter(setter);
    setter.setGetter(value);
    return setter;
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) SetterWithLocalDeclarations(org.eclipse.ceylon.model.loader.model.SetterWithLocalDeclarations) JavaParameterValue(org.eclipse.ceylon.model.loader.model.JavaParameterValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Aggregations

Value (org.eclipse.ceylon.model.typechecker.model.Value)190 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)135 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)77 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)74 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)70 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)69 Type (org.eclipse.ceylon.model.typechecker.model.Type)68 Function (org.eclipse.ceylon.model.typechecker.model.Function)50 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)47 Class (org.eclipse.ceylon.model.typechecker.model.Class)46 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)42 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)30 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)30 ArrayList (java.util.ArrayList)29 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)29 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)28 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)27 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)26 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)24 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)23