Improved calculation of function/methods sourceEnd for code folding
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / IfStatement.java
index 74b907b..d76577b 100644 (file)
@@ -10,8 +10,7 @@
  *******************************************************************************/
 package net.sourceforge.phpeclipse.internal.compiler.ast;
 
-import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
-import net.sourceforge.phpdt.internal.compiler.codegen.Label;
+import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
@@ -26,8 +25,11 @@ public class IfStatement extends Statement {
        public Expression condition;
        public Statement thenStatement;
        public Statement elseStatement;
-
+       public Expression[] elseifConditions;
+       public Statement[] elseifStatements;
+       public boolean checkUnreachable;
        boolean thenExit;
+       
 
        // for local variables table attributes
        int thenInitStateIndex = -1;
@@ -44,6 +46,7 @@ public class IfStatement extends Statement {
                this.thenStatement = thenStatement;
                sourceStart = s;
                sourceEnd = e;
+               checkUnreachable = true;
        }
 
        public IfStatement(
@@ -58,6 +61,7 @@ public class IfStatement extends Statement {
                this.elseStatement = elseStatement;
                sourceEnd = e;
                sourceStart = s;
+               checkUnreachable = true;
        }
 
        public FlowInfo analyseCode(
@@ -151,8 +155,8 @@ public class IfStatement extends Statement {
        /**
         * If code generation
         *
-        * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
-        * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
+        * @param currentScope net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
+        * @param codeStream net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
         */
 //     public void generateCode(BlockScope currentScope, CodeStream codeStream) {
 //
@@ -236,7 +240,19 @@ public class IfStatement extends Statement {
 //             }
 //             codeStream.recordPositionsFrom(pc, this.sourceStart);
 //     }
+       public StringBuffer printStatement(int indent, StringBuffer output) {
 
+               printIndent(indent, output).append("if ("); //$NON-NLS-1$
+               condition.printExpression(0, output).append(")\n");     //$NON-NLS-1$ 
+               thenStatement.printStatement(indent + 2, output);
+               if (elseStatement != null) {
+                       output.append('\n');
+                       printIndent(indent, output);
+                       output.append("else\n"); //$NON-NLS-1$
+                       elseStatement.printStatement(indent + 2, output);
+               }
+               return output;
+       }
        public void resolve(BlockScope scope) {
 
                TypeBinding type = condition.resolveTypeExpecting(scope, BooleanBinding);
@@ -259,7 +275,7 @@ public class IfStatement extends Statement {
        }
 
        public void traverse(
-               IAbstractSyntaxTreeVisitor visitor,
+           ASTVisitor visitor,
                BlockScope blockScope) {
 
                if (visitor.visit(this, blockScope)) {