com.intellij.ide.util.treeView.smartTree.TreeElement Java Examples

The following examples show how to use com.intellij.ide.util.treeView.smartTree.TreeElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StructureViewElement.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@NotNull
private List<TreeElement> buildModuleStructure(@NotNull PsiInnerModule moduleElement) {
    List<TreeElement> treeElements = new ArrayList<>();

    PsiSignature moduleSignature = moduleElement.getSignature();
    PsiElement rootElement = moduleSignature;
    if (rootElement == null) {
        rootElement = moduleElement.getBody();
    }

    if (rootElement != null) {
        rootElement.acceptChildren(new ElementVisitor(treeElements));
    }

    // Process body if there is a signature
    if (moduleSignature != null) {
        rootElement = moduleElement.getBody();
        if (rootElement != null) {
            treeElements.add(new StructureModuleImplView(rootElement));
        }
    }

    return treeElements;
}
 
Example #2
Source File: CustomRegionTreeElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public TreeElement[] getChildren() {
  if (mySubRegions == null || mySubRegions.isEmpty()) {
    return myChildElements.toArray(StructureViewTreeElement.EMPTY_ARRAY);
  }
  StructureViewTreeElement[] allElements = new StructureViewTreeElement[myChildElements.size() + mySubRegions.size()];
  int index = 0;
  for (StructureViewTreeElement child : myChildElements) {
    allElements[index++] = child;
  }
  for (StructureViewTreeElement subRegion : mySubRegions) {
    allElements[index++] = subRegion;
  }
  return allElements;
}
 
Example #3
Source File: CsvStructureViewElement.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
@Override
public TreeElement[] getChildren() {
    if (myElement instanceof CsvFile) {
        CsvFile csvFile = (CsvFile) myElement;
        CsvColumnInfoMap csvColumnInfoMap = csvFile.getColumnInfoMap();
        int maxRowNumbers = csvColumnInfoMap.getColumnInfo(0).getSize();
        if (csvColumnInfoMap.hasEmptyLastLine() && CsvEditorSettings.getInstance().isFileEndLineBreak()) {
            --maxRowNumbers;
        }
        Map<Integer, CsvColumnInfo<PsiElement>> columnInfoMap = csvColumnInfoMap.getColumnInfos();
        TreeElement[] children = new TreeElement[columnInfoMap.size()];
        for (Map.Entry<Integer, CsvColumnInfo<PsiElement>> entry : columnInfoMap.entrySet()) {
            CsvColumnInfo<PsiElement> columnInfo = entry.getValue();
            PsiElement psiElement = columnInfo.getHeaderElement();
            if (psiElement == null) {
                psiElement = CsvHelper.createEmptyCsvField(csvFile);
            }
            children[entry.getKey()] = new Header(psiElement, getElements(columnInfo, maxRowNumbers));
        }
        return children;
    } else {
        return EMPTY_ARRAY;
    }
}
 
Example #4
Source File: XQueryStructureViewElement.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
@Override
public TreeElement[] getChildren() {
    if (element instanceof XQueryFile) {
        XQueryFile file = (XQueryFile) element;
        List<TreeElement> treeElements = new ArrayList<TreeElement>();
        for (XQueryVarDecl variableDeclaration : file.getVariableDeclarations()) {
            treeElements.add(new XQueryStructureViewElement(variableDeclaration));
        }
        for (XQueryFunctionDecl functionDeclaration : file.getFunctionDeclarations()) {
            treeElements.add(new XQueryStructureViewElement(functionDeclaration));
        }
        if (file.getQueryBody() != null) {
            treeElements.add(new XQueryStructureViewElement(file.getQueryBody()));
        }
        return treeElements.toArray(new TreeElement[treeElements.size()]);
    } else {
        return EMPTY_ARRAY;
    }
}
 
