Skip to content

Commit

Permalink
add a test for method in interface
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Jun 5, 2024
1 parent 41c3dd7 commit 798699a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
28 changes: 27 additions & 1 deletion src/Famix2Java-Tests/FAMIX2JavaVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ FAMIX2JavaVisitorTest >> testVisitBasicInterface [
aClass accept: visitor ].
self assert: resultString equals: 'public interface DemoInterface {
}'
]

Expand Down Expand Up @@ -687,6 +686,33 @@ FAMIX2JavaVisitorTest >> testVisitClassWithMethodsAndAttributes [
}'
]

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

| model resultString anInterface voidPrimitive interfaceMethod |
model := FamixJavaModel new.
voidPrimitive := model newPrimitiveTypeNamed: 'void'.
anInterface := model newInterface
name: 'DemoInterface';
yourself.

"Add a method to the class"
interfaceMethod := model newMethodNamed: 'insert'.
interfaceMethod isPublic: true.
interfaceMethod declaredType: voidPrimitive.

anInterface addMethod: interfaceMethod.

resultString := String streamContents: [ :stream |
visitor currentStream: stream.
anInterface accept: visitor ].
self assert: resultString equals: 'public interface DemoInterface {
public void insert();
}'
]

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

Expand Down
19 changes: 5 additions & 14 deletions src/Famix2Java/FAMIX2JavaVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -407,22 +407,13 @@ FAMIX2JavaVisitor >> visitInterface: aClass [
currentStream << aClass name.
"printing inheritance and implementation"
self printExtends: aClass.
currentStream << ' {'.
self << ' {'.
self eol.
"Printing Attributs"
self indentPlus.
aClass attributes do: [ :attribute |
attribute accept: self clone.
self eol ].
self eol.
"Printing Methods"
aClass methods do: [ :method |
self eol.
method accept: self clone.
self eol ].
"Closing Class"
self printContentOfClass: aClass.
self eol.
currentStream << '}'
self indentMinus.
self <<| '}'
]

{ #category : #accessing }
Expand Down Expand Up @@ -465,7 +456,7 @@ FAMIX2JavaVisitor >> visitMethod: aMethod [
separatedBy: [ self << ', ' ] ].

"Printing body of method if class is not abstract or an interface"
((aMethod atScope: FamixTClass) anyOne isInterface or: [
(aMethod parentType isInterface or: [
aMethod isAbstract isNotNil and: [ aMethod isAbstract ] ])
ifTrue: [ self << ';' ]
ifFalse: [
Expand Down

0 comments on commit 798699a

Please sign in to comment.