From 144c2b31fade8cc912140d9ccee7b8d10dbafc21 Mon Sep 17 00:00:00 2001 From: John Brant Date: Wed, 27 Mar 2024 14:25:32 -0500 Subject: [PATCH] updating java importer for records --- .../GtJavaMethodVisitor.class.st | 6 +-- .../GtSmaCCJavaImporter.class.st | 45 ++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/GToolkit4Famix3-Java/GtJavaMethodVisitor.class.st b/src/GToolkit4Famix3-Java/GtJavaMethodVisitor.class.st index c9fb812..00ea4bc 100644 --- a/src/GToolkit4Famix3-Java/GtJavaMethodVisitor.class.st +++ b/src/GToolkit4Famix3-Java/GtJavaMethodVisitor.class.st @@ -1,8 +1,6 @@ Class { #name : #GtJavaMethodVisitor, - #superclass : #Object, - #traits : 'TJavaProgramNodeVisitor', - #classTraits : 'TJavaProgramNodeVisitor classTrait', + #superclass : #JavaProgramNodeVisitor, #instVars : [ 'importer', 'insideMethod' @@ -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 } diff --git a/src/GToolkit4Famix3-Java/GtSmaCCJavaImporter.class.st b/src/GToolkit4Famix3-Java/GtSmaCCJavaImporter.class.st index d67db90..76bafa0 100644 --- a/src/GToolkit4Famix3-Java/GtSmaCCJavaImporter.class.st +++ b/src/GToolkit4Famix3-Java/GtSmaCCJavaImporter.class.st @@ -142,6 +142,7 @@ GtSmaCCJavaImporter >> buildJavaModel [ self importNamespaces. self importInterfaces. self importClasses. + self importRecords. self importEnums. self addInheritedTypes. self addAnnotationTypes. @@ -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 ]. @@ -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 ] ] ] ] @@ -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