Example #5
Source File: ThriftStructureViewElement.java    From intellij-thrift with Apache License 2.0 6 votes vote down vote up
@Override
public TreeElement[] getChildren() {
  if (!myElement.isValid()) {
    return new TreeElement[0];
  }
  final List<TreeElement> result = new ArrayList<TreeElement>();
  if (myElement instanceof ThriftFile) {
    ThriftTopLevelDeclaration[] topLevelDeclarations = PsiTreeUtil.getChildrenOfType(myElement, ThriftTopLevelDeclaration.class);
    if (topLevelDeclarations != null) {
      for (ThriftTopLevelDeclaration subNamedComponent : topLevelDeclarations) {
        result.add(new ThriftStructureViewElement(subNamedComponent));
      }
    }
  }
  else if (myElement instanceof ThriftTopLevelDeclaration) {
    for (ThriftDeclaration subDeclaration : ((ThriftTopLevelDeclaration)myElement).findSubDeclarations()) {
      result.add(new ThriftStructureViewElement(subDeclaration));
    }
  }
  return result.toArray(new TreeElement[result.size()]);
}
 
Example #6
Source File: ProtoFieldsNodeProvider.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public Collection<TreeElement> provideNodes(@NotNull TreeElement parent) {
    if (parent instanceof AbstractTreeElement) {
        AbstractTreeElement element = (AbstractTreeElement) parent;
        PsiElement psiElement = element.getValue();
        List<TreeElement> treeElements = new ArrayList<>();
        for (PsiElement node : psiElement.getChildren()) {
            if (node instanceof FieldNode) {
                treeElements.add(new MessageFieldTreeElement((FieldNode) node));
            }
            if (node instanceof EnumConstantNode) {
                treeElements.add(new EnumConstantTreeElement((EnumConstantNode) node));
            }
            if (node instanceof RpcMethodNode) {
                treeElements.add(new ServiceMethodTreeElement((RpcMethodNode) node));
            }
        }
        return treeElements;
    }
    return Collections.emptyList();
}
 
Example #7
Source File: BashStructureViewElement.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@NotNull
public TreeElement[] getChildren() {
    final List<BashPsiElement> childrenElements = new ArrayList<BashPsiElement>();
    myElement.acceptChildren(new PsiElementVisitor() {
        public void visitElement(PsiElement element) {
            if (isBrowsableElement(element)) {
                childrenElements.add((BashPsiElement) element);
            } else {
                element.acceptChildren(this);
            }
        }
    });

    StructureViewTreeElement[] children = new StructureViewTreeElement[childrenElements.size()];
    for (int i = 0; i < children.length; i++) {
        children[i] = new BashStructureViewElement(childrenElements.get(i));
    }

    return children;
}
 
Example #8
Source File: GotoClassAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static StructureViewTreeElement findElement(StructureViewTreeElement node, PsiElement element, int hopes) {
  final Object value = node.getValue();
  if (value instanceof PsiElement) {
    if (((PsiElement)value).isEquivalentTo(element)) return node;
    if (hopes != 0) {
      for (TreeElement child : node.getChildren()) {
        if (child instanceof StructureViewTreeElement) {
          final StructureViewTreeElement e = findElement((StructureViewTreeElement)child, element, hopes - 1);
          if (e != null) {
            return e;
          }
        }
      }
    }
  }
  return null;
}
 
Example #9
Source File: StructureAwareNavBarModelExtension.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
private PsiElement findParentInModel(StructureViewTreeElement root, PsiElement psiElement) {
  for (TreeElement child : childrenFromNodeAndProviders(root)) {
    if(child instanceof StructureViewTreeElement) {
      if(Comparing.equal(((StructureViewTreeElement)child).getValue(), psiElement)) {
        return ObjectUtil.tryCast(root.getValue(), PsiElement.class);
      }
      PsiElement target = findParentInModel((StructureViewTreeElement)child, psiElement);
      if(target != null) {
        return target;
      }
    }
  }

  return null;
}
 
Example #10
Source File: HaskellStructureViewElement.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
/**
 * Populates the structure view. Uses HaskellUtil to get backing information.
 */
@NotNull
@Override
public TreeElement[] getChildren() {
    if (element instanceof HaskellFile) {
        List<PsiNamedElement> elems =
                HaskellUtil.findDefinitionNodes((HaskellFile) element.getContainingFile(),
                        null);
        List<TreeElement> treeElems = ContainerUtil.newArrayListWithCapacity(elems.size());
        for (PsiNamedElement elem : elems) {
            //noinspection ObjectAllocationInLoop
            treeElems.add(new HaskellStructureViewElement(elem));
        }
        return treeElems.toArray(new TreeElement[treeElems.size()]);
    }
    return EMPTY_ARRAY;
}
 
