예제 #1
0
        public void InheritAttributes(MetaMetadataField inheritFrom)
        {
            var classDescriptor = ClassDescriptor.GetClassDescriptor(this);

            foreach (MetaMetadataFieldDescriptor fieldDescriptor in classDescriptor.AllFieldDescriptors)
            {
                if (fieldDescriptor.IsInheritable)
                {
                    ScalarType scalarType = fieldDescriptor.ScalarType;
                    try
                    {
                        if (scalarType != null &&
                            scalarType.IsDefaultValue(fieldDescriptor.Field, this) &&
                            !scalarType.IsDefaultValue(fieldDescriptor.Field, inheritFrom))
                        {
                            Object value = fieldDescriptor.Field.GetValue(inheritFrom);
                            fieldDescriptor.Field.SetValue(this, value);
                            Debug.WriteLine("inherit\t" + this.Name + "." + fieldDescriptor.Name + "\t= " + value);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(inheritFrom.Name + " doesn't have field " + fieldDescriptor.Name + ", ignore it.");
                        //					e.printStackTrace();
                    }
                }
            }
        }
        public void Pop(MetaMetadataField mmField)
        {
            MetaMetadataField field = mmStack.Pop();

            Debug.WriteLine("popping " + field);
            scopeStack.Pop();
            if (mmField != field)
            {
                throw new MetaMetadataException("mmField != field");
            }
        }
예제 #3
0
        protected override bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler)
        {
            /*
             * the childComposite should hide all complexity between collection fields and composite fields,
             * through hooks when necessary.
             */
            int typeCode = this.GetFieldType();

            switch (typeCode)
            {
            case FieldTypes.CollectionElement:
            {
                // prepare childComposite: possibly new name, type, extends, tag and inheritedField
                MetaMetadataCompositeField childComposite = this.GetChildComposite();
                if (childComposite.Name == UNRESOLVED_NAME)
                {
                    childComposite.Name = (childType ?? Name);
                }
                childComposite.Type             = childType; // here not using setter to reduce unnecessary re-assignment of this.childType
                childComposite.ExtendsAttribute = ChildExtends;
                childComposite.Tag         = childTag;
                childComposite.Repository  = Repository;
                childComposite.PackageName = PackageName;

                if (SuperField != null)
                {
                    childComposite.SuperField = (SuperField as MetaMetadataCollectionField).GetChildComposite();
                }
                childComposite.DeclaringMmd = DeclaringMmd;
                childComposite.Scope        = Scope;

                childComposite.InheritMetaMetadata(inheritanceHandler); // inheritedMmd might be inferred from type/extends

                TypeMmd = childComposite.TypeMmd;
                Scope   = childComposite.Scope;
                break;
            }

            case FieldTypes.CollectionScalar:
            {
                MetaMetadataField inheritedField = SuperField;
                if (inheritedField != null)
                {
                    InheritAttributes(inheritedField);
                }
                break;
            }
            }

            return(true);
        }
