Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add syserr postfix completion #2620

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum PostfixTemplate {
NNULL(PostfixPreferences.NNULL_ID, JavaPostfixContextType.ID_ALL, PostfixPreferences.NNULL_CONTENT, PostfixPreferences.NNULL_DESCRIPTION),
NULL(PostfixPreferences.NULL_ID, JavaPostfixContextType.ID_ALL, PostfixPreferences.NULL_CONTENT, PostfixPreferences.NULL_DESCRIPTION),
SYSOUT(PostfixPreferences.SYSOUT_ID, JavaPostfixContextType.ID_ALL, PostfixPreferences.SYSOUT_CONTENT, PostfixPreferences.SYSOUT_DESCRIPTION),
SYSERR(PostfixPreferences.SYSERR_ID, JavaPostfixContextType.ID_ALL, PostfixPreferences.SYSERR_CONTENT, PostfixPreferences.SYSERR_DESCRIPTION),
THROW(PostfixPreferences.THROW_ID, JavaPostfixContextType.ID_ALL, PostfixPreferences.THROW_CONTENT, PostfixPreferences.THROW_DESCRIPTION),
VAR(PostfixPreferences.VAR_ID, JavaPostfixContextType.ID_ALL, PostfixPreferences.VAR_CONTENT, PostfixPreferences.VAR_DESCRIPTION),
WHILE(PostfixPreferences.WHILE_ID, JavaPostfixContextType.ID_ALL, PostfixPreferences.WHILE_CONTENT, PostfixPreferences.WHILE_DESCRIPTION);
Expand Down Expand Up @@ -63,6 +64,7 @@ class PostfixPreferences {
public static final String NNULL_ID = "org.eclipse.jdt.postfixcompletion.nnull";
public static final String NULL_ID = "org.eclipse.jdt.postfixcompletion.null";
public static final String SYSOUT_ID = "org.eclipse.jdt.postfixcompletion.sysout";
public static final String SYSERR_ID = "org.eclipse.jdt.postfixcompletion.syserr";
public static final String THROW_ID = "org.eclipse.jdt.postfixcompletion.throw";
public static final String VAR_ID = "org.eclipse.jdt.postfixcompletion.var";
public static final String WHILE_ID = "org.eclipse.jdt.postfixcompletion.while";
Expand Down Expand Up @@ -91,6 +93,7 @@ class PostfixPreferences {
"\t$${0}\n" +
"}";
public static final String SYSOUT_CONTENT = "System.out.println(${i:inner_expression(java.lang.Object)}${});$${0}";
public static final String SYSERR_CONTENT = "System.err.println(${i:inner_expression(java.lang.Object)}${});$${0}";
public static final String THROW_CONTENT = "throw ${true:inner_expression(java.lang.Throwable)};";
public static final String VAR_CONTENT = "${field:newType(inner_expression)} $${1:${var:newName(inner_expression)}} = ${inner_expression};$${0}";
public static final String WHILE_CONTENT = "while (${i:inner_expression(boolean)}) {\n" +
Expand All @@ -107,6 +110,7 @@ class PostfixPreferences {
public static final String NNULL_DESCRIPTION = "Creates an if statement and checks if the expression does not resolve to null";
public static final String NULL_DESCRIPTION = "Creates an if statement which checks if expression resolves to null";
public static final String SYSOUT_DESCRIPTION = "Sends the affected object to a System.out.println(..) call";
public static final String SYSERR_DESCRIPTION = "Sends the affected object to a System.err.println(..) call";
public static final String THROW_DESCRIPTION = "Throws the given Exception";
public static final String VAR_DESCRIPTION = "Creates a new variable";
public static final String WHILE_DESCRIPTION = "Creates a while loop";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,33 @@ public void test_sysout_object() throws JavaModelException {
assertEquals(new Range(new Position(4, 2), new Position(4, 12)), range);
}

@Test
public void test_syserr_object() throws JavaModelException {
//@formatter:off
ICompilationUnit unit = getWorkingCopy(
"src/org/sample/Test.java",
"package org.sample;\n" +
"public class Test {\n" +
" public void testMethod(String a) {\n" +
" Boolean foo = true;\n" +
" foo.syserr" +
" }\n" +
"}"
);
//@formatter:on
CompletionList list = requestCompletions(unit, "foo.syserr");

assertNotNull(list);

List<CompletionItem> items = new ArrayList<>(list.getItems());
CompletionItem item = items.get(0);
assertEquals("syserr", item.getLabel());
assertEquals(item.getInsertText(), "System.err.println(foo);${0}");
assertEquals(item.getInsertTextFormat(), InsertTextFormat.Snippet);
Range range = item.getAdditionalTextEdits().get(0).getRange();
assertEquals(new Range(new Position(4, 2), new Position(4, 12)), range);
}

@Test
public void test_throw() throws JavaModelException {
//@formatter:off
Expand Down