@@ -64,6 +64,7 @@ class Famix2Famix extends WorkflowComponentWithConfig {
6464 val List<FAMIXNamespace > packagesToMerge = newArrayList
6565 val Map<FAMIXMethod , List<FAMIXParameter > > parameters = newHashMap
6666 val static famixFactory = new FamixFactoryImpl ()
67+ val Map<String , Node > nodes = newHashMap
6768
6869 override protected invokeInternal (WorkflowContext ctx , ProgressMonitor monitor , Issues issues ) {
6970 log. info(" Famix2Famix has started." )
@@ -380,27 +381,27 @@ class Famix2Famix extends WorkflowComponentWithConfig {
380381 famixDocument. elements. addAll(accesses)
381382 famixDocument. elements. addAll(inheritances)
382383 famixDocument. elements. addAll(fileAnchors)
384+ if (FAMIXSettings :: WRITE_TO_DATABASE ) {
385+ graph = Database :: getInstance(FAMIXSettings :: DATABASE_NAME )
386+ val document = famixRoot. document
387+ var tx = graph. beginTx
388+ try {
389+ rootPackages. forEach[toDB(it , null )]
390+ document. elements. filter(FAMIXInvocation ). forEach[toDB(it )]
391+ document. elements. filter(FAMIXInheritance ). forEach[toDB(it )]
392+ document. elements. filter(FAMIXAccess ). forEach[toDB(it )]
393+ tx. success
394+ } finally {
395+ tx. close
396+ }
397+ }
383398 rootPackages. clear
384399 subPackages. clear
385400 allStructures. clear
386401 methods. clear
387402 attributes. clear
388403 enumValues. clear
389404 structures. clear
390- graph = Database :: getInstance(" ../databases/famix_graph.db" )
391- val document = famixRoot. document
392- val rootPackages = document. elements. filter(FAMIXNamespace ). filter[parentScope == = null ]
393- subPackages + = document. elements. filter(FAMIXNamespace ). filter[parentScope !== null ]
394- allStructures + = document. elements. filter(FAMIXStructure )
395- var tx = graph. beginTx
396- try {
397- rootPackages. forEach [ root |
398- toDB(root, null )
399- ]
400- tx. success
401- } finally {
402- tx. close
403- }
404405 return famixRoot
405406 }
406407
@@ -874,30 +875,175 @@ class Famix2Famix extends WorkflowComponentWithConfig {
874875 }
875876
876877 def Node toDB (FAMIXNamespace namespace , Node parent ) {
877- val node = graph. createNode(DBLabel . PACKAGE )
878+ val node = graph. createNode(Labels . Package )
878879 node. setProperty(" name" , namespace. value)
879880 node. setProperty(" fqn" , namespace. fqn)
880881 if (parent !== null ) {
881882 parent. createRelationshipTo(node, Rels . CONTAINS )
882883 }
883- allStructures . filter[container. ref. equals(namespace)]. forEach[toDB(node)]
884+ structures . filter[container. ref. equals(namespace)]. forEach[toDB(node)]
884885 subPackages. filter[parentScope. ref. equals(namespace)]. forEach[toDB(node)]
885886 return node
886887 }
887888
888889 def Node toDB (FAMIXStructure structure , Node parent ) {
889- val node = graph. createNode
890+ val node = graph. createNode(Labels . Type )
891+ node. setProperty(" fqn" , structure. fqn)
892+ node. setProperty(" name" , structure. value)
893+ var String fileName
890894 switch structure {
891895 FAMIXClass : {
892- node. addLabel(DBLabel . CLASS )
893- node. setProperty(" fqn" , structure. fqn)
896+ node. addLabel(Labels . Class )
894897 // md5 von JQAssisstant?
895898 node. setProperty(" md5" , structure. id)
899+ fileName = (structure. type. ref as FAMIXFileAnchor ). filename
900+ if (structure. isInterface == " true" ) {
901+ node. addLabel(Labels . Interface )
902+ } else {
903+ node. addLabel(Labels . Class )
904+ }
905+ }
906+ FAMIXEnum : {
907+ node. addLabel(Labels . Enum )
908+ fileName = (structure. sourceAnchor. ref as FAMIXFileAnchor ). filename
909+ enumValues. filter[parentEnum. ref. equals(structure)]. forEach[toDB(node)]
910+ }
911+ FAMIXAnnotationType : {
912+ node. addLabel(Labels . Annotation )
913+ fileName = (structure. sourceAnchor. ref as FAMIXFileAnchor ). filename
896914 }
897915 }
898- node. setProperty(" name" , structure. value)
916+ node. setProperty(" sourceFileName" , fileName)
917+ if (structure. modifiers. size != 0 ) {
918+ setModifierProperties(node, structure. modifiers)
919+ }
920+ nodes. put(structure. id, node)
899921 parent. createRelationshipTo(node, Rels . CONTAINS )
900922 structures. filter[container. ref. equals(structure)]. forEach[toDB(node)]
923+ methods. filter[parentType. ref. equals(structure)]. forEach[toDB(node)]
924+ attributes. filter[parentType. ref. equals(structure)]. forEach[toDB(node)]
901925 return node
902926 }
927+
928+ def toDB (FAMIXMethod method , Node parent ) {
929+ val node = graph. createNode(Labels . Method , Labels . Member )
930+ val fileAnchor = method. sourceAnchor. ref as FAMIXFileAnchor
931+ node. setProperty(" name" , method. value)
932+ node. setProperty(" effectiveLineCount" , method. numberOfStatements. longValue)
933+ node. setProperty(" cyclomaticComplexity" , method. cyclomaticComplexity. longValue)
934+ node. setProperty(" firstLineNumber" , fileAnchor. startline. longValue)
935+ node. setProperty(" lastLineNumber" , fileAnchor. endline. longValue)
936+ node. setProperty(" sourceFileName" , fileAnchor. filename)
937+ var signature = method. signature
938+ var FAMIXElement declaredType
939+ try {
940+ declaredType = method. declaredType. ref
941+ } catch (NullPointerException e) {
942+ declaredType = null
943+ }
944+ var String type
945+ switch declaredType {
946+ FAMIXPrimitiveType : type = (declaredType as FAMIXPrimitiveType ). value + " "
947+ FAMIXParameterizedType : type = (declaredType as FAMIXParameterizedType ). value + " "
948+ default: type = " "
949+ }
950+ signature = type + signature
951+ node. setProperty(" signature" , signature)
952+ if (method. modifiers. size != 0 ) {
953+ setFinalProperty(node, method. modifiers)
954+ setVisibilityProperty(node, method. modifiers)
955+ setStaticProperty(node, method. modifiers)
956+ }
957+ nodes. put(method. id, node)
958+ parent. createRelationshipTo(node, Rels . DECLARES )
959+ }
960+
961+ def toDB (FAMIXAttribute attribute , Node parent ) {
962+ val node = graph. createNode(Labels . Field , Labels . Member )
963+ node. setProperty(" name" , attribute. value)
964+ if (attribute. modifiers. size != 0 ) {
965+ setFinalProperty(node, attribute. modifiers)
966+ setVisibilityProperty(node, attribute. modifiers)
967+ setStaticProperty(node, attribute. modifiers)
968+ }
969+ nodes. put(attribute. id, node)
970+ parent. createRelationshipTo(node, Rels . DECLARES )
971+ }
972+
973+ def toDB (FAMIXInvocation invocation ) {
974+ val sender = invocation. sender. ref as FAMIXMethod
975+ val receiver = invocation. candidates. ref as FAMIXMethod
976+ val senderNode = nodes. get(sender. id)
977+ val receiverNode = nodes. get(receiver. id)
978+ if (senderNode !== null && receiverNode !== null ) {
979+ senderNode. createRelationshipTo(receiverNode, Rels . INVOKES )
980+ }
981+ }
982+
983+ def toDB (FAMIXInheritance inheritance ) {
984+ val subClass = inheritance. subclass. ref as FAMIXStructure
985+ val superClass = inheritance. superclass. ref as FAMIXStructure
986+ val subClassNode = nodes. get(subClass. id)
987+ val superClassNode = nodes. get(superClass. id)
988+ if (subClassNode !== null && superClassNode !== null ) {
989+ subClassNode. createRelationshipTo(superClassNode, Rels . EXTENDS )
990+ }
991+ }
992+
993+ def toDB (FAMIXAccess access ) {
994+ val method = access. accessor. ref as FAMIXMethod
995+ val attribute = access. variable. ref as FAMIXAttribute
996+ val methodNode = nodes. get(method. id)
997+ val attributeNode = nodes. get(attribute. id)
998+ if (methodNode !== null && attributeNode !== null ) {
999+ var Rels relationship
1000+ if (access. isWrite == " true" ) {
1001+ relationship = Rels . WRITES
1002+ } else {
1003+ relationship = Rels . READS
1004+ }
1005+ methodNode. createRelationshipTo(attributeNode, relationship)
1006+ }
1007+ }
1008+
1009+ def toDB (FAMIXEnumValue enumVal , Node parent ) {
1010+ val node = graph. createNode(Labels . Field , Labels . Member )
1011+ node. setProperty(" name" , enumVal. value)
1012+ parent. createRelationshipTo(node, Rels . DECLARES )
1013+ }
1014+
1015+ def setModifierProperties (Node node , EList<String > modifiers ) {
1016+ setAbstractProperty(node, modifiers)
1017+ setFinalProperty(node, modifiers)
1018+ setVisibilityProperty(node, modifiers)
1019+ setStaticProperty(node, modifiers)
1020+ }
1021+
1022+ def setAbstractProperty (Node node , EList<String > modifiers ) {
1023+ val abstract = modifiers. findFirst[it == " abstract" ]
1024+ if (abstract !== null ) {
1025+ node. setProperty(" abstract" , true )
1026+ }
1027+ }
1028+
1029+ def setFinalProperty (Node node , EList<String > modifiers ) {
1030+ val final = modifiers. findFirst[it == " final" ]
1031+ if (final !== null ) {
1032+ node. setProperty(" final" , true )
1033+ }
1034+ }
1035+
1036+ def setVisibilityProperty (Node node , EList<String > modifiers ) {
1037+ val visibility = modifiers. findFirst[it == " public" || it == " private" || it == " protected" || it == " package" ]
1038+ if (visibility !== null ) {
1039+ node. setProperty(" visibility" , visibility)
1040+ }
1041+ }
1042+
1043+ def setStaticProperty (Node node , EList<String > modifiers ) {
1044+ val static = modifiers. findFirst[it == " static" ]
1045+ if (static !== null ) {
1046+ node. setProperty(" static" , true )
1047+ }
1048+ }
9031049}
0 commit comments