new html templates
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / flow / LabelFlowContext.java
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
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.codegen.Label;
15 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
16 import net.sourceforge.phpdt.internal.compiler.util.CharOperation;
17
18 /**
19  * Reflects the context of code analysis, keeping track of enclosing
20  *      try statements, exception handlers, etc...
21  */
22 public class LabelFlowContext extends SwitchFlowContext {
23         public char[] labelName;
24         public LabelFlowContext(
25                 FlowContext parent,
26                 AstNode associatedNode,
27                 char[] labelName,
28                 Label breakLabel,
29                 BlockScope scope) {
30                 super(parent, associatedNode, breakLabel);
31                 this.labelName = labelName;
32                 checkLabelValidity(scope);
33         }
34
35         void checkLabelValidity(BlockScope scope) {
36                 // check if label was already defined above
37                 FlowContext current = parent;
38                 while (current != null) {
39                         char[] currentLabelName;
40                         if (((currentLabelName = current.labelName()) != null)
41                                 && CharOperation.equals(currentLabelName, labelName)) {
42                                 scope.problemReporter().alreadyDefinedLabel(labelName, associatedNode);
43                         }
44                         current = current.parent;
45                 }
46         }
47
48         public String individualToString() {
49                 return "Label flow context [label:" + String.valueOf(labelName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
50         }
51
52         public char[] labelName() {
53                 return labelName;
54         }
55 }