From 7160896b8a19fbe2ec967b2099d63e7f8b606e80 Mon Sep 17 00:00:00 2001 From: Benoit Verhaeghe Date: Fri, 3 May 2024 09:29:20 +0200 Subject: [PATCH] multilevel .java file export --- .../FAMIX2JavaVisitorTest.class.st | 40 +++++++++++++++++++ src/Famix2Java/FAMIX2JavaVisitor.class.st | 18 ++++----- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/Famix2Java-Tests/FAMIX2JavaVisitorTest.class.st b/src/Famix2Java-Tests/FAMIX2JavaVisitorTest.class.st index 23b5b9d..6da361c 100644 --- a/src/Famix2Java-Tests/FAMIX2JavaVisitorTest.class.st +++ b/src/Famix2Java-Tests/FAMIX2JavaVisitorTest.class.st @@ -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 [ diff --git a/src/Famix2Java/FAMIX2JavaVisitor.class.st b/src/Famix2Java/FAMIX2JavaVisitor.class.st index aa87674..8d56f7f 100644 --- a/src/Famix2Java/FAMIX2JavaVisitor.class.st +++ b/src/Famix2Java/FAMIX2JavaVisitor.class.st @@ -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 }