Skip to content

Commit

Permalink
Merge branch 'v5' into baseline-fast-java-caps
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou authored Oct 24, 2024
2 parents 052e4a1 + 3898add commit 2be15af
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 67 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@ Metacello new
load
```

## Use

Carrefour links entities in a FAST model to entities in a Famix model.
It is composed of 2 parts:
- Carrefour meta-model
- Binder with two main steps involved:
1. Generate the FAST model of a Famix entity (eg. a FamixMethod) with `#getFASTModel`
2. Bind the nodes in the FAST model to entities in the Famix model with `bindFASTModel:`

### Carrefour meta-model

Represents relations between Famix entities and FAST entities.

The relations are typically between:
- FamixMethod and FASTBehaviouralEntity
- FamixStructuralEntity and FASTVariableDeclarator, FASTExpression, or FASTAssignement
- FamixInvocation and FASTFunctionCall or FASTMessageSend
Note: *class names are only indicative, they do not really exist in any Famix or FAST meta-model*

### Generating the FAST model

Done by a *language dependent* parser.
Each concerned FamixEntity should know how to do it by implementing `#getFASTModel`.
For example in Java, this method is implemented by `FamixJavaMethod` and all the main "structured types" (`FamixJavaClass`, `FamixJavaEnum`, `FamixJavaException`).

### Binding

Done by visiting the FAST model (an AST) and looking for corresponding Famix entities to each FAST entity.
It is implemented in `bindFASTModel:`

## Developers

### Update tests
Expand Down
19 changes: 10 additions & 9 deletions src/BaselineOfCarrefour/BaselineOfCarrefour.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Class {
#name : #BaselineOfCarrefour,
#superclass : #BaselineOf,
#category : #BaselineOfCarrefour
#name : 'BaselineOfCarrefour',
#superclass : 'BaselineOf',
#category : 'BaselineOfCarrefour',
#package : 'BaselineOfCarrefour'
}

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfCarrefour >> baseline: spec [
<baseline>
spec
Expand All @@ -17,7 +18,7 @@ BaselineOfCarrefour >> baseline: spec [
self defineGroups: spec ]
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfCarrefour >> customProjectAttributes [

^ RPackageOrganizer default packages
Expand All @@ -26,13 +27,13 @@ BaselineOfCarrefour >> customProjectAttributes [
ifNone: [ #( #NeedsTinyLogger ) ]
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfCarrefour >> defineDependencies: spec [

spec baseline: 'FASTJava' with: [
spec
loads: #( 'all' );
repository: 'github://moosetechnology/FAST-JAVA:v3.0.5/src' ].
repository: 'github://moosetechnology/FAST-JAVA:v3.0.7/src' ].
spec
baseline: 'Famix2Java'
with: [
Expand All @@ -43,12 +44,12 @@ BaselineOfCarrefour >> defineDependencies: spec [
with: [ spec repository: 'github://jecisc/TinyLogger:v1.x.x/src' ] ]
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfCarrefour >> defineGroups: spec [
spec group: 'generator' with: #('Carrefour-Model-Generator')
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfCarrefour >> definePackages: spec [

spec
Expand Down
2 changes: 1 addition & 1 deletion src/BaselineOfCarrefour/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #BaselineOfCarrefour }
Package { #name : 'BaselineOfCarrefour' }
69 changes: 12 additions & 57 deletions src/Carrefour-Exporter/CRFExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,17 @@ Class {
}

{ #category : #accessing }
CRFExporter >> visitMethod: aMethod [
CRFExporter >> printStatementBlockOf: aMethod [

aMethod isStub ifTrue: [ ^ self ].
self printMethodAnnotations: aMethod.
self indent.
aMethod isPrivate ifTrue: [ self << 'private ' ].
aMethod isProtected ifTrue: [ self << 'protected ' ].
aMethod isPublic ifTrue: [ self << 'public ' ].
aMethod isClassSide ifTrue: [ self << 'static ' ].
"Printing return type for method"
aMethod declaredType ifNotNil: [ :declaredType |
self printDeclaredType: declaredType.
currentStream << String space ].
"Printing name + parameters of method"
(aMethod name = '<Initializer>' or: [
aMethod isAnInitializer and: [ aMethod isConstructor not ] ])
ifFalse: [
self
<< aMethod name;
<< '('.
(aMethod parameters sorted: [ :p :p2 |
p sourceAnchor startPos < p2 sourceAnchor startPos ])
do: [ :parameter | parameter accept: self clone ]
separatedBy: [ self << ', ' ].
self << ')' ]
ifTrue: [ self << 'static' ].
"print exception"
((aMethod withMethodsOverriding collect: [ :m |
m thrownExceptions , m declaredExceptions ]) flattened asSet
asOrderedCollection sorted: #name ascending) ifNotEmpty: [
:exceptions |
self << ' throws '.
exceptions
do: [ :exception | self << exception name ]
separatedBy: [ self << ', ' ] ].

"Printing body of method if class is not abstract or an interface"
((aMethod atScope: FamixTClass) anyOne isInterface or: [
aMethod isAbstract isNotNil and: [ aMethod isAbstract ] ])
ifTrue: [ self << ';' ]
ifFalse: [
aMethod fast
ifNotNil: [ :fastMethod |
| fastJavaExporterVisitor |
fastJavaExporterVisitor := FASTJavaExportVisitor new
outputStream: self currentStream;
indentSize: tabulationSize;
yourself.
self << ' '.
1 to: tabs do: [ :tab | fastJavaExporterVisitor indent ].
fastMethod statementBlock accept: fastJavaExporterVisitor ]
ifNil: [
self << ' {'.
self eol.
self << aMethod bodySourceText.
self
eol;
<<| '}' ] ]
aMethod fast
ifNotNil: [ :fastMethod |
| fastJavaExporterVisitor |
fastJavaExporterVisitor := FASTJavaExportVisitor new
outputStream: self currentStream;
indentSize: tabulationSize;
yourself.
self << ' '.
1 to: tabs do: [ :tab | fastJavaExporterVisitor indent ].
fastMethod statementBlock accept: fastJavaExporterVisitor ]
ifNil: [ super printStatementBlockOf: aMethod ]
]

0 comments on commit 2be15af

Please sign in to comment.