Skip to content

Commit

Permalink
updating java importer for records
Browse files Browse the repository at this point in the history
  • Loading branch information
j-brant committed Mar 27, 2024
1 parent a240953 commit 144c2b3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/GToolkit4Famix3-Java/GtJavaMethodVisitor.class.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Class {
#name : #GtJavaMethodVisitor,
#superclass : #Object,
#traits : 'TJavaProgramNodeVisitor',
#classTraits : 'TJavaProgramNodeVisitor classTrait',
#superclass : #JavaProgramNodeVisitor,
#instVars : [
'importer',
'insideMethod'
Expand All @@ -19,7 +17,7 @@ GtJavaMethodVisitor >> acceptNode: aSmaCCParseNode [
ifFalse: [ (importer methodNodeFor: aSmaCCParseNode)
ifNil: [ ^ self visitSmaCCParseNode: aSmaCCParseNode ].
insideMethod := true ].
^ [ aSmaCCParseNode acceptVisitor: self ] ensure: [ insideMethod := previous ]
^ [ super acceptNode: aSmaCCParseNode ] ensure: [ insideMethod := previous ]
]

{ #category : #accessing }
Expand Down
45 changes: 44 additions & 1 deletion src/GToolkit4Famix3-Java/GtSmaCCJavaImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ GtSmaCCJavaImporter >> buildJavaModel [
self importNamespaces.
self importInterfaces.
self importClasses.
self importRecords.
self importEnums.
self addInheritedTypes.
self addAnnotationTypes.
Expand Down Expand Up @@ -540,6 +541,37 @@ GtSmaCCJavaImporter >> ensureNamespaceFrom: aNode [
in: (self ensureNamespaceFrom: aNode nspace)
]

{ #category : #accessing }
GtSmaCCJavaImporter >> ensureRecordMethodAndVariableFrom: parm [
| attr famixFile method |
famixFile := parm topParent attributeNamed: #famixFile.
parm
attributeNamed: #entities
put: ({parm variable}
collect: [ :each |
attr := FAMIXAttribute new
name: each name source;
sourceAnchor: (self sourceAnchorFor: parm);
parentType: (self containerIn: parm parent);
declaredType: (self typeFrom: parm type);
mooseModel: model;
propertyNamed: #ast put: each;
yourself.
famixFile addEntity: attr.
attr ]).
method := FAMIXMethod new
name: parm variable name source;
sourceAnchor: (self sourceAnchorFor: parm);
parentType: (self containerIn: parm parent);
declaredType: (self typeFrom: parm type);
mooseModel: model;
propertyNamed: #ast put: parm;
yourself.
famixFile addEntity: method.
self addMethodSignature: method.
^ attr
]

{ #category : #accessing }
GtSmaCCJavaImporter >> ensureRootNamespace: aString [
rootNamespaces ifNil: [ rootNamespaces := Dictionary new ].
Expand Down Expand Up @@ -643,7 +675,9 @@ GtSmaCCJavaImporter >> importClassParts [
(each isKindOf: JavaTryStatementNode)
ifTrue: [ self ensureTryVariables: each ].
(each isKindOf: JavaCatchClauseNode)
ifTrue: [ self ensureCatchVariables: each ] ]
ifTrue: [ self ensureCatchVariables: each ].
(each isKindOf: JavaRecordDeclarationNode)
ifTrue: [ each parameters do: [ :parm | self ensureRecordMethodAndVariableFrom: parm ] ] ]
on: Error
do: [ :ex | ex return ] ] ]
]
Expand Down Expand Up @@ -703,6 +737,15 @@ GtSmaCCJavaImporter >> importNamespaces [
ifNotNil: [ :decl | each attributeNamed: #container put: (self ensureNamespaceFrom: decl name) ] ]
]

{ #category : #accessing }
GtSmaCCJavaImporter >> importRecords [
self
javaAstsDo: [ :node |
node
withAllNodesOfType: JavaRecordDeclarationNode
do: [ :each | self createClassOrInterfaceFrom: each ] ]
]

{ #category : #accessing }
GtSmaCCJavaImporter >> javaAstsDo: aBlock [
asts
Expand Down

0 comments on commit 144c2b3

Please sign in to comment.