Пример #1
0
 public static GuiClass CreateClass( StaticView parent, int x, int y, UmlClass cl )
 {
     GuiClass c = GuiClass.fromUML(cl);
     c.X = x;
     c.Y = y;
     parent.AddObject( c, UmlModel.GetUniversal(cl) );
     return c;
 }
Пример #2
0
        public static IEnumerable GetRelations( UmlClass cl, UmlModel m )
        {
            ArrayList l = new ArrayList();

            // get inheritances
            if( cl.BaseObjects != null )
                foreach( string s in cl.BaseObjects ) {
                    UmlClass obj = m.GetObject( s ) as UmlClass;
                    if( obj != null )
                        l.Add( new UmlRelation( obj, cl, obj.kind == UmlKind.Interface ? UmlRelationType.Realization : UmlRelationType.Inheritance, null, null, null, null ) );
                }

            // get associations
            Hashtable h = new Hashtable();
            if( cl.Members != null )
                foreach( UmlMember mb in cl.Members ) {
                    string name = mb.name, type = null;
                    switch( mb.Kind ) {
                        case UmlKind.Property:
                            type = ((UmlProperty)mb).Type;
                            break;
                        case UmlKind.Field:
                            type = ((UmlField)mb).Type;
                            break;
                    }

                    if( type != null ) {
                        if( type.IndexOf( '[' ) >= 0 ) {
                            int i = type.IndexOf( '[' );
                            name += type.Substring(i);
                            type = type.Substring(0, i);
                        }

                        UmlClass obj = m.GetObject( type ) as UmlClass;

                        if( obj != null && obj != cl ) {
                            if( h.ContainsKey( obj ) )
                                h[obj] = (string)h[obj] + "," + name;
                            else
                                h[obj] = name;
                        }
                    }
                }

            foreach( UmlClass obj in h.Keys ) {
                l.Add( new UmlRelation( obj, cl, UmlRelationType.Association, (string)h[obj], null, null, null ) );

            }

            return l;
        }
Пример #3
0
        internal UmlRelation(UmlClass src, UmlClass dest, UmlRelationType type, string src_role, string dest_role, string name, string stereo)
        {
            this.src       = src;
            this.dest      = dest;
            this.type      = type;
            this.src_role  = src_role;
            this.dest_role = dest_role;
            this.name      = name;
            this.stereo    = stereo;

            ID = type.ToString() + "#" + src.UniqueName + "#" + dest.UniqueName;
            if (stereo != null)
            {
                ID += "#[stereo]" + stereo;
            }
        }
Пример #4
0
        private UmlMember GetMember( string name, string signature, ModifiersNode mod, UmlKind kind, UmlClass cl )
        {
            UmlMember member = null;

            if( cl.Members == null )
                cl.Members = new ArrayList();
            else
                foreach( UmlMember m in cl.Members )
                    if( m.signature.Equals( signature ) ) {
                        member = m;
                        break;
                    }

            recreate:
            if( member == null ) {
                switch( kind ) {
                    case UmlKind.Constant:	member = new UmlConstant(); break;
                    case UmlKind.Field:		member = new UmlField(); break;
                    case UmlKind.Method:	member = new UmlMethod(); break;
                    case UmlKind.Property:	member = new UmlProperty(); break;
                    case UmlKind.Event:		member = new UmlEvent(); break;
                    case UmlKind.Indexer:	member = new UmlIndexer(); break;
                    case UmlKind.Operator:	member = new UmlOperator(); break;
                    case UmlKind.Constructor:member = new UmlConstructor(); break;
                    case UmlKind.Destructor:member = new UmlDestructor(); break;
                }
                System.Diagnostics.Debug.Assert( member != null, "unknown Member kind" );
                member.signature = signature;
                member.name = name;
                cl.Members.Add( member );
            } else {
                if( member.Kind != kind ) {
                    cl.Members.Remove( member );
                    member = null;
                    goto recreate;
                }

                member.Deleted = false;
            }

            member.visibility = cl.Kind == UmlKind.Interface ? UmlVisibility.Public : UmlVisibility.Private;
            if( mod != null ) {
                if( (mod.value & (int)Modifiers.Internal) != 0 && (mod.value & (int)Modifiers.Protected) != 0 )
                    member.visibility = UmlVisibility.ProtectedInternal;
                else if( (mod.value & (int)Modifiers.Internal) != 0 )
                    member.visibility = UmlVisibility.Internal;
                else if( (mod.value & (int)Modifiers.Protected) != 0 )
                    member.visibility = UmlVisibility.Protected;
                else if( (mod.value & (int)Modifiers.Public) != 0 )
                    member.visibility = UmlVisibility.Public;
                else if( (mod.value & (int)Modifiers.Private) != 0 )
                    member.visibility = UmlVisibility.Private;

                if( (mod.value & (int)Modifiers.Static) != 0 )
                    member.IsStatic = true;
                if( (mod.value & (int)Modifiers.Abstract) != 0 )
                    member.IsAbstract = true;
            }

            return member;
        }
