Makefile fixup
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / ThrowStatement.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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 org.eclipse.jdt.internal.compiler.ast;
12
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
15 import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
16 import org.eclipse.jdt.internal.compiler.flow.FlowContext;
17 import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
18 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
19 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
20
21 public class ThrowStatement extends Statement {
22         public Expression exception;
23         public TypeBinding exceptionType;
24
25         public ThrowStatement(Expression exception, int startPosition) {
26                 this.exception = exception;
27                 this.sourceStart = startPosition;
28                 this.sourceEnd = exception.sourceEnd;
29         }
30
31         public FlowInfo analyseCode(BlockScope currentScope, 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, currentScope);
36                 return FlowInfo.DEAD_END;
37         }
38
39         /**
40          * Throw code generation
41          *
42          * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
43          * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
44          */
45         public void generateCode(BlockScope currentScope, CodeStream codeStream) {
46
47                 if ((bits & IsReachableMASK) == 0)
48                         return;
49                 int pc = codeStream.position;
50                 exception.generateCode(currentScope, codeStream, true);
51                 codeStream.athrow();
52                 codeStream.recordPositionsFrom(pc, this.sourceStart);
53         }
54
55         public StringBuffer printStatement(int indent, StringBuffer output) {
56
57                 printIndent(indent, output).append("throw "); //$NON-NLS-1$
58                 exception.printExpression(0, output);
59                 return output.append(';');
60         }
61
62         public void resolve(BlockScope scope) {
63                 
64                 exceptionType = exception.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
65                 
66                 if (exceptionType == NullBinding
67                                 && scope.environment().options.complianceLevel <= ClassFileConstants.JDK1_3){
68                         // if compliant with 1.4, this problem will not be reported
69                         scope.problemReporter().cannotThrowNull(this);
70                 }
71                 exception.implicitWidening(exceptionType, exceptionType);
72         }
73
74         public void traverse(ASTVisitor visitor, BlockScope blockScope) {
75                 if (visitor.visit(this, blockScope))
76                         exception.traverse(visitor, blockScope);
77                 visitor.endVisit(this, blockScope);
78         }
79 }