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

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


public class TestBitAnnotations {

    @Test
    public void testEncode() {
        final Value v = new Value();
        int b = MetamodelGenerator.encodeAnnotations(v, null);
        Assert.assertEquals(0, b);
        v.getAnnotations().add(new Annotation("shared"));
        b = MetamodelGenerator.encodeAnnotations(v, null);
        Assert.assertEquals(1, b);
        v.getAnnotations().add(new Annotation("actual"));
        b = MetamodelGenerator.encodeAnnotations(v, null);
        Assert.assertEquals(3, b);
        v.getAnnotations().add(new Annotation("default"));
        b = MetamodelGenerator.encodeAnnotations(v, null);
        Assert.assertEquals(11, b);
    }
View Full Code Here


                param.setDeclaration(owner);
                param.setDefaulted(p.containsKey(MetamodelGenerator.KEY_DEFAULT));
                param.setSequenced(p.containsKey("seq"));
                param.setAtLeastOne(p.containsKey("$min1"));
                if (paramtype == null || "v".equals(paramtype)) {
                    Value _v = new Value();
                    param.setModel(_v);
                } else if ("f".equals(paramtype)) {
                    @SuppressWarnings("unchecked")
                    List<List<Map<String,Object>>> paramLists = (List<List<Map<String,Object>>>)p.get(MetamodelGenerator.KEY_PARAMS);
                    Method _m = new Method();
View Full Code Here

    }

    MethodOrValue loadAttribute(String name, Map<String, Object> m, Scope parent,
            List<TypeParameter> typeParameters) {
        String metatype = (String)m.get(MetamodelGenerator.KEY_METATYPE);
        Value d = new Value();
        d.setTransient(MetamodelGenerator.METATYPE_GETTER.equals(metatype));
        d.setName(name);
        d.setContainer(parent);
        d.setUnit(u2);
        if (parent == this) {
            u2.addDeclaration(d);
            addMember(null);
        }
        @SuppressWarnings("unchecked")
        final Map<String,Object> _anns = (Map<String,Object>)m.remove(MetamodelGenerator.KEY_ANNOTATIONS);
        setAnnotations(d, (Integer)m.remove(MetamodelGenerator.KEY_PACKED_ANNS), _anns);
        if (m.containsKey("var")) {
            ((Value)d).setVariable(true);
        }
        @SuppressWarnings("unchecked")
        final Map<String,Object> ktype = (Map<String,Object>)m.get(MetamodelGenerator.KEY_TYPE);
        d.setType(getTypeFromJson(ktype, parent instanceof Declaration ? (Declaration)parent : null, typeParameters));
        @SuppressWarnings("unchecked")
        final Map<String, Object> smap = (Map<String, Object>)m.remove("$set");
        if (smap != null) {
            Setter s = new Setter();
            s.setName(name);
            s.setContainer(parent);
            s.setUnit(u2);
            s.setGetter(d);
            d.setSetter(s);
            if (parent == this) {
                u2.addDeclaration(s);
                addMember(null);
            }
            @SuppressWarnings("unchecked")
            final Map<String,Object> sanns = (Map<String,Object>)smap.remove(MetamodelGenerator.KEY_ANNOTATIONS);
            setAnnotations(s, (Integer)smap.remove(MetamodelGenerator.KEY_PACKED_ANNS), sanns);
            s.setType(d.getType());
        }
        return d;
    }
View Full Code Here

    }

    /** Loads an object declaration, creating it if necessary, and returns its type declaration. */
    @SuppressWarnings("unchecked")
    TypeDeclaration loadObject(String name, Map<String, Object> m, Scope parent, List<TypeParameter> existing) {
        Value obj;
        if (m.get(MetamodelGenerator.KEY_METATYPE) instanceof Value) {
            obj = (Value)m.get(MetamodelGenerator.KEY_METATYPE);
        } else {
            obj = new Value();
            m.put(MetamodelGenerator.KEY_METATYPE, obj);
            obj.setName(name);
            obj.setContainer(parent);
            obj.setUnit(u2);
            com.redhat.ceylon.compiler.typechecker.model.Class type = new com.redhat.ceylon.compiler.typechecker.model.Class();
            type.setName(name);
            type.setAnonymous(true);
            type.setUnit(u2);
            type.setContainer(parent);
            if (parent == this) {
                u2.addDeclaration(obj);
                u2.addDeclaration(type);
            }
            parent.addMember(obj);
            obj.setType(type.getType());
            setAnnotations(obj, (Integer)m.get(MetamodelGenerator.KEY_PACKED_ANNS),
                    (Map<String,Object>)m.get(MetamodelGenerator.KEY_ANNOTATIONS));
            setAnnotations(obj.getTypeDeclaration(), (Integer)m.remove(MetamodelGenerator.KEY_PACKED_ANNS),
                    (Map<String,Object>)m.remove(MetamodelGenerator.KEY_ANNOTATIONS));
            if (type.getExtendedType() == null) {
                if (m.containsKey("super")) {
                    type.setExtendedType(getTypeFromJson((Map<String,Object>)m.remove("super"),
                            parent instanceof Declaration ? (Declaration)parent : null, existing));
                } else {
                    type.setExtendedType(getTypeFromJson(idobj, parent instanceof Declaration ? (Declaration)parent : null, existing));
                }
            }
            if (m.containsKey(MetamodelGenerator.KEY_SATISFIES)) {
                for (ProducedType sat : parseTypeList((List<Map<String,Object>>)m.remove(MetamodelGenerator.KEY_SATISFIES), existing)) {
                    Util.addToIntersection(type.getSatisfiedTypes(), sat, u2);
                }
            }
            if (m.containsKey(MetamodelGenerator.KEY_INTERFACES)) {
                for (Map.Entry<String,Map<String,Object>> inner : ((Map<String,Map<String,Object>>)m.remove(MetamodelGenerator.KEY_INTERFACES)).entrySet()) {
                    loadInterface(inner.getKey(), inner.getValue(), type, existing);
                }
            }
            if (m.containsKey(MetamodelGenerator.KEY_CLASSES)) {
                for (Map.Entry<String,Map<String,Object>> inner : ((Map<String,Map<String,Object>>)m.remove(MetamodelGenerator.KEY_CLASSES)).entrySet()) {
                    loadClass(inner.getKey(), inner.getValue(), type, existing);
                }
            }
            if (m.containsKey(MetamodelGenerator.KEY_OBJECTS)) {
                for (Map.Entry<String,Map<String,Object>> inner : ((Map<String,Map<String,Object>>)m.remove(MetamodelGenerator.KEY_OBJECTS)).entrySet()) {
                    loadObject(inner.getKey(), inner.getValue(), type, existing);
                }
            }
            addAttributesAndMethods(m, type, existing);
        }
        return obj.getTypeDeclaration();
    }
