Skip to content

Commit c9e7d82

Browse files
committed
Onboard legacy TypeHierarchy API
LSP/LSP4J doesn't maintain those API anymore, so let's include them into JDT-LS source code to allow moving JDT-LS to newer LSP/LSP4J version while still keeping current typeHierarchy commands.
1 parent 9f4e437 commit c9e7d82

10 files changed

Lines changed: 804 additions & 16 deletions

File tree

org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
3131
org.eclipse.core.filesystem;bundle-version="1.7.0",
3232
org.eclipse.jdt.apt.pluggable.core;bundle-version="1.2.0";resolution:=optional,
3333
org.eclipse.m2e.apt.core;bundle-version="1.3.0";resolution:=optional
34-
Export-Package: org.eclipse.jdt.ls.core.internal;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver",
34+
Export-Package: org.eclipse.jdt.ls.core.contentassist;x-friends:="org.eclipse.jdt.ls.tests",
35+
org.eclipse.jdt.ls.core.internal;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver",
3536
org.eclipse.jdt.ls.core.internal.cleanup;x-friends:="org.eclipse.jdt.ls.tests",
3637
org.eclipse.jdt.ls.core.internal.codemanipulation;x-friends:="org.eclipse.jdt.ls.tests",
3738
org.eclipse.jdt.ls.core.internal.commands;x-friends:="org.eclipse.jdt.ls.tests",
@@ -46,20 +47,19 @@ Export-Package: org.eclipse.jdt.ls.core.internal;x-friends:="org.eclipse.jdt.ls.
4647
org.eclipse.jdt.ls.core.internal.corext.util;x-internal:=true,
4748
org.eclipse.jdt.ls.core.internal.corrections;x-internal:=true,
4849
org.eclipse.jdt.ls.core.internal.corrections.proposals;x-internal:=true,
50+
org.eclipse.jdt.ls.core.internal.framework.protobuf;x-friends:="org.eclipse.jdt.ls.tests",
4951
org.eclipse.jdt.ls.core.internal.handlers;x-friends:="org.eclipse.jdt.ls.tests",
5052
org.eclipse.jdt.ls.core.internal.hover;x-friends:="org.eclipse.jdt.ls.tests",
5153
org.eclipse.jdt.ls.core.internal.javadoc;x-friends:="org.eclipse.jdt.ls.tests",
5254
org.eclipse.jdt.ls.core.internal.lsp;x-friends:="org.eclipse.jdt.ls.tests",
5355
org.eclipse.jdt.ls.core.internal.managers;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver",
54-
org.eclipse.jdt.ls.core.internal.framework.protobuf;x-friends:="org.eclipse.jdt.ls.tests",
5556
org.eclipse.jdt.ls.core.internal.preferences;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver",
5657
org.eclipse.jdt.ls.core.internal.semantictokens;x-friends:="org.eclipse.jdt.ls.tests",
5758
org.eclipse.jdt.ls.core.internal.syntaxserver;x-friends:="org.eclipse.jdt.ls.tests.syntaxserver",
5859
org.eclipse.jdt.ls.core.internal.text.correction;x-friends:="org.eclipse.jdt.ls.tests",
59-
org.eclipse.jdt.ls.core.contentassist;x-friends:="org.eclipse.jdt.ls.tests",
6060
org.eclipse.jdt.ls.internal.gradle.checksums;x-friends:="org.eclipse.jdt.ls.tests",
61-
org.eclipse.lsp4j.proposed;x-friends:="org.eclipse.jdt.ls.tests",
62-
org.eclipse.lsp4j.extended;x-friends:="org.eclipse.jdt.ls.tests"
61+
org.eclipse.lsp4j.extended;x-friends:="org.eclipse.jdt.ls.tests",
62+
org.eclipse.lsp4j.legacy.typeHierarchy;x-friends:="org.eclipse.jdt.ls.tests"
6363
Bundle-ClassPath: lib/jsoup-1.14.2.jar,
6464
lib/remark-1.2.0.jar,
6565
.

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTDelegateCommandHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
import org.eclipse.jdt.ls.core.internal.handlers.PasteEventHandler.PasteEventParams;
3737
import org.eclipse.jdt.ls.core.internal.handlers.ResolveSourceMappingHandler;
3838
import org.eclipse.jdt.ls.core.internal.managers.GradleProjectImporter;
39-
import org.eclipse.lsp4j.ResolveTypeHierarchyItemParams;
4039
import org.eclipse.lsp4j.SymbolInformation;
4140
import org.eclipse.lsp4j.TextDocumentPositionParams;
42-
import org.eclipse.lsp4j.TypeHierarchyDirection;
43-
import org.eclipse.lsp4j.TypeHierarchyItem;
44-
import org.eclipse.lsp4j.TypeHierarchyParams;
4541
import org.eclipse.lsp4j.WorkspaceEdit;
42+
import org.eclipse.lsp4j.legacy.typeHierarchy.ResolveTypeHierarchyItemParams;
43+
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyDirection;
44+
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyItem;
45+
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyParams;
4646

