GH-1280: do not show up mapping completions on the type declaration
This commit is contained in:
@@ -20,7 +20,12 @@ public interface JavaSnippetContext {
|
||||
JavaSnippetContext BOOT_MEMBERS = (node, offset, prefix) -> node instanceof TypeDeclaration || node instanceof SimpleName;
|
||||
|
||||
JavaSnippetContext AT_ROOT_LEVEL = (node, offset, prefix) -> {
|
||||
if (node instanceof TypeDeclaration) return true;
|
||||
if (node instanceof TypeDeclaration) {
|
||||
TypeDeclaration typeNode = (TypeDeclaration) node;
|
||||
SimpleName name = typeNode.getName();
|
||||
|
||||
return offset > (name.getStartPosition() + name.getLength());
|
||||
}
|
||||
|
||||
ASTNode nodeBeforePrefix = NodeFinder.perform(node.getRoot(), offset - (prefix.length() + 1), 0);
|
||||
return nodeBeforePrefix != null && nodeBeforePrefix instanceof TypeDeclaration;
|
||||
|
||||
@@ -14,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -227,13 +228,23 @@ public class RequestMappingSnippetTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSnippetNotShowUpOnClassDeclaration() throws Exception {
|
||||
prepareCase(CONTROLLER_CLASSNAME, "@Controller", "@Controller\n<*>");
|
||||
|
||||
List<CompletionItem> completions = editor.getCompletions();
|
||||
for (CompletionItem completionItem : completions) {
|
||||
assertNotEquals("@GetMapping(..) {..}", completionItem.getLabel());
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareCase(String className, String prefix) throws Exception {
|
||||
prepareCase(className, "class " + className + " {", "class " + className + " {\n\n" + prefix);
|
||||
}
|
||||
|
||||
private void prepareCase(String className, String replace, String replaceWith) throws Exception {
|
||||
InputStream resource = this.getClass().getResourceAsStream("/test-projects/test-request-mapping-completions/src/main/java/example/" + className + ".java");
|
||||
String content = IOUtils.toString(resource);
|
||||
String content = IOUtils.toString(resource, Charset.defaultCharset());
|
||||
|
||||
content = content.replace(replace, replaceWith);
|
||||
editor = new Editor(harness, content, LanguageId.JAVA);
|
||||
|
||||
Reference in New Issue
Block a user