/*
 * Copyright 2010 Jon S Akhtar (Sylvanaar)
 *  
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.sylvanaar.idea.Lua.editor.inspections.metrics;

import com.sylvanaar.idea.Lua.lang.psi.statements.LuaDoStatement;
import com.sylvanaar.idea.Lua.lang.psi.statements.LuaStatementElement;
import com.sylvanaar.idea.Lua.lang.psi.visitor.LuaRecursiveElementVisitor;
import org.jetbrains.annotations.NotNull;


class StatementCountVisitor extends LuaRecursiveElementVisitor {
  private int statementCount = 0;

//  public void visitElement(LuaPsiElement element) {
//    int oldCount = 0;
//    if (element instanceof LuaFunctionDefinitionStatement) {
//      oldCount = statementCount;
//    }
//    super.visitElement(element);
//
//    if (element instanceof LuaFunctionDefinitionStatement) {
//      statementCount = oldCount;
//    }
//  }

  public void visitStatement(@NotNull LuaStatementElement statement) {
    super.visitStatement(statement);
    if (statement instanceof LuaDoStatement) {
      return;
    }
    statementCount++;
  }


  public int getStatementCount() {
    return statementCount;
  }
}
@@ -734,18 +734,34 @@
 ents.Lua
-Do
+FunctionDefinition
 Statemen
@@ -1392,78 +1392,368 @@
  %7D%0A%0A
-  public void visitStatement(@NotNull LuaStatementElement statement) %7B
+%0A    public void visitFunctionDef(LuaFunctionDefinitionStatement e) %7B%0A        super.visitFunctionDef(e);%0A%0A        statementCount = 0;%0A    %7D%0A%0A%0A  public void visitStatement(@NotNull LuaStatementElement statement) %7B%0A    statementCount++;%0A    int oldCount = 0;%0A%0A    if (statement instanceof LuaFunctionDefinitionStatement) %7B%0A      oldCount = statementCount;%0A    %7D%0A
 %0A   
@@ -1786,16 +1786,17 @@
 ement);%0A
+%0A
     if (
@@ -1823,10 +1823,26 @@
  Lua
-Do
+FunctionDefinition
 Stat
@@ -1860,43 +1860,40 @@
     
-return;%0A    %7D%0A    statementCount++;
+statementCount = oldCount;%0A    %7D
 %0A  %7D

correct line counts on my limited tests