Skip to content

Commit

Permalink
Finish to migrate rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Jul 19, 2024
1 parent 2ba3820 commit f5d591c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,6 @@ FameNameConventionBetweenFM3AndSmalltalkRule class >> uniqueIdentifierName [
^ 'NameConventionBetweenFM3AndSmalltalk'
]

{ #category : #private }
FameNameConventionBetweenFM3AndSmalltalkRule >> addClass: aClass toMetaBuilderCollection: aCollectionOfClasses [
| classToAdd |
"we add the class itself"
aCollectionOfClasses addIfNotPresent: aClass.

"We add all classes described in properties pargmas :"
aClass methodDict
valuesDo: [ :each |
each pragmas
detect: [ :p | #(#FMProperty:type:opposite: #FMProperty:type:) includes: p selector ]
ifFound: [ :pragma |
classToAdd := (pragma argumentAt: 2) asString.
(#('String' 'Number' 'Boolean' 'Object') includes: classToAdd)
ifFalse: [ classToAdd = 'FM3.Property'
ifTrue: [ (aCollectionOfClasses includes: FM3Property) ifFalse: [ self addClass: FM3Property toMetaBuilderCollection: aCollectionOfClasses ] ]
ifFalse: [ classToAdd := Smalltalk classNamed: classToAdd.
(aCollectionOfClasses includes: classToAdd) ifFalse: [ self addClass: classToAdd toMetaBuilderCollection: aCollectionOfClasses ] ] ] ] ].
"we add the superclass and all classes linked to it: "
aClass classSide
compiledMethodAt: #annotation
ifPresent: [ :compiledMethod |
(compiledMethod pragmaAt: #FMClass:super:)
ifNotNil: [ :pragma |
| argument |
argument := pragma argumentAt: 2.
argument = #Object
ifFalse: [ classToAdd := (argument includes: $.)
ifTrue: [ classToAdd := ''.
(argument substrings: #($.)) do: [ :each | classToAdd := classToAdd , each ].
Smalltalk classNamed: classToAdd ]
ifFalse: [ Smalltalk classNamed: argument asString ].

(aCollectionOfClasses includes: classToAdd) ifFalse: [ self addClass: classToAdd toMetaBuilderCollection: aCollectionOfClasses ] ] ] ]
]

{ #category : #running }
FameNameConventionBetweenFM3AndSmalltalkRule >> basicCheck: aClass [

Expand Down
18 changes: 12 additions & 6 deletions src/Fame-Rules/FameOppositeClassNotExistRule.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ Check if the opposite class declared in a pragma #MSEProperty:type:opposite: is
"
Class {
#name : #FameOppositeClassNotExistRule,
#superclass : #RBBlockLintRule,
#superclass : #ReAbstractRule,
#category : #'Fame-Rules'
}

{ #category : #testing }
FameOppositeClassNotExistRule class >> checksMethod [

^ true
]

{ #category : #accessing }
FameOppositeClassNotExistRule class >> group [
^ 'Fame'
Expand All @@ -24,9 +30,9 @@ FameOppositeClassNotExistRule class >> uniqueIdentifierName [
]

{ #category : #running }
FameOppositeClassNotExistRule >> checkMethod: aContext [
| class |
class := aContext methodClass.
((class methodNamed: aContext selector) pragmaAt: #FMProperty:type:opposite:)
ifNotNil: [ :pragma | self class environment at: (pragma argumentAt: 2) ifPresent: [ :oppositeClass | result addClass: class selector: aContext selector ] ]
FameOppositeClassNotExistRule >> basicCheck: aMethod [

((aMethod methodClass methodNamed: aMethod selector) pragmaAt: #FMProperty:type:opposite:) ifNotNil: [ :pragma |
self class environment at: (pragma argumentAt: 2) ifPresent: [ :oppositeClass | ^ true ] ].
^ false
]
43 changes: 26 additions & 17 deletions src/Fame-Rules/FameSuperclassMetaDescribedExistRule.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ Check if a superclass defined in a FM3MetaDescription (generated by a class anot
"
Class {
#name : #FameSuperclassMetaDescribedExistRule,
#superclass : #RBBlockLintRule,
#superclass : #ReAbstractRule,
#category : #'Fame-Rules'
}

{ #category : #testing }
FameSuperclassMetaDescribedExistRule class >> checksClass [

^ true
]

{ #category : #accessing }
FameSuperclassMetaDescribedExistRule class >> group [
^ 'Fame'
Expand All @@ -24,20 +30,23 @@ FameSuperclassMetaDescribedExistRule class >> uniqueIdentifierName [
]

{ #category : #running }
FameSuperclassMetaDescribedExistRule >> checkClass: aContext [
| class pragmas pragma substrings metaSuperclassName |
class := aContext.
pragmas := Pragma allNamed: #FMClass:super: in: class.
pragmas ifEmpty: [ ^ self ].
pragmas size > 1
ifTrue: [ result addClass: class.
^ self ].

pragma := pragmas first.
metaSuperclassName := pragma argumentAt: 2.
substrings := metaSuperclassName asString substrings: #($.).

substrings size > 1
ifTrue: [ Smalltalk at: (substrings first , substrings second) asSymbol ifAbsent: [ result addClass: class classSide selector: #annotation ] ]
ifFalse: [ Smalltalk at: substrings first asSymbol ifAbsent: [ result addClass: class classSide selector: #annotation ] ]
FameSuperclassMetaDescribedExistRule >> basicCheck: aClass [

| class |
class := aClass isClassSide
ifTrue: [ aClass ]
ifFalse: [ aClass class ].

(Pragma allNamed: #FMClass:super: in: class) ifNotEmpty: [ :pragmas |
| pragma substrings metaSuperclassName |
pragmas size > 1 ifTrue: [ ^ true ].

pragma := pragmas first.
metaSuperclassName := pragma argumentAt: 2.
substrings := metaSuperclassName asString substrings: #( $. ).

substrings size > 1
ifTrue: [ Smalltalk at: (substrings first , substrings second) asSymbol ifAbsent: [ ^ true ] ]
ifFalse: [ Smalltalk at: substrings first asSymbol ifAbsent: [ ^ true ] ] ].
^ false
]

0 comments on commit f5d591c

Please sign in to comment.