Example #11
Source File: BashStructureViewModelTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testStructureView() throws Exception {
    VirtualFile file = configure();
    Assert.assertNotNull(file);

    MyTest myTest = new MyTest() {
        public void test(StructureViewComponent component) {
            StructureViewModel tree = component.getTreeModel();
            Assert.assertNotNull(tree);

            StructureViewTreeElement root = tree.getRoot();
            Assert.assertNotNull(root);

            TreeElement[] children = root.getChildren();
            Assert.assertEquals(1, children.length);

            TreeElement firstChild = children[0];
            Assert.assertNotNull(firstChild);

            Assert.assertEquals("a()", firstChild.getPresentation().getPresentableText());

            Assert.assertNotNull(firstChild.getChildren());
            Assert.assertEquals(0, firstChild.getChildren().length);
        }
    };

    doTest(myTest);
}
 
Example #12
Source File: LoadStatementsFilter.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isVisible(TreeElement treeNode) {
  if (treeNode instanceof BuildStructureViewElement) {
    BuildStructureViewElement buildElement = (BuildStructureViewElement) treeNode;
    return !(buildElement.getElement() instanceof LoadStatement);
  }
  return true;
}
 
Example #13
Source File: BuckStructureViewModel.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isVisible(TreeElement treeNode) {
  if (treeNode instanceof BuckStructureViewElement) {
    String text = treeNode.getPresentation().getPresentableText();
    return !text.trim().startsWith("_"); // Symbols starting with "_" are private
  } else {
    return true;
  }
}
 
Example #14
Source File: StructureViewElement.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public TreeElement[] getChildren() {
    List<TreeElement> treeElements = new ArrayList<>();
    m_rootElement.acceptChildren(new ElementVisitor(treeElements));
    return treeElements.toArray(new TreeElement[0]);
}
 
Example #15
Source File: GLSLStructureViewTreeElement.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
public final TreeElement[] getChildren() {
    children.clear();
    createChildren(element);
    Collections.sort(children);
    return children.toArray(new TreeElement[0]);
}
 
Example #16
Source File: CSharpInheritedMembersNodeProvider.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #17
Source File: CSharpLambdaNodeProvider.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<CSharpLambdaTreeElement> provideNodes(TreeElement node)
{
	if(!(node instanceof PsiTreeElementBase))
	{
		return Collections.emptyList();
	}
	PsiElement element = ((PsiTreeElementBase) node).getElement();
	return SyntaxTraverser.psiTraverser(element)
			.expand(o -> o == element || !(o instanceof DotNetQualifiedElement || o instanceof CSharpAnonymousMethodExpression))
			.filter(CSharpAnonymousMethodExpression.class)
			.filter(o -> o != element)
			.map(CSharpLambdaTreeElement::new)
			.toList();
}
 
Example #18
Source File: TestGrouper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<TreeElement> getChildren() {
  Collection<TreeElement> result = new LinkedHashSet<TreeElement>();
  for (TreeElement object : myChildren) {
    if (object.toString().indexOf(myString) >= 0) {
      result.add(object);
    }
  }
  return result;
}
 
Example #19
Source File: SampleStructureViewElement.java    From jetbrains-plugin-sample with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@NotNull
@Override
public TreeElement[] getChildren() {
	if ( element instanceof SamplePSIFileRoot ) {
		Collection<? extends PsiElement> funcs = XPath.findAll(SampleLanguage.INSTANCE, element, "/script/function/ID");
		List<TreeElement> treeElements = new ArrayList<>(funcs.size());
		for (PsiElement el : funcs) {
			treeElements.add(new SampleStructureViewElement(el));
		}
		return treeElements.toArray(new TreeElement[funcs.size()]);
	}
	return new TreeElement[0];
}
 
Example #20
Source File: MethodUpDownUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addStructureViewElements(final TreeElement parent, final Collection<PsiElement> array, @Nonnull PsiFile file) {
  for(TreeElement treeElement: parent.getChildren()) {
    Object value = ((StructureViewTreeElement)treeElement).getValue();
    if (value instanceof PsiElement) {
      PsiElement element = (PsiElement)value;
      if (array.contains(element) || !file.equals(element.getContainingFile())) continue;
      array.add(element);
    }
    addStructureViewElements(treeElement, array, file);
  }
}
 