예제 #4
0
        public String ParentString()
        {
            StringBuilder result = new StringBuilder();

            ElementState parent = this.Parent;

            while (parent is MetaMetadataField)
            {
                MetaMetadataField pf = (MetaMetadataField)parent;
                result.Insert(0, "<" + pf.Name + ">");
                parent = parent.Parent;
            }
            return(result.ToString());
        }
        public bool IsUsingGenerics(MetaMetadataField field)
        {
            if (field.GenericTypeVars != null && field.GenericTypeVars.Count > 0)
            {
                return(true);
            }
            MmdGenericTypeVarScope gtvScope = (MmdGenericTypeVarScope)scopeStack.Peek().Get(
                GENERIC_TYPE_VAR_SCOPE);

            if (gtvScope == null)
            {
                return(false);
            }
            if (((field.GetMmdType() != null) && gtvScope.ContainsKey(field.GetMmdType())) || field.GetMmdType() == null &&
                ((field.Name != null) && gtvScope.ContainsKey(field.Name)) ||
                ((field.GetMmdExtendsAttribute() != null) && gtvScope.ContainsKey(field.GetMmdExtendsAttribute())))
            {
                return(true);
            }
            return(false);
        }
        public override String GetTypeName()
        {
            String result   = null;
            Type   thisType = GetType();

            if (thisType == typeof(MetaMetadataCompositeField))
            {
                MetaMetadataCompositeField mmcf = (MetaMetadataCompositeField)this;
                if (mmcf.Type != null)
                {
                    result = mmcf.Type;
                }
            }
            else if (thisType == typeof(MetaMetadataCollectionField))
            {
                MetaMetadataCollectionField mmcf = (MetaMetadataCollectionField)this;
                if (mmcf.ChildType != null)
                {
                    result = mmcf.ChildType;
                }
                else if (mmcf.ChildScalarType != null)
                {
                    result = mmcf.ChildScalarType.CSharpTypeName;
                }
            }

            if (result == null)
            {
                MetaMetadataField inherited = SuperField;
                if (inherited != null)
                {
                    // use inherited field's type
                    result = inherited.GetTypeName();
                }
            }

            return(result ?? (Name));
        }
        public void Push(MetaMetadataField mmField)
        {
            Debug.WriteLine("pushing " + mmField);
            mmStack.Push(mmField);

            // put mmd scope
            MultiAncestorScope <Object> scope = new MultiAncestorScope <Object>();

            if (scopeStack.Count > 0)
            {
                scope.AddAncestor(scopeStack.Peek());
            }
            scopeStack.Push(scope);

            // put generic type var scope
            MmdGenericTypeVarScope existingMmdGenericTypeVarScope = (MmdGenericTypeVarScope)scope.Get(GENERIC_TYPE_VAR_SCOPE);
            MmdGenericTypeVarScope currentMmdGenericTypeVarScope  = mmField.GenericTypeVars;

            if (currentMmdGenericTypeVarScope != null && existingMmdGenericTypeVarScope != null)
            {
                currentMmdGenericTypeVarScope.InheritFrom(existingMmdGenericTypeVarScope, this);
            }
            scope.AddIfValueNotNull(GENERIC_TYPE_VAR_SCOPE, mmField.GenericTypeVars);
        }
