Removed unuse builder from project
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ThrowStatement.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
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;
18
19 public class ThrowStatement extends Statement {
20         public Expression exception;
21
22         public TypeBinding exceptionType;
23
24         public ThrowStatement(Expression exception, int startPosition) {
25                 this.exception = exception;
26                 this.sourceStart = startPosition;
27                 this.sourceEnd = exception.sourceEnd;
28         }
29
30         public FlowInfo analyseCode(BlockScope currentScope,
31                         FlowContext flowContext, FlowInfo flowInfo) {
32
33                 exception.analyseCode(currentScope, flowContext, flowInfo);
34                 // need to check that exception thrown is actually caught somewhere
35                 flowContext.checkExceptionHandlers(exceptionType, this, flowInfo,
36                                 currentScope);
37                 return FlowInfo.DEAD_END;
38         }
39
40         /**
41          * Throw code generation
42          * 
43          * @param currentScope
44          *            net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
45          * @param codeStream
46          *            net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
47          */
48         // public void generateCode(BlockScope currentScope, CodeStream codeStream)
49         // {
50         //
51         // if ((bits & IsReachableMASK) == 0)
52         // return;
53         // int pc = codeStream.position;
54         // exception.generateCode(currentScope, codeStream, true);
55         // codeStream.athrow();
56         // codeStream.recordPositionsFrom(pc, this.sourceStart);
57         // }
58         public void resolve(BlockScope scope) {
59
60                 exceptionType = exception.resolveTypeExpecting(scope, scope
61                                 .getJavaLangThrowable());
62
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);
68                 // }
69                 exception.implicitWidening(exceptionType, exceptionType);
70         }
71
72         public StringBuffer printStatement(int indent, StringBuffer output) {
73
74                 printIndent(indent, output).append("throw "); //$NON-NLS-1$
75                 exception.printExpression(0, output);
76                 return output.append(';');
77         }
78
79         public String toString(int tab) {
80                 String s = tabString(tab);
81                 s = s + "throw "; //$NON-NLS-1$
82                 s = s + exception.toStringExpression();
83                 return s;
84         }
85
86         public void traverse(ASTVisitor visitor, BlockScope blockScope) {
87                 if (visitor.visit(this, blockScope))
88                         exception.traverse(visitor, blockScope);
89                 visitor.endVisit(this, blockScope);
90         }
91 }