Example #21
Source File: SimpleStructureViewElement.java    From intellij-sdk-docs with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public TreeElement[] getChildren() {
  if (myElement instanceof SimpleFile) {
    List<SimpleProperty> properties = PsiTreeUtil.getChildrenOfTypeAsList(myElement, SimpleProperty.class);
    List<TreeElement> treeElements = new ArrayList<>(properties.size());
    for (SimpleProperty property : properties) {
      treeElements.add(new SimpleStructureViewElement((SimplePropertyImpl) property));
    }
    return treeElements.toArray(new TreeElement[0]);
  }
  return EMPTY_ARRAY;
}
 
Example #22
Source File: CsvStructureViewTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
private void doCheckTreeElement(TreeElement element, Class expectedClazz, String expectedText, String expectedLocation) {
    assertInstanceOf(element, expectedClazz);
    assertInstanceOf(element, ItemPresentation.class);

    ItemPresentation presentation = (ItemPresentation) element;
    assertEquals(expectedText, presentation.getPresentableText());
    if (expectedLocation != null) {
        assertEquals(expectedLocation, presentation.getLocationString());
    }
}
 
Example #23
Source File: CsvStructureViewElement.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public TreeElement[] getChildren() {
    int rowIndex = 0;
    TreeElement[] children = new TreeElement[getNumberOfChildren()];
    for (PsiElement element : this.myElements) {
        if (rowIndex > 0) {
            children[rowIndex - 1] = new Field(element == null ? CsvHelper.createEmptyCsvField(this.myElement.getContainingFile()) : element, rowIndex - 1);
        }
        ++rowIndex;
    }
    return children;
}
 
Example #24
Source File: StructureViewElement.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
private List<TreeElement> buildYaccTrailerStructure(@NotNull OclYaccTrailer root) {
    List<TreeElement> treeElements = new ArrayList<>();

    PsiElement rootElement = ORUtil.findImmediateFirstChildOfType(root, OclYaccTypes.OCAML_LAZY_NODE);
    if (rootElement != null) {
        rootElement.acceptChildren(new ElementVisitor(treeElements));
    }

    return treeElements;
}
 
Example #25
Source File: StructureViewElement.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
private List<TreeElement> buildYaccHeaderStructure(@NotNull OclYaccHeader root) {
    List<TreeElement> treeElements = new ArrayList<>();

    PsiElement rootElement = ORUtil.findImmediateFirstChildOfType(root, OclYaccTypes.OCAML_LAZY_NODE);
    if (rootElement != null) {
        rootElement.acceptChildren(new ElementVisitor(treeElements));
    }

    return treeElements;
}
 
Example #26
Source File: StructureViewElement.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
private List<TreeElement> buildStanzaStructure(@NotNull PsiStanza stanzaElement) {
    List<TreeElement> treeElements = new ArrayList<>();

    PsiElement rootElement = ORUtil.findImmediateFirstChildOfClass(stanzaElement, PsiDuneFields.class);
    if (rootElement != null) {
        rootElement.acceptChildren(new ElementVisitor(treeElements));
    }

    return treeElements;
}
 
Example #27
Source File: StructureViewElement.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
private List<TreeElement> buildClassStructure(@NotNull PsiClass classElement) {
    List<TreeElement> treeElements = new ArrayList<>();

    PsiElement rootElement = classElement.getClassBody();
    if (rootElement != null) {
        rootElement.acceptChildren(new ElementVisitor(treeElements));
    }

    return treeElements;
}
 
Example #28
Source File: StructureViewElement.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
private List<TreeElement> buildFunctorStructure(@NotNull PsiFunctor functor) {
    List<TreeElement> treeElements = new ArrayList<>();

    PsiElement binding = functor.getBinding();
    if (binding != null) {
        binding.acceptChildren(new ElementVisitor(treeElements));
    }

    return treeElements;
}
 
Example #29
Source File: StructureViewElementWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public StructureViewTreeElement[] getChildren() {
  TreeElement[] baseChildren = myTreeElement.getChildren();
  List<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>();
  for (TreeElement element : baseChildren) {
    StructureViewTreeElement wrapper = new StructureViewElementWrapper((StructureViewTreeElement)element, myMainFile);

    result.add(wrapper);
  }
  return result.toArray(new StructureViewTreeElement[result.size()]);
}
 
Example #30
Source File: VisibilityFilter.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isVisible(TreeElement element) {
    if (element instanceof XQueryStructureViewElement) {
        return ((XQueryStructureViewElement) element).isPublic();
    } else {
        return true;
    }
}