/*
 * Copyright 2011 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.lang.psi.impl;

import com.intellij.extapi.psi.StubBasedPsiElementBase;
import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProviders;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.impl.source.tree.SharedImplUtil;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubElement;
import com.sylvanaar.idea.Lua.LuaFileType;
import com.sylvanaar.idea.Lua.LuaIcons;
import com.sylvanaar.idea.Lua.lang.psi.LuaPsiElement;
import com.sylvanaar.idea.Lua.lang.psi.LuaPsiFile;
import com.sylvanaar.idea.Lua.lang.psi.visitor.LuaElementVisitor;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * @author ilyas
 */
public abstract class LuaStubElementBase<T extends StubElement> extends StubBasedPsiElementBase<T> implements
        LuaPsiElement {

    protected LuaStubElementBase(final T stub, IStubElementType nodeType) {
        super(stub, nodeType);
    }

    public LuaStubElementBase(final ASTNode node) {
        super(node);
    }

    @NotNull
    @Override
    public Language getLanguage() {
        return LuaFileType.LUA_LANGUAGE;
    }

    @Override
    public int getTextOffset() {
      return calcTreeElement().getTextOffset();
    }

    protected CompositeElement calcTreeElement() {
      return (CompositeElement)getNode();
    }

    @Override
    public PsiElement getParent() {
        return getParentByStub();
    }

    public void accept(LuaElementVisitor visitor) {
        visitor.visitLuaElement(this);
    }

    public void acceptChildren(LuaElementVisitor visitor) {
        //LuaPsiElementImpl.acceptLuaChildren(this, visitor);
        SharedImplUtil.acceptChildren(visitor, calcTreeElement());
    }

    protected PsiElement getDefinitionParent() {
        final PsiElement candidate = getParentByStub();
        if (candidate instanceof LuaPsiFile) {
            return candidate;
        }

        return SharedImplUtil.getParent(getNode());
    }

    @Override
    public Icon getIcon(int flags) {
        return LuaIcons.LUA_ICON;
    }

    public String getPresentationText() {
        return getText();
    }

    @Override
    public ItemPresentation getPresentation() {
        return ItemPresentationProviders.getItemPresentation(this);
    }

}
@@ -945,32 +945,76 @@
 si.PsiElement;%0D%0A
+import com.intellij.psi.PsiElementVisitor;%0D%0A
 import com.intel
@@ -2563,31 +2563,16 @@
         
-SharedImplUtil.
 acceptCh
@@ -3196,9 +3196,437 @@
    %7D%0D%0A%0D%0A
+%0D%0A    public static void acceptChildren(PsiElementVisitor var0, ASTNode var1) %7B%0D%0A        for(ASTNode var2 = var1.getFirstChildNode(); var2 != null; var2 = var2.getTreeNext()) %7B%0D%0A            PsiElement var3;%0D%0A            if(var2 instanceof PsiElement) %7B%0D%0A                var3 = (PsiElement)var2;%0D%0A            %7D else %7B%0D%0A                var3 = var2.getPsi();%0D%0A            %7D%0D%0A%0D%0A            var3.accept(var0);%0D%0A        %7D%0D%0A%0D%0A    %7D%0D%0A%0D%0A
 %7D

Fix IDLua-1998 java.lang.NoSuchMethodError: com.intellij.psi.impl.source.tree.SharedImplUtil.acceptChildren