Skip to content

Commit

Permalink
Changes to CopyVisitorCodeGenerator to make it working in more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
anquetil committed Nov 10, 2024
1 parent 0a9d1ba commit 246c458
Show file tree
Hide file tree
Showing 20 changed files with 428 additions and 334 deletions.
26 changes: 14 additions & 12 deletions src/FAST-Core-Tools-Tests/FASTCopyVisitorCodeGeneratorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@
A FASTCopyVisitorCodeGeneratorTest is a test class for testing the behavior of FASTCopyVisitorCodeGenerator
"
Class {
#name : #FASTCopyVisitorCodeGeneratorTest,
#superclass : #TestCase,
#name : 'FASTCopyVisitorCodeGeneratorTest',
#superclass : 'TestCase',
#instVars : [
'visitorClass',
'visitorMethods',
'generator'
],
#category : #'FAST-Core-Tools-Tests-VisitorGenerator'
#category : 'FAST-Core-Tools-Tests-VisitorGenerator',
#package : 'FAST-Core-Tools-Tests',
#tag : 'VisitorGenerator'
}

{ #category : #running }
{ #category : 'running' }
FASTCopyVisitorCodeGeneratorTest >> assertGeneratedMethod: aBlock [

visitorMethods
detect: [ :asso | aBlock value: asso key ]
ifNone: [ self fail ]
]

{ #category : #running }
{ #category : 'running' }
FASTCopyVisitorCodeGeneratorTest >> setUp [
super setUp.

Expand All @@ -33,7 +35,7 @@ FASTCopyVisitorCodeGeneratorTest >> setUp [
visitorMethods add: method -> category ]
]

{ #category : #tests }
{ #category : 'tests' }
FASTCopyVisitorCodeGeneratorTest >> testGenerateCopyMethod [

generator rootClass: FmxTraitsTestGenerateAccessorBEntity visitorClass: visitorClass.
Expand All @@ -42,7 +44,7 @@ FASTCopyVisitorCodeGeneratorTest >> testGenerateCopyMethod [
methodCode beginsWith: 'copy: ' ]
]

{ #category : #tests }
{ #category : 'tests' }
FASTCopyVisitorCodeGeneratorTest >> testShouldCopyPropertyFor [

| property |
Expand All @@ -51,12 +53,12 @@ FASTCopyVisitorCodeGeneratorTest >> testShouldCopyPropertyFor [
allProperties detect: [ :prop | prop name = 'relationToB' ].

generator package: (FmxTraitsTestGenerateAccessorBClassA metamodel packages detect: [ :p | p name = 'Famix-MetamodelBuilder-TestsTraitsResources-A' ]).
self assert: (generator shouldCopyProperty: property for: FmxTraitsTestGenerateAccessorBClassA).
self assert: (generator shouldCopyProperty: property).


]

{ #category : #tests }
{ #category : 'tests' }
FASTCopyVisitorCodeGeneratorTest >> testShouldNotCopyDerivedProperty [

| property |
Expand All @@ -65,10 +67,10 @@ FASTCopyVisitorCodeGeneratorTest >> testShouldNotCopyDerivedProperty [
allProperties detect: [ :prop | prop name = 'relationToA' ].

self assert: property isDerived.
self deny: (generator shouldCopyProperty: property for: FmxTraitsTestGenerateAccessorBClassB)
self deny: (generator shouldCopyProperty: property)
]

{ #category : #tests }
{ #category : 'tests' }
FASTCopyVisitorCodeGeneratorTest >> testShouldNotCopyPropertyFromOtherPackage [

| property |
Expand All @@ -77,5 +79,5 @@ FASTCopyVisitorCodeGeneratorTest >> testShouldNotCopyPropertyFromOtherPackage [
allProperties detect: [ :prop | prop name = 'relationToA' ].

generator package: (FmxTraitsTestGenerateAccessorBClassA metamodel packages detect: [ :p | p name = 'Famix-MetamodelBuilder-TestsTraitsResources-B' ]).
self assert: (generator shouldCopyProperty: property for: FmxTraitsTestGenerateAccessorBClassA)
self assert: (generator shouldCopyProperty: property)
]
30 changes: 16 additions & 14 deletions src/FAST-Core-Tools-Tests/FASTLocalResolverScopingTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
A FASTLocalResolverScopingTest is a test class for testing the behavior of FASTLocalResolverScoping
"
Class {
#name : #FASTLocalResolverScopingTest,
#superclass : #TestCase,
#name : 'FASTLocalResolverScopingTest',
#superclass : 'TestCase',
#instVars : [
'resolverScoping'
],
#category : #'FAST-Core-Tools-Tests-Resolver'
#category : 'FAST-Core-Tools-Tests-Resolver',
#package : 'FAST-Core-Tools-Tests',
#tag : 'Resolver'
}

{ #category : #running }
{ #category : 'running' }
FASTLocalResolverScopingTest >> setUp [
super setUp.

resolverScoping := FASTLocalResolverScoping new
]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testAddNonLocalDeclaration [
"testing helper method #addNonLocalDeclaration:"
resolverScoping resetScopes.
Expand All @@ -32,7 +34,7 @@ FASTLocalResolverScopingTest >> testAddNonLocalDeclaration [
self assert: (resolverScoping findDeclaration: 'blah') class equals: FASTNonLocalDeclaration
]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testFindDeclarationInCurrentScope [
|node|
node := FASTEntity new.
Expand All @@ -42,14 +44,14 @@ FASTLocalResolverScopingTest >> testFindDeclarationInCurrentScope [
self assert: (resolverScoping findDeclaration: 'blah') equals: node
]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testFindDeclarationInEmptyScope [
resolverScoping resetScopes.
self assert: (resolverScoping findDeclaration: 'blah') equals: nil.

]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testFindDeclarationInParentScope [
|node|
node := FASTEntity new.
Expand All @@ -60,7 +62,7 @@ FASTLocalResolverScopingTest >> testFindDeclarationInParentScope [
self assert: (resolverScoping findDeclaration: 'blah') equals: node
]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testFindDeclarationNotInScope [
|node|
node := FASTEntity new.
Expand All @@ -71,14 +73,14 @@ FASTLocalResolverScopingTest >> testFindDeclarationNotInScope [

]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testHasScopes [
"initialization creates a scope"

self assert: resolverScoping hasScopes
]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testLocalDeclarationFor [
"testing helper method #localDeclaration:for:"
| declNode refNode |
Expand All @@ -94,14 +96,14 @@ FASTLocalResolverScopingTest >> testLocalDeclarationFor [
self assert: declNode localUses first equals: refNode
]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testResetScopes [
resolverScoping resetScopes.
self assert: resolverScoping hasScopes.

]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testScopeAddDeclarationTwiceRaisesError [
|node|
node := FASTEntity new.
Expand All @@ -116,7 +118,7 @@ FASTLocalResolverScopingTest >> testScopeAddDeclarationTwiceRaisesError [
raise: DuplicatedVariableError
]

{ #category : #tests }
{ #category : 'tests' }
FASTLocalResolverScopingTest >> testScopeAddNonLocalDeclarationTwiceRaisesError [
|node|
node := FASTEntity new.
Expand Down
2 changes: 1 addition & 1 deletion src/FAST-Core-Tools-Tests/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'FAST-Core-Tools-Tests' }
Package { #name : 'FAST-Core-Tools-Tests' }
24 changes: 13 additions & 11 deletions src/FAST-Core-Tools/FASTAbstractDifferentialValidator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,57 +24,59 @@ For this, a suitable `acceptableAST:differentFrom:` method should be defined tha
There is a `skipPaths` list to allow skiping some paths in the main file directory
"
Class {
#name : #FASTAbstractDifferentialValidator,
#superclass : #FASTAbstractValidator,
#name : 'FASTAbstractDifferentialValidator',
#superclass : 'FASTAbstractValidator',
#instVars : [
'comparator'
],
#category : #'FAST-Core-Tools-Validator'
#category : 'FAST-Core-Tools-Validator',
#package : 'FAST-Core-Tools',
#tag : 'Validator'
}

{ #category : #accessing }
{ #category : 'accessing' }
FASTAbstractDifferentialValidator >> comparator [

^comparator ifNil: [ comparator := self comparatorClass new ]
]

{ #category : #accessing }
{ #category : 'accessing' }
FASTAbstractDifferentialValidator >> comparatorClass [

^FamixModelComparator
]

{ #category : #running }
{ #category : 'running' }
FASTAbstractDifferentialValidator >> compare: node1 to: node2 [

self comparator compare: node1 to: node2
]

{ #category : #utilities }
{ #category : 'utilities' }
FASTAbstractDifferentialValidator >> getASTFromFileReference: aFileReference [

^self getTopLevelNodes: (super getASTFromFileReference: aFileReference)
]

{ #category : #utilities }
{ #category : 'utilities' }
FASTAbstractDifferentialValidator >> getRootNode: aModel [

^aModel detect: [ : e | e allParents isEmpty ]
]

{ #category : #utilities }
{ #category : 'utilities' }
FASTAbstractDifferentialValidator >> getTopLevelNodes: model [

self subclassResponsibility
]

{ #category : #utilities }
{ #category : 'utilities' }
FASTAbstractDifferentialValidator >> reExportAST: ast [

self subclassResponsibility
]

{ #category : #running }
{ #category : 'running' }
FASTAbstractDifferentialValidator >> runOnSourceFile: aFileReference [

| astOrig astBis topLevelNodes |
Expand Down
34 changes: 18 additions & 16 deletions src/FAST-Core-Tools/FASTAbstractValidator.class.st
Original file line number Diff line number Diff line change
@@ -1,67 +1,69 @@
Class {
#name : #FASTAbstractValidator,
#superclass : #Object,
#name : 'FASTAbstractValidator',
#superclass : 'Object',
#instVars : [
'skipPaths',
'encoding'
],
#category : #'FAST-Core-Tools-Validator'
#category : 'FAST-Core-Tools-Validator',
#package : 'FAST-Core-Tools',
#tag : 'Validator'
}

{ #category : #accessing }
{ #category : 'accessing' }
FASTAbstractValidator >> defaultEncoding [
"other possibilities are 'latin1', 'utf8', ...
see `ZnCharacterEncoder knownEncodingIdentifiers` for all possibilities"
^encoding ifNil: [ 'iso-8859-1' ]
]

{ #category : #accessing }
{ #category : 'accessing' }
FASTAbstractValidator >> encoding [

^encoding
]

{ #category : #accessing }
{ #category : 'accessing' }
FASTAbstractValidator >> encoding: aString [

encoding := aString
]

{ #category : #utilities }
{ #category : 'utilities' }
FASTAbstractValidator >> getASTFromFileReference: aFileReference [

^aFileReference readStreamEncoded: self defaultEncoding do: [ :stream |
self getASTFromString: stream contents ]

]

{ #category : #utilities }
{ #category : 'utilities' }
FASTAbstractValidator >> getASTFromString: stream [

self subclassResponsibility
]

{ #category : #initialization }
{ #category : 'initialization' }
FASTAbstractValidator >> initialize [

super initialize.

skipPaths := #().
]

{ #category : #testing }
{ #category : 'testing' }
FASTAbstractValidator >> isSourceFile: aFileReference [

self subclassResponsibility
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
FASTAbstractValidator >> on: aDirectoryName [

self runOnFileReference: aDirectoryName asFileReference
]

{ #category : #running }
{ #category : 'running' }
FASTAbstractValidator >> runOnDirectory: aDirectory [

aDirectory isDirectory
Expand All @@ -70,7 +72,7 @@ FASTAbstractValidator >> runOnDirectory: aDirectory [
aDirectory children do: [ :fileRef | self runOnFileReference: fileRef ]
]

{ #category : #running }
{ #category : 'running' }
FASTAbstractValidator >> runOnFileReference: aFileReference [

(self skipPaths includes: aFileReference fullName)
Expand All @@ -84,19 +86,19 @@ FASTAbstractValidator >> runOnFileReference: aFileReference [

]

{ #category : #testing }
{ #category : 'testing' }
FASTAbstractValidator >> runOnSourceFile: aFileReference [

self subclassResponsibility
]

{ #category : #accessing }
{ #category : 'accessing' }
FASTAbstractValidator >> skipPaths [

^ skipPaths
]

{ #category : #accessing }
{ #category : 'accessing' }
FASTAbstractValidator >> skipPaths: anObject [

skipPaths := anObject
Expand Down
Loading

0 comments on commit 246c458

Please sign in to comment.