Skip to content

Commit 3bfa506

Browse files
gselzerclaude
andcommitted
code-lsp: show less of the jvm toolkit
Gone, with nothing calling them (Jython's own analysis was the last to use the first two): Callable.of, Signatures.arguments, Document.version and ClassIndex.addRoots. Private, as only their classes use them: most of ClassIndex's documentation lookup, Members.field, method and signature, Signatures.rate and loadType, and Callable.parameterList. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 58ba9c8 commit 3bfa506

5 files changed

Lines changed: 14 additions & 109 deletions

File tree

‎scijava-code-lsp/src/main/java/org/scijava/code/lsp/jvm/AbstractLanguageServer.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ public String text() {
156156
return text;
157157
}
158158

159-
public int version() {
160-
return version;
161-
}
162-
163159
/** The text of the line of an offset, up to it. */
164160
public String lineTo(final int offset) {
165161
final String t = text;

‎scijava-code-lsp/src/main/java/org/scijava/code/lsp/jvm/Callable.java‎

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,6 @@ public Callable(final String name, final List<Param> params,
100100
this.returnType = returnType;
101101
}
102102

103-
/**
104-
* Reads a callable back from a completion made by {@link #toItem()} (or
105-
* any with typed label details, e.g. {@code (double a, double b)}); or
106-
* returns null if it is not one.
107-
*/
108-
public static Callable of(final CompletionItem item) {
109-
final CompletionItemLabelDetails details = item.getLabelDetails();
110-
if (details == null || details.getDetail() == null || !details.getDetail()
111-
.startsWith("(")) return null;
112-
final String list = details.getDetail();
113-
final String inner = list.substring(1, list.endsWith(")") ? list.length() -
114-
1 : list.length()).trim();
115-
final List<Param> params = new ArrayList<>();
116-
if (!inner.isEmpty()) {
117-
int depth = 0, start = 0;
118-
for (int i = 0; i <= inner.length(); i++) {
119-
final char c = i < inner.length() ? inner.charAt(i) : ',';
120-
if (c == '(' || c == '[' || c == '{' || c == '<') depth++;
121-
else if (c == ')' || c == ']' || c == '}' || c == '>') depth--;
122-
else if (c == ',' && depth == 0) {
123-
final String p = inner.substring(start, i).trim();
124-
final int space = p.lastIndexOf(' ');
125-
params.add(space < 0 ? new Param(p, null) : new Param(p.substring(
126-
space + 1), p.substring(0, space).trim()));
127-
start = i + 1;
128-
}
129-
}
130-
}
131-
return new Callable(item.getLabel(), params, details.getDescription())
132-
.kind(item.getKind()).detail(item.getDetail());
133-
}
134-
135103
/** Sets the kind of completion (default: method). */
136104
public Callable kind(final CompletionItemKind k) {
137105
kind = k;
@@ -202,7 +170,7 @@ public SignatureInformation toSignature() {
202170
}
203171

204172
/** E.g. {@code (double a, double b)}. */
205-
public String parameterList() {
173+
private String parameterList() {
206174
final StringBuilder sb = new StringBuilder("(");
207175
for (int i = 0; i < params.size(); i++) {
208176
if (i > 0) sb.append(", ");

‎scijava-code-lsp/src/main/java/org/scijava/code/lsp/jvm/ClassIndex.java‎

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,13 @@
4343
import java.nio.file.Files;
4444
import java.nio.file.Path;
4545
import java.util.ArrayList;
46-
import java.util.Collections;
4746
import java.util.Enumeration;
4847
import java.util.HashMap;
4948
import java.util.HashSet;
50-
import java.util.LinkedHashSet;
5149
import java.util.LinkedList;
5250
import java.util.List;
5351
import java.util.Map;
5452
import java.util.Scanner;
55-
import java.util.Set;
5653
import java.util.jar.JarEntry;
5754
import java.util.jar.JarFile;
5855
import java.util.regex.Matcher;
@@ -72,11 +69,8 @@
7269
* without pulling in the Swing script editor.
7370
* </p>
7471
* <p>
75-
* By default the index scans the runtime classpath ({@code java.class.path}), the
76-
* JRE/JDK home, and (on Java 9+) the runtime image's own modules. Applications that load classes from elsewhere (e.g. an ImageJ
77-
* {@code jars/} directory) can contribute additional roots via
78-
* {@link #addRoots(String...)} <em>before</em> the index is first built; this
79-
* keeps application-specific paths out of this neutral utility.
72+
* The index scans the runtime classpath ({@code java.class.path}), the
73+
* JRE/JDK home, and (on Java 9+) the runtime image's own modules.
8074
* </p>
8175
*
8276
* @author Albert Cardona
@@ -100,26 +94,12 @@ public final class ClassIndex {
10094
private static final HashMap<String, String> scijava_javadoc_URLs =
10195
new HashMap<>();
10296

103-
/** Extra roots (jar files or directories) contributed by applications. */
104-
private static final Set<String> extraRoots = new LinkedHashSet<>();
105-
10697
private static boolean ready = false;
10798

10899
private ClassIndex() {
109100
// prevent instantiation of static utility class
110101
}
111102

112-
/**
113-
* Registers additional roots (jar files, or directories scanned recursively
114-
* for jars) to include when the index is built. Has no effect once the index
115-
* has been built.
116-
*/
117-
public static void addRoots(final String... roots) {
118-
synchronized (class_urls) {
119-
Collections.addAll(extraRoots, roots);
120-
}
121-
}
122-
123103
/** The default roots: the JRE/JDK home plus each classpath entry. */
124104
private static List<String> defaultRoots() {
125105
final List<String> roots = new ArrayList<>();
@@ -137,9 +117,7 @@ private static List<String> defaultRoots() {
137117
public static void ensureCache() {
138118
synchronized (class_urls) {
139119
if (!class_urls.isEmpty()) return;
140-
final List<String> roots = defaultRoots();
141-
roots.addAll(extraRoots);
142-
class_urls.putAll(findAllClasses(roots));
120+
class_urls.putAll(findAllClasses(defaultRoots()));
143121
findRuntimeClasses(class_urls);
144122
// Soft attempt at getting all packages (will get them wrong if
145123
// multiple jars share the same packages).
@@ -162,7 +140,7 @@ public static boolean isCacheReady() {
162140
}
163141

164142
/** Builds the cache of SciJava javadoc aggregator sub-URLs, if not done. */
165-
public static void ensureSciJavaSubURLCache() {
143+
private static void ensureSciJavaSubURLCache() {
166144
synchronized (scijava_javadoc_URLs) {
167145
if (!scijava_javadoc_URLs.isEmpty()) return;
168146
Scanner scanner = null;
@@ -191,7 +169,7 @@ public static void ensureSciJavaSubURLCache() {
191169
}
192170
}
193171

194-
public static HashMap<String, JarProperties> findClassDocumentationURLs(
172+
private static HashMap<String, JarProperties> findClassDocumentationURLs(
195173
final String s)
196174
{
197175
ensureCache();
@@ -305,7 +283,7 @@ public static HashMap<String, ArrayList<String>> findDocumentationForClass(
305283
}
306284

307285
/** Properties of a jar file: its display name and documentation URLs. */
308-
public static final class JarProperties {
286+
private static final class JarProperties {
309287

310288
public final ArrayList<String> urls;
311289
public String name;
@@ -376,7 +354,7 @@ private static String className(final String entry) {
376354
*
377355
* @param roots jar files, or directories scanned recursively for jars
378356
*/
379-
public static HashMap<String, JarProperties> findAllClasses(
357+
private static HashMap<String, JarProperties> findAllClasses(
380358
final List<String> roots)
381359
{
382360
// Find all jar files.
@@ -507,7 +485,7 @@ public static ArrayList<String> findSimpleClassNamesStartingWith(
507485
}
508486

509487
/** Builds an HTML link to the SciJava javadoc for the given class. */
510-
public static String getJavaDocLink(final Class<?> c) {
488+
private static String getJavaDocLink(final Class<?> c) {
511489
final String name = c.getCanonicalName();
512490
final String pkg = getDocPackage(name);
513491
if (pkg == null) return name;

‎scijava-code-lsp/src/main/java/org/scijava/code/lsp/jvm/Members.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static List<Callable> constructors(final Class<?> c) {
109109
}
110110

111111
/** A completion for a field. */
112-
public static CompletionItem field(final Field f) {
112+
private static CompletionItem field(final Field f) {
113113
final CompletionItem item = new CompletionItem(f.getName());
114114
item.setKind(CompletionItemKind.Field);
115115
item.setInsertText(f.getName());
@@ -121,7 +121,7 @@ public static CompletionItem field(final Field f) {
121121
}
122122

123123
/** A method, as a callable. */
124-
public static Callable method(final Method m) {
124+
private static Callable method(final Method m) {
125125
final List<Callable.Param> params = new ArrayList<>();
126126
for (final java.lang.reflect.Parameter p : m.getParameters()) {
127127
params.add(new Callable.Param(p.getName(), typeName(p.getType())));
@@ -131,7 +131,7 @@ public static Callable method(final Method m) {
131131
}
132132

133133
/** A readable method signature, e.g. {@code String concat(String)}. */
134-
public static String signature(final Method m) {
134+
private static String signature(final Method m) {
135135
final StringBuilder sb = new StringBuilder();
136136
sb.append(typeName(m.getReturnType())).append(' ').append(m.getName())
137137
.append('(');

‎scijava-code-lsp/src/main/java/org/scijava/code/lsp/jvm/Signatures.java‎

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static Fit fit(final String argType, final String paramType,
124124
* @param fit Rates an argument type against a parameter type, e.g.
125125
* {@link #fit(String, String, ClassLoader)}.
126126
*/
127-
public static Fit rate(final Callable callable, final List<String> argTypes,
127+
private static Fit rate(final Callable callable, final List<String> argTypes,
128128
final BiFunction<String, String, Fit> fit)
129129
{
130130
final List<Callable.Param> params = callable.params();
@@ -157,43 +157,6 @@ public static List<SignatureInformation> rateAll(
157157
return out;
158158
}
159159

160-
/**
161-
* Splits the arguments of the call whose opening parenthesis is at
162-
* {@code open} into their source text, up to {@code caret}: the last one
163-
* is the argument the caret is in. Understands nested brackets and quoted
164-
* strings (with {@code '} and {@code "}), as most scripting languages
165-
* write them.
166-
*
167-
* @return The arguments, or null if the call is closed before the caret.
168-
*/
169-
public static List<String> arguments(final String text, final int open,
170-
final int caret)
171-
{
172-
final List<String> args = new ArrayList<>();
173-
int start = open + 1, depth = 0;
174-
char quote = 0;
175-
for (int i = start; i < caret; i++) {
176-
final char c = text.charAt(i);
177-
if (quote != 0) {
178-
if (c == '\\') i++;
179-
else if (c == quote) quote = 0;
180-
continue;
181-
}
182-
if (c == '"' || c == '\'') quote = c;
183-
else if (c == '(' || c == '[' || c == '{') depth++;
184-
else if (c == ')' || c == ']' || c == '}') {
185-
if (depth == 0) return null;
186-
depth--;
187-
}
188-
else if (c == ',' && depth == 0) {
189-
args.add(text.substring(start, i));
190-
start = i + 1;
191-
}
192-
}
193-
args.add(text.substring(start, caret));
194-
return args;
195-
}
196-
197160
/**
198161
* Finds the opening parenthesis of the call around the caret: the nearest
199162
* unclosed {@code (} before it, on the same line; or -1 if none.
@@ -213,7 +176,7 @@ else if (c == '(' || c == '[' || c == '{') {
213176
}
214177

215178
/** Loads a type such as {@code int}, {@code long[]} or {@code a.b.C}. */
216-
public static Class<?> loadType(final String name, final ClassLoader loader) {
179+
private static Class<?> loadType(final String name, final ClassLoader loader) {
217180
if (name.endsWith("[]")) {
218181
final Class<?> component = loadType(name.substring(0, name.length() -
219182
2), loader);

0 commit comments

Comments
 (0)