1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
14 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
16 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
19 public class ThrowStatement extends Statement {
20 public Expression exception;
22 public TypeBinding exceptionType;
24 public ThrowStatement(Expression exception, int startPosition) {
25 this.exception = exception;
26 this.sourceStart = startPosition;
27 this.sourceEnd = exception.sourceEnd;
30 public FlowInfo analyseCode(BlockScope currentScope,
31 FlowContext flowContext, FlowInfo flowInfo) {
33 exception.analyseCode(currentScope, flowContext, flowInfo);
34 // need to check that exception thrown is actually caught somewhere
35 flowContext.checkExceptionHandlers(exceptionType, this, flowInfo,
37 return FlowInfo.DEAD_END;
41 * Throw code generation
44 * net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
46 * net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
48 // public void generateCode(BlockScope currentScope, CodeStream codeStream)
51 // if ((bits & IsReachableMASK) == 0)
53 // int pc = codeStream.position;
54 // exception.generateCode(currentScope, codeStream, true);
55 // codeStream.athrow();
56 // codeStream.recordPositionsFrom(pc, this.sourceStart);
58 public void resolve(BlockScope scope) {
60 exceptionType = exception.resolveTypeExpecting(scope, scope
61 .getJavaLangThrowable());
63 // if (exceptionType == NullBinding
64 // && scope.environment().options.complianceLevel <=
65 // CompilerOptions.JDK1_3){
66 // // if compliant with 1.4, this problem will not be reported
67 // scope.problemReporter().cannotThrowNull(this);
69 exception.implicitWidening(exceptionType, exceptionType);
72 public StringBuffer printStatement(int indent, StringBuffer output) {
74 printIndent(indent, output).append("throw "); //$NON-NLS-1$
75 exception.printExpression(0, output);
76 return output.append(';');
79 public String toString(int tab) {
80 String s = tabString(tab);
81 s = s + "throw "; //$NON-NLS-1$
82 s = s + exception.toStringExpression();
86 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
87 if (visitor.visit(this, blockScope))
88 exception.traverse(visitor, blockScope);
89 visitor.endVisit(this, blockScope);