Skip to content

Commit

Permalink
Fix checkstyle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
angjordn committed Sep 17, 2024
1 parent fb424c6 commit ed69b22
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
import software.aws.toolkits.eclipse.amazonq.views.model.Command;

public class ChatCommunicationManager {
public final class ChatCommunicationManager {

private final JsonHandler jsonHandler;
private final ChatMessageProvider chatMessageProivder;

public ChatCommunicationManager() {
this.jsonHandler = new JsonHandler();
this.chatMessageProivder = new ChatMessageProvider();
}

public void sendMessageToChatServerAsync(Command command, Object params) {
public void sendMessageToChatServerAsync(final Command command, final Object params) {

String jsonParams = jsonHandler.serialize(params);
switch(command) {

switch (command) {
case CHAT_TAB_ADD:
GenericTabParams tabParams = jsonHandler.deserialize(jsonParams, GenericTabParams.class);
chatMessageProivder.sendTabAdd(tabParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
import software.aws.toolkits.eclipse.amazonq.views.model.Command;

public class ChatMessageProvider {
public final class ChatMessageProvider {

private AmazonQLspServer amazonQLspServer;

public ChatMessageProvider() {
try {
amazonQLspServer = LspProvider.getAmazonQServer().get();
} catch (InterruptedException | ExecutionException e) {
PluginLogger.error("Error occurred while retrieving Amazon Q LSP server. Failed to instantiate ChatMessageProvider.");
}
}
public void sendTabAdd(GenericTabParams tabParams) {

public void sendTabAdd(final GenericTabParams tabParams) {
try {
PluginLogger.info("Sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server");
amazonQLspServer.tabAdd(tabParams).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public record ChatItemAction(
@JsonProperty("disabled") Boolean disabled,
@JsonProperty("description") String description,
@JsonProperty("type") String type
){};
) { };

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;

public record ChatPrompt (
public record ChatPrompt(
@JsonProperty("prompt") String prompt,
@JsonProperty("escapedPrompt") String escapedPrompt,
@JsonProperty("command") String command
) {}
) { }
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;

public record ChatRequestParams (
public record ChatRequestParams(
@JsonProperty("tabId") String tabId,
@JsonProperty("prompt") ChatPrompt prompt
) {}
) { }

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import com.fasterxml.jackson.annotation.JsonProperty;

public record ChatResult (
public record ChatResult(
@JsonProperty("body") String body,
@JsonProperty("messageId") String messageId,
@JsonProperty("canBeVoted") Boolean canBeVoted,
@JsonProperty("relatedContent") RelatedContent relatedContent,
@JsonProperty("followUp") FollowUp followUp,
@JsonProperty("codeReference") ReferenceTrackerInformation[] codeReference
) {};
) { };
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
public record FollowUp(
@JsonProperty("text") String text,
@JsonProperty("options") ChatItemAction[] options
){}
) { }

Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

public record GenericTabParams(
@JsonProperty("tabId") String tabId
) {}
) { }

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
public record RecommendationContentSpan(
@JsonProperty("start") Integer start,
@JsonProperty("end") Integer end
){};
) { };
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public record ReferenceTrackerInformation(
@JsonProperty("url") String url,
@JsonProperty("recommendationContentSpan") RecommendationContentSpan recommendationContentSpan,
@JsonProperty("information") String information
){};
) { };
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
public record RelatedContent(
@JsonProperty("title") String title,
@JsonProperty("content") SourceLink[] content
){}
) { }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public record SourceLink(
@JsonProperty("title") String title,
@JsonProperty("url") String url,
@JsonProperty("body") String body
){};
) { };
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface AmazonQLspServer extends LanguageServer {

@JsonRequest("aws/textDocument/inlineCompletionWithReferences")
CompletableFuture<InlineCompletionResponse> inlineCompletionWithReferences(InlineCompletionParams params);

@JsonNotification("aws/chat/tabAdd")
CompletableFuture<ChatResult> tabAdd(GenericTabParams params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonHandler {
public final class JsonHandler {
private final ObjectMapper objectMapper;

public JsonHandler() {
this.objectMapper = ObjectMapperFactory.getInstance();
}
public String serialize(Object obj) {

public String serialize(final Object obj) {
String serializedObj = null;
try {
serializedObj = objectMapper.writeValueAsString(obj);
Expand All @@ -22,13 +22,13 @@ public String serialize(Object obj) {
}
return serializedObj;
}
public <T> T deserialize(String jsonString, Class<T> cls) {

public <T> T deserialize(final String jsonString, final Class<T> cls) {
try {
T params = objectMapper.readValue(jsonString, cls);
return params;
} catch (JsonProcessingException e) {
PluginLogger.error("Error occurred while deserializing jsonString: " + jsonString ,e);
PluginLogger.error("Error occurred while deserializing jsonString: " + jsonString, e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
import software.aws.toolkits.eclipse.amazonq.views.model.ParsedCommand;

public class AmazonQChatViewActionHandler implements ViewActionHandler {
ChatCommunicationManager chatCommunicationManager;
private ChatCommunicationManager chatCommunicationManager;

public AmazonQChatViewActionHandler() {
chatCommunicationManager = new ChatCommunicationManager();
}

@Override
public final void handleCommand(ParsedCommand parsedCommand, final Browser browser) {
public final void handleCommand(final ParsedCommand parsedCommand, final Browser browser) {
Command command = parsedCommand.getCommand();
Object params = parsedCommand.getParams();

PluginLogger.info(command + " being processed by ActionHandler");

switch (command) {
case CHAT_READY:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public final Optional<ParsedCommand> parseCommand(final Object[] arguments) {
try {
CommandRequest commandRequest = objectMapper.readValue(jsonString, CommandRequest.class);
ParsedCommand parsedCommand = commandRequest.getParsedCommand();

if (parsedCommand.getCommand() == null) {
return Optional.empty();
}

return Optional.ofNullable(parsedCommand);
} catch (JsonProcessingException e) {
PluginLogger.error("Error parsing webview command JSON: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Optional<Command> fromString(final String value) {
PluginLogger.info("Unregistered command parsed: " + value);
return Optional.empty();
}

public String toString() {
return commandString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.fasterxml.jackson.annotation.JsonProperty;

public record CommandRequest(
@JsonProperty("command") String commandString,
@JsonProperty("params") Object params)
{
@JsonProperty("command") String commandString,
@JsonProperty("params") Object params) {

public ParsedCommand getParsedCommand() {
Command command = Command.fromString(commandString).orElse(null);
ParsedCommand parsedCommand = new ParsedCommand(command, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ParsedCommand {
private final Command command;
private final Object params;

public ParsedCommand(Command command, Object params) {
public ParsedCommand(final Command command, final Object params) {
this.command = command;
this.params = params;
}
Expand Down

0 comments on commit ed69b22

Please sign in to comment.