/*
 * Copyright 2013-2020 consulo.io
 *
 * 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 consulo.csharp.ide.structureView;

import com.intellij.ide.util.InheritedMembersNodeProvider;
import com.intellij.ide.util.treeView.smartTree.TreeElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import consulo.annotation.access.RequiredReadAction;
import consulo.csharp.lang.psi.CSharpTypeDeclaration;
import consulo.csharp.lang.psi.impl.resolve.CSharpResolveContextUtil;
import consulo.csharp.lang.psi.resolve.CSharpResolveContext;
import consulo.dotnet.resolve.DotNetGenericExtractor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author VISTALL
 * @since 2020-06-28
 */
public class CSharpInheritedMembersNodeProvider extends InheritedMembersNodeProvider<CSharpNamedTreeElement>
{
	public static final CSharpInheritedMembersNodeProvider INSTANCE = new CSharpInheritedMembersNodeProvider();

	@Override
	@RequiredReadAction
	public Collection<CSharpNamedTreeElement> provideNodes(TreeElement treeElement)
	{
		if(!(treeElement instanceof CSharpNamedTreeElement))
		{
			return Collections.emptyList();
		}

		PsiNamedElement value = ((CSharpNamedTreeElement) treeElement).getValue();

		if(!(value instanceof CSharpTypeDeclaration))
		{
			return Collections.emptyList();
		}

		CSharpResolveContext context = CSharpResolveContextUtil.createContext(DotNetGenericExtractor.EMPTY, value.getResolveScope(), value);

		List<PsiElement> elements = new ArrayList<>();
		context.processElements(element -> {
			elements.add(element);
			return true;
		}, true);

		// remove self elements
		context.processElements(element -> {
			elements.remove(element);
			return true;
		}, false);

		return elements.stream().map(element -> new CSharpNamedTreeElement((PsiNamedElement) element)).collect(Collectors.toList());
	}
}

@@ -1006,16 +1006,75 @@
 xtUtil;%0A
+import consulo.csharp.lang.psi.resolve.CSharpElementGroup;%0A
 import c
@@ -1202,99 +1202,9 @@
 til.
-ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0Aimport java.util.List
+*
 ;%0Aim
@@ -2030,19 +2030,18 @@
 ue);%0A%0A%09%09
-Lis
+Se
 t%3CPsiEle
@@ -2065,16 +2065,20 @@
 new 
-ArrayLis
+LinkedHashSe
 t%3C%3E(
@@ -2111,32 +2111,85 @@
 ts(element -%3E %7B%0A
+%09%09%09if(element instanceof CSharpElementGroup g)%0A%09%09%09%7B%0A%09
 %09%09%09elements.add(
@@ -2187,27 +2187,88 @@
 ents.add
-(e
+All(g.getE
 lement
+s()
 );%0A
+%09%09%09%7D%0A%09%09%09else%0A%09%09%09%7B%0A%09%09%09%09elements.add(element);%0A%09%09%09%7D%0A
 %09%09%09retur
@@ -2353,16 +2353,128 @@
 nt -%3E %7B%0A
+%09%09%09if(element instanceof CSharpElementGroup g)%0A%09%09%09%7B%0A%09%09%09%09elements.removeAll(g.getElements());%0A%09%09%09%7D%0A%09%09%09else%0A%09%09%09%7B%0A%09
 %09%09%09eleme
@@ -2494,16 +2494,21 @@
 ement);%0A
+%09%09%09%7D%0A
 %09%09%09retur

fix bug with unknown elements inside structure view inherit