예제 #8
0
 public MetadataFieldDescriptorProxy(MetaMetadataField outer)
 {
     this.outer = outer;
 }
        public MetaMetadata ResolveMmdName(String mmdName, NameType[] nameType)
        {
            if (mmdName == null)
            {
                return(null);
            }
            Object            resultObj = null;
            MetaMetadata      result    = null;
            MetaMetadataField field     = mmStack.Peek();

            if (nameType != null && nameType.Length > 0)
            {
                nameType[0] = NameType.NONE;
            }

            // step 1: try to resolve the name as a concrete meta-metadata name, using the mmdScope.
            if (field is MetaMetadataNestedField)
            {
                MetaMetadataNestedField nested = (MetaMetadataNestedField)field;
                nested.Scope.TryGetValue(mmdName, out resultObj);
                result = (MetaMetadata)resultObj;
                if (result != null)
                {
                    if (nameType != null && nameType.Length > 0)
                    {
                        nameType[0] = NameType.MMD;
                    }
                }
            }

            // step 2: if step 1 failed, try to use it as a generic type var name
            if (result == null && mmdName.ToUpper().Equals(mmdName))
            {
                List <Object> gtvScopes = scopeStack.Peek().GetAll(GENERIC_TYPE_VAR_SCOPE);
                foreach (MmdGenericTypeVarScope gtvScope_object in gtvScopes)
                {
                    if (!(gtvScope_object is MmdGenericTypeVarScope))
                    {
                        throw new MetaMetadataException("Object is not instance of MmdGenericTypeVarScope");
                    }
                    MmdGenericTypeVarScope gtvScope = gtvScope_object;

                    MmdGenericTypeVar gtv = gtvScope.Get(mmdName);
                    if (gtv != null)
                    {
                        if (gtv.Arg != null)
                        {
                            result = ResolveMmdName(gtv.Arg);
                        }
                        else if (gtv.ExtendsAttribute != null)
                        {
                            result = ResolveMmdName(gtv.ExtendsAttribute);
                        }
                        // TODO superAttribute?
                    }
                }
                if (result != null)
                {
                    if (nameType != null && nameType.Length > 0)
                    {
                        nameType[0] = NameType.GENERIC;
                    }
                }
            }

            return(result);
        }
        /**
         * bind metadata field descriptors to sub-fields of this nested field, with field names as keys,
         * but without mixins field.
         * <p>
         * sub-fields that lack corresponding field descriptors will be removed from this nested field.
         * <p>
         * note that this field no longer uses a boolean flag to prevent multiple invocation. this should
         * have been done by the bindClassDescriptor() method.
         *
         * @param metadataTScope
         *          the translation scope of (generated) metadata classes.
         * @param metadataClassDescriptor
         *          the metadata class descriptor where field descriptors can be found.
         */

        protected void BindMetadataFieldDescriptors(SimplTypesScope metadataTScope,
                                                    MetadataClassDescriptor metadataClassDescriptorToBind)
        {
            bool needCloneKids = false;

            // check if the class's base class is genereic typed, and make sure itself is not generic.
            MetadataClassDescriptor metadataCd = MetadataClassDescriptor;
            MetaMetadata            baseMmd    = TypeMmd;

            while (baseMmd != null && metadataCd != null)
            {
                if (metadataCd.GetGenericTypeVars().Count == 0 && baseMmd.GenericTypeVars != null)
                {
                    needCloneKids = true;
                    break;
                }
                metadataCd = baseMmd.MetadataClassDescriptor;
                baseMmd    = baseMmd.TypeMmd;
            }

            if (needCloneKids)
            {
                DictionaryList <string, MetaMetadataField> clonedKids = new DictionaryList <string, MetaMetadataField>();
                foreach (KeyValuePair <string, MetaMetadataField> entry in Kids)
                {
                    string            key   = entry.Key;
                    MetaMetadataField field = entry.Value;

                    // look up to see if the field is declared in a generic typed class. If not, it does not need to clone it.
                    MetaMetadata declaringMmd = field.DeclaringMmd;
                    if (declaringMmd != null && declaringMmd.GenericTypeVars != null && declaringMmd.IsGenericMetadata)
                    {
                        // clone the field
                        field = field.Clone();
                        // remove the inherited field descriptor
                        field.MetadataFieldDescriptor = null;
                    }
                    clonedKids.Put(key, field);
                }
                Kids = clonedKids;
            }


            // copy the kids collection first to prevent modification to the collection during iteration (which may invalidate the iterator).
            List <MetaMetadataField> fields = new List <MetaMetadataField>(Kids.Values);

            foreach (MetaMetadataField thatChild in fields)
            {
                // look up by field name and bind
                MetadataFieldDescriptor metadataFd = thatChild.BindMetadataFieldDescriptor(metadataTScope, metadataClassDescriptorToBind);
                if (metadataFd == null)
                {
                    Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "Cannot bind metadata field descriptor for " + thatChild);
                    Kids.Remove(thatChild.Name);
                    continue;
                }

                // set defininig mmdfield

                // process hide and shadows
                var isImage = thatChild is MetaMetadataCompositeField && "image".Equals(((MetaMetadataCompositeField)thatChild).Type);
                HashSet <String> nonDisplayedFieldNames = NonDisplayedFieldNames;
                if (thatChild.Hide && !isImage)
                {
                    nonDisplayedFieldNames.Add(thatChild.Name);
                }
                if (thatChild.Shadows != null)
                {
                    nonDisplayedFieldNames.Add(thatChild.Shadows);
                }

                // recursively process sub-fields
                Int32 fieldType = metadataFd.FdType;
                if (fieldType == FieldTypes.CompositeElement || fieldType == FieldTypes.CollectionElement)
                {
                    // bind class descriptor for nested sub-fields
                    MetaMetadataNestedField nested = (MetaMetadataNestedField)thatChild;
                    MetadataFieldDescriptor fd     = nested.MetadataFieldDescriptor;
                    if (fd.IsPolymorphic)
                    {
                        Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "Polymorphic field: " + nested + ", not binding an element class descriptor.");
                    }
                    else
                    {
                        MetadataClassDescriptor elementClassDescriptor =
                            ((MetaMetadataNestedField)thatChild).BindMetadataClassDescriptor(metadataTScope);
                        if (elementClassDescriptor != null)
                        {
                            MetaMetadata mmdForThatChild = nested.TypeMmd;
                            if (mmdForThatChild != null && mmdForThatChild.MetadataClassDescriptor == null)
                            {
                                //							mmdForThatChild.setMetadataClassDescriptor(elementClassDescriptor);
                                mmdForThatChild.BindMetadataClassDescriptor(metadataTScope);
                            }
                        }
                        else
                        {
                            Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "Cannot determine elementClassDescriptor for " + thatChild);
                            Kids.Remove(thatChild.Name);
                        }
                    }
                }

                if (this is MetaMetadata)
                {
                    MetaMetadata mmd       = (MetaMetadata)this;
                    String       naturalId = thatChild.AsNaturalId;
                    if (naturalId != null)
                    {
                        mmd.NaturalIds.Put(naturalId, thatChild);
                    }
                }
            }
        }