Skip to content

Commit

Permalink
Add support for completion using Java's Content Assist Favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 6, 2017
1 parent e6110f5 commit be25d6f
Show file tree
Hide file tree
Showing 19 changed files with 972 additions and 875 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ package org.codehaus.groovy.eclipse.codeassist.tests

import org.codehaus.groovy.eclipse.codeassist.requestor.GroovyCompletionProposalComputer
import org.eclipse.jdt.core.ICompilationUnit
import org.eclipse.jdt.ui.PreferenceConstants
import org.eclipse.jface.text.Document
import org.eclipse.jface.text.contentassist.ICompletionProposal
import org.junit.After
import org.junit.Test

/**
* Tests that Field completions are working properly.
*/
final class FieldCompletionTests extends CompletionTestSuite {

@After
void tearDown() {
setJavaPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, '')
}

@Test
void testSafeDeferencing() {
String contents = "public class SomeClass {\nint someProperty\nvoid someMethod() { someProperty?.x}}"
Expand Down Expand Up @@ -361,4 +366,58 @@ final class FieldCompletionTests extends CompletionTestSuite {
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "."), GroovyCompletionProposalComputer)
proposalExists(proposals, "forName", 2) // two public and one private
}

@Test
void testImportStaticField() {
String contents = '''\
import static java.util.regex.Pattern.DOTALL
DOT
'''.stripIndent()
ICompletionProposal[] proposals = performContentAssist(addGroovySource(contents), getLastIndexOf(contents, 'DOT'), GroovyCompletionProposalComputer)
proposalExists(proposals, 'DOTALL', 1)
}

@Test
void testImportStaticStarField() {
String contents = '''\
import static java.util.regex.Pattern.*
DOT
'''.stripIndent()
ICompletionProposal[] proposals = performContentAssist(addGroovySource(contents), getLastIndexOf(contents, 'DOT'), GroovyCompletionProposalComputer)
proposalExists(proposals, 'DOTALL', 1)
}

@Test
void testFavoriteStaticField() {
setJavaPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, 'java.util.regex.Pattern.DOTALL')

String contents = '''\
DOT
'''.stripIndent()
ICompletionProposal[] proposals = performContentAssist(addGroovySource(contents), getLastIndexOf(contents, 'DOT'), GroovyCompletionProposalComputer)
proposalExists(proposals, 'DOTALL', 1)

applyProposalAndCheck(new Document(contents), findFirstProposal(proposals, 'DOTALL', false), '''\
|import static java.util.regex.Pattern.DOTALL
|
|DOTALL
|'''.stripMargin())
}

@Test
void testFavoriteStaticStarField() {
setJavaPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, 'java.util.regex.Pattern.*')

String contents = '''\
DOT
'''.stripIndent()
ICompletionProposal[] proposals = performContentAssist(addGroovySource(contents), getLastIndexOf(contents, 'DOT'), GroovyCompletionProposalComputer)
proposalExists(proposals, 'DOTALL', 1)

applyProposalAndCheck(new Document(contents), findFirstProposal(proposals, 'DOTALL', false), '''\
|import static java.util.regex.Pattern.DOTALL
|
|DOTALL
|'''.stripMargin())
}
}
Loading

0 comments on commit be25d6f

Please sign in to comment.