mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Reorganized classes
This commit is contained in:
@@ -5,6 +5,7 @@ import android.text.TextUtils;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.java.utils.StringSearch;
|
||||
import com.itsaky.lsp.models.DocumentChangeEvent;
|
||||
import com.itsaky.lsp.models.DocumentCloseEvent;
|
||||
import com.itsaky.lsp.models.DocumentOpenEvent;
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.itsaky.lsp.api.ILanguageServer;
|
||||
import com.itsaky.lsp.api.IReferenceProvider;
|
||||
import com.itsaky.lsp.api.IServerSettings;
|
||||
import com.itsaky.lsp.api.ISignatureHelpProvider;
|
||||
import com.itsaky.lsp.java.compiler.JavaCompilerService;
|
||||
import com.itsaky.lsp.java.providers.JavaCompletionProvider;
|
||||
import com.itsaky.lsp.java.providers.SignatureProvider;
|
||||
import com.itsaky.lsp.java.models.JavaServerConfiguration;
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.itsaky.lsp.java;
|
||||
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
|
||||
public class ParseTask {
|
||||
public final JavacTask task;
|
||||
public final CompilationUnitTree root;
|
||||
|
||||
public ParseTask(JavacTask task, CompilationUnitTree root) {
|
||||
this.task = task;
|
||||
this.root = root;
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
package com.itsaky.lsp.java;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.internal.jrtfs.JrtFileSystemProvider;
|
||||
|
||||
class ScanClassPath {
|
||||
|
||||
// TODO delete this and implement findPublicTypeDeclarationInJdk some other way
|
||||
/** All exported modules that are present in JDK 10 or 11 */
|
||||
static String[] JDK_MODULES = {
|
||||
"java.activation",
|
||||
"java.base",
|
||||
"java.compiler",
|
||||
"java.corba",
|
||||
"java.datatransfer",
|
||||
"java.desktop",
|
||||
"java.instrument",
|
||||
"java.jnlp",
|
||||
"java.logging",
|
||||
"java.management",
|
||||
"java.management.rmi",
|
||||
"java.naming",
|
||||
"java.net.http",
|
||||
"java.prefs",
|
||||
"java.rmi",
|
||||
"java.scripting",
|
||||
"java.se",
|
||||
"java.se.ee",
|
||||
"java.security.jgss",
|
||||
"java.security.sasl",
|
||||
"java.smartcardio",
|
||||
"java.sql",
|
||||
"java.sql.rowset",
|
||||
"java.transaction",
|
||||
"java.transaction.xa",
|
||||
"java.xml",
|
||||
"java.xml.bind",
|
||||
"java.xml.crypto",
|
||||
"java.xml.ws",
|
||||
"java.xml.ws.annotation",
|
||||
"javafx.base",
|
||||
"javafx.controls",
|
||||
"javafx.fxml",
|
||||
"javafx.graphics",
|
||||
"javafx.media",
|
||||
"javafx.swing",
|
||||
"javafx.web",
|
||||
"jdk.accessibility",
|
||||
"jdk.aot",
|
||||
"jdk.attach",
|
||||
"jdk.charsets",
|
||||
"jdk.compiler",
|
||||
"jdk.crypto.cryptoki",
|
||||
"jdk.crypto.ec",
|
||||
"jdk.dynalink",
|
||||
"jdk.editpad",
|
||||
"jdk.hotspot.agent",
|
||||
"jdk.httpserver",
|
||||
"jdk.incubator.httpclient",
|
||||
"jdk.internal.ed",
|
||||
"jdk.internal.jvmstat",
|
||||
"jdk.internal.le",
|
||||
"jdk.internal.opt",
|
||||
"jdk.internal.vm.ci",
|
||||
"jdk.internal.vm.compiler",
|
||||
"jdk.internal.vm.compiler.management",
|
||||
"jdk.jartool",
|
||||
"jdk.javadoc",
|
||||
"jdk.jcmd",
|
||||
"jdk.jconsole",
|
||||
"jdk.jdeps",
|
||||
"jdk.jdi",
|
||||
"jdk.jdwp.agent",
|
||||
"jdk.jfr",
|
||||
"jdk.jlink",
|
||||
"jdk.jshell",
|
||||
"jdk.jsobject",
|
||||
"jdk.jstatd",
|
||||
"jdk.localedata",
|
||||
"jdk.management",
|
||||
"jdk.management.agent",
|
||||
"jdk.management.cmm",
|
||||
"jdk.management.jfr",
|
||||
"jdk.management.resource",
|
||||
"jdk.naming.dns",
|
||||
"jdk.naming.rmi",
|
||||
"jdk.net",
|
||||
"jdk.pack",
|
||||
"jdk.packager.services",
|
||||
"jdk.rmic",
|
||||
"jdk.scripting.nashorn",
|
||||
"jdk.scripting.nashorn.shell",
|
||||
"jdk.sctp",
|
||||
"jdk.security.auth",
|
||||
"jdk.security.jgss",
|
||||
"jdk.snmp",
|
||||
"jdk.unsupported",
|
||||
"jdk.unsupported.desktop",
|
||||
"jdk.xml.dom",
|
||||
"jdk.zipfs",
|
||||
};
|
||||
|
||||
static Set<String> classPathTopLevelClasses(Set<Path> classPath) {
|
||||
LOG.info(String.format(Locale.getDefault (), "Searching for top-level classes in %d classpath locations", classPath.size()));
|
||||
|
||||
URL[] urls = classPath.stream().map(ScanClassPath::toUrl).toArray(URL[]::new);
|
||||
ClassLoader classLoader = new URLClassLoader(urls, null);
|
||||
|
||||
ClassPath scanner;
|
||||
|
||||
try {
|
||||
scanner = ClassPath.from(classLoader);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Set<String> classes = new HashSet<String>();
|
||||
for (ClassPath.ClassInfo c : scanner.getTopLevelClasses()) {
|
||||
classes.add(c.getName());
|
||||
}
|
||||
|
||||
LOG.info(String.format(Locale.ROOT, "Found %d classes in classpath", classes.size()));
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static URL toUrl(@NonNull Path p) {
|
||||
try {
|
||||
return p.toUri().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger LOG = Logger.instance ("ScanClassPath");
|
||||
}
|
||||
+24
-5
@@ -1,7 +1,26 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.compiler;
|
||||
|
||||
import com.itsaky.androidide.utils.Environment;
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.java.FileStore;
|
||||
import com.itsaky.lsp.java.parser.Parser;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
|
||||
@@ -21,7 +40,7 @@ import javax.lang.model.element.Name;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
class CompileBatch implements AutoCloseable {
|
||||
public class CompileBatch implements AutoCloseable {
|
||||
|
||||
final JavaCompilerService parent;
|
||||
static ReusableCompiler.Borrow borrow;
|
||||
@@ -61,7 +80,7 @@ class CompileBatch implements AutoCloseable {
|
||||
Set<Path> needsAdditionalSources () {
|
||||
// Check for "class not found errors" that refer to package private classes
|
||||
Set<Path> addFiles = new HashSet<Path> ();
|
||||
for (Diagnostic err : parent.diags) {
|
||||
for (Diagnostic err : parent.diagnostics) {
|
||||
if (!err.getCode ().equals ("compiler.err.cant.resolve.location")) {
|
||||
continue;
|
||||
}
|
||||
@@ -112,11 +131,11 @@ class CompileBatch implements AutoCloseable {
|
||||
|
||||
private static ReusableCompiler.Borrow batchTask (JavaCompilerService parent, Collection<? extends JavaFileObject> sources) {
|
||||
|
||||
parent.diags.clear ();
|
||||
parent.diagnostics.clear ();
|
||||
final Iterable<String> options = options (parent.classPath);
|
||||
|
||||
return parent.compiler.getTask (parent.fileManager,
|
||||
parent.diags::add,
|
||||
parent.diagnostics::add,
|
||||
options,
|
||||
Collections.emptyList (),
|
||||
sources);
|
||||
+19
-1
@@ -1,7 +1,25 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.compiler;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.itsaky.lsp.java.compiler.CompileBatch;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import java.nio.file.Path;
|
||||
+20
-2
@@ -1,6 +1,23 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
package com.itsaky.lsp.java.compiler;
|
||||
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@@ -8,6 +25,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
public interface CompilerProvider {
|
||||
+28
-6
@@ -1,8 +1,30 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.compiler;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.java.FileStore;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.java.parser.Parser;
|
||||
import com.itsaky.lsp.java.utils.ScanClassPath;
|
||||
import com.itsaky.lsp.java.utils.Cache;
|
||||
import com.itsaky.lsp.java.utils.Extractors;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.utils.StringSearch;
|
||||
import com.itsaky.lsp.java.visitors.FindTypeDeclarations;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
|
||||
@@ -28,7 +50,7 @@ import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
class JavaCompilerService implements CompilerProvider {
|
||||
public class JavaCompilerService implements CompilerProvider {
|
||||
|
||||
private CompileBatch cachedCompile;
|
||||
|
||||
@@ -37,14 +59,14 @@ class JavaCompilerService implements CompilerProvider {
|
||||
final ReusableCompiler compiler = new ReusableCompiler ();
|
||||
final SynchronizedTask synchronizedTask = new SynchronizedTask ();
|
||||
final ReentrantLock lock = new ReentrantLock ();
|
||||
final List<Diagnostic<? extends JavaFileObject>> diags = new ArrayList<> ();
|
||||
final List<Diagnostic<? extends JavaFileObject>> diagnostics = new ArrayList<> ();
|
||||
final Map<JavaFileObject, Long> cachedModified = new HashMap<> ();
|
||||
|
||||
// Use the same file manager for multiple tasks, so we don't repeatedly re-compile the same files
|
||||
// TODO intercept files that aren't in the batch and erase method bodies so compilation is faster
|
||||
final SourceFileManager fileManager;
|
||||
|
||||
JavaCompilerService (Set<Path> classPath, Set<Path> docPath) {
|
||||
public JavaCompilerService (Set<Path> classPath, Set<Path> docPath) {
|
||||
LOG.debug ("Class path:");
|
||||
for (Path p : classPath) {
|
||||
LOG.debug (" " + p);
|
||||
@@ -341,7 +363,7 @@ class JavaCompilerService implements CompilerProvider {
|
||||
public synchronized SynchronizedTask compile (Collection<? extends JavaFileObject> sources) {
|
||||
synchronized (synchronizedTask) {
|
||||
final CompileBatch compile = compileBatch (sources);
|
||||
final CompileTask compileTask = new CompileTask (compile, diags);
|
||||
final CompileTask compileTask = new CompileTask (compile, diagnostics);
|
||||
synchronizedTask.setTask (compileTask);
|
||||
return synchronizedTask;
|
||||
}
|
||||
+18
-23
@@ -1,36 +1,31 @@
|
||||
// Forked from JavacTaskImpl
|
||||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java;
|
||||
// Forked from JavacTaskImpl
|
||||
package com.itsaky.lsp.java.compiler;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.source.util.TaskEvent;
|
||||
import com.sun.source.util.TaskListener;
|
||||
import com.sun.tools.javac.api.*;
|
||||
import com.sun.tools.javac.api.JavacTaskImpl;
|
||||
import com.sun.tools.javac.api.JavacTool;
|
||||
import com.sun.tools.javac.api.JavacTrees;
|
||||
import com.sun.tools.javac.api.MultiTaskListener;
|
||||
import com.sun.tools.javac.code.Types;
|
||||
import com.sun.tools.javac.comp.Annotate;
|
||||
import com.sun.tools.javac.comp.Check;
|
||||
@@ -78,7 +73,7 @@ import javax.tools.JavaFileObject;
|
||||
* <p><b>This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This
|
||||
* code and its internal interfaces are subject to change or deletion without notice.</b>
|
||||
*/
|
||||
class ReusableCompiler {
|
||||
public class ReusableCompiler {
|
||||
|
||||
private static final Logger LOG = Logger.instance ("ReusableCompiler");
|
||||
private static final JavacTool systemProvider = JavacTool.create ();
|
||||
+23
-4
@@ -1,5 +1,24 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.compiler;
|
||||
|
||||
import com.itsaky.lsp.java.FileStore;
|
||||
import com.itsaky.lsp.java.utils.StringSearch;
|
||||
import com.sun.tools.javac.api.JavacTool;
|
||||
|
||||
import java.io.File;
|
||||
@@ -12,9 +31,9 @@ import java.util.stream.Stream;
|
||||
|
||||
import javax.tools.*;
|
||||
|
||||
class SourceFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
|
||||
public class SourceFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
|
||||
|
||||
SourceFileManager() {
|
||||
public SourceFileManager() {
|
||||
super(createDelegateFileManager());
|
||||
}
|
||||
|
||||
@@ -40,7 +59,7 @@ class SourceFileManager extends ForwardingJavaFileManager<StandardJavaFileManage
|
||||
|
||||
private JavaFileObject asJavaFileObject(Path file) {
|
||||
// TODO erase method bodies of files that are not open
|
||||
return new SourceFileObject(file);
|
||||
return new SourceFileObject (file);
|
||||
}
|
||||
|
||||
@Override
|
||||
+20
-1
@@ -1,4 +1,23 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.compiler;
|
||||
|
||||
import com.itsaky.lsp.java.FileStore;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
+17
-2
@@ -15,9 +15,24 @@
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.utils;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
package com.itsaky.lsp.java.compiler;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.parser;
|
||||
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
|
||||
public class ParseTask {
|
||||
public final JavacTask task;
|
||||
public final CompilationUnitTree root;
|
||||
|
||||
public ParseTask(JavacTask task, CompilationUnitTree root) {
|
||||
this.task = task;
|
||||
this.root = root;
|
||||
}
|
||||
}
|
||||
+33
-14
@@ -1,8 +1,27 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import android.text.TextUtils;
|
||||
package com.itsaky.lsp.java.parser;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.java.FileStore;
|
||||
import com.itsaky.lsp.java.compiler.SourceFileManager;
|
||||
import com.itsaky.lsp.java.compiler.SourceFileObject;
|
||||
import com.itsaky.lsp.java.utils.StringSearch;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.sun.source.tree.BlockTree;
|
||||
@@ -47,7 +66,7 @@ import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
class Parser {
|
||||
public class Parser {
|
||||
|
||||
private static final JavaCompiler COMPILER = JavacTool.create ();
|
||||
private static final SourceFileManager FILE_MANAGER = new SourceFileManager ();
|
||||
@@ -66,11 +85,11 @@ class Parser {
|
||||
);
|
||||
}
|
||||
|
||||
final JavaFileObject file;
|
||||
final String contents;
|
||||
final JavacTask task;
|
||||
final CompilationUnitTree root;
|
||||
final Trees trees;
|
||||
public final JavaFileObject file;
|
||||
public final String contents;
|
||||
public final JavacTask task;
|
||||
public final CompilationUnitTree root;
|
||||
public final Trees trees;
|
||||
|
||||
private Parser (JavaFileObject file) {
|
||||
this.file = file;
|
||||
@@ -88,7 +107,7 @@ class Parser {
|
||||
this.trees = Trees.instance (task);
|
||||
}
|
||||
|
||||
static Parser parseFile (Path file) {
|
||||
public static Parser parseFile (Path file) {
|
||||
return parseJavaFileObject (new SourceFileObject (file));
|
||||
}
|
||||
|
||||
@@ -111,7 +130,7 @@ class Parser {
|
||||
cachedModified = file.getLastModified ();
|
||||
}
|
||||
|
||||
static Parser parseJavaFileObject (JavaFileObject file) {
|
||||
public static Parser parseJavaFileObject (JavaFileObject file) {
|
||||
if (needsParse (file)) {
|
||||
loadParse (file);
|
||||
} else {
|
||||
@@ -120,8 +139,8 @@ class Parser {
|
||||
return cachedParse;
|
||||
}
|
||||
|
||||
Set<Name> packagePrivateClasses () {
|
||||
Set<Name> result = new HashSet<Name> ();
|
||||
public Set<Name> packagePrivateClasses () {
|
||||
Set<Name> result = new HashSet<> ();
|
||||
for (Tree t : root.getTypeDecls ()) {
|
||||
if (t instanceof ClassTree) {
|
||||
ClassTree c = (ClassTree) t;
|
||||
@@ -134,7 +153,7 @@ class Parser {
|
||||
return result;
|
||||
}
|
||||
|
||||
static Range range (JavacTask task, CharSequence contents, TreePath path) {
|
||||
public static Range range (JavacTask task, CharSequence contents, TreePath path) {
|
||||
// Find start position
|
||||
Trees trees = Trees.instance (task);
|
||||
SourcePositions pos = trees.getSourcePositions ();
|
||||
@@ -258,7 +277,7 @@ class Parser {
|
||||
return leaf.toString ();
|
||||
}
|
||||
|
||||
List<String> accessibleClasses (String partialName, String fromPackage) {
|
||||
public List<String> accessibleClasses (String partialName, String fromPackage) {
|
||||
String toPackage = Objects.toString (root.getPackageName (), "");
|
||||
boolean samePackage = fromPackage.equals (toPackage) || toPackage.isEmpty ();
|
||||
List<String> result = new ArrayList<String> ();
|
||||
@@ -21,8 +21,8 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.api.ICodeActionProvider;
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.rewrite.AddException;
|
||||
import com.itsaky.lsp.java.rewrite.AddImport;
|
||||
import com.itsaky.lsp.java.rewrite.AddSuppressWarningAnnotation;
|
||||
@@ -36,7 +36,7 @@ import com.itsaky.lsp.java.rewrite.RemoveClass;
|
||||
import com.itsaky.lsp.java.rewrite.RemoveException;
|
||||
import com.itsaky.lsp.java.rewrite.RemoveMethod;
|
||||
import com.itsaky.lsp.java.rewrite.Rewrite;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.visitors.FindMethodDeclarationAt;
|
||||
import com.itsaky.lsp.java.visitors.FindTypeDeclarationAt;
|
||||
import com.itsaky.lsp.models.CodeActionItem;
|
||||
|
||||
@@ -24,17 +24,17 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.api.ICompletionProvider;
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.FileStore;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.SourceFileObject;
|
||||
import com.itsaky.lsp.java.StringSearch;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.java.compiler.SourceFileObject;
|
||||
import com.itsaky.lsp.java.utils.StringSearch;
|
||||
import com.itsaky.lsp.java.rewrite.AddImport;
|
||||
import com.itsaky.lsp.java.utils.EditHelper;
|
||||
import com.itsaky.lsp.java.utils.Extractors;
|
||||
import com.itsaky.lsp.java.utils.ScopeHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.visitors.FindCompletionsAt;
|
||||
import com.itsaky.lsp.java.visitors.PruneMethodBodies;
|
||||
import com.itsaky.lsp.models.Command;
|
||||
|
||||
@@ -20,14 +20,14 @@ package com.itsaky.lsp.java.providers;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.itsaky.lsp.api.ISignatureHelpProvider;
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.utils.FindHelper;
|
||||
import com.itsaky.lsp.java.MarkdownHelper;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.utils.MarkdownHelper;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.java.utils.ScopeHelper;
|
||||
import com.itsaky.lsp.java.utils.ShortTypePrinter;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.visitors.FindInvocationAt;
|
||||
import com.itsaky.lsp.models.ParameterInformation;
|
||||
import com.itsaky.lsp.models.SignatureHelp;
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.utils.FindHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
+2
-3
@@ -17,11 +17,10 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.utils.EditHelper;
|
||||
import com.itsaky.lsp.java.utils.FindHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.java.visitors.FindVariableAt;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.utils.EditHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.visitors.FindMethodCallAt;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.utils.EditHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.java.utils.EditHelper;
|
||||
import com.itsaky.lsp.java.utils.FindHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.java.utils.EditHelper;
|
||||
import com.itsaky.lsp.java.utils.FindHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.visitors.FindTypeDeclarationAt;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.java.utils.EditHelper;
|
||||
import com.itsaky.lsp.java.visitors.FindTypeDeclarationAt;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.utils.FindHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
*/
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.java.utils.EditHelper;
|
||||
import com.itsaky.lsp.java.utils.FindHelper;
|
||||
import com.itsaky.lsp.java.utils.SynchronizedTask;
|
||||
import com.itsaky.lsp.java.compiler.SynchronizedTask;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
import com.sun.source.tree.MethodTree;
|
||||
import com.sun.source.util.Trees;
|
||||
|
||||
@@ -17,12 +17,10 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.models.Range;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.itsaky.lsp.java.rewrite;
|
||||
|
||||
import com.itsaky.lsp.java.CompilerProvider;
|
||||
import com.itsaky.lsp.java.compiler.CompilerProvider;
|
||||
import com.itsaky.lsp.models.TextEdit;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
+20
-1
@@ -1,4 +1,23 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.utils;
|
||||
|
||||
import com.itsaky.lsp.java.FileStore;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package com.itsaky.lsp.java.utils;
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.ParseTask;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.itsaky.lsp.java.parser.ParseTask;
|
||||
import com.itsaky.lsp.java.visitors.FindTypeDeclarationNamed;
|
||||
import com.itsaky.lsp.models.Location;
|
||||
import com.itsaky.lsp.models.Position;
|
||||
|
||||
+19
-2
@@ -1,4 +1,21 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.utils;
|
||||
|
||||
import com.itsaky.lsp.models.MarkupContent;
|
||||
import com.itsaky.lsp.models.MarkupKind;
|
||||
@@ -194,7 +211,7 @@ public class MarkdownHelper {
|
||||
}
|
||||
|
||||
/** If `commentText` looks like HTML, convert it to markdown */
|
||||
static String asMarkdown(String commentText) {
|
||||
public static String asMarkdown(String commentText) {
|
||||
if (isHtml(commentText)) {
|
||||
commentText = htmlToMarkdown(commentText);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.utils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import com.itsaky.androidide.utils.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class ScanClassPath {
|
||||
|
||||
public static Set<String> classPathTopLevelClasses(Set<Path> classPath) {
|
||||
LOG.info(String.format(Locale.getDefault (), "Searching for top-level classes in %d classpath locations", classPath.size()));
|
||||
|
||||
URL[] urls = classPath.stream().map(ScanClassPath::toUrl).toArray(URL[]::new);
|
||||
ClassLoader classLoader = new URLClassLoader(urls, null);
|
||||
|
||||
ClassPath scanner;
|
||||
|
||||
try {
|
||||
scanner = ClassPath.from(classLoader);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Set<String> classes = new HashSet<> ();
|
||||
for (ClassPath.ClassInfo c : scanner.getTopLevelClasses()) {
|
||||
classes.add(c.getName());
|
||||
}
|
||||
|
||||
LOG.info(String.format(Locale.ROOT, "Found %d classes in classpath", classes.size()));
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static URL toUrl(@NonNull Path p) {
|
||||
try {
|
||||
return p.toUri().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger LOG = Logger.instance ("ScanClassPath");
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.itsaky.lsp.java.utils;
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.sun.source.tree.Scope;
|
||||
import com.sun.source.util.Trees;
|
||||
|
||||
|
||||
+28
-9
@@ -1,4 +1,23 @@
|
||||
package com.itsaky.lsp.java;
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.lsp.java.utils;
|
||||
|
||||
import com.itsaky.lsp.java.FileStore;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -150,7 +169,7 @@ public class StringSearch {
|
||||
return startsWord (text, offset) && endsWord (text, offset + pattern.length - 1);
|
||||
}
|
||||
|
||||
int nextWord (String text) {
|
||||
private int nextWord (String text) {
|
||||
return nextWord (text.getBytes ());
|
||||
}
|
||||
|
||||
@@ -218,7 +237,7 @@ public class StringSearch {
|
||||
private static final ByteBuffer SEARCH_BUFFER = ByteBuffer.allocateDirect (1024 * 1024);
|
||||
|
||||
// TODO cache the progress made by searching shorter queries
|
||||
static boolean containsWordMatching (Path java, String query) {
|
||||
public static boolean containsWordMatching (Path java, String query) {
|
||||
if (FileStore.activeDocuments ().contains (java)) {
|
||||
String text = FileStore.contents (java);
|
||||
return matchesTitleCase (text, query);
|
||||
@@ -240,7 +259,7 @@ public class StringSearch {
|
||||
}
|
||||
}
|
||||
|
||||
static boolean containsWord (Path java, String query) {
|
||||
public static boolean containsWord (Path java, String query) {
|
||||
StringSearch search = new StringSearch (query);
|
||||
if (FileStore.activeDocuments ().contains (java)) {
|
||||
byte[] text = FileStore.contents (java).getBytes ();
|
||||
@@ -349,7 +368,7 @@ public class StringSearch {
|
||||
return Character.isAlphabetic (c) || Character.isDigit (c) || c == '_' || c == '$';
|
||||
}
|
||||
|
||||
static boolean containsType (Path file, TypeElement el) {
|
||||
public static boolean containsType (Path file, TypeElement el) {
|
||||
switch (el.getKind ()) {
|
||||
case INTERFACE:
|
||||
return containsInterface (file, el.getSimpleName ().toString ());
|
||||
@@ -381,13 +400,13 @@ public class StringSearch {
|
||||
}
|
||||
|
||||
// TODO this doesn't work for inner classes, eliminate
|
||||
static String mostName (String name) {
|
||||
public static String mostName (String name) {
|
||||
int lastDot = name.lastIndexOf ('.');
|
||||
return lastDot == -1 ? "" : name.substring (0, lastDot);
|
||||
}
|
||||
|
||||
// TODO this doesn't work for inner classes, eliminate
|
||||
static String lastName (String name) {
|
||||
public static String lastName (String name) {
|
||||
int i = name.lastIndexOf ('.');
|
||||
if (i == -1) {
|
||||
return name;
|
||||
@@ -396,7 +415,7 @@ public class StringSearch {
|
||||
}
|
||||
}
|
||||
|
||||
static String fileName (URI uri) {
|
||||
public static String fileName (URI uri) {
|
||||
String[] parts = uri.toString ().split ("/");
|
||||
if (parts.length == 0) {
|
||||
return "";
|
||||
@@ -404,7 +423,7 @@ public class StringSearch {
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
|
||||
static String packageName (Path file) {
|
||||
public static String packageName (Path file) {
|
||||
Pattern packagePattern = Pattern.compile ("^package +(.*);");
|
||||
Pattern startOfClass = Pattern.compile ("^[\\w ]*class +\\w+");
|
||||
try (BufferedReader lines = FileStore.lines (file)) {
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.itsaky.lsp.java.visitors;
|
||||
|
||||
import com.itsaky.lsp.java.CompileTask;
|
||||
import com.itsaky.lsp.java.compiler.CompileTask;
|
||||
import com.itsaky.lsp.java.utils.FindHelper;
|
||||
import com.sun.source.tree.*;
|
||||
import com.sun.source.util.*;
|
||||
|
||||
Reference in New Issue
Block a user