Skip to content

Commit

Permalink
can export parametricClass inside another class
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed May 3, 2024
1 parent 366d0ae commit 2d06709
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
33 changes: 33 additions & 0 deletions src/Famix2Java-Tests/FAMIX2JavaVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,39 @@ FAMIX2JavaVisitorTest >> testExportAnnotationImport [
'
]

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

| model resultString aClass k orgPackage innerParametricClass |
model := FamixJavaModel new.
orgPackage := model newPackageNamed: 'org'.
aClass := model newClassNamed: 'DemoClass'.
orgPackage addType: aClass.

innerParametricClass := FamixJavaParametricClass new.
innerParametricClass name: 'DemoClass'.
model add: innerParametricClass.
aClass addType: innerParametricClass.

k := FamixJavaParameterType named: 'K'.
model add: k.
innerParametricClass genericParameters: { k }.

resultString := String streamContents: [ :stream |
visitor currentStream: stream.
aClass accept: visitor ].
self assert: resultString equals: 'package org;
public class DemoClass {
public class DemoClass<K> {
}
}'
]

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

Expand Down
16 changes: 8 additions & 8 deletions src/Famix2Java/FAMIX2JavaVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,23 @@ FAMIX2JavaVisitor >> visitParametricClass: aFamixJavaParametricClass [
annotationInstance accept: self clone.
self eol ].
"Printing Class declaration"
currentStream << 'public class '.
currentStream << aFamixJavaParametricClass name.
currentStream << '<'.
self <<| 'public class '.
self << aFamixJavaParametricClass name.
self << '<'.
aFamixJavaParametricClass genericParameters
do: [ :genericParam | currentStream << genericParam name ]
separatedBy: [ currentStream << ', ' ].
currentStream << '>'.
do: [ :genericParam | self << genericParam name ]
separatedBy: [ self << ', ' ].
self << '>'.
"printing inheritance and implementation"
self printExtends: aFamixJavaParametricClass.
self printImplements: aFamixJavaParametricClass.
currentStream << ' {'.
self << ' {'.
self eol.
"Printing Attributs"
self indentPlus.
self printContentOfClass: aFamixJavaParametricClass.
self indentMinus.
"Closing Class"
self eol.
currentStream << '}'
self <<| '}'
]

0 comments on commit 2d06709

Please sign in to comment.