01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.flow;
11:
12: import org.eclipse.jdt.internal.compiler.ast.ASTNode;
13: import org.eclipse.jdt.internal.compiler.lookup.Binding;
14: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
15: import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
16: import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
17:
18: /**
19: * Reflects the context of code analysis, keeping track of enclosing
20: * try statements, exception handlers, etc...
21: */
22: public class InitializationFlowContext extends
23: ExceptionHandlingFlowContext {
24:
25: public int exceptionCount;
26: public TypeBinding[] thrownExceptions = new TypeBinding[5];
27: public ASTNode[] exceptionThrowers = new ASTNode[5];
28: public FlowInfo[] exceptionThrowerFlowInfos = new FlowInfo[5];
29:
30: public InitializationFlowContext(FlowContext parent,
31: ASTNode associatedNode, BlockScope scope) {
32: super (parent, associatedNode, Binding.NO_EXCEPTIONS, // no exception allowed by default
33: scope, FlowInfo.DEAD_END);
34: }
35:
36: public void checkInitializerExceptions(BlockScope currentScope,
37: FlowContext initializerContext, FlowInfo flowInfo) {
38: for (int i = 0; i < exceptionCount; i++) {
39: initializerContext.checkExceptionHandlers(
40: thrownExceptions[i], exceptionThrowers[i],
41: exceptionThrowerFlowInfos[i], currentScope);
42: }
43: }
44:
45: public String individualToString() {
46:
47: StringBuffer buffer = new StringBuffer(
48: "Initialization flow context"); //$NON-NLS-1$
49: for (int i = 0; i < exceptionCount; i++) {
50: buffer.append('[').append(
51: thrownExceptions[i].readableName());
52: buffer.append('-').append(
53: exceptionThrowerFlowInfos[i].toString())
54: .append(']');
55: }
56: return buffer.toString();
57: }
58:
59: public void recordHandlingException(ReferenceBinding exceptionType,
60: UnconditionalFlowInfo flowInfo,
61: TypeBinding raisedException, ASTNode invocationSite,
62: boolean wasMasked) {
63:
64: // even if unreachable code, need to perform unhandled exception diagnosis
65: int size = thrownExceptions.length;
66: if (exceptionCount == size) {
67: System.arraycopy(thrownExceptions, 0,
68: (thrownExceptions = new TypeBinding[size * 2]), 0,
69: size);
70: System.arraycopy(exceptionThrowers, 0,
71: (exceptionThrowers = new ASTNode[size * 2]), 0,
72: size);
73: System
74: .arraycopy(
75: exceptionThrowerFlowInfos,
76: 0,
77: (exceptionThrowerFlowInfos = new FlowInfo[size * 2]),
78: 0, size);
79: }
80: thrownExceptions[exceptionCount] = raisedException;
81: exceptionThrowers[exceptionCount] = invocationSite;
82: exceptionThrowerFlowInfos[exceptionCount++] = flowInfo.copy();
83: }
84: }
|