4747
public class JDTDelegateCommandHandler implements IDelegateCommandHandler {
4848

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
import org.eclipse.lsp4j.Location;
3737
import org.eclipse.lsp4j.Position;
3838
import org.eclipse.lsp4j.Range;
39-
import org.eclipse.lsp4j.ResolveTypeHierarchyItemParams;
4039
import org.eclipse.lsp4j.TextDocumentIdentifier;
41-
import org.eclipse.lsp4j.TypeHierarchyDirection;
42-
import org.eclipse.lsp4j.TypeHierarchyItem;
43-
import org.eclipse.lsp4j.TypeHierarchyParams;
40+
import org.eclipse.lsp4j.legacy.typeHierarchy.ResolveTypeHierarchyItemParams;
41+
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyDirection;
42+
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyItem;
43+
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyParams;
4444

4545
public class TypeHierarchyCommand {
4646

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
These files are extracted from lsp4j-0.12.0-sources.jar.
2+
They're still used by JDT-LS but aren't supported by newer LSP/LSP4J.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/**
2+
* Copyright (c) 2016-2018 TypeFox and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
package org.eclipse.lsp4j.legacy.typeHierarchy;
13+
14+
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
15+
import org.eclipse.lsp4j.util.Preconditions;
16+
import org.eclipse.xtext.xbase.lib.Pure;
17+
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
18+
19+
import com.google.common.annotations.Beta;
20+
21+
/**
22+
* Request to resolve an unresolved {@link TypeHierarchyItem type hierarchy item} which is indicated if the
23+
* {@link TypeHierarchyItem#getParents parents} or the {@link TypeHierarchyItem#getChildren children} is not
24+
* defined. If resolved and no {@code parents} or {@code children} are available then an empty list is returned.
25+
*/
26+
@Beta
27+
@SuppressWarnings("all")
28+
public class ResolveTypeHierarchyItemParams {
29+
/**
30+
* The hierarchy item to resolve.
31+
*/
32+
@NonNull
33+
private TypeHierarchyItem item;
34+
35+
/**
36+
* The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level.
37+
*/
38+
private int resolve;
39+
40+
/**
41+
* The direction of the type hierarchy resolution.
42+
*/
43+
@NonNull
44+
private TypeHierarchyDirection direction;
45+
46+
public ResolveTypeHierarchyItemParams() {
47+
}
48+
49+
public ResolveTypeHierarchyItemParams(@NonNull final TypeHierarchyItem item, final int resolve, @NonNull final TypeHierarchyDirection direction) {
50+
this.item = Preconditions.<TypeHierarchyItem>checkNotNull(item, "item");
51+
this.resolve = resolve;
52+
this.direction = Preconditions.<TypeHierarchyDirection>checkNotNull(direction, "direction");
53+
}
54+
55+
/**
56+
* The hierarchy item to resolve.
57+
*/
58+
@Pure
59+
@NonNull
60+
public TypeHierarchyItem getItem() {
61+
return this.item;
62+
}
63+
64+
/**
65+
* The hierarchy item to resolve.
66+
*/
67+
public void setItem(@NonNull final TypeHierarchyItem item) {
68+
this.item = Preconditions.checkNotNull(item, "item");
69+
}
70+
71+
/**
72+
* The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level.
73+
*/
74+
@Pure
75+
public int getResolve() {
76+
return this.resolve;
77+
}
78+
79+
/**
80+
* The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level.
81+
*/
82+
public void setResolve(final int resolve) {
83+
this.resolve = resolve;
84+
}
85+
86+
/**
87+
* The direction of the type hierarchy resolution.
88+
*/
89+
@Pure
90+
@NonNull
91+
public TypeHierarchyDirection getDirection() {
92+
return this.direction;
93+
}
94+
95+
/**
96+
* The direction of the type hierarchy resolution.
97+
*/
98+
public void setDirection(@NonNull final TypeHierarchyDirection direction) {
99+
this.direction = Preconditions.checkNotNull(direction, "direction");
100+
}
101+
102+
@Override
103+
@Pure
104+
public String toString() {
105+
ToStringBuilder b = new ToStringBuilder(this);
106+
b.add("item", this.item);
107+
b.add("resolve", this.resolve);
108+
b.add("direction", this.direction);
109+
return b.toString();
110+
}
111+
112+
@Override
113+
@Pure
114+
public boolean equals(final Object obj) {
115+
if (this == obj) {
116+
return true;
117+
}
118+
if (obj == null) {
119+
return false;
120+
}
121+
if (getClass() != obj.getClass()) {
122+
return false;
123+
}
124+
ResolveTypeHierarchyItemParams other = (ResolveTypeHierarchyItemParams) obj;
125+
if (this.item == null) {
126+
if (other.item != null) {
127+
return false;
128+
}
129+
} else if (!this.item.equals(other.item)) {
130+
return false;
131+
}
132+
if (other.resolve != this.resolve) {
133+
return false;
134+
}
135+
if (this.direction == null) {
136+
if (other.direction != null) {
137+
return false;
138+
}
139+
} else if (!this.direction.equals(other.direction)) {
140+
return false;
141+
}
142+
return true;
143+
}
144+
145+
@Override
146+
@Pure
147+
public int hashCode() {
148+
final int prime = 31;
149+
int result = 1;
150+
result = prime * result + ((this.item== null) ? 0 : this.item.hashCode());
151+
result = prime * result + this.resolve;
152+
return prime * result + ((this.direction== null) ? 0 : this.direction.hashCode());
153+
}
154+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright (c) 2016-2018 TypeFox and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
package org.eclipse.lsp4j.legacy.typeHierarchy;
13+
14+
import org.eclipse.lsp4j.DynamicRegistrationCapabilities;
15+
import org.eclipse.xtext.xbase.lib.Pure;
16+
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
17+
18+
import com.google.common.annotations.Beta;
19+
20+
/**
21+
* Capabilities specific to the {@code textDocument/typeHierarchy}.
22+
*
23+
* <p>
24+
* <b>Note:</b> the <a href=
25+
* "https://github.com/Microsoft/vscode-languageserver-node/pull/426">{@code textDocument/typeHierarchy}
26+
* language feature</a> is not yet part of the official LSP specification.
27+
*/
28+
@Beta
29+
@SuppressWarnings("all")
30+
public class TypeHierarchyCapabilities extends DynamicRegistrationCapabilities {
31+
public TypeHierarchyCapabilities() {
32+
}
33+
34+
public TypeHierarchyCapabilities(final Boolean dynamicRegistration) {
35+
super(dynamicRegistration);
36+
}
37+
38+
@Override
39+
@Pure
40+
public String toString() {
41+
ToStringBuilder b = new ToStringBuilder(this);
42+
b.add("dynamicRegistration", getDynamicRegistration());
43+
return b.toString();
44+
}
45+
46+
@Override
47+
@Pure
48+
public boolean equals(final Object obj) {
49+
if (this == obj) {
50+
return true;
51+
}
52+
if (obj == null) {
53+
return false;
54+
}
55+
if (getClass() != obj.getClass()) {
56+
return false;
57+
}
58+
if (!super.equals(obj)) {
59+
return false;
60+
}
61+
return true;
62+
}
63+
64+
@Override
65+
@Pure
66+
public int hashCode() {
67+
return super.hashCode();
68+
}
69+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/******************************************************************************
2+
* Copyright (c) 2019 TypeFox and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
******************************************************************************/
12+
package org.eclipse.lsp4j.legacy.typeHierarchy;
13+
14+
import org.eclipse.lsp4j.services.TextDocumentService;
15+
16+
/**
17+
* Direction specific to the
18+
* {@link TextDocumentService#typeHierarchy(TypeHierarchyParams)
19+
* textDocument/typeHierarchy} and
20+
* {@link TextDocumentService#resolveTypeHierarchy(ResolveTypeHierarchyItemParams)
21+
* typeHierarchy/resolve} LS methods.
22+
*
23+
* <p>
24+
* Valid values are:
25+
* <ul>
26+
* <li>{@link TypeHierarchyDirection#Children Children},</li>
27+
* <li>{@link TypeHierarchyDirection#Parents Parents},</li>
28+
* <li>{@link TypeHierarchyDirection#Both Both}.</li>
29+
* </ul>
30+
*
31+
*/
32+
public enum TypeHierarchyDirection {
33+
34+
/**
35+
* Flag for retrieving/resolving the subtypes. Value: {@code 0}.
36+
*/
37+
Children,
38+
39+
/**
40+
* Flag to use when retrieving/resolving the supertypes. Value: {@code 1}.
41+
*/
42+
Parents,
43+
44+
/**
45+
* Flag for resolving both the super- and subtypes. Value: {@code 2}.
46+
*/
47+
Both;
48+
49+
public static TypeHierarchyDirection forValue(int value) {
50+
TypeHierarchyDirection[] values = TypeHierarchyDirection.values();
51+
if (value < 0 || value >= values.length) {
52+
throw new IllegalArgumentException("Illegal enum value: " + value);
53+
}
54+
return values[value];
55+
}
56+
57+
}

0 commit comments

Comments
 (0)