@@ -35,47 +35,18 @@ public class GraphBuilder {
3535 private Map <BlockReference , BlockOutline > referenceMap = new IdentityHashMap <BlockReference , BlockOutline >();
3636
3737 public StateClass buildGraph (DescriptorOutline descriptor ) {
38+
3839 // resolve block references
39- Map <String , BlockOutline > blocks = new HashMap <String , BlockOutline >();
40- findAllBlocks (blocks , descriptor );
40+ Map <String , BlockOutline > blocks = BlockOutline .findAllBlocks (descriptor );
4141 initializeReferenceMap (blocks , referenceMap , descriptor );
4242
4343 return convertBlock (descriptor );
4444 }
4545
46- private static void findAllBlocks (Map <String , BlockOutline > blocks , BlockOutline block ) {
47- if (block instanceof BlockReference ) {
48- return ;
49- }
50-
51- final String blockName = block .getName ();
52-
53- // Defensive, but really it is never ok to have reference cycles,
54- // and usually it means the helpers were called incorrectly.
55- if (blocks .containsKey (blockName )) {
56- if (blocks .get (blockName ) == block ) {
57- return ;
58- } else {
59- throw new DescriptorBuilderException ("Duplicate block name: " +blockName );
60- }
61- }
62-
63- blocks .put (blockName , block );
64-
65- for (MethodOutline method : block .getAllMethods ()) {
66- for (BlockOutline chain : method .getBlockChain ()) {
67- findAllBlocks (blocks , chain );
68- }
69- }
70-
71- for (BlockOutline child : block .getBlocks ()) {
72- findAllBlocks (blocks , child );
73- }
74- }
75-
76- private static void initializeReferenceMap (Map <String , BlockOutline > blocks ,
77- Map <BlockReference , BlockOutline > references ,
78- BlockOutline block
46+ private static void initializeReferenceMap (
47+ Map <String , BlockOutline > blocks ,
48+ Map <BlockReference , BlockOutline > references ,
49+ BlockOutline block
7950 ){
8051 if (block instanceof BlockReference ) {
8152 final BlockReference reference = (BlockReference ) block ;
@@ -131,7 +102,7 @@ private StateClass convertBlock(BlockOutline block) {
131102 // create the sibling states
132103 Set <StateClass > seen = Collections .newSetFromMap (new IdentityHashMap <StateClass , Boolean >());
133104 Set <Set <MethodOutline >> workingSet = new HashSet <Set <MethodOutline >>();
134- workingSet .add (new TreeSet <MethodOutline >(allMethods ));
105+ workingSet .add (new TreeSet <>(allMethods ));
135106
136107 while (!workingSet .isEmpty ()) {
137108 Set <Set <MethodOutline >> nextSet = new HashSet <Set <MethodOutline >>();
0 commit comments