Пример #5
0
 public static GuiClass fromUML( UmlClass st )
 {
     GuiClass s = new GuiClass();
     s.name = st.UniqueName;
     s.st = st;
     s.Created();
     return s;
 }
Пример #6
0
 public override void PostLoad()
 {
     st = parent.proj.model.GetObject( name ) as UmlClass;
     fillHash();
     base.PostLoad();
 }
Пример #7
0
 public void ImportClass( UmlClass cl )
 {
     if( parent.FindClass( cl ) == null ) {
         GuiClass gc = GuiElementFactory.CreateClass( parent, x_coord_counter, ancest ? Y - 100 : Y + Height + 100, cl );
         x_coord_counter += 20 + gc.Width;
     }
 }
Пример #8
0
 public void EditedName( string name )
 {
     ObjectState before = GetState();
     this.name = name;
     st = parent.proj.model.GetObject( name ) as UmlClass;
     RefreshContent();
     parent.Undo.Push( new StateOperation( this, before, GetState() ), false );
 }
Пример #9
0
        public void Apply(ObjectState v)
        {
            State t = v as State;
            X = t.x;
            Y = t.y;
            show_members = t.b1;
            show_vars = t.b2;
            show_properties = t.b3;
            show_full_qual = t.b4;
            show_method_signatures = t.b5;
            show_only_public = t.b6;
            stereo = t.stereo;

            if( t.members != null ) {
                members = new ArrayList( t.members.Count );
                foreach( GuiMember m in t.members )
                    members.Add( m.Clone() );
            } else
                members = null;
            fillHash();

            name = t.name;
            st = parent.proj.model.GetObject( name ) as UmlClass;

            RefreshContent();
            SetHidden( t.hidden );
        }
Пример #10
0
        private void LoadClass( UmlTypeHolder scope, ClassDecl decl, UsingBlock usings )
        {
            // get cl from old classes, or create a new one
            UmlClass cl = null;
            foreach( UmlType ent in scope.Types ) {
                if( ent.name.Equals( decl.name.identifier ) && ent is UmlClass ) {
                    cl = (UmlClass)ent;
                    break;
                }
            }
            if( cl == null ) {
                cl = new UmlClass();
                scope.Types.Add( cl );
                added_classes.Add( cl );
            }

            // register class
            classes[cl] = decl;

            // fill with information
            switch( decl.kind ) {
                case Kind.Class:
                    cl.kind = UmlKind.Class; break;
                case Kind.Interface:
                    cl.kind = UmlKind.Interface; break;
                case Kind.Struct:
                    cl.kind = UmlKind.Struct; break;
            }
            cl.name = decl.name.identifier;
            cl.using_chain = usings;
            cl.Deleted = false;
            cl.IsAbstract = ( decl.modifiers != null && (decl.modifiers.value & (int)Modifiers.Abstract) != 0 );
            FillClassWithTypes( cl, decl );
        }
Пример #11
0
 private ArrayList GetParameters( ListNode ln, UmlClass cl )
 {
     ArrayList l = new ArrayList();
     if( ln != null )
         foreach( ParameterNode pn in ln.nodes ) {
             UmlParameter param = new UmlParameter();
             param.name = pn.name.identifier;
             param.Type = GetFullTypeName( GetTypeName( pn.type ), cl );
             l.Add( param );
         }
     return l;
 }
Пример #12
0
        internal UmlRelation( UmlClass src, UmlClass dest, UmlRelationType type, string src_role, string dest_role, string name, string stereo )
        {
            this.src = src;
            this.dest = dest;
            this.type = type;
            this.src_role = src_role;
            this.dest_role = dest_role;
            this.name = name;
            this.stereo = stereo;

            ID = type.ToString() + "#" + src.UniqueName + "#" + dest.UniqueName;
            if( stereo != null )
                ID += "#[stereo]" + stereo;
        }
