From 33003a0fb419a6e57f1295ed24af0804e4e54be9 Mon Sep 17 00:00:00 2001 From: anquetil Date: Thu, 26 Oct 2023 18:51:52 +0200 Subject: [PATCH 1/2] commiting changes to reload whole package to try to correct bug with slots --- .../FASTJavaMetamodelGenerator.class.st | 9 ++--- .../FASTJavaAnnotation.class.st | 30 ++-------------- .../FASTJavaMethodEntity.class.st | 2 +- .../FASTJavaVariableExpression.class.st | 34 +++---------------- .../JavaSmaCCAnnotation.class.st | 34 +++++++++++++++++++ .../JavaSmaCCMethodModifiersTest.class.st | 6 ++-- ...vaSmaCCProgramNodeImporterVisitor.class.st | 16 ++++++--- .../FASTJavaExportVisitorTest.class.st | 24 +++++++++++++ 8 files changed, 83 insertions(+), 72 deletions(-) create mode 100644 src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotation.class.st diff --git a/src/FAST-Java-Model-Generator/FASTJavaMetamodelGenerator.class.st b/src/FAST-Java-Model-Generator/FASTJavaMetamodelGenerator.class.st index 0e76a7f..56b7f68 100644 --- a/src/FAST-Java-Model-Generator/FASTJavaMetamodelGenerator.class.st +++ b/src/FAST-Java-Model-Generator/FASTJavaMetamodelGenerator.class.st @@ -968,8 +968,10 @@ FASTJavaMetamodelGenerator >> defineHierarchy [ javaModifier --|> tModifier. javaModifier --|> tExpression. - javaAnnotationExpression --|> tExpression. + javaAnnotationExpression --|> tNamedEntity. javaAnnotationExpression --|> tModifier. + javaAnnotationExpression --|> #TWithArguments. + javaParameterExpression --|> tExpression. javaParameterExpression --|> tVariableEntity. javaConditionalExpression --|> tReceiver. @@ -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'). diff --git a/src/FAST-Java-Model/FASTJavaAnnotation.class.st b/src/FAST-Java-Model/FASTJavaAnnotation.class.st index 1045102..39a9304 100644 --- a/src/FAST-Java-Model/FASTJavaAnnotation.class.st +++ b/src/FAST-Java-Model/FASTJavaAnnotation.class.st @@ -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' } @@ -24,26 +21,3 @@ FASTJavaAnnotation class >> annotation [ ^ self ] - -{ #category : #accessing } -FASTJavaAnnotation >> expression [ - "Relation named: #expression type: #FASTJavaVariableExpression opposite: #annotationExpressionOwner" - - - - ^ expression -] - -{ #category : #accessing } -FASTJavaAnnotation >> expression: anObject [ - - - expression := anObject -] - -{ #category : #navigation } -FASTJavaAnnotation >> expressionGroup [ - - - ^ MooseSpecializedGroup with: self expression -] diff --git a/src/FAST-Java-Model/FASTJavaMethodEntity.class.st b/src/FAST-Java-Model/FASTJavaMethodEntity.class.st index d716508..89e5282 100644 --- a/src/FAST-Java-Model/FASTJavaMethodEntity.class.st +++ b/src/FAST-Java-Model/FASTJavaMethodEntity.class.st @@ -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' diff --git a/src/FAST-Java-Model/FASTJavaVariableExpression.class.st b/src/FAST-Java-Model/FASTJavaVariableExpression.class.st index 54ce2e4..ad10eca 100644 --- a/src/FAST-Java-Model/FASTJavaVariableExpression.class.st +++ b/src/FAST-Java-Model/FASTJavaVariableExpression.class.st @@ -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' } @@ -29,31 +28,6 @@ FASTJavaVariableExpression class >> annotation [ ^ self ] -{ #category : #accessing } -FASTJavaVariableExpression >> annotationExpressionOwner [ - "Relation named: #annotationExpressionOwner type: #FASTJavaAnnotation opposite: #expression" - - - - - - ^ annotationExpressionOwner -] - -{ #category : #accessing } -FASTJavaVariableExpression >> annotationExpressionOwner: anObject [ - - - annotationExpressionOwner := anObject -] - -{ #category : #navigation } -FASTJavaVariableExpression >> annotationExpressionOwnerGroup [ - - - ^ MooseSpecializedGroup with: self annotationExpressionOwner -] - { #category : #accessing } FASTJavaVariableExpression >> javaCastExpressionTypeOwner [ "Relation named: #javaCastExpressionTypeOwner type: #FASTJavaCastExpression opposite: #type" diff --git a/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotation.class.st b/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotation.class.st new file mode 100644 index 0000000..2e8df1d --- /dev/null +++ b/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotation.class.st @@ -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 +] diff --git a/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCMethodModifiersTest.class.st b/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCMethodModifiersTest.class.st index e136fc7..810f12c 100644 --- a/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCMethodModifiersTest.class.st +++ b/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCMethodModifiersTest.class.st @@ -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 } diff --git a/src/FAST-Java-SmaCC-Importer/JavaSmaCCProgramNodeImporterVisitor.class.st b/src/FAST-Java-SmaCC-Importer/JavaSmaCCProgramNodeImporterVisitor.class.st index e3a6479..642603c 100644 --- a/src/FAST-Java-SmaCC-Importer/JavaSmaCCProgramNodeImporterVisitor.class.st +++ b/src/FAST-Java-SmaCC-Importer/JavaSmaCCProgramNodeImporterVisitor.class.st @@ -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 ] @@ -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 ] diff --git a/src/FAST-Java-Tools-Tests/FASTJavaExportVisitorTest.class.st b/src/FAST-Java-Tools-Tests/FASTJavaExportVisitorTest.class.st index 08ab205..28b4115 100644 --- a/src/FAST-Java-Tools-Tests/FASTJavaExportVisitorTest.class.st +++ b/src/FAST-Java-Tools-Tests/FASTJavaExportVisitorTest.class.st @@ -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 [ @@ -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 [ From 4a1c43011b2f88fe32720e3662ba5be4e6ca38f4 Mon Sep 17 00:00:00 2001 From: anquetil Date: Thu, 26 Oct 2023 22:43:40 +0200 Subject: [PATCH 2/2] Import Annotations + tests --- ...SmaCCAnnotationWithNamedArguments.class.st | 34 +++++++++++++++++++ ...maCCAnnotationWithUnnamedArgument.class.st | 34 +++++++++++++++++++ ...vaSmaCCProgramNodeImporterVisitor.class.st | 13 +++++++ 3 files changed, 81 insertions(+) create mode 100644 src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotationWithNamedArguments.class.st create mode 100644 src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotationWithUnnamedArgument.class.st diff --git a/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotationWithNamedArguments.class.st b/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotationWithNamedArguments.class.st new file mode 100644 index 0000000..105c869 --- /dev/null +++ b/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotationWithNamedArguments.class.st @@ -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 +] diff --git a/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotationWithUnnamedArgument.class.st b/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotationWithUnnamedArgument.class.st new file mode 100644 index 0000000..bd588ce --- /dev/null +++ b/src/FAST-Java-SmaCC-Importer-Tests/JavaSmaCCAnnotationWithUnnamedArgument.class.st @@ -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 +] diff --git a/src/FAST-Java-SmaCC-Importer/JavaSmaCCProgramNodeImporterVisitor.class.st b/src/FAST-Java-SmaCC-Importer/JavaSmaCCProgramNodeImporterVisitor.class.st index 642603c..36eedbb 100644 --- a/src/FAST-Java-SmaCC-Importer/JavaSmaCCProgramNodeImporterVisitor.class.st +++ b/src/FAST-Java-SmaCC-Importer/JavaSmaCCProgramNodeImporterVisitor.class.st @@ -525,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.