fixed switch { .. default: case 'test': ... bug
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / DefaultCase.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.phpeclipse.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.codegen.CaseLabel;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
16 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
17 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
18 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
19 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
20
21
22 public class DefaultCase extends Statement {
23
24         public CaseLabel targetLabel;
25         /**
26          * DefautCase constructor comment.
27          */
28         public DefaultCase(int sourceEnd, int sourceStart) {
29
30                 this.sourceStart = sourceStart;
31                 this.sourceEnd = sourceEnd;
32         }
33
34         public FlowInfo analyseCode(
35                 BlockScope currentScope,
36                 FlowContext flowContext,
37                 FlowInfo flowInfo) {
38
39                 return flowInfo;
40         }
41
42         /**
43          * Default case code generation
44          *
45          * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
46          * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
47          */
48 //      public void generateCode(BlockScope currentScope, CodeStream codeStream) {
49 //
50 //              if ((bits & IsReachableMASK) == 0) {
51 //                      return;
52 //              }
53 //              int pc = codeStream.position;
54 //              targetLabel.place();
55 //              codeStream.recordPositionsFrom(pc, this.sourceStart);
56 //
57 //      }
58         /**
59          * No-op : should use resolveCase(...) instead.
60          */
61         public void resolve(BlockScope scope) {
62         }
63
64         public Constant resolveCase(
65                 BlockScope scope,
66                 TypeBinding testType,
67                 SwitchStatement switchStatement) {
68
69                 // remember the default case into the associated switch statement
70                 if (switchStatement.defaultCase != null)
71                         scope.problemReporter().duplicateDefaultCase(this);
72
73                 // on error the last default will be the selected one .... (why not) ....       
74                 switchStatement.defaultCase = this;
75                 resolve(scope);
76                 return null;
77         }
78
79         public String toString(int tab) {
80
81                 String s = tabString(tab);
82                 s = s + "default : "; //$NON-NLS-1$
83                 return s;
84         }
85
86         public void traverse(
87                 IAbstractSyntaxTreeVisitor visitor,
88                 BlockScope blockScope) {
89
90                 visitor.visit(this, blockScope);
91                 visitor.endVisit(this, blockScope);
92         }
93 }