View Full Code Here

        }
    }
   
    @Override public void visit(Tree.AttributeDeclaration that) {
        super.visit(that);
        Value dec = that.getDeclarationModel();
        Tree.SpecifierOrInitializerExpression sie =
                that.getSpecifierOrInitializerExpression();
        inferType(that, sie);
        Tree.Type type = that.getType();
        if (type!=null) {
          ProducedType t = type.getTypeModel();
          if (type instanceof Tree.LocalModifier) {
            if (dec.isParameter()) {
              type.addError("parameter may not have inferred type: '" +
                  dec.getName() + "' must declare an explicit type");
            }
            else if (isTypeUnknown(t)) {
                if (sie==null) {
                    type.addError("value must specify an explicit type or definition", 200);
                }
                else if (!hasError(sie)) {
                    type.addError("value type could not be inferred");
                }
            }
          }
          if (!isTypeUnknown(t)) {
            checkType(t, dec.getName(), sie, 2100);
          }
        }
      Setter setter = dec.getSetter();
      if (setter!=null) {
        setter.getParameter().getModel().setType(dec.getType());
      }
    }
View Full Code Here

        return d.getProducedReference(supertype,
                Collections.<ProducedType>emptyList());
    }
   
    private void refineValue(Tree.SpecifierStatement that) {
        Value refinedValue = (Value) that.getRefined();
        Value value = (Value) that.getDeclaration();
        ClassOrInterface ci = (ClassOrInterface) value.getContainer();
        ProducedReference refinedProducedReference =
                getRefinedMember(refinedValue, ci);
        value.setType(refinedProducedReference.getType());
    }
View Full Code Here

    }
   
    @Override public void visit(Tree.AttributeGetterDefinition that) {
        Tree.Type type = that.getType();
        Tree.Type rt = beginReturnScope(type);
        Value dec = that.getDeclarationModel();
        Declaration od = beginReturnDeclaration(dec);
        super.visit(that);
        endReturnScope(rt, dec);
        endReturnDeclaration(od);
        Setter setter = dec.getSetter();
        if (setter!=null) {
            setter.getParameter().getModel().setType(dec.getType());
        }
        if (type instanceof Tree.LocalModifier) {
            if (isTypeUnknown(type.getTypeModel())) {
                type.addError("getter type could not be inferred");
            }
View Full Code Here

                ProducedType type = types.get(j);
                Tree.Parameter ap = aps.get(j);
                if (ap instanceof Tree.InitializerParameter) {
                    Parameter parameter = ap.getParameterModel();
                    if (parameter.getModel()==null) {
                        Value model = new Value();
                        model.setUnit(unit);
                        model.setType(type);
                        model.setName(parameter.getName());
                        parameter.setModel(model);
                        model.setInitializerParameter(parameter);
                        Method fun = anon.getDeclarationModel();
                        model.setContainer(fun);
                        fun.addMember(model);
                    }
                }
            }
        }
View Full Code Here

                if (ap instanceof Tree.InitializerParameter) {
                    Parameter parameter = ap.getParameterModel();
                    if (parameter.getModel()==null) {
                        ProducedType t =
                                pr.getTypedParameter(fp).getType();
                        Value model = new Value();
                        model.setUnit(unit);
                        model.setType(t);
                        model.setName(parameter.getName());
                        parameter.setModel(model);
                        model.setInitializerParameter(parameter);
                        Method fun = anon.getDeclarationModel();
                        model.setContainer(fun);
                        fun.addMember(model);
                    }
                }
            }
        }
View Full Code Here

            Declaration dec = smte.getDeclaration();
            if (dec!=null &&
                    (!isEffectivelyBaseMemberExpression(smte) ||
                     !unit.equals(dec.getUnit()))) { //Note: other cases handled in SpecificationVisitor
                if (dec instanceof Value) {
                    Value value = (Value) dec;
                    if (!value.isVariable() && !value.isLate()) {
                        that.addError("value is not a variable: '" +
                                dec.getName(unit) + "'", 800);
                    }
                }
                else {
View Full Code Here

TOP

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

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.