]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph/src/org/simantics/graph/refactoring/PrintReferencesTool.java
(refs #7215) Preserve identity types in NamespaceMigrationStep
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / refactoring / PrintReferencesTool.java
1 package org.simantics.graph.refactoring;
2
3 import gnu.trove.map.hash.THashMap;
4
5 import java.io.File;
6 import java.io.IOException;
7 import java.util.ArrayList;
8 import java.util.Collections;
9
10 import org.simantics.databoard.Files;
11 import org.simantics.graph.query.TransferableGraphConversion;
12 import org.simantics.graph.representation.old.OldTransferableGraph1;
13 import org.simantics.graph.store.IdentityStore;
14 import org.simantics.graph.store.IdentityStore.ConsistsOf;
15
16 public class PrintReferencesTool {
17
18     public static void main(String[] args) throws Exception {
19         print(new File(args[0]));
20     }
21     
22     public static void print(File input) throws IOException {
23         OldTransferableGraph1 tg = (OldTransferableGraph1)
24                 Files.readFile(input, OldTransferableGraph1.BINDING);
25         GraphRefactoringUtils.fixIncorrectRoot(tg.identities);
26         IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg);
27         printExternals(idStore, idStore.getRoot(""), 0);
28     }
29
30     private static void printExternals(IdentityStore idStore, int cur, int indentation) {
31         THashMap<String, ConsistsOf> map = idStore.getChildMap(cur);
32         if(map == null)
33             return;
34         ArrayList<String> names = new ArrayList<String>(map.keySet());
35         Collections.sort(names);
36         for(String name : names) {
37             ConsistsOf co = map.get(name);
38             if(!idStore.isNewResource(co.child)) {
39                 for(int i=0;i<indentation;++i)
40                     System.out.print("    ");
41                 System.out.println(name);
42                 printExternals(idStore, co.child, indentation+1);
43             }
44         }
45     }
46     
47 }