Пример #13
0
 private string GenerateSignature( string name, ListNode parms, UmlClass cl, bool is_indexer )
 {
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     if( parms != null )
         foreach( ParameterNode pn in parms.nodes ) {
             if( sb.Length != 0 )
                 sb.Append( "," );
             string type = GetFullTypeName( GetTypeName( pn.type ), cl );
             if( pn.modifiers != null ) {
                 if( (pn.modifiers.value & (int)Modifiers.Out) != 0 )
                     sb.Append( "out " );
                 if( (pn.modifiers.value & (int)Modifiers.Ref) != 0 )
                     sb.Append( "ref " );
                 if( (pn.modifiers.value & (int)Modifiers.Params) != 0 )
                     sb.Append( "params " );
             }
             sb.Append( type );
         }
     return is_indexer ? name + "[" + sb.ToString() + "]"
                       : name + "(" + sb.ToString() + ")";
 }
Пример #14
0
 private void FillClassWithTypes( UmlClass cl, ClassDecl classdecl )
 {
     if( classdecl.members != null )
         foreach( DeclNode decl in classdecl.members.nodes )
             switch( decl.kind ) {
                 case Kind.Interface:
                 case Kind.Struct:
                 case Kind.Class:
                     LoadClass( cl, (ClassDecl)decl, null );
                     break;
                 case Kind.Delegate:
                     LoadDelegate( cl, (DelegateNode)decl, null );
                     break;
                 case Kind.Enum:
                     LoadEnum( cl, (EnumDecl)decl, null );
                     break;
             }
 }
Пример #15
0
 void CollectDeleted( UmlClass scope )
 {
     if( scope.Types != null )
         FilterDeleted( ref scope.Types );
 }
Пример #16
0
        private void UpdateClass( UmlClass cl, ClassDecl classdecl )
        {
            if( classdecl.members != null )
                foreach( DeclNode decl in classdecl.members.nodes )
                    switch( decl.kind ) {
                        case Kind.Const:
                        case Kind.Fields:
                            FieldsDecl var = (FieldsDecl)decl;
                            string type = GetFullTypeName( GetTypeName( var.type ), cl );
                            string name;
                            foreach( Node n in var.declarators.nodes ) {
                                name = n is VariableNode ? ((VariableNode)n).name.identifier : n is ConstantNode ? ((ConstantNode)n).name.identifier : null;
                                UmlField f = (UmlField)GetMember( name, name, var.modifiers, decl.kind == Kind.Fields ? UmlKind.Field : UmlKind.Constant, cl );
                                f.Type = type;
                            }
                            break;
                        case Kind.UnaryOperator:
                        case Kind.BinaryOperator:
                        case Kind.Method:
                            MethodDecl meth = (MethodDecl)decl;
                            UmlKind uml_kind = decl.kind == Kind.Method ? UmlKind.Method : UmlKind.Operator;
                            UmlMethod m = (UmlMethod)GetMember( meth.name.identifier, GenerateSignature( meth.name.identifier, meth.parameters, cl, false ), meth.modifiers, uml_kind, cl );
                            m.ReturnType = GetFullTypeName( GetTypeName( meth.return_type ), cl );
                            m.Params = GetParameters( meth.parameters, cl );
                            break;
                        case Kind.Constructor:
                        case Kind.Destructor:
                            MethodDecl cdtor = (MethodDecl)decl;
                            name = decl.kind == Kind.Constructor ? cdtor.name.identifier : "~" + cdtor.name.identifier;
                            UmlMethod cdmemb = (UmlMethod)GetMember( name, GenerateSignature( name, cdtor.parameters, cl, false ), cdtor.modifiers, decl.kind == Kind.Constructor ? UmlKind.Constructor : UmlKind.Destructor, cl );
                            cdmemb.Params = GetParameters( cdtor.parameters, cl );
                            break;
                        case Kind.ConversionOperator:
                            meth = (MethodDecl)decl;
                            name = "operator " + GetFullTypeName( GetTypeName( meth.return_type ), cl );
                            UmlOperator op = (UmlOperator)GetMember( name, GenerateSignature( name, meth.parameters, cl, false ), meth.modifiers, UmlKind.Operator, cl );
                            op.Params = GetParameters( meth.parameters, cl );
                            break;
                        case Kind.Property:
                            PropertyNode prop = (PropertyNode)decl;
                            UmlProperty p = (UmlProperty)GetMember( prop.name.identifier, prop.name.identifier, prop.modifiers, UmlKind.Property, cl );
                            p.Type = GetFullTypeName( GetTypeName( prop.type ), cl );
                            p.Accessors = string.Empty;
                            if( prop.accessors != null )
                                foreach( AccessorNode an in prop.accessors.nodes )
                                    p.Accessors += an.name.identifier + ";";
                            break;
                        case Kind.EventVars:
                            UmlEvent ev;
                            EventNode evnt = (EventNode)decl;
                            type = GetFullTypeName( GetTypeName( evnt.type ), cl );
                            foreach( VariableNode n in evnt.vars.nodes ) {
                                ev = (UmlEvent)GetMember( n.name.identifier, n.name.identifier, evnt.modifiers, UmlKind.Event, cl );
                                ev.Type = type;
                                ev.Accessors = null;
                            }
                            break;
                        case Kind.EventWithAccessors:
                            evnt = (EventNode)decl;
                            ev = (UmlEvent)GetMember( evnt.name.identifier, evnt.name.identifier, evnt.modifiers, UmlKind.Event, cl );
                            ev.Type = GetFullTypeName( GetTypeName( evnt.type ), cl );
                            ev.Accessors = String.Empty;
                            if( evnt.accessors != null )
                                foreach( AccessorNode an in evnt.accessors.nodes )
                                    ev.Accessors += an.name.identifier + ";";
                            break;
                        case Kind.Indexer:
                            IndexerNode inode = (IndexerNode)decl;
                            UmlIndexer indx = (UmlIndexer)GetMember( inode.name.identifier, GenerateSignature( inode.name.identifier, inode.formal_params, cl, true ), inode.modifiers, UmlKind.Indexer, cl );
                            indx.ReturnType = GetFullTypeName( GetTypeName( inode.type ), cl );
                            indx.Params = GetParameters( inode.formal_params, cl );
                            break;
                        case Kind.Delegate:
                        case Kind.Enum:
                        case Kind.Class:
                        case Kind.Interface:
                        case Kind.Struct:
                            break;      // handled earlier
                        default:
                            System.Diagnostics.Debug.Fail( "unknown class member" );
                            break;
                    }

            // kill deleted
            if( cl.Members != null )
                for( int i = 0; i < cl.Members.Count; i++ ) {
                    UmlObject obj = (UmlObject)cl.Members[i];
                    if( obj.Deleted ) {
                        cl.Members.RemoveAt( i );
                        i--;
                    }
                }
        }
