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

Support java.lang.Object for sysout postfix completion #2559

Merged
merged 1 commit into from
Mar 28, 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 @@ -90,7 +90,7 @@ class PostfixPreferences {
public static final String NULL_CONTENT = "if (${i:inner_expression(java.lang.Object,array)} == null) {\n" +
"\t$${0}\n" +
"}";
public static final String SYSOUT_CONTENT = "System.out.println(${i:inner_expression(java.lang.String)}${});$${0}";
public static final String SYSOUT_CONTENT = "System.out.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 @@ -106,7 +106,7 @@ class PostfixPreferences {
public static final String IF_DESCRIPTION = "Creates a if statement";
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 string to a System.out.println(..) call";
public static final String SYSOUT_DESCRIPTION = "Sends the affected object to a System.out.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 @@ -130,7 +130,9 @@ public Either<List<CompletionItem>, CompletionList> completion(CompletionParams

public void onDidCompletionItemSelect(String requestId, String proposalId) throws CoreException {
triggerSignatureHelp();

if (proposalId.isEmpty() || requestId.isEmpty()) {
return;
}
int pId = Integer.parseInt(proposalId);
long rId = Long.parseLong(requestId);
CompletionResponse completionResponse = CompletionResponses.get(rId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,33 @@ public void test_sysout() throws JavaModelException {
assertEquals(new Range(new Position(3, 2), new Position(3, 10)), range);
}

@Test
public void test_sysout_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.sysout" +
" }\n" +
"}"
);
//@formatter:on
CompletionList list = requestCompletions(unit, "foo.sysout");

assertNotNull(list);

List<CompletionItem> items = new ArrayList<>(list.getItems());
CompletionItem item = items.get(0);
assertEquals("sysout", item.getLabel());
assertEquals(item.getInsertText(), "System.out.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