A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / flow / InitializationFlowContext.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.flow;
12
13 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
14 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
15 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
16 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
17
18 /**
19  * Reflects the context of code analysis, keeping track of enclosing try
20  * statements, exception handlers, etc...
21  */
22 public class InitializationFlowContext extends ExceptionHandlingFlowContext {
23
24         public int exceptionCount;
25
26         public TypeBinding[] thrownExceptions = new TypeBinding[5];
27
28         public ASTNode[] exceptionThrowers = new ASTNode[5];
29
30         public FlowInfo[] exceptionThrowerFlowInfos = new FlowInfo[5];
31
32         public InitializationFlowContext(FlowContext parent,
33                         ASTNode associatedNode, BlockScope scope) {
34                 super(parent, associatedNode, NoExceptions, // no exception allowed by
35                                                                                                         // default
36                                 scope, FlowInfo.DEAD_END);
37         }
38
39         public void checkInitializerExceptions(BlockScope currentScope,
40                         FlowContext initializerContext, FlowInfo flowInfo) {
41                 for (int i = 0; i < exceptionCount; i++) {
42                         initializerContext.checkExceptionHandlers(thrownExceptions[i],
43                                         exceptionThrowers[i], exceptionThrowerFlowInfos[i],
44                                         currentScope);
45                 }
46         }
47
48         public String individualToString() {
49
50                 StringBuffer buffer = new StringBuffer("Initialization flow context"); //$NON-NLS-1$
51                 for (int i = 0; i < exceptionCount; i++) {
52                         buffer.append('[').append(thrownExceptions[i].readableName());
53                         buffer.append('-').append(exceptionThrowerFlowInfos[i].toString())
54                                         .append(']');
55                 }
56                 return buffer.toString();
57         }
58
59         public void recordHandlingException(ReferenceBinding exceptionType,
60                         UnconditionalFlowInfo flowInfo, TypeBinding raisedException,
61                         ASTNode invocationSite, boolean wasMasked) {
62
63                 // even if unreachable code, need to perform unhandled exception
64                 // diagnosis
65                 int size = thrownExceptions.length;
66                 if (exceptionCount == size) {
67                         System.arraycopy(thrownExceptions, 0,
68                                         (thrownExceptions = new TypeBinding[size * 2]), 0, size);
69                         System.arraycopy(exceptionThrowers, 0,
70                                         (exceptionThrowers = new ASTNode[size * 2]), 0, size);
71                         System.arraycopy(exceptionThrowerFlowInfos, 0,
72                                         (exceptionThrowerFlowInfos = new FlowInfo[size * 2]), 0,
73                                         size);
74                 }
75                 thrownExceptions[exceptionCount] = raisedException;
76                 exceptionThrowers[exceptionCount] = invocationSite;
77                 exceptionThrowerFlowInfos[exceptionCount++] = flowInfo.copy();
78         }
79 }