Skip to content

Commit

Permalink
Add new aliases for sysout and syserr snippets
Browse files Browse the repository at this point in the history
Signed-off-by: Hope Hadfield <[email protected]>
  • Loading branch information
hopehadfield authored and rgrunber committed Oct 25, 2023
1 parent 9c5cb1f commit 7f75fbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public enum CodeSnippetTemplate {
SOUTM(TemplatePreferences.SOUTM_ID, JavaContextType.ID_STATEMENTS, TemplatePreferences.SYSTRACE_CONTENT, TemplatePreferences.SYSTRACE_DESCRIPTION),
ITER(TemplatePreferences.ITER_ID, JavaContextType.ID_STATEMENTS, TemplatePreferences.FOREACH_CONTENT, TemplatePreferences.FOREACH_DESCRIPTION),
PSVM(TemplatePreferences.PSVM_ID, JavaContextType.ID_MEMBERS, TemplatePreferences.MAIN_CONTENT, TemplatePreferences.MAIN_DESCRIPTION),
PRINT(TemplatePreferences.PRINT_ID, JavaContextType.ID_STATEMENTS, TemplatePreferences.SYSOUT_CONTENT, TemplatePreferences.SYSOUT_DESCRIPTION),
SYS_OUT(TemplatePreferences.SYS_OUT_ID, "System.out.println()", JavaContextType.ID_STATEMENTS, TemplatePreferences.SYSOUT_CONTENT, TemplatePreferences.SYSOUT_DESCRIPTION),
SYS_ERR(TemplatePreferences.SYS_ERR_ID, "System.err.println()", JavaContextType.ID_STATEMENTS, TemplatePreferences.SYSERR_CONTENT, TemplatePreferences.SYSERR_DESCRIPTION),
PUBLIC_MAIN(TemplatePreferences.PUBLIC_MAIN_ID, "public static void main(String[] args)", JavaContextType.ID_MEMBERS, TemplatePreferences.MAIN_CONTENT, TemplatePreferences.MAIN_DESCRIPTION);

//@formatter:on
Expand Down Expand Up @@ -109,7 +110,8 @@ class TemplatePreferences {
public static final String STATICMETHOD_ID = "org.eclipse.jdt.ls.templates.staticmethod";
public static final String NEW_ID = "org.eclipse.jdt.ls.templates.new";
public static final String FIELD_ID = "org.eclipse.jdt.ls.templates.field";
public static final String PRINT_ID = "org.eclipse.jdt.ls.templates.print";
public static final String SYS_OUT_ID = "org.eclipse.jdt.ls.templates.sys_out";
public static final String SYS_ERR_ID = "org.eclipse.jdt.ls.templates.sys_err";
public static final String PUBLIC_MAIN_ID = "org.eclipse.jdt.ls.templates.publicmain";

// DefaultContents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3705,7 +3705,7 @@ public void testCompletion_MatchCaseFirstLetter() throws Exception {
CompletionList list = requestCompletions(unit, " i");
assertFalse(list.getItems().isEmpty());
boolean hasUpperCase = list.getItems().stream()
.anyMatch(t -> Character.isUpperCase(t.getLabel().charAt(0)));
.anyMatch(t -> t.getKind() != CompletionItemKind.Snippet && Character.isUpperCase(t.getLabel().charAt(0)));
assertFalse(hasUpperCase);
} finally {
preferenceManager.getPreferences().setCompletionMatchCaseMode(CompletionMatchCaseMode.OFF);
Expand Down Expand Up @@ -3831,7 +3831,7 @@ void f() {
}

@Test
public void testCompletion_printSnippet() throws JavaModelException {
public void testCompletion_printSnippets() throws JavaModelException {
preferenceManager.getPreferences().setCompletionLazyResolveTextEditEnabled(false);
ICompilationUnit unit = getWorkingCopy(
//@formatter:off
Expand All @@ -3846,10 +3846,12 @@ void f() {
//@formatter:on
CompletionList list = requestCompletions(unit, "prin");
assertNotNull(list);
assertEquals(4, list.getItems().size());
CompletionItem item = list.getItems().get(3);
assertEquals("print", item.getLabel());
assertEquals(new Range(new Position(2, 2), new Position(2, 6)), item.getTextEdit().map(TextEdit::getRange, InsertReplaceEdit::getReplace));
CompletionItem outItem = list.getItems().get(3);
CompletionItem errItem = list.getItems().get(4);
assertEquals("System.out.println()", outItem.getLabel());
assertEquals("System.err.println()", errItem.getLabel());
assertEquals(new Range(new Position(2, 2), new Position(2, 6)), outItem.getTextEdit().map(TextEdit::getRange, InsertReplaceEdit::getReplace));
assertEquals(new Range(new Position(2, 2), new Position(2, 6)), errItem.getTextEdit().map(TextEdit::getRange, InsertReplaceEdit::getReplace));
}

@Test
Expand Down

0 comments on commit 7f75fbb

Please sign in to comment.