Skip to content

Commit

Permalink
[feenkcom/gtoolkit#4072] Pass on the analysis for extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chisandrei committed Oct 21, 2024
1 parent 49f686b commit 87a961f
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Class {
#superclass : #Object,
#instVars : [
'currentCompiledMethod',
'previousSourceCode'
'previousSourceCode',
'changeType'
],
#category : #'GToolkit-Utility-ExtensionMethodsAnalysis'
}
Expand All @@ -14,6 +15,16 @@ GtExtensionMethodWrapper class >> forCompiledMethod: aCompiledMethod [
currentCompiledMethod: aCompiledMethod
]

{ #category : #accessing }
GtExtensionMethodWrapper >> changeType [
^ changeType
]

{ #category : #accessing }
GtExtensionMethodWrapper >> changeType: aSymbol [
changeType := aSymbol
]

{ #category : #accessing }
GtExtensionMethodWrapper >> currentCompiledMethod [
^ currentCompiledMethod
Expand Down Expand Up @@ -57,6 +68,27 @@ GtExtensionMethodWrapper >> gtViewTwoPanesDiffFor: aView [
yourself
]

{ #category : #testing }
GtExtensionMethodWrapper >> isNewMethod [
^ changeType = #isNewMethod
]

{ #category : #testing }
GtExtensionMethodWrapper >> isOverrideOrReplace [
^ self isOverridingSupperclassMethod or: [
self isReplacingMethodInClass ]
]

{ #category : #testing }
GtExtensionMethodWrapper >> isOverridingSupperclassMethod [
^ changeType = #isOverridingSupperclassMethod
]

{ #category : #testing }
GtExtensionMethodWrapper >> isReplacingMethodInClass [
^ changeType = #isReplacingMethodInClass
]

{ #category : #accessing }
GtExtensionMethodWrapper >> methodClass [
^ currentCompiledMethod methodClass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Class {
#name : #GtExtensionMethodsBaseImageOverridesReport,
#superclass : #Object,
#instVars : [
'baseImageExtensionMethodsData'
],
#category : #'GToolkit-Utility-ExtensionMethodsAnalysis'
}

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesReport >> baseImageExtensionMethodsData [
^ baseImageExtensionMethodsData
]

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesReport >> baseImageExtensionMethodsData: anObject [
baseImageExtensionMethodsData := anObject
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To perform this:
- it checks if any of those methods replaces or overrides a method in a reference image
"
Class {
#name : #GtExtensionMethodsBaseImageOverridesBuilder,
#name : #GtExtensionMethodsBaseImageOverridesReportBuilder,
#superclass : #Object,
#instVars : [
'imageName',
Expand All @@ -17,36 +17,34 @@ Class {
}

{ #category : #analysis }
GtExtensionMethodsBaseImageOverridesBuilder class >> forGToolkit [
^ self new buildWrapperForGToolkit
GtExtensionMethodsBaseImageOverridesReportBuilder class >> forGToolkit [
^ self new buildReportForGToolkit
]

{ #category : #analysis }
GtExtensionMethodsBaseImageOverridesBuilder >> buildWrapperForComparisonResult: aResult forExtensionMethods: aCollection inProject: aProject [
| targetMethods |
GtExtensionMethodsBaseImageOverridesReportBuilder >> buildReportForComparisonResult: aResult forExtensionMethods: aCollection inProject: aProject [
aCollection withIndexDo: [ :aMethodWrapper :anIndex |
(aResult at: anIndex) ifNotNil: [ :aSourceCode |
aMethodWrapper previousSourceCode: aSourceCode ] ].

targetMethods := aCollection withIndexSelect: [ :aMethodWrapper :anIndex |
(aResult at: anIndex) notNil ].
aMethodWrapper changeType: (aResult at: anIndex) first.
aMethodWrapper isOverrideOrReplace ifTrue: [
aMethodWrapper previousSourceCode: (aResult
at: anIndex) second ] ].

^ GtExtensionMethodsProjectBuilder new
buildProjectWrapperForMethodWrappers: targetMethods
buildProjectWrapperForMethodWrappers: aCollection
inProject: aProject
]

{ #category : #analysis }
GtExtensionMethodsBaseImageOverridesBuilder >> buildWrapperForGToolkit [
^ self buildWrapperForProject: BaselineOfGToolkit fullBaselineProject
GtExtensionMethodsBaseImageOverridesReportBuilder >> buildReportForGToolkit [
^ self buildReportForProject: BaselineOfGToolkit fullBaselineProject
]

{ #category : #analysis }
GtExtensionMethodsBaseImageOverridesBuilder >> buildWrapperForProject: aProject [
GtExtensionMethodsBaseImageOverridesReportBuilder >> buildReportForProject: aProject [
| wrapperProject extensionMethods analysisCode analysisResult |

wrapperProject := GtExtensionMethodsProjectBuilder new
buildWrapperForProject: aProject.
buildReportForProject: aProject.

extensionMethods := wrapperProject extensionMethods.
analysisCode := self detectionCodeForMethods: extensionMethods.
Expand All @@ -55,13 +53,13 @@ GtExtensionMethodsBaseImageOverridesBuilder >> buildWrapperForProject: aProject
analysisResult := self comparisonResultsForAnalysisCode: analysisCode.

^ self
buildWrapperForComparisonResult: analysisResult
buildReportForComparisonResult: analysisResult
forExtensionMethods: extensionMethods
inProject: aProject
]

{ #category : #utils }
GtExtensionMethodsBaseImageOverridesBuilder >> comparisonResultsForAnalysisCode: analysisSourceCode [
GtExtensionMethodsBaseImageOverridesReportBuilder >> comparisonResultsForAnalysisCode: analysisSourceCode [
| command newProcess arguments resultString |

command := GtVirtualMachine instance
Expand Down Expand Up @@ -89,11 +87,11 @@ GtExtensionMethodsBaseImageOverridesBuilder >> comparisonResultsForAnalysisCode:
]

{ #category : #utils }
GtExtensionMethodsBaseImageOverridesBuilder >> detectionCodeForMethods: aCollection [
GtExtensionMethodsBaseImageOverridesReportBuilder >> detectionCodeForMethods: aCollection [
| expensionsData |

expensionsData := aCollection asArray collect: [ :aMethod |
{aMethod methodClass name . aMethod selector asString } ].
{ aMethod methodClass name . aMethod selector asString } ].

^ String streamContents: [ :aStream |
aStream << '| expensionsData |'; lf.
Expand All @@ -104,10 +102,10 @@ GtExtensionMethodsBaseImageOverridesBuilder >> detectionCodeForMethods: aCollect

isMeta := false.
(className endsWith: ' class') ifTrue: [
className := className withoutSuffix: ' class'.
className := (className withoutSuffix: ' class') asSymbol.
isMeta := true ].
(className endsWith: ' classTrait') ifTrue: [
className := className withoutSuffix: ' classTrait'.
className := (className withoutSuffix: ' classTrait') asSymbol.
isMeta := true ].

Smalltalk globals
Expand All @@ -119,15 +117,26 @@ GtExtensionMethodsBaseImageOverridesBuilder >> detectionCodeForMethods: aCollect
targetClass := aClass classSide ].
targetClass
classAndMethodFor: array second asSymbol
do: [ :c :m | m sourceCode ]
ifAbsent: [ nil ] ]
ifAbsent: [ nil ] ]
do: [ :methodClas :foundMethod |
targetClass = methodClas
ifTrue: [
{
#isReplacingMethodInClass.
foundMethod sourceCode
}]
ifFalse: [
{
#isOverridingSupperclassMethod.
foundMethod sourceCode
} ] ]
ifAbsent: [ {#isNewMethod} ] ]
ifAbsent: [ {#isMissingClass} ] ]
] sourceNode sourceCode).
aStream << ' value: expensionsData' ]
]

{ #category : #utils }
GtExtensionMethodsBaseImageOverridesBuilder >> ensureImageDownloaded [
GtExtensionMethodsBaseImageOverridesReportBuilder >> ensureImageDownloaded [
| targetFolder |
targetFolder := self targetFolder.
(targetFolder / self imageName) exists
Expand All @@ -143,39 +152,39 @@ GtExtensionMethodsBaseImageOverridesBuilder >> ensureImageDownloaded [
]

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesBuilder >> imageArchiveName [
GtExtensionMethodsBaseImageOverridesReportBuilder >> imageArchiveName [
^ imageArchiveName ifNil: [
'Pharo10-SNAPSHOT.build.521.sha.14f5413.arch.64bit.zip' ]
]

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesBuilder >> imageArchiveName: anArchiveName [
GtExtensionMethodsBaseImageOverridesReportBuilder >> imageArchiveName: anArchiveName [
imageArchiveName := anArchiveName
]

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesBuilder >> imageName [
GtExtensionMethodsBaseImageOverridesReportBuilder >> imageName [
^ imageName ifNil: [
'Pharo10-SNAPSHOT-64bit-14f5413.image' ]
]

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesBuilder >> imageName: anImageName [
GtExtensionMethodsBaseImageOverridesReportBuilder >> imageName: anImageName [
imageName := anImageName
]

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesBuilder >> imageUrl [
GtExtensionMethodsBaseImageOverridesReportBuilder >> imageUrl [
^ imageUrl ifNil: [
'https://dl.feenk.com/pharo/', self imageArchiveName ]
]

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesBuilder >> imageUrl: anUrlString [
GtExtensionMethodsBaseImageOverridesReportBuilder >> imageUrl: anUrlString [
imageUrl := anUrlString
]

{ #category : #accessing }
GtExtensionMethodsBaseImageOverridesBuilder >> targetFolder [
GtExtensionMethodsBaseImageOverridesReportBuilder >> targetFolder [
^ FileLocator localDirectory / 'analysis-extension-methods'
]
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,33 @@ GtExtensionMethodsPackageWrapper >> extensionsDescription [
<< ('extension method' asPluralBasedOn: self numberOfExtensions) ]
]

{ #category : #accessing }
GtExtensionMethodsPackageWrapper >> groupByMethodChangeType [
| extensionMethodsGroup |
extensionMethodsGroup := self extensionMethods
groupedBy: [ :each | each changeType ].

^ extensionMethodsGroup
]

{ #category : #'accessing - grouping' }
GtExtensionMethodsPackageWrapper >> groupedByClass [
^ self extensionMethods groupedBy: [ :aMethod |
aMethod methodClass ]
]

{ #category : #'accessing - grouping' }
GtExtensionMethodsPackageWrapper >> groupedByExtendedClassPackage [
^ self extensionMethods groupedBy: [ :aMethod |
aMethod methodClass package ]
]

{ #category : #'gt - extensions' }
GtExtensionMethodsPackageWrapper >> gtViewExtensionMethodsByClassFor: aView [
<gtView>

^ aView columnedList
title: 'By class';
title: 'By extended class';
priority: 45;
items: [ self groupedByClass associations
sorted: [ :assoc | assoc value size ] descending ];
Expand All @@ -52,6 +67,20 @@ GtExtensionMethodsPackageWrapper >> gtViewExtensionMethodsByClassFor: aView [
send: [ :assoc | assoc value ]
]

{ #category : #'gt - extensions' }
GtExtensionMethodsPackageWrapper >> gtViewExtensionMethodsByExtendedClassPackageFor: aView [
<gtView>

^ aView columnedList
title: 'By extended class package';
priority: 46;
items: [ self groupedByExtendedClassPackage associations
sorted: [ :assoc | assoc value size ] descending ];
column: 'Package' text: [ :assoc | assoc key ];
column: 'Number of Extension Methods' text: [ :assoc | assoc value size ];
send: [ :assoc | assoc value ]
]

{ #category : #'gt - extensions' }
GtExtensionMethodsPackageWrapper >> gtViewExtensionMethodsFor: aView [
<gtView>
Expand All @@ -65,6 +94,23 @@ GtExtensionMethodsPackageWrapper >> gtViewExtensionMethodsFor: aView [
column: 'Package' text: [ :aMethod | aMethod package name ]
]

{ #category : #'gt - extensions' }
GtExtensionMethodsPackageWrapper >> gtViewGroupsByChangeTypeFor: aView [
<gtView>

^ aView columnedList
title: 'By change type';
priority: 49;
items: [
self groupByMethodChangeType associations ];
column: 'Change type' text: [ :assoc |
assoc key capitalized "piecesCutWhereCamelCase asCommaString" ];
column: 'Number of methods' text: [ :assoc |
assoc value size ];
send: [ :assoc |
assoc value ]
]

{ #category : #testing }
GtExtensionMethodsPackageWrapper >> hasExtensionMethods [
^ self numberOfExtensions > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GtExtensionMethodsProjectBuilder class >> forGToolkit [
<gtExample>

^ self new
buildWrapperForProject: BaselineOfGToolkit fullBaselineProject
buildReportForProject: BaselineOfGToolkit fullBaselineProject
]

{ #category : #analysis }
Expand Down Expand Up @@ -65,7 +65,7 @@ GtExtensionMethodsProjectBuilder >> buildProjectWrapperForMethods: aCollection i
]

{ #category : #analysis }
GtExtensionMethodsProjectBuilder >> buildWrapperForProject: aProject [
GtExtensionMethodsProjectBuilder >> buildReportForProject: aProject [
| systemExtensions |
systemExtensions := self extensionsToSystemClassesForProject: aProject.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ GtExtensionMethodsProjectWrapper >> extensionMethods [
aPackage extensionMethods ]
]

{ #category : #'accessing - grouping' }
GtExtensionMethodsProjectWrapper >> groupByMethodChangeType [
| extensionMethodsGroup |
extensionMethodsGroup := self extensionMethods
groupedBy: [ :each | each changeType ].

^ extensionMethodsGroup collect: [ :aGroup |
GtExtensionMethodsProjectBuilder new
buildProjectWrapperForMethodWrappers: aGroup
inProject: self project ]
]

{ #category : #'gt - extensions' }
GtExtensionMethodsProjectWrapper >> gtViewExtensionMethodsFor: aView [
<gtView>
Expand All @@ -31,6 +43,23 @@ GtExtensionMethodsProjectWrapper >> gtViewExtensionMethodsFor: aView [
column: 'Package' text: [ :aMethod | aMethod package name ]
]

{ #category : #'gt - extensions' }
GtExtensionMethodsProjectWrapper >> gtViewGroupsByChangeTypeFor: aView [
<gtView>

^ aView columnedList
title: 'Extension Methods (by change type)';
priority: 55;
items: [
self groupByMethodChangeType associations ];
column: 'Change type' text: [ :assoc |
assoc key capitalized "piecesCutWhereCamelCase asCommaString" ];
column: 'Number of methods' text: [ :assoc |
assoc value numberOfExtensions ];
send: [ :assoc |
assoc value ]
]

{ #category : #'gt - extensions' }
GtExtensionMethodsProjectWrapper >> gtViewPackageWrappersFor: aView [
<gtView>
Expand Down

0 comments on commit 87a961f

Please sign in to comment.