def metaclassCheck(modelPackage, validateOnly): ###get stereotype package if not isinstance(modelPackage, Profile): profilePackage = getProfilePackage(modelPackage) if not profilePackage: gl.log('****ERROR: The code is not being run on a Profile. Stopping Execution') return else: profilePackage = modelPackage infraPack = filter(lambda element: isinstance(element, Package) and "_"==element.getName(), profilePackage.getOwnedElement()) if len(infraPack)>0: infraPack = infraPack[0] else: return['No underscore Package'] stereotypePackage = filter(lambda element: isinstance(element, Package) and "_Stereotypes" in element.getName(), infraPack.getOwnedElement()) if len(stereotypePackage)==0: gl.log('****ERROR: There is no package named "_Stereotypes" that is a direct child of the Profile. Stopping Execution') return ['no stereotype Package'] else: stereotypePackage = stereotypePackage[0] sMMeta=[] ####Collect stereotypes with >1 metaclasses for s in stereotypePackage.getOwnedElement(): if isinstance(s, Stereotype): sMeta = StereotypesHelper.getBaseClasses(s) if len(sMeta)>1: sMMeta.append(s) if validateOnly!= True: gl.log('There is no codified fix for this problem. Modeler must rectify') return sMMeta
def getMissing(A, B): missing =[] nameMatch = {} metaMismatch=[] applyMismatch=[] for a in A: aName = a.getName() if isinstance(a, Property): aName = propertyCheck(a) elif isinstance(a, Stereotype) and StereotypesHelper.getBaseClassesAsClasses(a)[0] == Property: aGens = filter(lambda element: isinstance(element, Generalization), a.get_directedRelationshipOfSource()) if len(filter(lambda element: element.getGeneral() == StereotypesHelper.getStereotype(project, "ConstraintProperty"), aGens))!=0: if a.getName().find("constraint property")==-1: aName = a.getName() + " constraint property" elif len(filter(lambda element: element.getGeneral() == StereotypesHelper.getStereotype(project, "SharedProperty"), aGens))!=0: if a.getName().find("shared property")==-1: aName = a.getName() + " shared property" elif len(filter(lambda element: element.getGeneral() == StereotypesHelper.getStereotype(project, "DistributedProperty"), aGens))!=0: if a.getName().find("distributed property")==-1: aName = a.getName() + " distributed property" elif len(filter(lambda element: element.getGeneral() == StereotypesHelper.getStereotype(project, "FlowProperty"), aGens))!=0: if a.getName().find("flow property")==-1: aName = a.getName() + " flow property" elif len(filter(lambda element: element.getGeneral() == StereotypesHelper.getStereotype(project, "ValueProperty"), aGens))!=0: if a.getName().find("value property")==-1: aName = a.getName() + " value property" elif len(filter(lambda element: element.getGeneral() == StereotypesHelper.getStereotype(project, "ReferenceProperty"), aGens))!=0: if a.getName().find("reference property")==-1: aName = a.getName() + " reference property" else: if a.getName().find("part property")==-1: aName=a.getName() + " part property" elif isinstance(a, Stereotype) and StereotypesHelper.getBaseClassAsClasses(a)[0] == Port: if a.getName().find("port")==-1: aName = a.getName() + " port" bExist = 0 for b in B: if aName == b.getName(): nameMatch[a]=b bExist = 1 if b not in StereotypesHelper.getAllAssignedStereotypes([a]): noApply[a]=b if bExist == 0: missing.append(a) for n in nameMatch: ###get generalizations of stereotype stereotype = nameMatch[n] nGeneral = filter(lambda element: isinstance(element, Generalization), stereotype.get_directedRelationshipOfSource()) general = [] for g in nGeneral: general.append(g.getGeneral()) ###keep only SysML generalizations gSys = filter(lambda element: StereotypesHelper.getProfileForStereotype(element) == StereotypesHelper.getProfile(project, "SysML"), general) if gSys and not StereotypesHelper.checkForAllDerivedStereotypes(n, gSys[0]): applyMismatch.append(n) ###check if same if n.getName() != "_Unused Stereotypes": if not isinstance(n, StereotypesHelper.getClassOfMetaClass(StereotypesHelper.getBaseClasses(nameMatch[n])[0])): metaMismatch.append(n) return [missing, applyMismatch, metaMismatch]
def stereotypesForElements(modelPackage, validateOnly, elementType, stereotypesIgnore, packagesIgnore): if not stereotypesIgnore: stereotypesIgnore=[] profilePackage = profilePackCheck(modelPackage) if not profilePackage: return ['no Profile Package', 'no Profile Package', 'no Profile Package', 'no Profile Package'] infraPack = filter(lambda element: isinstance(element, Package) and "_"==element.getName(), profilePackage.getOwnedElement()) if len(infraPack)>0: infraPack = infraPack[0] else: return['no underscore pacakage, no underscore pacakage,no underscore pacakage,no underscore pacakage'] stereotypePackage=packageCheck(profilePackage, infraPack, validateOnly, "_Stereotypes") if not stereotypePackage: return ['no Stereotype Package', 'no Stereotype Package', 'no Stereotype Package', 'no Stereotype Package'] baseClass = getElements(getEverything(modelPackage), profilePackage) baseClass = filter(lambda element: "_" not in element.getName(), baseClass) if not isinstance(modelPackage, Profile): baseClass.append(modelPackage) ###intialize counts sterCreate = 0 nameChange = 0 unapply = 0 apply = 0 ### if elementType != 'Misc': baseClass = filter(lambda element: isinstance(element, elementType), baseClass) for s in stereotypesIgnore: baseClass = filter(lambda element: StereotypesHelper.hasStereotypeOrDerived(element, s) == False, baseClass) ignoredPackEls = [] for i in packagesIgnore: baseClass = filter(lambda element: element not in getEverything(i), baseClass) result = getMissing(baseClass, filter(lambda element: isinstance(element, NamedElement),stereotypePackage.getOwnedElement())) bNoSter = result[0] bWrongSter = result[1] bWrongMeta = result[2] applySter = [] for n in noApply: if n not in bWrongSter and n not in bWrongMeta and n in baseClass: applySter.append(n) if validateOnly!=True: ('[FIXING]:' + str(elementType)) successful = [] bWS = [] bWM=[] noFix=[] for b in bNoSter: bStillMissing = getMissing([b], filter(lambda element: isinstance(element, NamedElement), stereotypePackage.getOwnedElement())) bWS = bStillMissing[1] bWM = bStillMissing[2] if bStillMissing[0]: ###check if any local stereotype is applied bLocalSter = filter(lambda element: element.getOwner() == stereotypePackage, StereotypesHelper.getStereotypes(b)) if len(bLocalSter)>0: for bL in bLocalSter: localSterApply = filter(lambda element: bL in StereotypesHelper.getStereotypes(element), getElements(getEverything(profilePackage), profilePackage)) if len(localSterApply)==1: ###if local stereotype is applied to only this element in the base class then change the name of stereotype. Otherwise create new ster and unapply this one. bL.setName(propertyCheck(b)) gl.log('[FIX]:Stereotype name was changed to match applied element name: ' + b.getQualifiedName()) nameChange+=1 elif filter(lambda element: propertyCheck(element) == bL.getName(), getElements(getEverything(profilePackage), profilePackage)): createStereotype(stereotypePackage, b, stereotypePackage) unapplyStereotypes([b]) gl.log('[FIX]:Stereotype Created ' +b.getName()) gl.log('\t\t Location = ' + b.getQualifiedName()) sterCreate+=1 else: ###get sysml extension, unapply stereotype and apply sysml extension bLgeneralizations = getGeneralizationTree(bL) bLSysGen = filter(lambda element: StereotypesHelper.getProfileForStereotype(element) == StereotypesHelper.getProfile(project, "SysML") or StereotypesHelper.getProfileForStereotype(element) == StereotypesHelper.getProfile(project, "additional_stereotypes"), bLgeneralizations) unapplyStereotypes([b]) if bLSysGen: StereotypesHelper.addStereotype(b, bLSysGen[0]) gl.log('[FIX]:Stereotype applied to multiple elements, none with matching name. Unapplied stereotype:' + bL.getName()) unapply+=1 createStereotype(stereotypePackage, b, stereotypePackage) unapplyStereotypes([b]) gl.log('[FIX]:Stereotype Created ' +b.getName()) gl.log('\t\t Location = ' + b.getQualifiedName()) sterCreate+=1 else: createStereotype(stereotypePackage, b, stereotypePackage) unapplyStereotypes([b]) gl.log('[FIX]:Stereotype Created ' +b.getName()) gl.log('\t\t Location = ' + b.getQualifiedName()) sterCreate+=1 for b in bWS: if not isinstance(b, Interface) and StereotypesHelper.getBaseClassAsClasses(b)[0] == Port: if b.getName().find("part property")==0: bPort = filter(lambda element: element.getName() == b.getName() + " port", filter(lambda element: isinstance(element, NamedElement), stereotypePackage.getOwnedElement())) if len(bPort)!=0: bApplied = filter(lambda element: StereotypesHelper.isElementStereotypedBy(element, b.getName())==True, baseClass) for f in bApplied: StereotypesHelper.removeStereotypes(f, [b]) StereotypesHelper.addStereotype(f, bPort) ###Apply applicable stereotypes for b in noApply: if b not in bWrongSter and b not in bWrongMeta and b not in bWS and b not in bWM and b in baseClass: if StereotypesHelper.getBaseClasses(noApply[b])[0].getName() != 'Element': StereotypesHelper.addStereotype(b, noApply[b]) unapplyStereotypes([b]) gl.log('[FIX]: Stereotype Applied ' + b.getName()) gl.log('\t\t Location = '+b.getQualifiedName()) apply+=1 if len(bWrongSter)>0: gl.log('[UNFIXABLE]: Inheritance Mismatch (see validation log for details)') for b in bWrongMeta: gl.log('[UNFIXABLE]: Metaclass Mismatch: '+ b.getQualifiedName()) # if elementType == Classifier and validateOnly!=True: localGeneralizations(modelPackage, validateOnly, True) ###Messages Log if apply!=0 or sterCreate!=0 or nameChange !=0 or unapply!=0: gl.log('[FIX SUMMARY]:') gl.log(str(apply) + " existing stereotype(s) applied") gl.log(str(sterCreate) + " stereotypes created") gl.log(str(nameChange) + " stereotype names changed") gl.log(str(unapply) + " stereotypes unapplied") else: gl.log('No Fixes Needed') if len(bWrongSter)!=0 or bWrongMeta!=0: gl.log('[UNFIXABLE SUMMARY]:') if len(bWrongSter)>0: gl.log(str(len(bWrongSter))+ " stereotype inheritance mismatch") if len(bWrongMeta)>0: gl.log(str(len(bWrongMeta))+ " stereotype metaclasses and element types not matching") else: gl.log('No modeler fixes needed') ################ return [bNoSter, bWrongSter, bWrongMeta, applySter] else: baseClass = filter(lambda element: not isinstance(element, Class), baseClass) baseClass = filter(lambda element: not isinstance(element, Package), baseClass) baseClass = filter(lambda element: not isinstance(element, Property), baseClass) baseClass = filter(lambda element: not isinstance(element, Operation), baseClass) baseClass = filter(lambda element: not isinstance(element, Diagram), baseClass) baseClass = filter(lambda element: not isinstance(element, Dependency), baseClass) for s in stereotypesIgnore: baseClass = filter(lambda element: StereotypesHelper.hasStereotypeOrDerived(element, s) == False, baseClass) ignoredPackEls = [] for i in packagesIgnore: baseClass = filter(lambda element: element not in getEverything(i), baseClass) resultMisc = getMissing(baseClass, stereotypePackage.getOwnedElement()) mNoSter = resultMisc[0] mWrongSter = resultMisc[1] mWrongMeta = resultMisc[2] applySter = [] for n in noApply: if n not in mWrongSter and n not in mWrongMeta and n in baseClass: applySter.append(n) if validateOnly!=True: gl.log('[FIX]:' + str(elementType)) successful = [] for b in mNoSter: mStillMissing = getMissing([b], stereotypePackage.getOwnedElement()) if mStillMissing[0]: createStereotype(stereotypePackage, b, stereotypePackage) unapplyStereotypes([b]) gl.log('\t Stereotype Created ' +b.getName()) gl.log('\t\t Location = ' + b.getQualifiedName()) for b in noApply: if b not in mWrongSter and b not in mWrongMeta and n in baseClass: StereotypesHelper.addStereotype(b, noApply[b]) unapplyStereotypes([b]) gl.log('\t Stereotype Applied ' + b.getName()) gl.log('\t\t Location = '+b.getQualifiedName()) if len(mWrongSter)>0: gl.log('UNFIXABLE: Inheritance Mismatch (see validation log for details)') if len(mWrongMeta)>0: gl.log('UNFIXABLE: Metaclass Mismatch (see validation log for details)') return [mNoSter, mWrongSter, mWrongMeta, applySter]
def stereotypeGenCheck(modelPackage, validateOnly): ###Packages profilePackage = profilePackCheck(modelPackage) if not profilePackage: return ['No Profile Package'] infraPack = filter(lambda element: isinstance(element, Package) and "_"==element.getName(), profilePackage.getOwnedElement()) if len(infraPack)>0: infraPack = infraPack[0] else: return['No underscore Package'] stereotypePackage = packageCheck(profilePackage, infraPack, validateOnly, "_Stereotypes") if not stereotypePackage: return['No Stereotype Package'] stereotypes =filter(lambda element: isinstance(element, Stereotype), stereotypePackage.getOwnedElement()) badG = [] badGs=[] noSys = [] sBad = [] for s in stereotypes: sGenerals = filter(lambda element: isinstance(element, Generalization), s.getOwnedElement()) sGeneral =[] for sg in sGenerals: sGeneral.extend(s.getGeneral()) sSysML = filter(lambda element: StereotypesHelper.getProfileForStereotype(element) == StereotypesHelper.getProfile(project, "SysML"), sGeneral) sAdd = filter(lambda element: StereotypesHelper.getProfileForStereotype(element)==StereotypesHelper.getProfile(project, "additional_stereotypes"), sGeneral) # if StereotypesHelper.getProfileForStereotype(sGeneral) in ignoreProfile: # sSyMLInh = filter(lambda element: StereotypesHelper.getProfileForStereotype(element)==StereotypesHelper.getProfile(project, "SysML"), SR.getGeneralizationTree(sg)) ###Collect stereotypes with no sysml generalization if len(sSysML)==0 and len(sAdd)==0: noSys.append(s) ###Collect stereotypes with generalizations to non sysml elements and not part of ignore profiles sBad = filter(lambda element: StereotypesHelper.getProfileForStereotype(element) != StereotypesHelper.getProfile(project, "SysML"), sGeneral) sBad = filter(lambda element: StereotypesHelper.getProfileForStereotype(element) != StereotypesHelper.getProfile(project, "additional_stereotypes"), sBad) sBad = filter(lambda element: StereotypesHelper.getProfileForStereotype(element) != profilePackage, sBad) sBad = filter(lambda element: element.getOwner() != stereotypePackage, sBad) # for i in ignoreProfile: # sBad = filter(lambda element: StereotypesHelper.getProfileForStereotype(element) != StereotypesHelper.getProfile(project, i.getName()), sBad) sBad = filter(lambda element: element not in stereotypes, sBad) for n in sBad: badG.append(filter(lambda element: isinstance(element, Generalization) and element.getGeneral() == n and element.getSpecific() == s, s.get_directedRelationshipOfSource())) badG = flatten(badG) if validateOnly!=True: for b in badG: gl.log('[FIX]: removing generalization between '+ b.getGeneral().getName() + ' and '+ b.getSpecific().getName()) mem.removeElement(b) ###refine stereotypes with no sysml generalization collection noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Package") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Dependency") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project,"Connector") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Operation") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Diagram") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Port") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Activity") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "DataType") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "GeneralizationSet") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Association") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Reception") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Interaction") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Interface") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Enumeration") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Constraint") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Signal") not in StereotypesHelper.getBaseClasses(element), noSys) noSys = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "SignalEvent") not in StereotypesHelper.getBaseClasses(element), noSys) if validateOnly != True: gl.log('['+ str(len(noSys))+'] possible SysML specializations. No codified fix for stereotypes that can specialize SysML. Modeler must do. ') return [sBad, noSys]
def createCustomizationsForStereotypes(modelPackage, validateOnly): ###Checks for: ###stereotypes with no customizations (stereotypesNoCustomizations) ###customizations with no supertype (noType) ###customizations with multiple supertypes (multTypes) ###customizations with no target (noCustTargs) ###customizations with multiple targets (multCust) ###customization name/target name mismatch (stereotypesCustNameMisMatch) ###customization name/type name mismatch (elementCustNameMisMatch) newcust = 0 bummer = 0 bummerType =[] ###get packages if not isinstance(modelPackage, Profile): profilePackage = VP.getProfilePackage(modelPackage) if not profilePackage: gl.log('***ERROR: The code is not being run on a Profile. Stopping Execution***') return else: profilePackage = modelPackage infraPack = filter(lambda element: isinstance(element, Package) and "_"==element.getName(), profilePackage.getOwnedElement()) if not infraPack: sterPack = filter(lambda element: isinstance(element, Package) and "_Stereotypes" in element.getName(), profilePackage.getOwnedElement()) if sterPack: sterPack = sterPack[0] else: return['no stereotypes package'] else: infraPack = infraPack[0] stereotypePackage = filter(lambda element: isinstance(element, Package) and "_Stereotypes" in element.getName(),infraPack.getOwnedElement())[0] customPackage = filter(lambda element: isinstance(element, Package) and element.getName() == "_Customizations", infraPack.getOwnedElement())[0] allElements = VP.getEverything(profilePackage) ###Validation Customizations = filter(lambda element: StereotypesHelper.hasStereotype(element, "Customization"), allElements) Stereotypes = filter(lambda element: isinstance(element, Stereotype) and element.getOwner() == stereotypePackage, allElements) Stereotypes = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Dependency") not in StereotypesHelper.getBaseClasses(element), Stereotypes) Stereotypes = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Association") not in StereotypesHelper.getBaseClasses(element), Stereotypes) Stereotypes = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Property") not in StereotypesHelper.getBaseClasses(element), Stereotypes) Stereotypes = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Port") not in StereotypesHelper.getBaseClasses(element), Stereotypes) els = VP.getElements(allElements, profilePackage) custSter = StereotypesHelper.getStereotype(project, "Customization") custTypeNames =[] multCust =[] multTypes=[] custTargsName=[] custNames=[] custTypes=[] cignore=[] noCustTargs=[] noType=[] for c in Customizations: if "part property" in c.getName() or "port" in c.getName(): mem.removeElement(c) else: custNames.append(c.getName()) custTarg = StereotypesHelper.getStereotypePropertyValue(c, custSter, "customizationTarget") if len(custTarg)>0: if len(custTarg)>1:multCust.append(c) custTargsName.append(StereotypesHelper.getStereotypePropertyValue(c, custSter, "customizationTarget")[0].getName()) else: cignore.append(c) noCustTargs.append(c) gl.log('[ERROR] No customization target = ' +c.getName()) custType = StereotypesHelper.getStereotypePropertyValue(c, custSter, "superTypes") if len(custType)>0: if len(custType)>1:multTypes.append(c) custTypes.extend(StereotypesHelper.getStereotypePropertyValue(c, custSter, "superTypes")) custTypeNames.append(StereotypesHelper.getStereotypePropertyValue(c, custSter, "superTypes")[0].getName()) else: noType.append(c) gl.log('[ERROR] No customization type = ' + c. getName()) stereotypesNoCustomizations = filter(lambda element: element.getName() not in custTargsName, Stereotypes) stereotypesNoCustomizations = filter(lambda element: StereotypesHelper.getMetaClassByName(project, "Association") not in StereotypesHelper.getBaseClasses(element), stereotypesNoCustomizations) stereotypesCustNameMisMatch = filter(lambda element: element.getName() not in custNames, Stereotypes) stereotypesCustNameMisMatch = filter(lambda element: element not in stereotypesNoCustomizations, stereotypesCustNameMisMatch) elementCustNameMisMatch = filter(lambda element: element.getName() not in custNames, custTypes) ###Fixes if validateOnly!=True: ###stereotypes with no customizations->Fix: create customization, assign target, superType(if possible), and hide metatype multName=[] for s in stereotypesNoCustomizations: if s.getName() not in custNames: gl.log('[FIX]: created customization: '+ s.getName()) newCust = VP.createCustomization(s.getName(), customPackage) newcust+=1 ######assign customization tags sMeta = StereotypesHelper.getBaseClasses(s) if len(sMeta)>1: gl.log('\t [FIX ERROR]: stereotype has multiple metaclasses. No customization tags assigned. Modeler must rectify.') bummer+=1 else: sMC = StereotypesHelper.getClassOfMetaClass(sMeta[0]) sMCer = Classifier.isAssignableFrom(sMC) if sMCer == True: base = filter(lambda element: element.getName() == s.getName(), els) if len(base)>0: base = base[0] else: base = False bummerType.append(newCust) VP.assignCustomizationTags(s, newCust, base) else: bummerType.append(newCust) VP.assignCustomizationTags(s, newCust, False) else: gl.log('[FIX ERROR]: Unable to create customization for stereotype '+ s.getName() + '. Customization already exists with that name') multName.append(s) ###stereotype-customization name mismatch->Fix: change name of customization to match name of stereotype if supertype name doesn't match as well. else keep flagged fixSterCustMis=[] for s in stereotypesCustNameMisMatch: sterCust = filter(lambda element: s in StereotypesHelper.getStereotypePropertyValue(element, custSter, "customizationTarget"), Customizations) cusType = StereotypesHelper.getStereotypePropertyValue(sterCust[0], custSter, "superTypes") if custType: if sterCust[0].getName() != custType[0].getName(): sterCust[0].setName(s.getName()) gl.log('[FIX]:Changed name of customization to match name of customizationTarget: ' + sterCust[0].getName()) else: gl.log('[FIX ERROR]: Unable to change name of customization to match name of customizationTarget since customization name matches superType name: ' + sterCust[0].getName()) fixSterCustMis.append(sterCust[0]) ###element-customization name mismatch->Fix: change name of customization to match name of element fixElCustMis=[] for e in elementCustNameMisMatch: eCust = filter(lambda element: e in StereotypesHelper.getStereotypePropertyValue(element, custSter, "superTypes"), Customizations) eTarg = StereotypesHelper.getStereotypePropertyValue(eCust[0], custSter, "customizationTarget") if eTarg: if eCust[0].getName() != eTarg[0].getName(): eCust[0].setName(e.getName()) gl.log('[FIX]: Changed name of customization to match name of superType: '+ eCust[0].getName()) else: gl.log('[FIX ERROR]: Unable to change name of customization to match name of superType since customization name matches customization target name: ' + eCust[0].getName()) fixElCustMis.append(eCust[0]) ###multiple customization targets->Fix: if a target matches name of customization, delete all others. Else delete them all & flag customization fixNoCustTarg=[] for c in multCust: cTargs= StereotypesHelper.getStereotypePropertyValue(c, custSter, "customizationTarget") targetSlot = StereotypesHelper.getSlot(c, custSter, "customizationTarget", False, False) for t in filter(lambda element: element.getName() != c.getName(), cTargs): StereotypesHelper.removeSlotValue(targetSlot, t) gl.log('[FIX]: Removing customizationTarget(s) with names not matching customization name: '+ c.getName()) if len(StereotypesHelper.getStereotypePropertyValue(c, custSter, "customizationTarget"))==0: fixNoCustTarg.append(c) gl.log('[FIX ERROR]: Customization now has no target: '+ c.getName()) ###multiple customization types->Fix: if a type matches name of customization, delete all other. Else delete them all & flag customization fixNoCustType=[] for c in multTypes: cTypes = StereotypesHelper.getStereotypePropertyValue(c, custSter, "superTypes") typeSlot = StereotypesHelper.getSlot(c, custSter, "superTypes", False, False) for t in filter(lambda element: element.getName() != c.getName(), cTypes): StereotypesHelper.removeSlotValue(typeSlot, t) gl.log('[FIX]: Removing superType(s) with names not matching customization name: '+ c.getName()) if len(StereotypesHelper.getStereotypePropertyValue(c, custSter, "superTypes"))==0: fixNoCustType.append(c) gl.log('[FIX ERROR]: Customization now has no superType: '+ c.getName()) ###no customization target->Fix: if a stereotype matches with same name and is not assigned to another customization, assign as target, else keep flagged fixNoTargsMult=[] fixNoTargs=[] for c in noCustTargs: custSters = filter(lambda element: element.getName() == c.getName(), Stereotypes) if custSters and c.getName() not in custTargsName: StereotypesHelper.setStereotypePropertyValue(c, custSter, "customizationTarget", custSters[0]) gl.log('[FIX]: Setting customization target for '+ c.getName() +" to " + custSters[0].getName()) elif custSters and c.getName() in custTargsName: fixNoTargsMult.append(c) gl.log('[FIX ERROR]: Another customization already has stereotype of same customization name as target. No target applied for '+ c.getName()) else: fixNoTargs.append(c) gl.log('[FIX ERROR]: No stereotype exists with same name as customization. No target applied for ' + c.getName()) ###no customization type->Fix: if an element matches with same name and is not assigned to another customizaiton assign as type, else keep flagged fixNoTypeMult=[] fixNoType=[] for c in noType: custEl = filter(lambda element: element.getName() == c.getName(), els) if custEl and c.getName() not in custTypeNames: StereotypesHelper.setStereotypePropertyValue(c, custSter, "superTypes", custEl[0]) gl.log('[FIX]: Setting customization superType for '+c.getName() +" to "+ custEl[0].getName()) elif custEl and c.getName() in custTypeNames: fixNoTypeMult.append(c) gl.log('[FIX ERROR]: Another customization already has this element as its superType. No superType applied for ' + c.getName()) else: fixNoType.append(c) gl.log('[FIX ERROR]: No base element exists with same name as customization. Not superType applied for '+ c.getName()) ###Message Logs gl.log('SUMMARY') if validateOnly != True: gl.log('Customizations created = ' + str(newcust)) gl.log('Customization FIX ERRORS(Modeler must fix)(See Messages Log):') gl.log('\t No tags assigned. Stereotype has multiple metaclasses = '+str(bummer)) gl.log('\t Customization not created. Customization with same name already exists = '+str(len(multName))) gl.log('\t Customization name not changed. Name already matches Type, wont change to match Target = '+str(len(fixSterCustMis))) gl.log('\t Customization name not changed. Name already matches Target, wont change to match Type = '+str(len(fixElCustMis))) gl.log('\t Customizations with no Target = '+str(len(fixNoCustTarg))) gl.log('\t Customizations with No Type = '+str(len(fixNoCustType))) gl.log('\t Customization Target not assigned. Another customization already exists with the given Target = '+str(len(fixNoTargsMult))) gl.log('\t Customization Target not assigned. No stereotype with matching name exists = '+str(len(fixNoTargs))) gl.log('\t Customization Type not assigned. Another customization already exists with the given Type = '+str(len(fixNoTypeMult))) gl.log('\t Customization Type not assigned. No element with matching name exists = '+str(len(fixNoType))) #### return [stereotypesNoCustomizations, stereotypesCustNameMisMatch, multCust, noCustTargs, noType, multTypes, elementCustNameMisMatch]