Skip to content

Commit 3d49ab9

Browse files
committed
change the way token are checked/add isPrivate token/test
1 parent 4f29cda commit 3d49ab9

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/FamixJavaModelUpdater-Tests/FJMUModelUpdaterTest.class.st

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ FJMUModelUpdaterTest >> testVisitFASTJavaParameter [
191191
{ #category : 'tests' }
192192
FJMUModelUpdaterTest >> testVisitFASTJavaVariableDeclarator [
193193

194-
| fasVariableDeclarator fastVarDeclStatement fastClassDeclaration fastJavaModel famixClass |
194+
| fasVariableDeclarator fastVarDeclStatement fastClassDeclaration fastJavaModel famixClass annotationValue modifierPrivate |
195195
fastJavaModel := FASTJavaModel new.
196196
fastClassDeclaration := FASTJavaClassDeclaration new.
197197
fastVarDeclStatement := FASTJavaVarDeclStatement new.
@@ -200,16 +200,28 @@ FJMUModelUpdaterTest >> testVisitFASTJavaVariableDeclarator [
200200
famixClass := FamixJavaClass new.
201201
fastClassDeclaration famixTypeDefinition: famixClass.
202202
famixModel add: famixClass.
203+
204+
annotationValue := FASTJavaAnnotation new
205+
name: 'Value';
206+
elements: { (FASTJavaStringLiteral new primitiveValue: '${com.example}').}.
207+
fastVarDeclStatement addModifier: annotationValue.
208+
modifierPrivate := FASTJavaModifier new token: 'private'.
209+
fastVarDeclStatement addModifier: modifierPrivate.
210+
203211
fasVariableDeclarator variable: (FASTJavaVariableExpression new
204212
name: 'variableName';
205213
yourself).
214+
206215
fastVarDeclStatement addDeclarator: fasVariableDeclarator.
207216
fastJavaModel addAll: { fastClassDeclaration. fastVarDeclStatement. fasVariableDeclarator }.
208-
fasVariableDeclarator accept: modelUpdater.
217+
fastVarDeclStatement accept: modelUpdater.
209218
self
210219
assert: (famixModel allWithType: FamixJavaAttribute) size
211220
equals: 1.
212221
self
213222
assert: (famixModel allWithType: FamixJavaAttribute) anyOne name
214-
equals: 'variableName'
223+
equals: 'variableName'.
224+
self
225+
assert: (famixModel allWithType: FamixJavaAttribute) first isPrivate
226+
equals: true.
215227
]

src/FamixJavaModelUpdater/FJMUModelUpdater.class.st

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ FJMUModelUpdater >> visitFASTJavaVariableDeclarator: aFASTJavaVariableDeclarator
243243
from: aFASTJavaVariableDeclarator ].
244244
famixVariable name: aFASTJavaVariableDeclarator variable name.
245245
(aFASTJavaVariableDeclarator atScope: FASTJavaVarDeclStatement)
246-
anyOne modifiers do: [ :modifier |
247-
(modifier respondsTo: #token) ifTrue: [
246+
anyOne modifiers do: [ :modifier |
247+
(modifier isKindOf: FASTJavaModifier) ifTrue: [
248248
modifier token = 'public' ifTrue: [ famixVariable isPublic: true ].
249249
modifier token = 'final' ifTrue: [ famixVariable isFinal: true ].
250250
modifier token = 'static' ifTrue: [ famixVariable isClassSide: true ].
251-
].
251+
modifier token = 'private' ifTrue: [ famixVariable isPrivate: true ].
252+
].
252253
].
253254
(aFASTJavaVariableDeclarator varDeclOwner type isKindOf:
254255
FASTJavaClassTypeExpression) ifTrue: [
@@ -257,5 +258,5 @@ FJMUModelUpdater >> visitFASTJavaVariableDeclarator: aFASTJavaVariableDeclarator
257258
ifNotNil: [ :type | famixVariable declaredType: type ] ].
258259
(scope isKindOf: FASTJavaMethodEntity)
259260
ifTrue: [ scope famixMethod addLocalVariable: famixVariable ]
260-
ifFalse: [ scope famixTypeDefinition addAttribute: famixVariable ]
261+
ifFalse: [ scope famixTypeDefinition addAttribute: famixVariable ].
261262
]

0 commit comments

Comments
 (0)