From 1e3eca864c38afca7f9bf7a68de0965b01d9cdf6 Mon Sep 17 00:00:00 2001 From: George Fraser Date: Mon, 1 Apr 2019 20:33:30 -0700 Subject: Dead code --- src/main/java/org/javacs/CompileFile.java | 92 ------------------------------ src/test/java/org/javacs/CodeLensTest.java | 14 ----- 2 files changed, 106 deletions(-) diff --git a/src/main/java/org/javacs/CompileFile.java b/src/main/java/org/javacs/CompileFile.java index bbe7b47..7d00270 100644 --- a/src/main/java/org/javacs/CompileFile.java +++ b/src/main/java/org/javacs/CompileFile.java @@ -5,10 +5,8 @@ import com.sun.source.util.*; import java.io.IOException; import java.net.URI; import java.util.*; -import java.util.function.Predicate; import java.util.logging.Logger; import javax.lang.model.element.*; -import org.javacs.lsp.*; public class CompileFile implements AutoCloseable { private final JavaCompilerService parent; @@ -86,60 +84,6 @@ public class CompileFile implements AutoCloseable { return Optional.of(el); } - public Optional path(Element e) { - return Optional.ofNullable(trees.getPath(e)); - } - - public Optional find(Ptr target) { - class FindPtr extends TreePathScanner { - TreePath found = null; - - boolean toStringEquals(Object left, Object right) { - return Objects.equals(Objects.toString(left, ""), Objects.toString(right, "")); - } - - /** Check if the declaration at the current path is the same symbol as `e` */ - boolean sameSymbol() { - var path = getCurrentPath(); - var el = trees.getElement(path); - return new Ptr(el).equals(target); - } - - void check() { - if (sameSymbol()) { - found = getCurrentPath(); - } - } - - @Override - public Void visitClass(ClassTree node, Void aVoid) { - check(); - return super.visitClass(node, aVoid); - } - - @Override - public Void visitMethod(MethodTree node, Void aVoid) { - check(); - // Ptr can't point inside a method - return null; - } - - @Override - public Void visitVariable(VariableTree node, Void aVoid) { - check(); - // Ptr can't point inside a method - return null; - } - } - var find = new FindPtr(); - find.scan(root, null); - return Optional.ofNullable(find.found); - } - - public Optional range(TreePath path) { - return ParseFile.range(borrow.task, contents, path); - } - private List overrides(ExecutableElement method) { var elements = borrow.task.getElements(); var types = borrow.task.getTypes(); @@ -270,41 +214,5 @@ public class CompileFile implements AutoCloseable { return sorted; } - public List allClassNames() { - var result = new ArrayList(); - class FindClasses extends TreeScanner { - @Override - public Void visitClass(ClassTree classTree, Void __) { - var className = Objects.toString(classTree.getSimpleName(), ""); - result.add(className); - return null; - } - } - root.accept(new FindClasses(), null); - return result; - } - - public Predicate> signatureMatches() { - // Precompute qualified names of all classes in this file - var thisClasses = new ArrayList(); - for (var c : root.getTypeDecls()) { - var path = trees.getPath(root, c); - var el = (TypeElement) trees.getElement(path); - var name = el.getQualifiedName().toString(); - thisClasses.add(name); - } - return i -> { - // For each pointer, check if it refers to something in this file that no longer exists - for (var ptr : i) { - if (thisClasses.contains(ptr.qualifiedClassName()) && !find(ptr).isPresent()) { - LOG.info( - String.format("`%s` refers to signature that no longer exists in %s", ptr, file.getPath())); - return false; - } - } - return true; - }; - } - private static final Logger LOG = Logger.getLogger("main"); } diff --git a/src/test/java/org/javacs/CodeLensTest.java b/src/test/java/org/javacs/CodeLensTest.java index 48f8803..9da33d2 100644 --- a/src/test/java/org/javacs/CodeLensTest.java +++ b/src/test/java/org/javacs/CodeLensTest.java @@ -72,20 +72,6 @@ public class CodeLensTest { assertThat(titles, not(hasItem("4:0 references"))); } - @Test - public void signatureMatches() { - var file = "/org/javacs/example/ConstructorRefs.java"; - var uri = FindResource.uri(file); - var compile = server.compiler.compileFile(uri); - var signatureMatches = compile.signatureMatches(); - - var good = List.of(new Ptr("org.javacs.example/ConstructorRefs#(int)")); - assertTrue(signatureMatches.test(good)); - - var bad = List.of(new Ptr("org.javacs.example/ConstructorRefs#(int,int)")); - assertFalse(signatureMatches.test(bad)); - } - @Test public void placement() { var lenses = lenses("/org/javacs/example/CodeLensPlacement.java"); -- cgit v1.2.3