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;
21 public TypeBinding exceptionType;
23 public ThrowStatement(Expression exception, int startPosition) {
24 this.exception = exception;
25 this.sourceStart = startPosition;
26 this.sourceEnd = exception.sourceEnd;
29 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
31 exception.analyseCode(currentScope, flowContext, flowInfo);
32 // need to check that exception thrown is actually caught somewhere
33 flowContext.checkExceptionHandlers(exceptionType, this, flowInfo, currentScope);
34 return FlowInfo.DEAD_END;
38 * Throw code generation
40 * @param currentScope net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
41 * @param codeStream net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
43 // public void generateCode(BlockScope currentScope, CodeStream codeStream) {
45 // if ((bits & IsReachableMASK) == 0)
47 // int pc = codeStream.position;
48 // exception.generateCode(currentScope, codeStream, true);
49 // codeStream.athrow();
50 // codeStream.recordPositionsFrom(pc, this.sourceStart);
53 public void resolve(BlockScope scope) {
55 exceptionType = exception.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
57 // if (exceptionType == NullBinding
58 // && scope.environment().options.complianceLevel <= CompilerOptions.JDK1_3){
59 // // if compliant with 1.4, this problem will not be reported
60 // scope.problemReporter().cannotThrowNull(this);
62 exception.implicitWidening(exceptionType, exceptionType);
64 public StringBuffer printStatement(int indent, StringBuffer output) {
66 printIndent(indent, output).append("throw "); //$NON-NLS-1$
67 exception.printExpression(0, output);
68 return output.append(';');
70 public String toString(int tab) {
71 String s = tabString(tab);
72 s = s + "throw "; //$NON-NLS-1$
73 s = s + exception.toStringExpression();
77 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
78 if (visitor.visit(this, blockScope))
79 exception.traverse(visitor, blockScope);
80 visitor.endVisit(this, blockScope);