Skip to content

Commit

Permalink
add test with full example
Browse files Browse the repository at this point in the history
improve export style by default
  • Loading branch information
badetitou committed May 2, 2024
1 parent 8351dca commit bc1c92a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
46 changes: 41 additions & 5 deletions src/Famix2Java-Tests/FAMIX2JavaVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ FAMIX2JavaVisitorTest >> testVisitBasicClass [
aClass accept: visitor ].
self assert: resultString equals: 'public class DemoClass {
}'
]

Expand Down Expand Up @@ -273,7 +272,6 @@ FAMIX2JavaVisitorTest >> testVisitBasicClassThatHasOneInterface [
assert: resultString
equals: 'public class DemoClass implements DemoOneInterface {
}'
]

Expand Down Expand Up @@ -304,7 +302,6 @@ FAMIX2JavaVisitorTest >> testVisitBasicClassThatHasSuperClass [
assert: resultString
equals: 'public class DemoClass extends DemoSuperClass {
}'
]

Expand Down Expand Up @@ -346,7 +343,6 @@ FAMIX2JavaVisitorTest >> testVisitBasicClassThatHasTwoInterfaces [
equals:
'public class DemoClass implements DemoOneInterface, DemoTwoInterface {
}'
]

Expand All @@ -369,7 +365,6 @@ FAMIX2JavaVisitorTest >> testVisitBasicClassWithAnnotation [
self assert: resultString equals: '@AnAnnotation
public class DemoClass {
}'
]

Expand Down Expand Up @@ -463,6 +458,47 @@ FAMIX2JavaVisitorTest >> testVisitClassWithDependencyAttributeAlsoStub [
'
]

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

| model resultString aClass primitiveVoid method method2 attributeDeclaredType attribute |
model := FamixJavaModel new.
aClass := model newClassNamed: 'DemoClass'.

attributeDeclaredType := model newClassNamed: 'AttributeClass'.
attribute := model newAttributeNamed: 'anAttribute'.
attribute declaredType: attributeDeclaredType.
aClass addAttribute: attribute.

primitiveVoid := model newPrimitiveTypeNamed: 'void'.
method := model newMethodNamed: 'aMethod'.

method declaredType: primitiveVoid.
aClass addMethod: method.

method2 := model newMethodNamed: 'aMethodTwo'.
method2 declaredType: primitiveVoid.
aClass addMethod: method2.


resultString := String streamContents: [ :stream |
visitor currentStream: stream.
aClass accept: visitor ].
self assert: resultString equals: 'public class DemoClass {
AttributeClass anAttribute;
void aMethod() {
}
void aMethodTwo() {
}
}'
]

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

Expand Down
23 changes: 12 additions & 11 deletions src/Famix2Java/FAMIX2JavaVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ FAMIX2JavaVisitor >> initialize [

super initialize.
self endOfLine: OSPlatform current lineEnding.
tabs := 0.
tabulationSize := 4
self reset
]

{ #category : #accessing }
Expand Down Expand Up @@ -332,15 +331,17 @@ FAMIX2JavaVisitor >> visitClass: aClass [
self eol.
"Printing Attributs"
self indentPlus.
aClass attributes do: [ :attribute |
attribute accept: self clone.
self eol ].
self eol.
"Printing Methods"
aClass methods do: [ :method |
aClass attributes ifNotEmpty: [ :attributes |
self eol.
method accept: self clone.
self eol ].
attributes do: [ :attribute |
attribute accept: self clone.
self eol ] ].
"Printing Methods"
aClass methods ifNotEmpty: [ :methods |
methods do: [ :method |
self eol.
method accept: self clone.
self eol ] ].
"Closing Class"
self eol.
currentStream << '}'
Expand Down Expand Up @@ -443,7 +444,7 @@ FAMIX2JavaVisitor >> visitMethod: aMethod [
ifFalse: [
currentStream << ' {'.
self eol.
self << aMethod bodySourceText.
self <<< aMethod bodySourceText.
self
eol;
<< '}' ]
Expand Down

0 comments on commit bc1c92a

Please sign in to comment.