Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fighting slots #116

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,10 @@ FASTJavaMetamodelGenerator >> defineHierarchy [
javaModifier --|> tModifier.
javaModifier --|> tExpression.

javaAnnotationExpression --|> tExpression.
javaAnnotationExpression --|> tNamedEntity.
javaAnnotationExpression --|> tModifier.
javaAnnotationExpression --|> #TWithArguments.

javaParameterExpression --|> tExpression.
javaParameterExpression --|> tVariableEntity.
javaConditionalExpression --|> tReceiver.
Expand Down Expand Up @@ -1364,11 +1366,6 @@ FASTJavaMetamodelGenerator >> defineRelations [
<>-* ((tModifier property: #javaModifierOwner) comment:
'The owner of the modifier').

((javaAnnotationExpression property: #expression) comment:
'My expression (because annotation can be complex)')
<>- ((javaVariableExpression property: #annotationExpressionOwner)
comment: 'The annotation that owns me').

((tWithAssignable property: #variable) comment: 'My variable')
<>- ((tAssignable property: #javaVariableAssignmentOwner) comment:
'The owner of the assignment').
Expand Down
30 changes: 2 additions & 28 deletions src/FAST-Java-Model/FASTJavaAnnotation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ example:
Class {
#name : #FASTJavaAnnotation,
#superclass : #FASTJavaEntity,
#traits : 'FASTJavaTModifier + FASTTExpression',
#classTraits : 'FASTJavaTModifier classTrait + FASTTExpression classTrait',
#instVars : [
'#expression => FMOne type: #FASTJavaVariableExpression opposite: #annotationExpressionOwner'
],
#traits : 'FASTJavaTModifier + FASTTNamedEntity + FASTTWithArguments',
#classTraits : 'FASTJavaTModifier classTrait + FASTTNamedEntity classTrait + FASTTWithArguments classTrait',
#category : #'FAST-Java-Model-Entities'
}

Expand All @@ -24,26 +21,3 @@ FASTJavaAnnotation class >> annotation [
<generated>
^ self
]

{ #category : #accessing }
FASTJavaAnnotation >> expression [
"Relation named: #expression type: #FASTJavaVariableExpression opposite: #annotationExpressionOwner"

<generated>
<FMComment: 'My expression (because annotation can be complex)'>
^ expression
]

{ #category : #accessing }
FASTJavaAnnotation >> expression: anObject [

<generated>
expression := anObject
]

{ #category : #navigation }
FASTJavaAnnotation >> expressionGroup [
<generated>
<navigation: 'Expression'>
^ MooseSpecializedGroup with: self expression
]
2 changes: 1 addition & 1 deletion src/FAST-Java-Model/FASTJavaMethodEntity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Class {
#traits : 'FASTJavaTDeclaration + FASTJavaTWithModifiers + FASTTNamedBehaviouralEntity + FamixTHasImmediateSource',
#classTraits : 'FASTJavaTDeclaration classTrait + FASTJavaTWithModifiers classTrait + FASTTNamedBehaviouralEntity classTrait + FamixTHasImmediateSource classTrait',
#instVars : [
'#type => FMOne type: #FASTJavaVariableExpression opposite: #javaMethodTypeOwner',
'#throws => FMMany type: #FASTJavaClassTypeExpression opposite: #javaMethodThrowsOwner',
'#type => FMOne type: #FASTJavaVariableExpression opposite: #javaMethodTypeOwner',
'#typeParameters => FMMany type: #FASTJavaTypeParameterExpression opposite: #javaMethodTypeParameterOwner'
],
#category : #'FAST-Java-Model-Entities'
Expand Down
34 changes: 4 additions & 30 deletions src/FAST-Java-Model/FASTJavaVariableExpression.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ Class {
#traits : 'FASTJavaTAssignable + FASTJavaTReceiver + FASTTVariableExpression',
#classTraits : 'FASTJavaTAssignable classTrait + FASTJavaTReceiver classTrait + FASTTVariableExpression classTrait',
#instVars : [
'#javaVariableDeclaratorOwner => FMOne type: #FASTJavaVariableDeclarator opposite: #variable',
'#javaCastExpressionTypeOwner => FMOne type: #FASTJavaCastExpression opposite: #type',
'#javaClassPropertyOwner => FMOne type: #FASTJavaClassProperty opposite: #type',
'#javaNewExpressionOwner => FMOne type: #FASTJavaNewExpression opposite: #type',
'#javaOuterThisOwner => FMOne type: #FASTJavaOuterThis opposite: #type',
'#javaCatchParameterOwnler => FMOne type: #FASTJavaCatchPartStatement opposite: #parameter',
'#javaClassPropertyOwner => FMOne type: #FASTJavaClassProperty opposite: #type',
'#javaMethodReferenceOwner => FMOne type: #FASTJavaMethodReference opposite: #receiver',
'#javaMethodTypeOwner => FMOne type: #FASTJavaMethodEntity opposite: #type',
'#javaNewExpressionOwner => FMOne type: #FASTJavaNewExpression opposite: #type',
'#javaOuterThisOwner => FMOne type: #FASTJavaOuterThis opposite: #type',
'#javaParameterTypeOwner => FMOne type: #FASTJavaParameter opposite: #type',
'#javaParameterVariableOwner => FMOne type: #FASTJavaParameter opposite: #variable',
'#javaVarDeclTypeOwner => FMOne type: #FASTJavaVarDeclStatement opposite: #type',
'#annotationExpressionOwner => FMOne type: #FASTJavaAnnotation opposite: #expression'
'#javaVariableDeclaratorOwner => FMOne type: #FASTJavaVariableDeclarator opposite: #variable'
],
#category : #'FAST-Java-Model-Entities'
}
Expand All @@ -29,31 +28,6 @@ FASTJavaVariableExpression class >> annotation [
^ self
]

{ #category : #accessing }
FASTJavaVariableExpression >> annotationExpressionOwner [
"Relation named: #annotationExpressionOwner type: #FASTJavaAnnotation opposite: #expression"

<generated>
<FMComment: 'The annotation that owns me'>
<container>
<derived>
^ annotationExpressionOwner
]

{ #category : #accessing }
FASTJavaVariableExpression >> annotationExpressionOwner: anObject [

<generated>
annotationExpressionOwner := anObject
]

{ #category : #navigation }
FASTJavaVariableExpression >> annotationExpressionOwnerGroup [
<generated>
<navigation: 'AnnotationExpressionOwner'>
^ MooseSpecializedGroup with: self annotationExpressionOwner
]

{ #category : #accessing }
FASTJavaVariableExpression >> javaCastExpressionTypeOwner [
"Relation named: #javaCastExpressionTypeOwner type: #FASTJavaCastExpression opposite: #type"
Expand Down
34 changes: 34 additions & 0 deletions src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotation.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Class {
#name : #JavaSmaCCAnnotation,
#superclass : #JavaSmaCCImporterTest,
#category : #'FAST-Java-SmaCC-Importer-Tests'
}

{ #category : #running }
JavaSmaCCAnnotation >> javaMethod [
^'@Useless
void mth() {
}'
]

{ #category : #tests }
JavaSmaCCAnnotation >> testAnnotatedEntity [
self
assert: (fastModel allWithType: FASTJavaAnnotation) anyOne javaModifierOwner class
equals: FASTJavaMethodEntity
]

{ #category : #tests }
JavaSmaCCAnnotation >> testNameOfAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) anyOne name equals: 'Useless'
]

{ #category : #tests }
JavaSmaCCAnnotation >> testNumberOfAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) size equals: 1
]

{ #category : #tests }
JavaSmaCCAnnotation >> testNumberOfArgumentsToAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) anyOne arguments size equals: 0
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Class {
#name : #JavaSmaCCAnnotationWithNamedArguments,
#superclass : #JavaSmaCCImporterTest,
#category : #'FAST-Java-SmaCC-Importer-Tests'
}

{ #category : #running }
JavaSmaCCAnnotationWithNamedArguments >> javaMethod [
^'@Useless(arg1="Argument 1",arg2=AClass.A_Constant)
void mth() {
}'
]

{ #category : #tests }
JavaSmaCCAnnotationWithNamedArguments >> testAnnotatedEntity [
self
assert: (fastModel allWithType: FASTJavaAnnotation) anyOne javaModifierOwner class
equals: FASTJavaMethodEntity
]

{ #category : #tests }
JavaSmaCCAnnotationWithNamedArguments >> testNameOfAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) anyOne name equals: 'Useless'
]

{ #category : #tests }
JavaSmaCCAnnotationWithNamedArguments >> testNumberOfAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) size equals: 1
]

{ #category : #tests }
JavaSmaCCAnnotationWithNamedArguments >> testNumberOfArgumentsToAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) anyOne arguments size equals: 2
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Class {
#name : #JavaSmaCCAnnotationWithUnnamedArgument,
#superclass : #JavaSmaCCImporterTest,
#category : #'FAST-Java-SmaCC-Importer-Tests'
}

{ #category : #running }
JavaSmaCCAnnotationWithUnnamedArgument >> javaMethod [
^'@Useless("Argument 1")
void mth() {
}'
]

{ #category : #tests }
JavaSmaCCAnnotationWithUnnamedArgument >> testAnnotatedEntity [
self
assert: (fastModel allWithType: FASTJavaAnnotation) anyOne javaModifierOwner class
equals: FASTJavaMethodEntity
]

{ #category : #tests }
JavaSmaCCAnnotationWithUnnamedArgument >> testNameOfAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) anyOne name equals: 'Useless'
]

{ #category : #tests }
JavaSmaCCAnnotationWithUnnamedArgument >> testNumberOfAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) size equals: 1
]

{ #category : #tests }
JavaSmaCCAnnotationWithUnnamedArgument >> testNumberOfArgumentsToAnnotation [
self assert: (fastModel allWithType: FASTJavaAnnotation) anyOne arguments size equals: 1
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ JavaSmaCCMethodModifiersTest >> javaMethod [
]

{ #category : #tests }
JavaSmaCCMethodModifiersTest >> testMethodAnnotationExpression [
self assert: (fastModel allWithType: FASTJavaAnnotation) anyOne expression class equals: FASTJavaVariableExpression
JavaSmaCCMethodModifiersTest >> testMethodModifiersAnnotationNumber [
self
assert: ((fastModel allWithType: FASTJavaMethodEntity) anyOne modifiers count: [ :mod | mod class = FASTJavaAnnotation ])
equals: 1
]

{ #category : #tests }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ JavaSmaCCProgramNodeImporterVisitor >> visitAbstractMethodDeclaration: anAbstrac
{ #category : #visitor }
JavaSmaCCProgramNodeImporterVisitor >> visitAnnotation: anAnnotation [
self create: FASTJavaAnnotation from: anAnnotation.
currentFASTEntity expression: (self clone accept: anAnnotation name).
currentFASTEntity name: anAnnotation name name value.

anAnnotation values do: [ :expression |
currentFASTEntity addArgument: (self clone accept: expression) ].

^ currentFASTEntity
]

Expand Down Expand Up @@ -438,11 +442,13 @@ JavaSmaCCProgramNodeImporterVisitor >> visitCharacterLiteral: aCharacterLiteral
{ #category : #visitor }
JavaSmaCCProgramNodeImporterVisitor >> visitClassDeclaration: aClassDeclaration [
self create: FASTJavaClassDeclaration from: aClassDeclaration.
aClassDeclaration declarations do: [ :declaration | currentFASTEntity addDeclaration: (self clone accept: declaration) ].
aClassDeclaration interfaces do: [ :interface | currentFASTEntity addInterface: (self clone accept: interface) ].
aClassDeclaration superclass ifNotNil: [ :superclass | currentFASTEntity superclass: (self clone accept: superclass) ].
aClassDeclaration modifiers do: [ :modifier | currentFASTEntity addModifier: (self clone accept: modifier) ].
currentFASTEntity name: aClassDeclaration name value.

aClassDeclaration modifiers do: [ :modifier | currentFASTEntity addModifier: (self clone accept: modifier) ].
aClassDeclaration superclass ifNotNil: [ :superclass | currentFASTEntity superclass: (self clone accept: superclass) ].
aClassDeclaration interfaces do: [ :interface | currentFASTEntity addInterface: (self clone accept: interface) ].
aClassDeclaration declarations do: [ :declaration | currentFASTEntity addDeclaration: (self clone accept: declaration) ].

^ currentFASTEntity
]

Expand Down Expand Up @@ -519,6 +525,19 @@ JavaSmaCCProgramNodeImporterVisitor >> visitDoubleType: aByteType [
^ currentFASTEntity
]

{ #category : #visitor }
JavaSmaCCProgramNodeImporterVisitor >> visitElementValuePair: anElementValuePair [
"'key = value' as argument of an Annotation
treat it as an Assignement Expression"

currentFASTEntity := self create: FASTJavaAssignmentExpression from: anElementValuePair.
currentFASTEntity variable: (self clone visitVariableName: anElementValuePair).
currentFASTEntity operator: '='.
currentFASTEntity expression: (self clone accept: anElementValuePair value).

^ currentFASTEntity
]

{ #category : #visitor }
JavaSmaCCProgramNodeImporterVisitor >> visitEmptyDeclaration: anEmptyDeclaration [
currentFASTEntity := self addToModel: FASTJavaEmptyMethodDeclaration new.
Expand Down
24 changes: 24 additions & 0 deletions src/FAST-Java-Tools-Tests/FASTJavaExportVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ FASTJavaExportVisitorTest >> testVisitFASTEmptyReturn [
'
]

{ #category : #tests }
FASTJavaExportVisitorTest >> testVisitFASTJavaAnnotatedMethod [

| expr |
expr := self methodAST: '@Useless void mth() { }'.

self export: expr equals: '@Useless
void mth() {
}
'
]

{ #category : #tests }
FASTJavaExportVisitorTest >> testVisitFASTJavaAnnotation [

Expand All @@ -81,6 +93,18 @@ FASTJavaExportVisitorTest >> testVisitFASTJavaAnnotation [
self export: anno equals: '@Deprecated'.
]

{ #category : #tests }
FASTJavaExportVisitorTest >> testVisitFASTJavaAnnotattionWithArgument [

| expr |
expr := self methodAST: '@Useless("an argument") void mth() { }'.

self export: expr equals: '@Useless("an argument")
void mth() {
}
'
]

{ #category : #tests }
FASTJavaExportVisitorTest >> testVisitFASTJavaAnonymousClassDeclaration [

Expand Down