diff options
author | George Fraser <george@fivetran.com> | 2019-01-08 20:50:25 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2019-01-08 20:50:25 -0800 |
commit | 04e4f359cb80c7b8e450103dc7331f6deb363872 (patch) | |
tree | b164426b6d85ba9bdcca10205eb395105efb2c47 /src/main/java | |
parent | 938fce4f8d2630d456caea03b0c178508680e945 (diff) | |
download | java-language-server-04e4f359cb80c7b8e450103dc7331f6deb363872.zip |
Fixes
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/javacs/Docs.java | 2 | ||||
-rw-r--r-- | src/main/java/org/javacs/JavaCompilerService.java | 40 |
2 files changed, 14 insertions, 28 deletions
diff --git a/src/main/java/org/javacs/Docs.java b/src/main/java/org/javacs/Docs.java index 29d4c28..07c81e2 100644 --- a/src/main/java/org/javacs/Docs.java +++ b/src/main/java/org/javacs/Docs.java @@ -42,7 +42,6 @@ public class Docs { // Find the file el was declared in var className = ptr.qualifiedClassName(); try { - // TODO should get current contents of open files from FileStore var fromSourcePath = fileManager.getJavaFileForInput( StandardLocation.SOURCE_PATH, className, JavaFileObject.Kind.SOURCE); @@ -53,7 +52,6 @@ public class Docs { for (var module : Classes.JDK_MODULES) { var moduleLocation = fileManager.getLocationForModule(StandardLocation.MODULE_SOURCE_PATH, module); if (moduleLocation == null) continue; - // TODO should get current contents of open files from FileStore var fromModuleSourcePath = fileManager.getJavaFileForInput(moduleLocation, className, JavaFileObject.Kind.SOURCE); if (fromModuleSourcePath != null) { diff --git a/src/main/java/org/javacs/JavaCompilerService.java b/src/main/java/org/javacs/JavaCompilerService.java index 1087e5f..80fbd2b 100644 --- a/src/main/java/org/javacs/JavaCompilerService.java +++ b/src/main/java/org/javacs/JavaCompilerService.java @@ -8,7 +8,6 @@ import java.net.URI; import java.nio.file.*; import java.util.*; import java.util.logging.Logger; -import java.util.regex.Pattern; import java.util.stream.Collectors; import javax.lang.model.element.*; import javax.tools.*; @@ -234,7 +233,13 @@ public class JavaCompilerService { } boolean method() { - return getCurrentPath().getParentPath().getLeaf() instanceof MethodInvocationTree; + var leaf = getCurrentPath().getLeaf(); + var parent = getCurrentPath().getParentPath().getLeaf(); + if (parent instanceof MethodInvocationTree) { + var method = (MethodInvocationTree) parent; + return method.getMethodSelect() == leaf; + } + return false; } @Override @@ -386,31 +391,14 @@ public class JavaCompilerService { /** Find the file `e` was declared in */ private Optional<URI> findDeclaringFile(TypeElement e) { var name = e.getQualifiedName().toString(); - var lastDot = name.lastIndexOf('.'); - var packageName = lastDot == -1 ? "" : name.substring(0, lastDot); - var className = name.substring(lastDot + 1); - var isPublic = e.getModifiers().contains(Modifier.PUBLIC); - for (var file : FileStore.list(packageName)) { - // Public classes have to be declared in files named ClassName.java - if (isPublic && !file.getFileName().toString().equals(className + ".java")) continue; - if (containsTopLevelDeclaration(file, className)) { - return Optional.of(file.toUri()); - } - } - return Optional.empty(); - } - - private boolean containsTopLevelDeclaration(Path file, String simpleClassName) { - var find = Pattern.compile("\\b(class|interface|enum) +" + simpleClassName + "\\b"); - try (var lines = FileStore.lines(file)) { - for (var line = lines.readLine(); line != null; line = lines.readLine()) { - if (find.matcher(line).find()) return true; - line = lines.readLine(); - } - } catch (IOException e) { - throw new RuntimeException(e); + JavaFileObject file; + try { + file = fileManager.getJavaFileForInput(StandardLocation.SOURCE_PATH, name, JavaFileObject.Kind.SOURCE); + } catch (IOException err) { + throw new RuntimeException(err); } - return false; + if (file == null) return Optional.empty(); + return Optional.of(file.toUri()); } private Collection<Path> possibleFiles(Element to) { |