package com.simpleplugin;

import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.util.treeView.smartTree.*;
import com.intellij.navigation.*;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.simpleplugin.psi.*;

import java.util.*;

public class SimpleStructureViewElement implements StructureViewTreeElement, SortableTreeElement {
  private PsiElement element;

  public SimpleStructureViewElement(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();
  }

  @Override
  public String getAlphaSortKey() {
    return element instanceof PsiNamedElement ? ((PsiNamedElement) element).getName() : null;
  }

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

  @Override
  public TreeElement[] getChildren() {
    if (element instanceof SimpleFile) {
      SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(element, SimpleProperty.class);
      List<TreeElement> treeElements = new ArrayList<TreeElement>(properties.length);
      for (SimpleProperty property : properties) {
        treeElements.add(new SimpleStructureViewElement(property));
      }
      return treeElements.toArray(new TreeElement[treeElements.size()]);
    } else {
      return EMPTY_ARRAY;
    }
  }
}
@@ -20,16 +20,70 @@
 lugin;%0A%0A
+import com.intellij.ide.projectView.PresentationData;%0A
 import c
@@ -186,17 +186,96 @@
 artTree.
-*
+SortableTreeElement;%0Aimport com.intellij.ide.util.treeView.smartTree.TreeElement
 ;%0Aimport
@@ -299,17 +299,32 @@
 igation.
-*
+ItemPresentation
 ;%0Aimport
@@ -341,17 +341,37 @@
 lij.psi.
-*
+NavigatablePsiElement
 ;%0Aimport
@@ -438,30 +438,209 @@
 psi.
-*;%0A%0Aimport java.util.*
+SimpleFile;%0Aimport com.simpleplugin.psi.SimpleProperty;%0Aimport com.simpleplugin.psi.impl.SimplePropertyImpl;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List
 ;%0A%0Ap
@@ -747,16 +747,27 @@
 private 
+Navigatable
 PsiEleme
@@ -815,16 +815,27 @@
 Element(
+Navigatable
 PsiEleme
@@ -1014,81 +1014,15 @@
     
-if (
 element
- instanceof NavigationItem) %7B%0A      ((NavigationItem) element)
 .nav
@@ -1042,22 +1042,16 @@
 Focus);%0A
-    %7D%0A
   %7D%0A%0A  @
@@ -1114,75 +1114,8 @@
 ment
- instanceof NavigationItem &&%0A           ((NavigationItem) element)
 .can
@@ -1206,75 +1206,8 @@
 ment
- instanceof NavigationItem &&%0A           ((NavigationItem) element)
 .can
@@ -1223,32 +1223,43 @@
 oSource();%0A  %7D%0A%0A
+  @NotNull%0A
   @Override%0A  pu
@@ -1298,78 +1298,29 @@
     
-return element instanceof PsiNamedElement ? ((PsiNamedElement)
+String name =
  element
 ).ge
@@ -1311,25 +1311,24 @@
 me = element
-)
 .getName() :
@@ -1325,29 +1325,70 @@
 etName()
- : null;%0A  %7D%0A
+;%0A    return name != null ? name : %22%22;%0A  %7D%0A%0A  @NotNull
 %0A  @Over
@@ -1446,89 +1446,120 @@
     
-return element instanceof NavigationItem ?%0A        ((NavigationItem) element).get
+ItemPresentation presentation = element.getPresentation();%0A    return presentation != null ? presentation : new 
 Pres
@@ -1570,17 +1570,14 @@
 tion
-() : null
+Data()
 ;%0A  
@@ -1962,16 +1962,37 @@
 Element(
+(SimplePropertyImpl) 
 property

Fix nullability issues in SimpleStructureViewElement (IJSDK-333)