01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.flow;
11:
12: import org.eclipse.jdt.core.compiler.CharOperation;
13: import org.eclipse.jdt.internal.compiler.ast.ASTNode;
14: import org.eclipse.jdt.internal.compiler.codegen.BranchLabel;
15: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
16:
17: /**
18: * Reflects the context of code analysis, keeping track of enclosing
19: * try statements, exception handlers, etc...
20: */
21: public class LabelFlowContext extends SwitchFlowContext {
22:
23: public char[] labelName;
24:
25: public LabelFlowContext(FlowContext parent, ASTNode associatedNode,
26: 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
39: .equals(currentLabelName, labelName)) {
40: scope.problemReporter().alreadyDefinedLabel(labelName,
41: associatedNode);
42: }
43: current = current.parent;
44: }
45: }
46:
47: public String individualToString() {
48: return "Label flow context [label:" + String.valueOf(labelName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
49: }
50:
51: public char[] labelName() {
52: return labelName;
53: }
54: }
|