Skip to content

Commit

Permalink
Merge pull request #811 from moosetechnology/810-Accessing-the-top-Le…
Browse files Browse the repository at this point in the history
…vel-package-of-a-java-Entity-should-be-possible

Adding methods and tests to compute topLevelPackage from any entities…
  • Loading branch information
ClotildeToullec authored Aug 26, 2024
2 parents 1b5ccf2 + 6dc5d74 commit 95a68ce
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Famix-Java-Entities/FamixJavaNamedEntity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ FamixJavaNamedEntity >> stubFormattedName [
attribute: TextEmphasis italic ]
ifFalse: [ Text fromString: self name ]
]

{ #category : #testing }
FamixJavaNamedEntity >> topLevelPackage [
^ (self atScope: FamixTPackage) anyOne topLevelPackage
]
10 changes: 10 additions & 0 deletions src/Famix-Java-Entities/FamixJavaPackage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ FamixJavaPackage >> instability [
^ efferentCoupling / (efferentCoupling + afferentCoupling)
]

{ #category : #testing }
FamixJavaPackage >> isTopLevelPackage [
^ self topLevelPackage == self.
]

{ #category : #'Famix-Extensions-metrics' }
FamixJavaPackage >> martinCohesion [
"Computing cohesion as described by Robert C. Martin"
Expand Down Expand Up @@ -295,3 +300,8 @@ FamixJavaPackage >> relativeImportanceForSystem [
ifFalse: [0]
]
]

{ #category : #testing }
FamixJavaPackage >> topLevelPackage [
^ (self parentPackage isNotNil and: [ self parentPackage childEntities anySatisfy: #isType ] ) ifTrue: [ self parentPackage topLevelPackage ] ifFalse: [ self ]
]
72 changes: 72 additions & 0 deletions src/Famix-Java-Tests/FamixJavaTest.class.st
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
Class {
#name : #FamixJavaTest,
#superclass : #TestCase,
#instVars : [
'pkg1',
'pkg2',
'subPkg',
'subSubPkg',
'model',
'cls',
'meth',
'att',
'subPkg2',
'intf',
'cls2',
'meth2'
],
#category : #'Famix-Java-Tests'
}

{ #category : #running }
FamixJavaTest >> setUp [

super setUp.
model := FamixJavaModel new.
pkg1 := FamixJavaPackage new name: 'package1'.
pkg2 := FamixJavaPackage new name: 'package2'.
subPkg := FamixJavaPackage new name: 'subpackage'.
subSubPkg := FamixJavaPackage new name: 'subsubpackage'.
subPkg2 := FamixJavaPackage new name: 'subpackage2'.
subSubPkg parentPackage: subPkg.
subPkg parentPackage: pkg1.
subPkg2 parentPackage: pkg2 .


cls := FamixJavaClass new name: 'Class1' ; parentPackage: subSubPkg .
cls2 := FamixJavaClass new name: 'Class2' ; parentPackage: subPkg .
meth := FamixJavaMethod new name: 'Method1' ; parentType: cls.
att := FamixJavaAttribute new name: 'Attribute1' ; parentType: cls.
intf := FamixJavaInterface new name: 'Interface1' ; parentPackage: subPkg2 .
meth2 := FamixJavaMethod new name: 'Method2' ; parentType: intf.
model addAll: { cls. meth. att . pkg1 . pkg2 . subPkg . subPkg2 . subSubPkg }.
]

{ #category : #tests }
FamixJavaTest >> testImportAnnotations [
| model |
Expand Down Expand Up @@ -93,7 +131,41 @@ FamixJavaTest >> testInferNamespaces [
self assert: model allPackages size equals: 4
]

{ #category : #tests }
FamixJavaTest >> testIsTopLevelPackage [

self assert: model allPackages size equals: 5.
self assert: pkg1 isTopLevelPackage.
self assert: pkg2 isTopLevelPackage.
self assert: subPkg isTopLevelPackage.
self assert: subPkg2 isTopLevelPackage.
self deny: subSubPkg isTopLevelPackage .
]

{ #category : #tests }
FamixJavaTest >> testModelImportableFromFile [
self assert: FamixJavaModel canBeImportedFromFile
]

{ #category : #tests }
FamixJavaTest >> testTopLevelPackage [

self assert: model allPackages size equals: 5.
self assert: pkg1 topLevelPackage equals: pkg1.
self assert: pkg2 topLevelPackage equals: pkg2.
self assert: subPkg topLevelPackage equals: subPkg .
self assert: subPkg2 topLevelPackage equals: subPkg2 .
self assert: subSubPkg topLevelPackage equals: subPkg .
]

{ #category : #tests }
FamixJavaTest >> testTopLevelPackageForOtherEntities [

self assert: cls topLevelPackage equals: subPkg .
self assert: meth topLevelPackage equals: subPkg .
self assert: att topLevelPackage equals: subPkg .
self assert: cls2 topLevelPackage equals: subPkg .
self assert: intf topLevelPackage equals: subPkg2 .
self assert: meth2 topLevelPackage equals: subPkg2 .

]

0 comments on commit 95a68ce

Please sign in to comment.