KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > flow > InitializationFlowContext


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.flow;
12
13 import org.eclipse.jdt.internal.compiler.ast.ASTNode;
14 import org.eclipse.jdt.internal.compiler.lookup.Binding;
15 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
16 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
17 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
18
19 /**
20  * Reflects the context of code analysis, keeping track of enclosing
21  * try statements, exception handlers, etc...
22  */

23 public class InitializationFlowContext extends 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(
31         FlowContext parent,
32         ASTNode associatedNode,
33         BlockScope scope) {
34         super(
35             parent,
36             associatedNode,
37             Binding.NO_EXCEPTIONS, // no exception allowed by default
38
scope,
39             FlowInfo.DEAD_END);
40     }
41
42     public void checkInitializerExceptions(
43         BlockScope currentScope,
44         FlowContext initializerContext,
45         FlowInfo flowInfo) {
46         for (int i = 0; i < exceptionCount; i++) {
47             initializerContext.checkExceptionHandlers(
48                 thrownExceptions[i],
49                 exceptionThrowers[i],
50                 exceptionThrowerFlowInfos[i],
51                 currentScope);
52         }
53     }
54
55     public String JavaDoc individualToString() {
56         
57         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("Initialization flow context"); //$NON-NLS-1$
58
for (int i = 0; i < exceptionCount; i++) {
59             buffer.append('[').append(thrownExceptions[i].readableName());
60             buffer.append('-').append(exceptionThrowerFlowInfos[i].toString()).append(']');
61         }
62         return buffer.toString();
63     }
64     
65     public void recordHandlingException(
66         ReferenceBinding exceptionType,
67         UnconditionalFlowInfo flowInfo,
68         TypeBinding raisedException,
69         ASTNode invocationSite,
70         boolean wasMasked) {
71             
72         // even if unreachable code, need to perform unhandled exception diagnosis
73
int size = thrownExceptions.length;
74         if (exceptionCount == size) {
75             System.arraycopy(
76                 thrownExceptions,
77                 0,
78                 (thrownExceptions = new TypeBinding[size * 2]),
79                 0,
80                 size);
81             System.arraycopy(
82                 exceptionThrowers,
83                 0,
84                 (exceptionThrowers = new ASTNode[size * 2]),
85                 0,
86                 size);
87             System.arraycopy(
88                 exceptionThrowerFlowInfos,
89                 0,
90                 (exceptionThrowerFlowInfos = new FlowInfo[size * 2]),
91                 0,
92                 size);
93         }
94         thrownExceptions[exceptionCount] = raisedException;
95         exceptionThrowers[exceptionCount] = invocationSite;
96         exceptionThrowerFlowInfos[exceptionCount++] = flowInfo.copy();
97     }
98 }
99
Popular Tags