Skip to content

Commit

Permalink
Intellisense not work on close source jar
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
  • Loading branch information
snjeza committed Dec 26, 2019
1 parent e9c903b commit ab53584
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.jdt.core.CompletionProposal;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
import org.eclipse.jdt.internal.corext.template.java.SignatureUtil;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.handlers.CompletionResolveHandler;
Expand Down Expand Up @@ -137,7 +138,14 @@ private StringBuilder appendUnboundedParameterList(StringBuilder buffer, Complet
// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
// gets fixed.
char[] signature= SignatureUtil.fix83600(methodProposal.getSignature());
char[][] parameterNames= methodProposal.findParameterNames(null);
char[][] parameterNames;
try {
parameterNames = methodProposal.findParameterNames(null);
} catch (Exception e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
parameterNames = CompletionEngine.createDefaultParameterNames(Signature.getParameterCount(signature));
methodProposal.setParameterNames(parameterNames);
}
char[][] parameterTypes= Signature.getParameterTypes(signature);

for (int i= 0; i < parameterTypes.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
import org.eclipse.jdt.internal.corext.dom.IASTSharedValues;
import org.eclipse.jdt.internal.corext.template.java.SignatureUtil;
import org.eclipse.jdt.ls.core.internal.ChangeUtil;
Expand Down Expand Up @@ -443,7 +444,15 @@ private void appendMethodNameReplacement(StringBuilder buffer, CompletionProposa
}

private void appendGuessingCompletion(StringBuilder buffer, CompletionProposal proposal) {
char[][] parameterNames= proposal.findParameterNames(null);
char[][] parameterNames;
try {
parameterNames = proposal.findParameterNames(null);
} catch (Exception e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
char[] signature = SignatureUtil.fix83600(proposal.getSignature());
parameterNames = CompletionEngine.createDefaultParameterNames(Signature.getParameterCount(signature));
proposal.setParameterNames(parameterNames);
}

int count= parameterNames.length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,13 @@ public List<CompletionItem> getCompletionItems() {
CompletionProposalReplacementProvider proposalProvider = new CompletionProposalReplacementProvider(unit, getContext(), response.getOffset(), preferenceManager.getClientPreferences());
for (int i = 0; i < limit; i++) {
CompletionProposal proposal = proposals.get(i);
CompletionItem item = toCompletionItem(proposal, i);
proposalProvider.updateReplacement(proposal, item, '\0');
completionItems.add(item);
try {
CompletionItem item = toCompletionItem(proposal, i);
proposalProvider.updateReplacement(proposal, item, '\0');
completionItems.add(item);
} catch (Exception e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
return completionItems;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ public void appendMethodLabel(IMethod method, long flags) {
}
String[] names= null;
if (getFlag(flags, JavaElementLabels.M_PARAMETER_NAMES) && method.exists()) {
names= method.getParameterNames();
try {
names= method.getParameterNames();
} catch (Exception e) {
names = method.getRawParameterNames();
}
if (isPolymorphic) {
// handled specially below
} else if (types == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import org.eclipse.jdt.internal.corext.util.JdtFlags;
import org.eclipse.jdt.internal.corext.util.MethodOverrideTester;
import org.eclipse.jdt.internal.corext.util.SuperTypeHierarchyCache;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.hover.JavaElementLabels;

/**
Expand Down Expand Up @@ -590,7 +591,14 @@ public static String getHTMLContent(IJavaElement element, boolean useAttachedJav
if (sourceJavadoc == null || sourceJavadoc.length() == 0 || sourceJavadoc.trim().equals("{@inheritDoc}")) { //$NON-NLS-1$
if (useAttachedJavadoc) {
if (element.getOpenable().getBuffer() == null) { // only if no source available
return element.getAttachedJavadoc(null);
String attachedJavadoc;
try {
attachedJavadoc = element.getAttachedJavadoc(null);
} catch (Exception e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
return null;
}
return attachedJavadoc;
}
IMember member = null;
if (element instanceof ILocalVariable) {
Expand Down
176 changes: 176 additions & 0 deletions org.eclipse.jdt.ls.tests/projects/maven/aspose/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aspose-word-test</groupId>
<artifactId>aspose-word-test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>15.12.0</version>
<classifier>jdk16</classifier>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>15.12.0</version>
<classifier>javadoc</classifier>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.10</version>
</dependency>
<dependency>
<groupId>com.github.ngeor</groupId>
<artifactId>checkstyle-rules</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>

<!--
You can run jacoco in the default profile with:
mvn jacoco:prepare-agent test jacoco:report
-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>
</reporting>

<profiles>
<!--
This profile enables jacoco when unit tests are run.
You can run it with mvn -P jacoco test.
It also activates itself on Travis.
-->
<profile>
<id>jacoco</id>
<activation>
<property>
<name>env.TRAVIS</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<phase>validate</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<!--
For the Travis profile:
- we want to break the build on any checkstyle violation.
- we want to be able to publish coverage report to coveralls.
-->
<profile>
<id>travis</id>
<activation>
<property>
<name>env.TRAVIS</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sample;

import java.io.File;

import com.aspose.words.Document;
public final class TestJavadoc {
public static void main(String[] args) throws Exception {
File file = File.createTempFile("test", "txt");
Document doc = new Document(file.getAbsolutePath());
doc.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.Job;
Expand Down Expand Up @@ -2563,6 +2565,28 @@ public void testCompletion_FilterTypesKeepMethods() throws JavaModelException {
}
}

@Test
public void testCompletion_InvalidJavadoc() throws Exception {
importProjects("maven/aspose");
IProject project = null;
ICompilationUnit unit = null;
try {
project = ResourcesPlugin.getWorkspace().getRoot().getProject("aspose-word-test");
IJavaProject javaProject = JavaCore.create(project);
unit = (ICompilationUnit) javaProject.findElement(new Path("org/sample/TestJavadoc.java"));
unit.becomeWorkingCopy(null);
int[] loc = findCompletionLocation(unit, "doc.");
CompletionParams position = JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]));
CompletionList list = server.completion(position).join().getRight();
CompletionItem ci = list.getItems().stream().filter(item -> item.getLabel().equals("accept(DocumentVisitor visitor) : boolean")).findFirst().orElse(null);
assertNotNull(ci);
} finally {
if (unit != null) {
unit.discardWorkingCopy();
}
}
}

@Test
public void testCompletion_ConstantDefaultValue() throws JavaModelException {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ls.core.internal.ClassFileUtil;
import org.eclipse.jdt.ls.core.internal.DependencyUtil;
Expand Down Expand Up @@ -190,6 +192,32 @@ public void testMissingUnit() throws Exception {
assertEquals("Should find empty hover for " + payload, "", hover.getContents().getLeft().get(0).getLeft());
}

@Test
public void testInvalidJavadoc() throws Exception {
importProjects("maven/aspose");
IProject project = null;
ICompilationUnit unit = null;
try {
project = ResourcesPlugin.getWorkspace().getRoot().getProject("aspose-word-test");
IJavaProject javaProject = JavaCore.create(project);
IType type = javaProject.findType("org.sample.TestJavadoc");
unit = type.getCompilationUnit();
unit.becomeWorkingCopy(null);
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
TextDocumentPositionParams position = new TextDocumentPositionParams(textDocument, new Position(8, 24));
Hover hover = handler.hover(position, monitor);
assertNotNull(hover);
assertNotNull(hover.getContents());
assertEquals(1, hover.getContents().getLeft().size());
assertEquals("com.aspose.words.Document.Document(String fileName) throws Exception", hover.getContents().getLeft().get(0).getRight().getValue());
} finally {
if (unit != null) {
unit.discardWorkingCopy();
}
}
}

String createHoverRequest(String file, int line, int kar) {
URI uri = project.getFile(file).getRawLocationURI();
return createHoverRequest(uri, line, kar);
Expand Down

0 comments on commit ab53584

Please sign in to comment.