1 19 20 package jode.flow; 21 import jode.decompiler.LocalInfo; 22 import jode.decompiler.TabbedPrintWriter; 23 import jode.expr.Expression; 24 import jode.util.SimpleSet; 25 26 import java.util.Set ; 27 28 33 public class SynchronizedBlock extends StructuredBlock { 34 35 Expression object; 36 LocalInfo local; 37 boolean isEntered; 38 39 StructuredBlock bodyBlock; 40 41 public SynchronizedBlock(LocalInfo local) { 42 this.local = local; 43 } 44 45 48 public void setBodyBlock(StructuredBlock body) { 49 bodyBlock = body; 50 body.outer = this; 51 body.setFlowBlock(flowBlock); 52 } 53 54 57 public StructuredBlock[] getSubBlocks() { 58 return new StructuredBlock[] { bodyBlock }; 59 } 60 61 67 public boolean replaceSubBlock(StructuredBlock oldBlock, 68 StructuredBlock newBlock) { 69 if (bodyBlock == oldBlock) 70 bodyBlock = newBlock; 71 else 72 return false; 73 return true; 74 } 75 76 public Set getDeclarables() { 77 Set used = new SimpleSet(); 78 if (object != null) 79 object.fillDeclarables(used); 80 else 81 used.add(local); 82 return used; 83 } 84 85 public void dumpInstruction(TabbedPrintWriter writer) 86 throws java.io.IOException 87 { 88 if (!isEntered) 89 writer.println("MISSING MONITORENTER"); 90 writer.print("synchronized ("); 91 if (object != null) 92 object.dumpExpression(writer.EXPL_PAREN, writer); 93 else 94 writer.print(local.getName()); 95 writer.print(")"); 96 writer.openBrace(); 97 writer.tab(); 98 bodyBlock.dumpSource(writer); 99 writer.untab(); 100 writer.closeBrace(); 101 } 102 103 public void simplify() { 104 if (object != null) 105 object = object.simplify(); 106 super.simplify(); 107 } 108 109 110 public boolean doTransformations() { 111 StructuredBlock last = flowBlock.lastModified; 112 return (!isEntered && CompleteSynchronized.enter(this, last)) 113 || (isEntered && object == null 114 && CompleteSynchronized.combineObject(this, last)); 115 } 116 } 117 | Popular Tags |