@@ -44,7 +44,6 @@ import org.neo4j.graphdb.GraphDatabaseService
4444import org.svis.lib.database.Database
4545import org.svis.lib.database.DBConnector
4646import org.neo4j.graphdb.Node
47- import org.neo4j.graphdb.Label
4847import org.neo4j.graphdb.Direction
4948import org.neo4j.graphdb.traversal.Uniqueness
5049import org.svis.xtext.famix.FAMIXElement
@@ -76,12 +75,12 @@ class Famix2Famix extends WorkflowComponentWithConfig {
7675 dbConnector = new DBConnector (graph)
7776
7877 // Create Namespaces
79- val packageLabel = Label . label(" Package" )
80- val classLabel = Label . label(" Class" )
8178 val namespaces = newHashMap
8279 val classes = newHashMap
8380 val methods = newHashMap
8481 val attributes = newHashMap
82+ val enums = newHashMap
83+ val annotations = newHashMap
8584 val famixEvaluator = new FamixEvaluator ()
8685 var tx = graph. beginTx
8786 try {
@@ -105,16 +104,18 @@ class Famix2Famix extends WorkflowComponentWithConfig {
105104 parent = null
106105 }
107106 var type = " "
108- for (label : node. labels) {
109- if (label. name == " Package" ) {
110- type = " Package"
111- } else if (label. name == " Class" ) {
112- type = " Class"
113- } else if (label. name == " Method" ) {
114- type = " Method"
115- } else if (label. name == " Field" ) {
116- type = " Field"
117- }
107+ if (node. hasLabel(DBLabel . PACKAGE )) {
108+ type = " Package"
109+ } else if (node. hasLabel(DBLabel . CLASS ) || node. hasLabel(DBLabel . INTERFACE )) {
110+ type = " Class"
111+ } else if (node. hasLabel(DBLabel . ENUM )) {
112+ type = " Enum"
113+ } else if (node. hasLabel(DBLabel . ANNOTATION )) {
114+ type = " Annotation"
115+ } else if (node. hasLabel(DBLabel . METHOD )) {
116+ type = " Method"
117+ } else if (node. hasLabel(DBLabel . FIELD )) {
118+ type = " Field"
118119 }
119120 switch (type) {
120121 case " Package" : {
@@ -128,30 +129,84 @@ class Famix2Famix extends WorkflowComponentWithConfig {
128129 }
129130 case " Class" : {
130131 var FAMIXElement container
131- if (parent. hasLabel(packageLabel )) {
132+ if (parent. hasLabel(DBLabel . PACKAGE )) {
132133 container = namespaces. get(parent. id) as FAMIXNamespace
133134 }
134-
135- if (parent. hasLabel(classLabel)) {
135+ if (parent. hasLabel(DBLabel . CLASS ) || parent. hasLabel(DBLabel . INTERFACE )) {
136136 container = classes. get(parent. id) as FAMIXClass
137137 }
138+ if (parent. hasLabel(DBLabel . ANNOTATION )) {
139+ container = annotations. get(parent. id) as FAMIXAnnotationType
140+ }
138141 val class = createClass(node, container)
139142 classes. put(node. id, class)
140143 famixDocument. elements + = class
141144 }
145+ case " Enum" : {
146+ var FAMIXElement container
147+ if (parent. hasLabel(DBLabel . PACKAGE )) {
148+ container = namespaces. get(parent. id) as FAMIXNamespace
149+ }
150+ if (parent. hasLabel(DBLabel . CLASS ) || parent. hasLabel(DBLabel . INTERFACE )) {
151+ container = classes. get(parent. id) as FAMIXClass
152+ }
153+ if (parent. hasLabel(DBLabel . ENUM )) {
154+ container = enums. get(parent. id) as FAMIXEnum
155+ }
156+ if (parent. hasLabel(DBLabel . ANNOTATION )) {
157+ container = annotations. get(parent. id) as FAMIXAnnotationType
158+ }
159+ val enum = createEnum(node, container)
160+ enums. put(node. id, enum)
161+ famixDocument. elements + = enum
162+ }
163+ case " Annotation" : {
164+ var FAMIXElement container
165+ if (parent. hasLabel(DBLabel . PACKAGE )) {
166+ container = namespaces. get(parent. id)
167+ }
168+ if (parent. hasLabel(DBLabel . CLASS ) || parent. hasLabel(DBLabel . INTERFACE )) {
169+ container = classes. get(parent. id) as FAMIXClass
170+ }
171+ if (parent. hasLabel(DBLabel . ENUM )) {
172+ container = enums. get(parent. id) as FAMIXEnum
173+ }
174+ val annotation = createAnnotation(node, container)
175+ annotations. put(node. id, annotation)
176+ famixDocument. elements + = annotation
177+ }
142178 case " Method" : {
143- val parentClass = classes. get(parent. id)
179+ var FAMIXStructure container
180+ if (parent. hasLabel(DBLabel . CLASS ) || parent. hasLabel(DBLabel . INTERFACE )) {
181+ container = classes. get(parent. id) as FAMIXClass
182+ }
183+ if (parent. hasLabel(DBLabel . ENUM )) {
184+ container = enums. get(parent. id) as FAMIXEnum
185+ }
186+ if (parent. hasLabel(DBLabel . ANNOTATION )) {
187+ container = annotations. get(parent. id) as FAMIXAnnotationType
188+ }
144189 val fileAnchor = famixFactory. createFAMIXFileAnchor
145190 fileAnchor. filename = parent. getProperty(" sourceFileName" ) as String
146- val method = createMethod(node, parentClass , fileAnchor)
191+ val method = createMethod(node, container , fileAnchor)
147192 methods. put(node. id, method)
148193 famixDocument. elements + = method
149194 }
150195 case " Field" : {
151196 val parentClass = classes. get(parent. id)
197+ var FAMIXStructure container
198+ if (parent. hasLabel(DBLabel . CLASS ) || parent. hasLabel(DBLabel . INTERFACE )) {
199+ container = classes. get(parent. id) as FAMIXClass
200+ }
201+ if (parent. hasLabel(DBLabel . ENUM )) {
202+ container = enums. get(parent. id) as FAMIXEnum
203+ }
204+ if (parent. hasLabel(DBLabel . ANNOTATION )) {
205+ container = annotations. get(parent. id) as FAMIXAnnotationType
206+ }
152207 val fileAnchor = famixFactory. createFAMIXFileAnchor
153208 fileAnchor. filename = parent. getProperty(" sourceFileName" ) as String
154- val attribute = createAttribute(node, parentClass , fileAnchor)
209+ val attribute = createAttribute(node, container , fileAnchor)
155210 attributes. put(node. id, attribute)
156211 famixDocument. elements + = attribute
157212 }
@@ -200,8 +255,6 @@ class Famix2Famix extends WorkflowComponentWithConfig {
200255 ]
201256 println(" finish" )
202257 tx. success
203- } catch (Exception e) {
204- print(e)
205258 } finally {
206259 tx. close
207260 }
@@ -733,8 +786,12 @@ class Famix2Famix extends WorkflowComponentWithConfig {
733786 var ref = famixFactory. createIntegerReference
734787 if (parent instanceof FAMIXNamespace ) {
735788 ref. ref = parent as FAMIXNamespace
736- } else {
789+ } else if (parent instanceof FAMIXClass ) {
737790 ref. ref = parent as FAMIXClass
791+ } else if (parent instanceof FAMIXEnum ) {
792+ ref. ref = parent as FAMIXEnum
793+ } else {
794+ ref. ref = parent as FAMIXAnnotationType
738795 }
739796 class. container = ref
740797 val anchorRef = famixFactory. createIntegerReference
@@ -748,7 +805,45 @@ class Famix2Famix extends WorkflowComponentWithConfig {
748805 return class
749806 }
750807
751- def createMethod (Node node , FAMIXClass parent , FAMIXFileAnchor fileAnchor ) {
808+ def createEnum (Node node , FAMIXElement parent ) {
809+ val enum = famixFactory. createFAMIXEnum
810+ enum. name = node. id. toString
811+ enum. id = node. id. toString
812+ enum. value = node. getProperty(" name" ) as String
813+ var ref = famixFactory. createIntegerReference
814+ if (parent instanceof FAMIXNamespace ) {
815+ ref. ref = parent as FAMIXNamespace
816+ } else if (parent instanceof FAMIXClass ) {
817+ ref. ref = parent as FAMIXClass
818+ } else if (parent instanceof FAMIXEnum ) {
819+ ref. ref = parent as FAMIXEnum
820+ } else {
821+ ref. ref = parent as FAMIXAnnotationType
822+ }
823+ enum. container = ref
824+ return enum
825+ }
826+
827+ def createAnnotation (Node node , FAMIXElement parent ) {
828+ val annotation = famixFactory. createFAMIXAnnotationType
829+ annotation. name = node. id. toString
830+ annotation. id = node. id. toString
831+ if (node. hasProperty(" name" )) {
832+ annotation. value = node. getProperty(" name" ) as String
833+ }
834+ var ref = famixFactory. createIntegerReference
835+ if (parent instanceof FAMIXNamespace ) {
836+ ref. ref = parent as FAMIXNamespace
837+ } else if (parent instanceof FAMIXClass ) {
838+ ref. ref = parent as FAMIXClass
839+ } else {
840+ ref. ref = parent as FAMIXEnum
841+ }
842+ annotation. container = ref
843+ return annotation
844+ }
845+
846+ def createMethod (Node node , FAMIXStructure parent , FAMIXFileAnchor fileAnchor ) {
752847 val method = famixFactory. createFAMIXMethod
753848 method. name = node. id. toString
754849 method. id = node. id. toString
@@ -766,7 +861,13 @@ class Famix2Famix extends WorkflowComponentWithConfig {
766861 method. signature = node. getProperty(" signature" ) as String
767862 method. fqn = parent. fqn + " ." + method. value + " ()"
768863 var ref = famixFactory. createIntegerReference
769- ref. ref = parent
864+ if (parent instanceof FAMIXClass ) {
865+ ref. ref = parent as FAMIXClass
866+ } else if (parent instanceof FAMIXEnum ) {
867+ ref. ref = parent as FAMIXEnum
868+ } else {
869+ ref. ref = parent as FAMIXAnnotationType
870+ }
770871 method. parentType = ref
771872 if (node. hasProperty(" firstLineNumber" )) {
772873 val firstLineNumber = node. getProperty(" firstLineNumber" ) as Long
@@ -785,7 +886,7 @@ class Famix2Famix extends WorkflowComponentWithConfig {
785886 return method
786887 }
787888
788- def createAttribute (Node node , FAMIXClass parent , FAMIXFileAnchor fileAnchor ) {
889+ def createAttribute (Node node , FAMIXStructure parent , FAMIXFileAnchor fileAnchor ) {
789890 val attribute = famixFactory. createFAMIXAttribute
790891 attribute. name = node. id. toString
791892 attribute. id = node. id. toString
@@ -796,7 +897,13 @@ class Famix2Famix extends WorkflowComponentWithConfig {
796897 attribute. modifiers + = node. getProperty(" visibility" ) as String
797898 }
798899 var ref = famixFactory. createIntegerReference
799- ref. ref = parent
900+ if (parent instanceof FAMIXClass ) {
901+ ref. ref = parent as FAMIXClass
902+ } else if (parent instanceof FAMIXEnum ) {
903+ ref. ref = parent as FAMIXEnum
904+ } else {
905+ ref. ref = parent as FAMIXAnnotationType
906+ }
800907 attribute. parentType = ref
801908 val anchorRef = famixFactory. createIntegerReference
802909 val attributeRef = famixFactory. createIntegerReference
0 commit comments