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

Parametric #3

Merged
merged 5 commits into from
Feb 16, 2024
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 @@ -13,7 +13,7 @@ FamixValueUnknownType >> concreteTypeName [
]

{ #category : #'*Famix-Value-Entities-Extensions' }
FamixValueUnknownType >> isParameterizedType [
FamixValueUnknownType >> isParametricEntity [

^ false
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ FamixValue2FASTJavaVisitorTest >> testVisitCollection [

| collection |
collection := FamixValueOfCollection new type:
(FamixJavaParameterizedType new
parameterizableClass:
(FamixJavaParameterizableClass new name: 'List');
arguments: { (FamixJavaClass new name: 'String') }).
(FamixJavaParametricClass new
name: 'List';
genericization:
(FamixJavaConcretization new genericEntity:
(FamixJavaParametricInterface named: 'List'));
concreteParameters:
{ (FamixJavaClass named: 'String') }).

self assert: collection asJavaSourceCode equals: '{
List<String> list0 = new ArrayList<String>();
Expand Down Expand Up @@ -78,36 +81,42 @@ FamixValue2FASTJavaVisitorTest >> testVisitCollection [
{ #category : #tests }
FamixValue2FASTJavaVisitorTest >> testVisitDeepCollection [

| collection inner |
| list object collection element |
list := FamixJavaParametricInterface named: 'List'.
object := FamixJavaParametricInterface named: 'Object'.
collection := FamixValueOfCollection new type:
(FamixJavaParameterizedType new
parameterizableClass:
(FamixJavaParameterizableClass new name: 'List');
arguments: { (FamixJavaParameterizedType new
parameterizableClass:
(FamixJavaParameterizableClass new name: 'List');
arguments:
{ (FamixJavaClass new name: 'Object') }) }).
inner := FamixValueOfCollection new type:
(FamixJavaParameterizedType new
parameterizableClass:
(FamixJavaParameterizableClass new name: 'List');
arguments: { (FamixJavaClass new name: 'Object') }).
(FamixJavaParametricInterface new
genericization:
(FamixJavaConcretization new genericEntity: list);
concreteParameters:
{ (FamixJavaParametricInterface new
name: 'List';
genericization:
(FamixJavaConcretization new genericEntity: list);
concreteParameters: { object }) }).
element := FamixValueOfCollection new type:
(FamixJavaParametricInterface new
name: 'List';
genericization:
(FamixJavaConcretization new genericEntity: list);
concreteParameters: { object }).

self assert: collection asJavaSourceCode equals: '{
List<List<Object>> list0 = new ArrayList<List<Object>>();
}
'.

collection addValue: (FamixValueOfCollectionElement new value: inner).
collection addValue:
(FamixValueOfCollectionElement new value: element).
self assert: collection asJavaSourceCode equals: '{
List<List<Object>> list0 = new ArrayList<List<Object>>();
List<Object> list1 = new ArrayList<Object>();
list0.add(list1);
}
'.

inner addValue: (FamixValueOfCollectionElement new value: nullString).
element addValue:
(FamixValueOfCollectionElement new value: nullString).
self assert: collection asJavaSourceCode equals: '{
List<List<Object>> list0 = new ArrayList<List<Object>>();
List<Object> list1 = new ArrayList<Object>();
Expand All @@ -123,10 +132,14 @@ FamixValue2FASTJavaVisitorTest >> testVisitDictionary [

| dictionary |
dictionary := FamixValueOfDictionary new type:
(FamixJavaParameterizedType new
parameterizableClass:
(FamixJavaParameterizableClass new name: 'Map');
arguments: { (FamixJavaClass new name: 'Object') }).
(FamixJavaParametricInterface new
name: 'Map';
genericization:
(FamixJavaConcretization new genericEntity:
(FamixJavaParametricInterface named: 'Map'));
concreteParameters:
{ (FamixJavaClass named: 'Object') }).

self assert: dictionary asJavaSourceCode equals: '{
Map<Object, Object> map0 = new HashMap<Object, Object>();
}
Expand Down
73 changes: 72 additions & 1 deletion src/Famix-Value-Exporter-Tests/FamixValueExtensionsTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,78 @@ Class {
}

{ #category : #tests }
FamixValueExtensionsTest >> testSplitJavaArguments [
FamixValueExtensionsTest >> test_FamixTParametricEntity_keyType [

| string integer |
string := FamixJavaClass named: 'String'.
integer := FamixJavaClass named: 'Integer'.

self
assert: (FamixJavaParametricClass new concreteParameters: {
string.
integer }) keyType
equals: string.
self
assert: (FamixJavaParametricClass new concreteParameters: {
integer.
string }) keyType
equals: integer.
self
assert:
(FamixJavaParametricClass new concreteParameters: { string })
keyType
equals: string
]

{ #category : #tests }
FamixValueExtensionsTest >> test_FamixTParametricEntity_typeName [

| map string integer |
map := FamixJavaParametricClass named: 'Map'.
string := FamixJavaClass named: 'String'.
integer := FamixJavaClass named: 'Integer'.

self
assert: (map concreteParameters: {
string.
integer }) typeName
equals: 'Map<String, Integer>'.
self
assert: (map concreteParameters: {
integer.
string }) typeName
equals: 'Map<Integer, String>'.
self
assert: (map concreteParameters: { string }) typeName
equals: 'Map<String, String>'
]

{ #category : #tests }
FamixValueExtensionsTest >> test_FamixTParametricEntity_valueType [

| string integer |
string := FamixJavaClass named: 'String'.
integer := FamixJavaClass named: 'Integer'.

self
assert: (FamixJavaParametricClass new concreteParameters: {
string.
integer }) valueType
equals: integer.
self
assert: (FamixJavaParametricClass new concreteParameters: {
integer.
string }) valueType
equals: string.
self
assert:
(FamixJavaParametricClass new concreteParameters: { string })
valueType
equals: string
]

{ #category : #tests }
FamixValueExtensionsTest >> test_String_splitJavaArguments [

self assert: '' splitJavaArguments equals: { }.
self
Expand Down
12 changes: 6 additions & 6 deletions src/Famix-Value-Exporter/FASTJavaBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ FASTJavaBuilder >> makeImportDeclarations [
FASTJavaBuilder >> processType: aFamixType [

| type |
type := aFamixType isParameterizedType
type := aFamixType isParametricEntity
ifTrue: [
aFamixType arguments do: [ :argument |
self processType: argument ].
aFamixType parameterizableClass ]
aFamixType concreteParameters do: [ :parameter |
self processType: parameter ].
aFamixType genericEntity ]
ifFalse: [ aFamixType ].
type needsJavaImport ifTrue: [ self registerType: type ]
]
Expand All @@ -73,8 +73,8 @@ FASTJavaBuilder >> referType: aFamixType [
^ self model newClassTypeExpression typeName:
((registeredType == aFamixType or: [
aFamixType needsJavaImport not or: [
aFamixType isParameterizedType and: [
registeredType == aFamixType parameterizableClass ] ] ])
aFamixType isParametricEntity and: [
registeredType == aFamixType genericEntity ] ] ])
ifTrue: [ "has import"
model newTypeName name: aFamixType baseName ]
ifFalse: [ "no import"
Expand Down

This file was deleted.

43 changes: 0 additions & 43 deletions src/Famix-Value-Exporter/FamixJavaParameterizedType.extension.st

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Extension { #name : #FamixJavaParametricClass }

{ #category : #'*Famix-Value-Exporter' }
FamixJavaParametricClass >> concreteTypeNameOn: stream [

stream nextPutAll: name.
stream nextPutAll: '<>'
]
11 changes: 11 additions & 0 deletions src/Famix-Value-Exporter/FamixJavaParametricInterface.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Extension { #name : #FamixJavaParametricInterface }

{ #category : #'*Famix-Value-Exporter' }
FamixJavaParametricInterface >> concreteTypeNameOn: stream [

(#( Map Set ) includes: name)
ifTrue: [ stream nextPutAll: 'Hash' ]
ifFalse: [ 'List' = name ifTrue: [ stream nextPutAll: 'Array' ] ].
stream nextPutAll: name.
stream nextPutAll: '<>'
]
2 changes: 2 additions & 0 deletions src/Famix-Value-Exporter/FamixTClass.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ FamixTClass >> constructorsOrderedByScore [
{ #category : #'*Famix-Value-Exporter' }
FamixTClass >> findSetterOf: aFamixAttribute [

(self isParametricEntity and: [ self isConcreteEntity ]) ifTrue: [
^ self genericEntity findSetterOf: aFamixAttribute ].
^ self methods
detect: [ :method |
method isSetterLax and: [
Expand Down
19 changes: 0 additions & 19 deletions src/Famix-Value-Exporter/FamixTParameterizedType.extension.st

This file was deleted.

42 changes: 42 additions & 0 deletions src/Famix-Value-Exporter/FamixTParametricEntity.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Extension { #name : #FamixTParametricEntity }

{ #category : #'*Famix-Value-Exporter' }
FamixTParametricEntity >> keyType [

^ self allTypeParameters first
]

{ #category : #'*Famix-Value-Exporter' }
FamixTParametricEntity >> typeNameOn: stream [

stream nextPutAll: self name.
self typeParameterNamesOn: stream
]

{ #category : #'*Famix-Value-Exporter' }
FamixTParametricEntity >> typeParameterNamesOn: stream [

stream nextPut: $<.
self isDictionaryType
ifTrue: [
self keyType typeNameOn: stream.
stream nextPutAll: ', '.
self valueType typeNameOn: stream ]
ifFalse: [
self allTypeParameters
do: [ :parameter |
parameter isParameterType
ifTrue: [ stream nextPutAll: 'Object' ]
ifFalse: [ parameter typeNameOn: stream ] ]
separatedBy: [ stream nextPutAll: ', ' ] ].
stream nextPut: $>
]

{ #category : #'*Famix-Value-Exporter' }
FamixTParametricEntity >> valueType [

| typeParameters |
^ (typeParameters := self allTypeParameters) size = 1
ifTrue: [ typeParameters first ]
ifFalse: [ typeParameters second ]
]
Loading
Loading