1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.internal.compiler.ASTVisitor; 14 import org.eclipse.jdt.internal.compiler.codegen.*; 15 import org.eclipse.jdt.internal.compiler.flow.*; 16 import org.eclipse.jdt.internal.compiler.lookup.*; 17 18 public class Block extends Statement { 19 20 public Statement[] statements; 21 public int explicitDeclarations; 22 public BlockScope scope; 24 25 public Block(int explicitDeclarations) { 26 this.explicitDeclarations = explicitDeclarations; 27 } 28 29 public FlowInfo analyseCode( 30 BlockScope currentScope, 31 FlowContext flowContext, 32 FlowInfo flowInfo) { 33 34 if (statements == null) return flowInfo; 36 boolean didAlreadyComplain = false; 37 for (int i = 0, max = statements.length; i < max; i++) { 38 Statement stat = statements[i]; 39 if (!stat.complainIfUnreachable(flowInfo, scope, didAlreadyComplain)) { 40 flowInfo = stat.analyseCode(scope, flowContext, flowInfo); 41 } else { 42 didAlreadyComplain = true; 43 } 44 } 45 return flowInfo; 46 } 47 50 public void generateCode(BlockScope currentScope, CodeStream codeStream) { 51 52 if ((bits & IsReachable) == 0) { 53 return; 54 } 55 int pc = codeStream.position; 56 if (statements != null) { 57 for (int i = 0, max = statements.length; i < max; i++) { 58 statements[i].generateCode(scope, codeStream); 59 } 60 } if (scope != currentScope) { codeStream.exitUserScope(scope); 63 } 64 codeStream.recordPositionsFrom(pc, this.sourceStart); 65 } 66 67 public boolean isEmptyBlock() { 68 69 return statements == null; 70 } 71 72 public StringBuffer printBody(int indent, StringBuffer output) { 73 74 if (this.statements == null) return output; 75 for (int i = 0; i < statements.length; i++) { 76 statements[i].printStatement(indent + 1, output); 77 output.append('\n'); 78 } 79 return output; 80 } 81 82 public StringBuffer printStatement(int indent, StringBuffer output) { 83 84 printIndent(indent, output); 85 output.append("{\n"); printBody(indent, output); 87 return printIndent(indent, output).append('}'); 88 } 89 90 public void resolve(BlockScope upperScope) { 91 92 if ((this.bits & UndocumentedEmptyBlock) != 0) { 93 upperScope.problemReporter().undocumentedEmptyBlock(this.sourceStart, this.sourceEnd); 94 } 95 if (statements != null) { 96 scope = 97 explicitDeclarations == 0 98 ? upperScope 99 : new BlockScope(upperScope, explicitDeclarations); 100 for (int i = 0, length = statements.length; i < length; i++) { 101 statements[i].resolve(scope); 102 } 103 } 104 } 105 106 public void resolveUsing(BlockScope givenScope) { 107 108 if ((this.bits & UndocumentedEmptyBlock) != 0) { 109 givenScope.problemReporter().undocumentedEmptyBlock(this.sourceStart, this.sourceEnd); 110 } 111 scope = givenScope; 113 if (statements != null) { 114 for (int i = 0, length = statements.length; i < length; i++) { 115 statements[i].resolve(scope); 116 } 117 } 118 } 119 120 public void traverse( 121 ASTVisitor visitor, 122 BlockScope blockScope) { 123 124 if (visitor.visit(this, blockScope)) { 125 if (statements != null) { 126 for (int i = 0, length = statements.length; i < length; i++) 127 statements[i].traverse(visitor, scope); 128 } 129 } 130 visitor.endVisit(this, blockScope); 131 } 132 133 136 public void branchChainTo(BranchLabel label) { 137 if (this.statements != null) { 138 this.statements[statements.length - 1].branchChainTo(label); 139 } 140 } 141 142 } 143 | Popular Tags |