checkNotNull(direction, "direction");
- }
-
- /**
- * The hierarchy item to resolve.
- */
- @Pure
- @NonNull
- public TypeHierarchyItem getItem() {
- return this.item;
- }
-
- /**
- * The hierarchy item to resolve.
- */
- public void setItem(@NonNull final TypeHierarchyItem item) {
- this.item = Preconditions.checkNotNull(item, "item");
- }
-
- /**
- * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level.
- */
- @Pure
- public int getResolve() {
- return this.resolve;
- }
-
- /**
- * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level.
- */
- public void setResolve(final int resolve) {
- this.resolve = resolve;
- }
-
- /**
- * The direction of the type hierarchy resolution.
- */
- @Pure
- @NonNull
- public TypeHierarchyDirection getDirection() {
- return this.direction;
- }
-
- /**
- * The direction of the type hierarchy resolution.
- */
- public void setDirection(@NonNull final TypeHierarchyDirection direction) {
- this.direction = Preconditions.checkNotNull(direction, "direction");
- }
-
- @Override
- @Pure
- public String toString() {
- ToStringBuilder b = new ToStringBuilder(this);
- b.add("item", this.item);
- b.add("resolve", this.resolve);
- b.add("direction", this.direction);
- return b.toString();
- }
-
- @Override
- @Pure
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- ResolveTypeHierarchyItemParams other = (ResolveTypeHierarchyItemParams) obj;
- if (this.item == null) {
- if (other.item != null) {
- return false;
- }
- } else if (!this.item.equals(other.item)) {
- return false;
- }
- if (other.resolve != this.resolve) {
- return false;
- }
- if (this.direction == null) {
- if (other.direction != null) {
- return false;
- }
- } else if (!this.direction.equals(other.direction)) {
- return false;
- }
- return true;
- }
-
- @Override
- @Pure
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((this.item== null) ? 0 : this.item.hashCode());
- result = prime * result + this.resolve;
- return prime * result + ((this.direction== null) ? 0 : this.direction.hashCode());
- }
-}
diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyCapabilities.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyCapabilities.java
deleted file mode 100644
index e9129646e5..0000000000
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyCapabilities.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright (c) 2016-2018 TypeFox and others.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0,
- * or the Eclipse Distribution License v. 1.0 which is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
- */
-package org.eclipse.lsp4j.legacy.typeHierarchy;
-
-import org.eclipse.lsp4j.DynamicRegistrationCapabilities;
-import org.eclipse.xtext.xbase.lib.Pure;
-import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
-
-import com.google.common.annotations.Beta;
-
-/**
- * Capabilities specific to the {@code textDocument/typeHierarchy}.
- *
- *
- * Note: the {@code textDocument/typeHierarchy}
- * language feature is not yet part of the official LSP specification.
- */
-@Beta
-@SuppressWarnings("all")
-public class TypeHierarchyCapabilities extends DynamicRegistrationCapabilities {
- public TypeHierarchyCapabilities() {
- }
-
- public TypeHierarchyCapabilities(final Boolean dynamicRegistration) {
- super(dynamicRegistration);
- }
-
- @Override
- @Pure
- public String toString() {
- ToStringBuilder b = new ToStringBuilder(this);
- b.add("dynamicRegistration", getDynamicRegistration());
- return b.toString();
- }
-
- @Override
- @Pure
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- if (!super.equals(obj)) {
- return false;
- }
- return true;
- }
-
- @Override
- @Pure
- public int hashCode() {
- return super.hashCode();
- }
-}
diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyDirection.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyDirection.java
deleted file mode 100644
index acc45835d1..0000000000
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyDirection.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2019 TypeFox and others.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0,
- * or the Eclipse Distribution License v. 1.0 which is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
- ******************************************************************************/
-package org.eclipse.lsp4j.legacy.typeHierarchy;
-
-import org.eclipse.lsp4j.services.TextDocumentService;
-
-/**
- * Direction specific to the
- * {@link TextDocumentService#typeHierarchy(TypeHierarchyParams)
- * textDocument/typeHierarchy} and
- * {@link TextDocumentService#resolveTypeHierarchy(ResolveTypeHierarchyItemParams)
- * typeHierarchy/resolve} LS methods.
- *
- *
- * Valid values are:
- *
- * - {@link TypeHierarchyDirection#Children Children},
- * - {@link TypeHierarchyDirection#Parents Parents},
- * - {@link TypeHierarchyDirection#Both Both}.
- *
- *
- */
-public enum TypeHierarchyDirection {
-
- /**
- * Flag for retrieving/resolving the subtypes. Value: {@code 0}.
- */
- Children,
-
- /**
- * Flag to use when retrieving/resolving the supertypes. Value: {@code 1}.
- */
- Parents,
-
- /**
- * Flag for resolving both the super- and subtypes. Value: {@code 2}.
- */
- Both;
-
- public static TypeHierarchyDirection forValue(int value) {
- TypeHierarchyDirection[] values = TypeHierarchyDirection.values();
- if (value < 0 || value >= values.length) {
- throw new IllegalArgumentException("Illegal enum value: " + value);
- }
- return values[value];
- }
-
-}
diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyItem.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyItem.java
deleted file mode 100644
index 68668f73e1..0000000000
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyItem.java
+++ /dev/null
@@ -1,390 +0,0 @@
-/**
- * Copyright (c) 2016-2018 TypeFox and others.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0,
- * or the Eclipse Distribution License v. 1.0 which is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
- */
-package org.eclipse.lsp4j.legacy.typeHierarchy;
-
-import java.util.List;
-
-import org.eclipse.lsp4j.Range;
-import org.eclipse.lsp4j.SymbolKind;
-import org.eclipse.lsp4j.jsonrpc.json.adapters.JsonElementTypeAdapter;
-import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
-import org.eclipse.lsp4j.util.Preconditions;
-import org.eclipse.xtext.xbase.lib.Pure;
-import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
-
-import com.google.common.annotations.Beta;
-import com.google.gson.annotations.JsonAdapter;
-
-/**
- * Representation of an item that carries type information (such as class, interface, enumeration, etc) with additional parentage details.
- */
-@Beta
-@SuppressWarnings("all")
-public class TypeHierarchyItem {
- /**
- * The human readable name of the hierarchy item.
- */
- @NonNull
- private String name;
-
- /**
- * Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method.
- */
- private String detail;
-
- /**
- * The kind of the hierarchy item. For instance, class or interface.
- */
- @NonNull
- private SymbolKind kind;
-
- /**
- * {@code true} if the hierarchy item is deprecated. Otherwise, {@code false}. It is {@code false} by default.
- */
- private Boolean deprecated;
-
- /**
- * The URI of the text document where this type hierarchy item belongs to.
- */
- @NonNull
- private String uri;
-
- /**
- * The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else
- * like comments. This information is typically used to determine if the clients cursor is inside the type
- * hierarchy item to reveal in the symbol in the UI.
- *
- * @see TypeHierarchyItem#selectionRange
- */
- @NonNull
- private Range range;
-
- /**
- * The range that should be selected and revealed when this type hierarchy item is being picked, e.g the name of a function.
- * Must be contained by the the {@link TypeHierarchyItem#getRange range}.
- *
- * @see TypeHierarchyItem#range
- */
- @NonNull
- private Range selectionRange;
-
- /**
- * If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does not have any
- * direct parents. If not defined, the parents have not been resolved yet.
- */
- private List parents;
-
- /**
- * If this type hierarchy item is resolved, it contains the direct children of the current item.
- * Could be empty if the item does not have any descendants. If not defined, the children have not been resolved.
- */
- private List children;
-
- /**
- * An optional data field can be used to identify a type hierarchy item in a resolve request.
- */
- @JsonAdapter(JsonElementTypeAdapter.Factory.class)
- private Object data;
-
- /**
- * The human readable name of the hierarchy item.
- */
- @Pure
- @NonNull
- public String getName() {
- return this.name;
- }
-
- /**
- * The human readable name of the hierarchy item.
- */
- public void setName(@NonNull final String name) {
- this.name = Preconditions.checkNotNull(name, "name");
- }
-
- /**
- * Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method.
- */
- @Pure
- public String getDetail() {
- return this.detail;
- }
-
- /**
- * Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method.
- */
- public void setDetail(final String detail) {
- this.detail = detail;
- }
-
- /**
- * The kind of the hierarchy item. For instance, class or interface.
- */
- @Pure
- @NonNull
- public SymbolKind getKind() {
- return this.kind;
- }
-
- /**
- * The kind of the hierarchy item. For instance, class or interface.
- */
- public void setKind(@NonNull final SymbolKind kind) {
- this.kind = Preconditions.checkNotNull(kind, "kind");
- }
-
- /**
- * {@code true} if the hierarchy item is deprecated. Otherwise, {@code false}. It is {@code false} by default.
- */
- @Pure
- public Boolean getDeprecated() {
- return this.deprecated;
- }
-
- /**
- * {@code true} if the hierarchy item is deprecated. Otherwise, {@code false}. It is {@code false} by default.
- */
- public void setDeprecated(final Boolean deprecated) {
- this.deprecated = deprecated;
- }
-
- /**
- * The URI of the text document where this type hierarchy item belongs to.
- */
- @Pure
- @NonNull
- public String getUri() {
- return this.uri;
- }
-
- /**
- * The URI of the text document where this type hierarchy item belongs to.
- */
- public void setUri(@NonNull final String uri) {
- this.uri = Preconditions.checkNotNull(uri, "uri");
- }
-
- /**
- * The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else
- * like comments. This information is typically used to determine if the clients cursor is inside the type
- * hierarchy item to reveal in the symbol in the UI.
- *
- * @see TypeHierarchyItem#selectionRange
- */
- @Pure
- @NonNull
- public Range getRange() {
- return this.range;
- }
-
- /**
- * The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else
- * like comments. This information is typically used to determine if the clients cursor is inside the type
- * hierarchy item to reveal in the symbol in the UI.
- *
- * @see TypeHierarchyItem#selectionRange
- */
- public void setRange(@NonNull final Range range) {
- this.range = Preconditions.checkNotNull(range, "range");
- }
-
- /**
- * The range that should be selected and revealed when this type hierarchy item is being picked, e.g the name of a function.
- * Must be contained by the the {@link TypeHierarchyItem#getRange range}.
- *
- * @see TypeHierarchyItem#range
- */
- @Pure
- @NonNull
- public Range getSelectionRange() {
- return this.selectionRange;
- }
-
- /**
- * The range that should be selected and revealed when this type hierarchy item is being picked, e.g the name of a function.
- * Must be contained by the the {@link TypeHierarchyItem#getRange range}.
- *
- * @see TypeHierarchyItem#range
- */
- public void setSelectionRange(@NonNull final Range selectionRange) {
- this.selectionRange = Preconditions.checkNotNull(selectionRange, "selectionRange");
- }
-
- /**
- * If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does not have any
- * direct parents. If not defined, the parents have not been resolved yet.
- */
- @Pure
- public List getParents() {
- return this.parents;
- }
-
- /**
- * If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does not have any
- * direct parents. If not defined, the parents have not been resolved yet.
- */
- public void setParents(final List parents) {
- this.parents = parents;
- }
-
- /**
- * If this type hierarchy item is resolved, it contains the direct children of the current item.
- * Could be empty if the item does not have any descendants. If not defined, the children have not been resolved.
- */
- @Pure
- public List getChildren() {
- return this.children;
- }
-
- /**
- * If this type hierarchy item is resolved, it contains the direct children of the current item.
- * Could be empty if the item does not have any descendants. If not defined, the children have not been resolved.
- */
- public void setChildren(final List children) {
- this.children = children;
- }
-
- /**
- * An optional data field can be used to identify a type hierarchy item in a resolve request.
- */
- @Pure
- public Object getData() {
- return this.data;
- }
-
- /**
- * An optional data field can be used to identify a type hierarchy item in a resolve request.
- */
- public void setData(final Object data) {
- this.data = data;
- }
-
- @Override
- @Pure
- public String toString() {
- ToStringBuilder b = new ToStringBuilder(this);
- b.add("name", this.name);
- b.add("detail", this.detail);
- b.add("kind", this.kind);
- b.add("deprecated", this.deprecated);
- b.add("uri", this.uri);
- b.add("range", this.range);
- b.add("selectionRange", this.selectionRange);
- b.add("parents", this.parents);
- b.add("children", this.children);
- b.add("data", this.data);
- return b.toString();
- }
-
- @Override
- @Pure
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- TypeHierarchyItem other = (TypeHierarchyItem) obj;
- if (this.name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!this.name.equals(other.name)) {
- return false;
- }
- if (this.detail == null) {
- if (other.detail != null) {
- return false;
- }
- } else if (!this.detail.equals(other.detail)) {
- return false;
- }
- if (this.kind == null) {
- if (other.kind != null) {
- return false;
- }
- } else if (!this.kind.equals(other.kind)) {
- return false;
- }
- if (this.deprecated == null) {
- if (other.deprecated != null) {
- return false;
- }
- } else if (!this.deprecated.equals(other.deprecated)) {
- return false;
- }
- if (this.uri == null) {
- if (other.uri != null) {
- return false;
- }
- } else if (!this.uri.equals(other.uri)) {
- return false;
- }
- if (this.range == null) {
- if (other.range != null) {
- return false;
- }
- } else if (!this.range.equals(other.range)) {
- return false;
- }
- if (this.selectionRange == null) {
- if (other.selectionRange != null) {
- return false;
- }
- } else if (!this.selectionRange.equals(other.selectionRange)) {
- return false;
- }
- if (this.parents == null) {
- if (other.parents != null) {
- return false;
- }
- } else if (!this.parents.equals(other.parents)) {
- return false;
- }
- if (this.children == null) {
- if (other.children != null) {
- return false;
- }
- } else if (!this.children.equals(other.children)) {
- return false;
- }
- if (this.data == null) {
- if (other.data != null) {
- return false;
- }
- } else if (!this.data.equals(other.data)) {
- return false;
- }
- return true;
- }
-
- @Override
- @Pure
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((this.name== null) ? 0 : this.name.hashCode());
- result = prime * result + ((this.detail== null) ? 0 : this.detail.hashCode());
- result = prime * result + ((this.kind== null) ? 0 : this.kind.hashCode());
- result = prime * result + ((this.deprecated== null) ? 0 : this.deprecated.hashCode());
- result = prime * result + ((this.uri== null) ? 0 : this.uri.hashCode());
- result = prime * result + ((this.range== null) ? 0 : this.range.hashCode());
- result = prime * result + ((this.selectionRange== null) ? 0 : this.selectionRange.hashCode());
- result = prime * result + ((this.parents== null) ? 0 : this.parents.hashCode());
- result = prime * result + ((this.children== null) ? 0 : this.children.hashCode());
- return prime * result + ((this.data== null) ? 0 : this.data.hashCode());
- }
-}
diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyParams.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyParams.java
deleted file mode 100644
index a6ef5f4a34..0000000000
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyParams.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Copyright (c) 2016-2018 TypeFox and others.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0,
- * or the Eclipse Distribution License v. 1.0 which is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
- */
-package org.eclipse.lsp4j.legacy.typeHierarchy;
-
-import org.eclipse.lsp4j.TextDocumentPositionParams;
-import org.eclipse.xtext.xbase.lib.Pure;
-import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
-
-import com.google.common.annotations.Beta;
-
-/**
- * The type hierarchy request is sent from the client resolve a {@link TypeHierarchyItem type hierarchy item} for
- * a give cursor location in the text document. The request would also allow to specify if the item should be resolved
- * and whether sub- or supertypes are to be resolved.
- */
-@Beta
-@SuppressWarnings("all")
-public class TypeHierarchyParams extends TextDocumentPositionParams {
- /**
- * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. It defaults to {@code 0}.
- */
- private int resolve;
-
- /**
- * The direction of the type hierarchy resolution. If not defined, defaults to {@link TypeHierarchyDirection#Children Children}.
- */
- private TypeHierarchyDirection direction;
-
- /**
- * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. It defaults to {@code 0}.
- */
- @Pure
- public int getResolve() {
- return this.resolve;
- }
-
- /**
- * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. It defaults to {@code 0}.
- */
- public void setResolve(final int resolve) {
- this.resolve = resolve;
- }
-
- /**
- * The direction of the type hierarchy resolution. If not defined, defaults to {@link TypeHierarchyDirection#Children Children}.
- */
- @Pure
- public TypeHierarchyDirection getDirection() {
- return this.direction;
- }
-
- /**
- * The direction of the type hierarchy resolution. If not defined, defaults to {@link TypeHierarchyDirection#Children Children}.
- */
- public void setDirection(final TypeHierarchyDirection direction) {
- this.direction = direction;
- }
-
- @Override
- @Pure
- public String toString() {
- ToStringBuilder b = new ToStringBuilder(this);
- b.add("resolve", this.resolve);
- b.add("direction", this.direction);
- b.add("textDocument", getTextDocument());
- b.add("position", getPosition());
- return b.toString();
- }
-
- @Override
- @Pure
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- if (!super.equals(obj)) {
- return false;
- }
- TypeHierarchyParams other = (TypeHierarchyParams) obj;
- if (other.resolve != this.resolve) {
- return false;
- }
- if (this.direction == null) {
- if (other.direction != null) {
- return false;
- }
- } else if (!this.direction.equals(other.direction)) {
- return false;
- }
- return true;
- }
-
- @Override
- @Pure
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + this.resolve;
- return prime * result + ((this.direction== null) ? 0 : this.direction.hashCode());
- }
-}
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommandTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommandTest.java
deleted file mode 100644
index 1d3678cf06..0000000000
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommandTest.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021 Microsoft Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Microsoft Corporation - initial API and implementation
-*******************************************************************************/
-package org.eclipse.jdt.ls.core.internal.commands;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.ls.core.internal.WorkspaceHelper;
-import org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest;
-import org.eclipse.lsp4j.Position;
-import org.eclipse.lsp4j.SymbolKind;
-import org.eclipse.lsp4j.TextDocumentIdentifier;
-import org.eclipse.lsp4j.legacy.typeHierarchy.ResolveTypeHierarchyItemParams;
-import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyDirection;
-import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyItem;
-import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyParams;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TypeHierarchyCommandTest extends AbstractInvisibleProjectBasedTest {
-
- private IProject fJProject;
- private TypeHierarchyCommand fCommand;
-
- @Before
- public void setup() throws Exception {
- importProjects("maven/salut");
- fJProject = WorkspaceHelper.getProject("salut");
- fCommand = new TypeHierarchyCommand();
- }
-
- @Test
- public void testTypeHierarchy() throws Exception {
- IProgressMonitor monitor = new NullProgressMonitor();
- TypeHierarchyParams params = new TypeHierarchyParams();
- String uriString = fJProject.getFile("src/main/java/org/sample/TestJavadoc.java").getLocationURI().toString();
- TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
- Position position = new Position(4, 20);
- params.setTextDocument(identifier);
- params.setResolve(1);
- params.setDirection(TypeHierarchyDirection.Both);
- params.setPosition(position);
- TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
- assertNotNull(item);
- assertEquals(item.getName(), "TestJavadoc");
- assertNotNull(item.getChildren());
- assertEquals(item.getChildren().size(), 0);
- assertNotNull(item.getParents());
- assertEquals(item.getParents().size(), 1);
- assertEquals(item.getParents().get(0).getName(), "Object");
- }
-
- @Test
- public void testSuperTypeHierarchy() throws Exception {
- IProgressMonitor monitor = new NullProgressMonitor();
- TypeHierarchyParams params = new TypeHierarchyParams();
- String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString();
- TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
- Position position = new Position(7, 27);
- params.setTextDocument(identifier);
- params.setResolve(1);
- params.setDirection(TypeHierarchyDirection.Parents);
- params.setPosition(position);
- TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
- assertNotNull(item);
- assertEquals(item.getName(), "CallHierarchy$FooBuilder");
- assertNull(item.getChildren());
- assertEquals(item.getParents().size(), 2);
- TypeHierarchyItem builder = item.getParents().get(0);
- assertNotNull(builder);
- assertEquals(builder.getName(), "Builder");
- assertNull(builder.getParents());
- TypeHierarchyItem object = item.getParents().get(1);
- assertNotNull(object);
- assertEquals(object.getName(), "Object");
- assertNull(object.getParents());
- }
-
- @Test
- public void testSubTypeHierarchy() throws Exception {
- IProgressMonitor monitor = new NullProgressMonitor();
- TypeHierarchyParams params = new TypeHierarchyParams();
- String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString();
- TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
- Position position = new Position(2, 43);
- params.setTextDocument(identifier);
- params.setResolve(2);
- params.setDirection(TypeHierarchyDirection.Children);
- params.setPosition(position);
- TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
- assertNotNull(item);
- assertEquals(item.getName(), "Builder");
- assertNull(item.getParents());
- assertEquals(item.getChildren().size(), 9);
- for (TypeHierarchyItem child : item.getChildren()) {
- List subChild = child.getChildren();
- assertNotNull(subChild);
- if (subChild.size() == 1) {
- assertEquals(subChild.get(0).getName(), "ReflectionToStringBuilder");
- }
- }
- }
-
- // https://github.com/redhat-developer/vscode-java/issues/2871
- @Test
- public void testMultipleProjects() throws Exception {
- importProjects("eclipse/gh2871");
- IProject project = WorkspaceHelper.getProject("project1");
- IProgressMonitor monitor = new NullProgressMonitor();
- TypeHierarchyParams params = new TypeHierarchyParams();
- String uriString = project.getFile("src/org/sample/First.java").getLocationURI().toString();
- TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
- Position position = new Position(1, 22);
- params.setTextDocument(identifier);
- params.setResolve(1);
- params.setDirection(TypeHierarchyDirection.Both);
- params.setPosition(position);
- TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
- assertNotNull(item);
- assertEquals(item.getName(), "First");
- assertNotNull(item.getChildren());
- assertEquals(item.getChildren().size(), 1);
- assertEquals(item.getChildren().get(0).getName(), "Second");
- }
-
- @Test
- public void testMethodHierarchy() throws Exception {
- importProjects("maven/type-hierarchy");
- IProject project = WorkspaceHelper.getProject("type-hierarchy");
- String uriString = project.getFile("src/main/java/org/example/Zero.java").getLocationURI().toString();
- TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
- Position position = new Position(3, 17); // public void f[o]o()
- TypeHierarchyParams zeroParams = new TypeHierarchyParams();
- zeroParams.setTextDocument(identifier);
- zeroParams.setResolve(1);
- zeroParams.setDirection(TypeHierarchyDirection.Both);
- zeroParams.setPosition(position);
- TypeHierarchyItem zero = fCommand.typeHierarchy(zeroParams, monitor);
-
- // do not show java.lang.Object if target method isn't from there
- assertEquals(0, zero.getParents().size());
-
- assertEquals(SymbolKind.Class, zero.getKind()); // zero
- assertEquals(SymbolKind.Class, zero.getChildren().get(0).getKind()); // one
- assertEquals(SymbolKind.Null, zero.getChildren().get(1).getKind()); // two
-
- ResolveTypeHierarchyItemParams oneParams = new ResolveTypeHierarchyItemParams();
- oneParams.setItem(zero.getChildren().get(0));
- oneParams.setDirection(TypeHierarchyDirection.Both);
- oneParams.setResolve(1);
- TypeHierarchyItem one = fCommand.resolveTypeHierarchy(oneParams, monitor);
-
- assertEquals(SymbolKind.Null, one.getChildren().get(1).getKind()); // three
- assertEquals(SymbolKind.Class, one.getChildren().get(0).getKind()); // four
-
- ResolveTypeHierarchyItemParams twoParams = new ResolveTypeHierarchyItemParams();
- twoParams.setItem(zero.getChildren().get(1));
- twoParams.setDirection(TypeHierarchyDirection.Both);
- twoParams.setResolve(1);
- TypeHierarchyItem two = fCommand.resolveTypeHierarchy(twoParams, monitor);
-
- assertEquals(SymbolKind.Null, two.getChildren().get(0).getKind()); // five
- assertEquals(SymbolKind.Class, two.getChildren().get(1).getKind()); // six
- }
-}
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/TypeHierarchyHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/TypeHierarchyHandlerTest.java
new file mode 100644
index 0000000000..ca7219a027
--- /dev/null
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/TypeHierarchyHandlerTest.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Microsoft Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Microsoft Corporation - initial API and implementation
+*******************************************************************************/
+package org.eclipse.jdt.ls.core.internal.handlers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.ls.core.internal.WorkspaceHelper;
+import org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest;
+import org.eclipse.lsp4j.Position;
+import org.eclipse.lsp4j.SymbolKind;
+import org.eclipse.lsp4j.TextDocumentIdentifier;
+import org.eclipse.lsp4j.TypeHierarchyItem;
+import org.eclipse.lsp4j.TypeHierarchyPrepareParams;
+import org.eclipse.lsp4j.TypeHierarchySubtypesParams;
+import org.eclipse.lsp4j.TypeHierarchySupertypesParams;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TypeHierarchyHandlerTest extends AbstractInvisibleProjectBasedTest {
+
+ private IProject fJProject;
+ private TypeHierarchyHandler fHandler;
+
+ @Before
+ public void setup() throws Exception {
+ importProjects("maven/salut");
+ fJProject = WorkspaceHelper.getProject("salut");
+ fHandler = new TypeHierarchyHandler();
+ }
+
+ @Test
+ public void testSuperTypeHierarchy() throws Exception {
+ IProgressMonitor monitor = new NullProgressMonitor();
+ TypeHierarchyPrepareParams params = new TypeHierarchyPrepareParams();
+ String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString();
+ TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
+ Position position = new Position(7, 27);
+ params.setTextDocument(identifier);
+ params.setPosition(position);
+ List items = fHandler.prepareTypeHierarchy(params, monitor);
+ assertNotNull(items);
+ assertEquals(1, items.size());
+ assertEquals(items.get(0).getName(), "CallHierarchy$FooBuilder");
+ TypeHierarchySupertypesParams supertypesParams = new TypeHierarchySupertypesParams();
+ supertypesParams.setItem(items.get(0));
+ List supertypesItems = fHandler.getSupertypeItems(supertypesParams, monitor);
+ assertNotNull(supertypesItems);
+ assertEquals(2, supertypesItems.size());
+ assertEquals(supertypesItems.get(0).getName(), "Builder");
+ assertEquals(supertypesItems.get(0).getKind(), SymbolKind.Interface);
+ assertEquals(supertypesItems.get(1).getName(), "Object");
+ assertEquals(supertypesItems.get(1).getKind(), SymbolKind.Class);
+ }
+
+ @Test
+ public void testSubTypeHierarchy() throws Exception {
+ IProgressMonitor monitor = new NullProgressMonitor();
+ TypeHierarchyPrepareParams params = new TypeHierarchyPrepareParams();
+ String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString();
+ TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
+ Position position = new Position(2, 43);
+ params.setTextDocument(identifier);
+ params.setPosition(position);
+ List items = fHandler.prepareTypeHierarchy(params, monitor);
+ assertNotNull(items);
+ assertEquals(1, items.size());
+ assertEquals(items.get(0).getName(), "Builder");
+ TypeHierarchySubtypesParams supertypesParams = new TypeHierarchySubtypesParams();
+ supertypesParams.setItem(items.get(0));
+ List subtypesItems = fHandler.getSubtypeItems(supertypesParams, monitor);
+ assertNotNull(subtypesItems);
+ assertEquals(9, subtypesItems.size());
+ }
+
+ // https://github.com/redhat-developer/vscode-java/issues/2871
+ @Test
+ public void testMultipleProjects() throws Exception {
+ importProjects("eclipse/gh2871");
+ IProject project = WorkspaceHelper.getProject("project1");
+ IProgressMonitor monitor = new NullProgressMonitor();
+ TypeHierarchyPrepareParams params = new TypeHierarchyPrepareParams();
+ String uriString = project.getFile("src/org/sample/First.java").getLocationURI().toString();
+ TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
+ Position position = new Position(1, 22);
+ params.setTextDocument(identifier);
+ params.setPosition(position);
+ List items = fHandler.prepareTypeHierarchy(params, monitor);
+ assertNotNull(items);
+ assertEquals(1, items.size());
+ assertEquals("First", items.get(0).getName());
+ TypeHierarchySubtypesParams supertypesParams = new TypeHierarchySubtypesParams();
+ supertypesParams.setItem(items.get(0));
+ List subtypesItems = fHandler.getSubtypeItems(supertypesParams, monitor);
+ assertNotNull(subtypesItems);
+ assertEquals(1, subtypesItems.size());
+ assertEquals("Second", subtypesItems.get(0).getName());
+ }
+
+ @Test
+ public void testMethodHierarchy() throws Exception {
+ importProjects("maven/type-hierarchy");
+ IProject project = WorkspaceHelper.getProject("type-hierarchy");
+ String uriString = project.getFile("src/main/java/org/example/Zero.java").getLocationURI().toString();
+ TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
+ Position position = new Position(3, 17); // public void f[o]o()
+ TypeHierarchyPrepareParams zeroParams = new TypeHierarchyPrepareParams();
+ zeroParams.setTextDocument(identifier);
+ zeroParams.setPosition(position);
+ List zeroItems = fHandler.prepareTypeHierarchy(zeroParams, monitor);
+ assertNotNull(zeroItems);
+ assertEquals(1, zeroItems.size());
+ assertEquals("Zero", zeroItems.get(0).getName());
+ assertEquals(SymbolKind.Class, zeroItems.get(0).getKind());
+
+ TypeHierarchySupertypesParams supertypesParams = new TypeHierarchySupertypesParams();
+ supertypesParams.setItem(zeroItems.get(0));
+ List supertypesItems = fHandler.getSupertypeItems(supertypesParams, monitor);
+ assertNotNull(supertypesItems);
+ // do not show java.lang.Object if target method isn't from there
+ assertEquals(0, supertypesItems.size());
+
+ TypeHierarchySubtypesParams subtypesParams = new TypeHierarchySubtypesParams();
+ subtypesParams.setItem(zeroItems.get(0));
+ List subtypesItems = fHandler.getSubtypeItems(subtypesParams, monitor);
+ assertNotNull(subtypesItems);
+ assertEquals(SymbolKind.Class, subtypesItems.get(0).getKind()); // one
+ assertEquals("One", subtypesItems.get(0).getName()); // one
+ assertEquals(SymbolKind.Null, subtypesItems.get(1).getKind()); // two
+ assertEquals("Two", subtypesItems.get(1).getName()); // two
+
+ TypeHierarchyItem one = subtypesItems.get(0);
+ TypeHierarchyItem two = subtypesItems.get(1);
+ subtypesParams.setItem(one);
+ subtypesItems = fHandler.getSubtypeItems(subtypesParams, monitor);
+ assertNotNull(subtypesItems);
+ assertEquals(SymbolKind.Null, subtypesItems.get(1).getKind()); // three
+ assertEquals("Three", subtypesItems.get(1).getName()); // three
+ assertEquals(SymbolKind.Class, subtypesItems.get(0).getKind()); // four
+ assertEquals("Four", subtypesItems.get(0).getName()); // four
+
+ subtypesParams.setItem(two);
+ subtypesItems = fHandler.getSubtypeItems(subtypesParams, monitor);
+ assertNotNull(subtypesItems);
+ assertEquals(SymbolKind.Null, subtypesItems.get(0).getKind()); // five
+ assertEquals("Five", subtypesItems.get(0).getName()); // five
+ assertEquals(SymbolKind.Class, subtypesItems.get(1).getKind()); // six
+ assertEquals("Six", subtypesItems.get(1).getName()); // six
+ }
+}