Skip to content

Commit

Permalink
multilevel .java file export
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed May 3, 2024
1 parent da8488f commit 7160896
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
40 changes: 40 additions & 0 deletions src/Famix2Java-Tests/FAMIX2JavaVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,46 @@ public class DemoClass {
}'
]

{ #category : #test }
FAMIX2JavaVisitorTest >> testExportMultiLevelPackagesWithClassAtMultipleLevel [

| model orgClass aCompanyClass orgPackage companyPackage memory |
model := FamixJavaModel new.
orgPackage := model newPackageNamed: 'org'.
companyPackage := model newPackageNamed: 'company'.
orgClass := model newClassNamed: 'OrgClass'.
aCompanyClass := model newClassNamed: 'CompanyClass'.
orgPackage addType: orgClass.
orgPackage addChildEntity: companyPackage.
companyPackage addType: aCompanyClass.
"Export the model"
memory := FileSystem memory.
FAMIX2JavaVisitor new
rootFolder: (memory / 'exported') asFileReference;
export: model.
self assert: (memory / 'exported') asFileReference exists.
self assert: (memory / 'exported' / 'org') asFileReference exists.
self assert:
(memory / 'exported' / 'org') asFileReference isDirectory.
self assert:
(memory / 'exported' / 'org' / 'OrgClass.java') asFileReference
exists.
self assert:
(memory / 'exported' / 'org' / 'OrgClass.java') asFileReference
isFile.
self assert:
(memory / 'exported' / 'org' / 'company') asFileReference exists.
self assert:
(memory / 'exported' / 'org' / 'company') asFileReference
isDirectory.
self assert:
(memory / 'exported' / 'org' / 'company' / 'CompanyClass.java')
asFileReference exists.
self assert:
(memory / 'exported' / 'org' / 'company' / 'CompanyClass.java')
asFileReference isFile
]

{ #category : #test }
FAMIX2JavaVisitorTest >> testExportOneClassInAnotherClass [

Expand Down
18 changes: 8 additions & 10 deletions src/Famix2Java/FAMIX2JavaVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,14 @@ FAMIX2JavaVisitor >> visitPackage: aFamixJavaPackage [
self rootFolder ensureCreateDirectory ].
self rootFolder: self rootFolder / aFamixJavaPackage name.
self rootFolder ensureCreateDirectory ].
aFamixJavaPackage children do: [ :child |
child isPackage
ifTrue: [ child accept: self ]
ifFalse: [ "I am a class or interface, or anything else that will be a file"
| file |
file := self rootFolder / (child name , '.java').
file deleteIfAbsent: [ ].
file writeStreamDo: [ :stream |
currentStream := stream.
child accept: self ] ] ]
aFamixJavaPackage types do: [ :type |
| file |
file := self rootFolder / (type name , '.java').
file deleteIfAbsent: [ ].
file writeStreamDo: [ :stream |
currentStream := stream.
type accept: self ] ].
aFamixJavaPackage childEntities do: [ :child | child accept: self ]
]

{ #category : #generated }
Expand Down

0 comments on commit 7160896

Please sign in to comment.