KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.compiler.CharOperation;
14 import org.eclipse.jdt.internal.compiler.ast.ASTNode;
15 import org.eclipse.jdt.internal.compiler.codegen.BranchLabel;
16 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
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     
24     public char[] labelName;
25     
26 public LabelFlowContext(FlowContext parent, ASTNode associatedNode, char[] labelName, BranchLabel breakLabel, BlockScope scope) {
27     super(parent, associatedNode, breakLabel);
28     this.labelName = labelName;
29     checkLabelValidity(scope);
30 }
31
32 void checkLabelValidity(BlockScope scope) {
33     // check if label was already defined above
34
FlowContext current = parent;
35     while (current != null) {
36         char[] currentLabelName;
37         if (((currentLabelName = current.labelName()) != null)
38             && CharOperation.equals(currentLabelName, labelName)) {
39             scope.problemReporter().alreadyDefinedLabel(labelName, associatedNode);
40         }
41         current = current.parent;
42     }
43 }
44
45 public String JavaDoc individualToString() {
46     return "Label flow context [label:" + String.valueOf(labelName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
47
}
48
49 public char[] labelName() {
50     return labelName;
51 }
52 }
53
Popular Tags