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.classfmt.ClassFileConstants; 15 import org.eclipse.jdt.internal.compiler.codegen.CodeStream; 16 import org.eclipse.jdt.internal.compiler.flow.FlowContext; 17 import org.eclipse.jdt.internal.compiler.flow.FlowInfo; 18 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; 19 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 20 import org.eclipse.jdt.internal.compiler.lookup.TypeIds; 21 22 public class ThrowStatement extends Statement { 23 24 public Expression exception; 25 public TypeBinding exceptionType; 26 27 public ThrowStatement(Expression exception, int sourceStart, int sourceEnd) { 28 this.exception = exception; 29 this.sourceStart = sourceStart; 30 this.sourceEnd = sourceEnd; 31 } 32 33 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { 34 this.exception.analyseCode(currentScope, flowContext, flowInfo); 35 flowContext.checkExceptionHandlers(this.exceptionType, this, flowInfo, currentScope); 37 return FlowInfo.DEAD_END; 38 } 39 40 46 public void generateCode(BlockScope currentScope, CodeStream codeStream) { 47 if ((this.bits & ASTNode.IsReachable) == 0) 48 return; 49 int pc = codeStream.position; 50 this.exception.generateCode(currentScope, codeStream, true); 51 codeStream.athrow(); 52 codeStream.recordPositionsFrom(pc, this.sourceStart); 53 } 54 55 public StringBuffer printStatement(int indent, StringBuffer output) { 56 printIndent(indent, output).append("throw "); this.exception.printExpression(0, output); 58 return output.append(';'); 59 } 60 61 public void resolve(BlockScope scope) { 62 this.exceptionType = this.exception.resolveType(scope); 63 if (this.exceptionType != null && this.exceptionType.isValidBinding()) { 64 if (this.exceptionType == TypeBinding.NULL) { 65 if (scope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_3){ 66 scope.problemReporter().cannotThrowNull(this.exception); 68 } 69 } else if (exceptionType.findSuperTypeErasingTo(TypeIds.T_JavaLangThrowable, true) == null) { 70 scope.problemReporter().cannotThrowType(this.exception, this.exceptionType); 71 } 72 this.exception.computeConversion(scope, this.exceptionType, this.exceptionType); 73 } 74 } 75 76 public void traverse(ASTVisitor visitor, BlockScope blockScope) { 77 if (visitor.visit(this, blockScope)) 78 this.exception.traverse(visitor, blockScope); 79 visitor.endVisit(this, blockScope); 80 } 81 } 82 | Popular Tags |