Added externaltools plugin
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / 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.phpeclipse.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         public TypeBinding exceptionType;
22
23         public ThrowStatement(Expression exception, int startPosition) {
24                 this.exception = exception;
25                 this.sourceStart = startPosition;
26                 this.sourceEnd = exception.sourceEnd;
27         }
28
29         public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
30
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;
35         }
36
37         /**
38          * Throw code generation
39          *
40          * @param currentScope net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
41          * @param codeStream net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
42          */
43 //      public void generateCode(BlockScope currentScope, CodeStream codeStream) {
44 //
45 //              if ((bits & IsReachableMASK) == 0)
46 //                      return;
47 //              int pc = codeStream.position;
48 //              exception.generateCode(currentScope, codeStream, true);
49 //              codeStream.athrow();
50 //              codeStream.recordPositionsFrom(pc, this.sourceStart);
51 //      }
52
53         public void resolve(BlockScope scope) {
54                 
55                 exceptionType = exception.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
56                 
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);
61 //              }
62                 exception.implicitWidening(exceptionType, exceptionType);
63         }
64         public StringBuffer printStatement(int indent, StringBuffer output) {
65
66                 printIndent(indent, output).append("throw "); //$NON-NLS-1$
67                 exception.printExpression(0, output);
68                 return output.append(';');
69         }
70         public String toString(int tab) {
71                 String s = tabString(tab);
72                 s = s + "throw "; //$NON-NLS-1$
73                 s = s + exception.toStringExpression();
74                 return s;
75         }
76
77         public void traverse(ASTVisitor visitor, BlockScope blockScope) {
78                 if (visitor.visit(this, blockScope))
79                         exception.traverse(visitor, blockScope);
80                 visitor.endVisit(this, blockScope);
81         }
82 }