// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package io.v.vdl;

import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.util.treeView.smartTree.TreeElement;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.NavigationItem;
import com.intellij.psi.PsiElement;
import io.v.vdl.psi.VdlFile;
import io.v.vdl.psi.VdlTypeSpec;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class VdlStructureViewElement implements StructureViewTreeElement {
    private PsiElement element;

    public VdlStructureViewElement(PsiElement element) {
        this.element = element;
    }

    @Override
    public Object getValue() {
        return element;
    }

    @Override
    public void navigate(boolean requestFocus) {
        if (element instanceof NavigationItem) {
            ((NavigationItem) element).navigate(requestFocus);
        }
    }

    @Override
    public boolean canNavigate() {
        return element instanceof NavigationItem && ((NavigationItem) element).canNavigate();
    }

    @Override
    public boolean canNavigateToSource() {
        return element instanceof NavigationItem && ((NavigationItem) element).canNavigateToSource();
    }

    @NotNull
    @Override
    public ItemPresentation getPresentation() {
        return element instanceof NavigationItem ? ((NavigationItem) element).getPresentation() : null;
    }

    @NotNull
    @Override
    public TreeElement[] getChildren() {
        List<TreeElement> result = new ArrayList<TreeElement>();

        if (element instanceof VdlFile) {
            for (VdlTypeSpec typeSpec : ((VdlFile) element).getTypes()) {
                result.add(new VdlStructureViewElement(typeSpec));
            }
        }
        return result.toArray(new TreeElement[result.size()]);
    }
}

@@ -464,16 +464,118 @@
 dlFile;%0A
+import io.v.vdl.psi.VdlInterfaceType;%0Aimport io.v.vdl.psi.VdlMethodSpec;%0Aimport io.v.vdl.psi.VdlType;%0A
 import i
@@ -1991,32 +1991,402 @@
 ;%0A            %7D%0A
+        %7D else if (element instanceof VdlTypeSpec) %7B%0A            VdlType type = ((VdlTypeSpec) element).getSpecType().getType();%0A            if (type instanceof VdlInterfaceType) %7B%0A                for (VdlMethodSpec spec : ((VdlInterfaceType)type).getMethodSpecList()) %7B%0A                    result.add(new VdlStructureViewElement(spec));%0A                %7D%0A            %7D%0A
         %7D%0A      

add methods to structure view