Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
some styling cleanup, etc for new javaDoc groovy completion arg
Browse files Browse the repository at this point in the history
refs #496
  • Loading branch information
ervandew committed Jan 29, 2017
1 parent 01b036c commit 7723c1b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2014
* Copyright (C) 2014 - 2016
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -55,12 +55,9 @@
* Command which provides code completion for groovy files.
*
* @param javaDoc
* The {@code javaDoc} parameter specifies if a javaDoc URI should be returned
* for each of the completion proposals.
* If {@code javaDoc} = true for each completion a eclipse style java doc URI
* will be returned which can be converted to java doc over the
* {@code java_element_doc} command.
* If {@code javaDoc} = false no javadoc URI will be returned
* If {@code javaDoc} is set, then each completion result will include an
* eclipse style javadoc URI which can supplied to the
* {@code java_element_doc} command to obtain the javadoc content.
*/
@Command(
name = "groovy_complete",
Expand All @@ -70,7 +67,7 @@
"REQUIRED o offset ARG," +
"REQUIRED e encoding ARG," +
"REQUIRED l layout ARG," +
"OPTIONAL j javaDoc ARG NOARG"
"OPTIONAL j javaDoc NOARG"
)
public final class CodeCompleteCommand
extends org.eclim.plugin.jdt.command.complete.CodeCompleteCommand
Expand Down Expand Up @@ -116,8 +113,8 @@ protected List<CodeCompleteResult> getCompletionResults(
boolean javaDocEnabled = commandLine.hasOption(Options.JAVA_DOC_OPTION);
ArrayList<CodeCompleteResult> results = new ArrayList<CodeCompleteResult>();
for(ICompletionProposal proposal : proposals){
results.add(createCompletionResult((IJavaCompletionProposal) proposal,
javaDocEnabled));
results.add(createCompletionResult(
(IJavaCompletionProposal)proposal, javaDocEnabled));
}
Collections.sort(results, COMPLETION_COMPARATOR);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2014 Eric Van Dewoestine
* Copyright (C) 2014 - 2016 Eric Van Dewoestine
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,9 +16,6 @@
*/
package org.eclim.plugin.groovy.command.complete;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;
import java.util.Map;

Expand All @@ -28,6 +25,8 @@

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Test case for CodeCompleteCommand.
*
Expand All @@ -36,9 +35,9 @@
public class CodeCompleteCommandTest
{
private static final String TEST_FILE =
"src/org/eclim/test/complete/TestCompletion.groovy";
"src/org/eclim/test/complete/TestCompletion.groovy";
private static final String TEST_JAVA_DOC_FILE =
"src/org/eclim/test/complete/TestCompletionJavaDoc.groovy";
"src/org/eclim/test/complete/TestCompletionJavaDoc.groovy";

@Test
@SuppressWarnings("unchecked")
Expand All @@ -63,62 +62,40 @@ public void completionByPrefix()
}

@Test
@SuppressWarnings("unchecked")
public void javaDoc(){
assertTrue("Groovy project doesn't exist.",
Eclim.projectExists(Groovy.TEST_PROJECT));
int count = getJavaDocCount("anything");
assertJavaDocPresent(count);
}

@Test
public void JavaDocEmpty(){
assertTrue("Groovy project doesn't exist.",
Eclim.projectExists(Groovy.TEST_PROJECT));
int count = getJavaDocCount("");
assertJavaDocPresent(count);
}

private void assertJavaDocPresent(int count)
{
// We do not compare with the actual number to make
// the test more robust ==> if something in eclipse
// changes and some elements do not exist anymore /
// do not have a javaDoc element the test still
// succeeds.
int minimalCount = 50;
assertTrue("We should receive some JavaDoc links", count > minimalCount);
}

@Test
public void noJavaDoc(){
assertTrue("Groovy project doesn't exist.",
Eclim.projectExists(Groovy.TEST_PROJECT));
int count = getJavaDocCountNoJavaDocFlag();
assertEquals("We should receive no JavaDoc links, since the java doc flag is not set", 0, count);
}

@SuppressWarnings("unchecked")
private int getJavaDocCount(String javaDocArg){
assertTrue("Groovy project doesn't exist.",
Eclim.projectExists(Groovy.TEST_PROJECT));

List<Map<String, String>> results = (List<Map<String, String>>) Eclim
.execute(new String[] { "groovy_complete", "-p", Groovy.TEST_PROJECT, "-f",
TEST_JAVA_DOC_FILE, "-l", "compact", "-o", "99", "-e", "utf-8", "-j", javaDocArg });
List<Map<String, String>> results = (List<Map<String, String>>)
Eclim.execute(new String[]{
"groovy_complete", "-p", Groovy.TEST_PROJECT,
"-f", TEST_JAVA_DOC_FILE, "-l", "compact", "-o", "99", "-e", "utf-8",
"-j"
});

return countJavaDocOccurence(results);
// just check that at least some results have a javaDocURI in the response
// (number of results can vary by the user's environment).
int count = countJavaDocOccurence(results);
assertTrue(count > 0);
}

@Test
@SuppressWarnings("unchecked")
private int getJavaDocCountNoJavaDocFlag(){
public void noJavaDoc(){
assertTrue("Groovy project doesn't exist.",
Eclim.projectExists(Groovy.TEST_PROJECT));

List<Map<String, String>> results = (List<Map<String, String>>) Eclim
.execute(new String[] { "groovy_complete", "-p", Groovy.TEST_PROJECT, "-f",
TEST_JAVA_DOC_FILE, "-l", "compact", "-o", "99", "-e", "utf-8",});
List<Map<String, String>> results = (List<Map<String, String>>)
Eclim.execute(new String[]{
"groovy_complete", "-p", Groovy.TEST_PROJECT,
"-f", TEST_JAVA_DOC_FILE, "-l", "compact", "-o", "99", "-e", "utf-8"
});

return countJavaDocOccurence(results);
int count = countJavaDocOccurence(results);
assertEquals(count, 0);
}

private int countJavaDocOccurence(List<Map<String, String>> results)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2005 - 2014 Eric Van Dewoestine
* Copyright (C) 2005 - 2016 Eric Van Dewoestine
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -135,7 +135,7 @@ protected CodeCompleteResult createCompletionResult(
String completion = null;
String menu = proposal.getDisplayString();
Integer offset = null;
String javaDocURI = "";
String javaDocURI = null;

int kind = -1;
if(proposal instanceof JavaCompletionProposal){
Expand Down Expand Up @@ -227,10 +227,9 @@ private String getJavaDocLink(IJavaCompletionProposal proposal)
IJavaElement javaElement = getJavaElement(proposal);
if (javaElement == null) {
return "";
} else {
return JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME,
javaElement);
}
return JavaElementLinks.createURI(
JavaElementLinks.JAVADOC_SCHEME, javaElement);
} catch (Exception e) {
logger.error("Could not calculate the javaDoc link", e);
return "";
Expand All @@ -242,8 +241,7 @@ private String getJavaDocLink(IJavaCompletionProposal proposal)
* {@code proposal} does not contain an {@code IJavaElement} null will be
* returned.
*
* @param proposal
* The proposal from which we want the IJavaElement
* @param proposal The proposal from which we want the IJavaElement
* @return IJavaElement The IJavaElement which is behind the {@code proposal}
* if there is one.
* @throws NoSuchMethodException
Expand All @@ -252,29 +250,30 @@ private String getJavaDocLink(IJavaCompletionProposal proposal)
* @throws JavaModelException
*/
private IJavaElement getJavaElement(IJavaCompletionProposal proposal)
throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException, JavaModelException
throws NoSuchMethodException,
IllegalAccessException,
InvocationTargetException,
JavaModelException
{
if (!(AbstractJavaCompletionProposal.class
.isAssignableFrom(proposal.getClass())))
{
// We do not throw an exception here since it may be that only some
// elements cannot create a javaDocLink and not all of them.
logger.error("The proposal " + proposal.toString() +
" does not inherit from class AbstractJavaCompletionProposal." +
" ==> We cannot create the javaDoc link.");
" does not inherit from class AbstractJavaCompletionProposal," +
" so a javaDoc link cannot be created.");
return null;
}
Method getProposal = AbstractJavaCompletionProposal.class
.getDeclaredMethod("getProposalInfo");

getProposal.setAccessible(true);
ProposalInfo proposalInfo = (ProposalInfo) getProposal
.invoke((AbstractJavaCompletionProposal) proposal);
ProposalInfo proposalInfo = (ProposalInfo)getProposal
.invoke((AbstractJavaCompletionProposal) proposal);
if (proposalInfo != null) {
return proposalInfo.getJavaElement();
} else {
return null;
}
return null;
}
}

0 comments on commit 7723c1b

Please sign in to comment.