'***Patrick Rutledge, 9/98 'This script copies the abstract operations of a base class to its child class. 'It works on the selected child class. You might want to change it to work 'on all classes 'ops are equal if they have same name and parameters Function OpsEqual (inOp1 As Operation, inOp2 As Operation) As Boolean OpsEqual = False Dim param1 As parameter Dim param2 As Parameter If inOp1.name = inOp2.name Then If inOp1.Parameters.Count = inOp1.Parameters.Count Then For i% = 1 To inOp1.Parameters.Count Set param1 = inOp1.Parameters.GetAt(i%) Set param2 = inOp2.Parameters.Getat(i%) If param1.name <> param2.name Or _ param1.type <> param2.type Then Exit Function End If Next i% OpsEqual = True End If End If End Function 'returns true if an op equals to inOp exists in inOps Function OpExists (inOps As OperationCollection, inOp As Operation) As Boolean OpExists = False Dim op As Operation For i% = 1 To inOps.Count Set op = inOps.GetAt(i%) If OpsEqual (op, inOp) Then OpExists = True Exit Function End If Next i% End Function Sub CloneOperation (inClass As Class, inOp As Operation) Dim cloneOp As Operation Dim param As Parameter Set cloneOp = inClass.AddOperation (inOp.name, inOp.ReturnType) cloneOp.Virtual = inOp.Virtual cloneOp.Preconditions = inOp.Preconditions cloneOp.Semantics = inOp.Semantics cloneOp.Postconditions = inOp.Postconditions cloneOp.Protocol = inOp.Protocol cloneOp.Qualification = inOp.Qualification cloneOp.Exceptions = inOp.Exceptions cloneOp.Time = inOp.Time cloneOp.Size = inOp.Size cloneOp.ExportControl = inOp.ExportControl For j% = 1 To inOp.Parameters.Count Set param = inOp.Parameters.GetAt(j%) Set x = cloneOp.AddParameter (param.name, param.Type, param.InitValue, j%) Next j% End Sub Function GetAbstractFunctions(inClass As Class) As OperationCollection Dim ops As New OperationCollection Dim anOp As Operation For i% = 1 To inClass.Operations.Count Set anOp = inClass.Operations.GetAt(i%) propValue$ = anOp.GetPropertyValue("cg", "OperationKind") If propValue$ = "Abstract" Then ops.Add anOp End If Next i% Set GetAbstractFunctions = ops End Function Sub Main Dim selClasses As ClassCollection Dim selClass As Class Dim parentClass As Class Dim inherits As InheritRelationCollection Dim abstractOps As OperationCollection Dim anOp As Operation Set selClasses = RoseApp.CurrentModel.GetSelectedClasses() For i% = 1 To selClasses.Count Set selClass = selClasses.GetAt(i%) Set inherits = selClass.GetInheritRelations() For j% = 1 To inherits.Count Set parentClass = inherits.GetAt(j%).GetSupplierClass() Set abstractOps = GetAbstractFunctions(parentClass) For k% = 1 To abstractOps.Count Set anOp = abstractOps.GetAt(k%) If Not OpExists (selClass.Operations, anOp) Then CloneOperation selClass, anOp End If Next k% Next j% Next i% MsgBox "Done" End Sub