1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
16 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
17 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
18 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
19 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
21 public class ThrowStatement extends Statement {
22 public Expression exception;
23 public TypeBinding exceptionType;
25 public ThrowStatement(Expression exception, int startPosition) {
26 this.exception = exception;
27 this.sourceStart = startPosition;
28 this.sourceEnd = exception.sourceEnd;
31 public FlowInfo analyseCode(BlockScope currentScope, 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, currentScope);
36 return FlowInfo.DeadEnd;
40 * Throw code generation
42 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
43 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
45 public void generateCode(BlockScope currentScope, CodeStream codeStream) {
47 if ((bits & IsReachableMASK) == 0)
49 int pc = codeStream.position;
50 exception.generateCode(currentScope, codeStream, true);
52 codeStream.recordPositionsFrom(pc, this.sourceStart);
55 public void resolve(BlockScope scope) {
57 exceptionType = exception.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
59 if (exceptionType == NullBinding
60 && scope.environment().options.complianceLevel <= CompilerOptions.JDK1_3){
61 // if compliant with 1.4, this problem will not be reported
62 scope.problemReporter().cannotThrowNull(this);
64 exception.implicitWidening(exceptionType, exceptionType);
67 public String toString(int tab) {
68 String s = tabString(tab);
69 s = s + "throw "; //$NON-NLS-1$
70 s = s + exception.toStringExpression();
74 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
75 if (visitor.visit(this, blockScope))
76 exception.traverse(visitor, blockScope);
77 visitor.endVisit(this, blockScope);