1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.flow;
13 import net.sourceforge.phpdt.internal.compiler.ast.AstNode;
14 import net.sourceforge.phpdt.internal.compiler.ast.NameReference;
15 import net.sourceforge.phpdt.internal.compiler.ast.Reference;
16 import net.sourceforge.phpdt.internal.compiler.lookup.BindingIds;
17 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
18 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
19 import net.sourceforge.phpdt.internal.compiler.lookup.VariableBinding;
22 * Reflects the context of code analysis, keeping track of enclosing
23 * try statements, exception handlers, etc...
25 public class FinallyFlowContext extends FlowContext {
27 Reference finalAssignments[];
30 public FinallyFlowContext(FlowContext parent, AstNode associatedNode) {
31 super(parent, associatedNode);
35 * Given some contextual initialization info (derived from a try block or a catch block), this
36 * code will check that the subroutine context does not also initialize a final variable potentially set
39 public void complainOnRedundantFinalAssignments(
42 for (int i = 0; i < assignCount; i++) {
44 if (((ref = finalAssignments[i]).bits & BindingIds.FIELD) != 0) {
46 if (flowInfo.isPotentiallyAssigned(ref.fieldBinding())) {
47 scope.problemReporter().duplicateInitializationOfBlankFinalField(ref.fieldBinding(), ref);
50 // final local variable
52 .isPotentiallyAssigned((LocalVariableBinding) ((NameReference) ref).binding)) {
53 scope.problemReporter().duplicateInitializationOfFinalLocal(
54 (LocalVariableBinding) ((NameReference) ref).binding,
58 // any reference reported at this level is removed from the parent context
59 // where it could also be reported again
60 FlowContext currentContext = parent;
61 while (currentContext != null) {
62 if (currentContext.isSubRoutine()) {
63 currentContext.removeFinalAssignmentIfAny(ref);
65 currentContext = currentContext.parent;
70 public boolean isSubRoutine() {
74 boolean recordFinalAssignment(
75 VariableBinding binding,
76 Reference finalAssignment) {
77 if (assignCount == 0) {
78 finalAssignments = new Reference[5];
80 if (assignCount == finalAssignments.length)
84 (finalAssignments = new Reference[assignCount * 2]),
88 finalAssignments[assignCount++] = finalAssignment;