Пример #17
0
        public GuiClass FindClass( UmlClass cl )
        {
            foreach( GuiObject obj in active_objects ) {
                GuiClass gcl = obj as GuiClass;
                if( gcl != null && gcl.st == cl )
                    return gcl;
            }

            return null;
        }
Пример #18
0
        public static IEnumerable GetRelations(UmlClass cl, UmlModel m)
        {
            ArrayList l = new ArrayList();

            // get inheritances
            if (cl.BaseObjects != null)
            {
                foreach (string s in cl.BaseObjects)
                {
                    UmlClass obj = m.GetObject(s) as UmlClass;
                    if (obj != null)
                    {
                        l.Add(new UmlRelation(obj, cl, obj.kind == UmlKind.Interface ? UmlRelationType.Realization : UmlRelationType.Inheritance, null, null, null, null));
                    }
                }
            }

            // get associations
            Hashtable h = new Hashtable();

            if (cl.Members != null)
            {
                foreach (UmlMember mb in cl.Members)
                {
                    string name = mb.name, type = null;
                    switch (mb.Kind)
                    {
                    case UmlKind.Property:
                        type = ((UmlProperty)mb).Type;
                        break;

                    case UmlKind.Field:
                        type = ((UmlField)mb).Type;
                        break;
                    }

                    if (type != null)
                    {
                        if (type.IndexOf('[') >= 0)
                        {
                            int i = type.IndexOf('[');
                            name += type.Substring(i);
                            type  = type.Substring(0, i);
                        }

                        UmlClass obj = m.GetObject(type) as UmlClass;

                        if (obj != null && obj != cl)
                        {
                            if (h.ContainsKey(obj))
                            {
                                h[obj] = (string)h[obj] + "," + name;
                            }
                            else
                            {
                                h[obj] = name;
                            }
                        }
                    }
                }
            }

            foreach (UmlClass obj in h.Keys)
            {
                l.Add(new UmlRelation(obj, cl, UmlRelationType.Association, (string)h[obj], null, null, null));
            }

            return(l);
        }