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

Codequality #117

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
- rolled back some bad changes concerning static initialization
- added exceptions for workspaceservice
- updated syntax of commands, now start with lower letter
- Tried to implement the singleton pattern, but removed this changes because they were wrong
- ignored some unneccessary code smells from sonarqube
CptKaNe committed Aug 13, 2021

Unverified

This user has not yet uploaded their public signing key.
commit 12fe99360ba60a3169870f3d06d8a75c215dd42c
25 changes: 9 additions & 16 deletions src/main/java/Client/ConsoleClientLauncher.java
Original file line number Diff line number Diff line change
@@ -27,24 +27,16 @@ public class ConsoleClientLauncher {
private static final Logger logger = LoggerFactory.getLogger(ConsoleClientLauncher.class);
public static Future<Void> clientListening;

static {
socket = null;
client = null;
menu = null;
}

public ConsoleClientLauncher(String host, int port) throws IOException {
ConsoleClientLauncher.host = host;
ConsoleClientLauncher.port = port;
client = new MopeLSPClient();
socket = new Socket(host, port);
menu = new ConsoleMenu(client);
}
public static void setExecutorPool() {
executor = Executors.newFixedThreadPool(2);
}

public Future<Void> launchClient() throws IOException {
public static Future<Void> launchClient() throws IOException {
executor = Executors.newFixedThreadPool(2);
Launcher<ModelicaLanguageServer> cLauncher = new LSPLauncher.Builder<ModelicaLanguageServer>()
.setLocalService(client)
.setRemoteInterface(ModelicaLanguageServer.class)
@@ -81,6 +73,12 @@ public static void stopClient() throws ExecutionException{
logger.info("Client Finished");
}

public static void connectToServer() {
System.out.println("Serverip: ");
host= sc.next();
System.out.println("Serverport: ");
port = sc.nextInt();
}


public static void shutdownServer() throws ExecutionException {
@@ -93,12 +91,7 @@ public static void shutdownServer() throws ExecutionException {
}

public static void main(String[] args) throws Exception {
System.out.println("Serverip:");
host= sc.next();
System.out.println("Serverport:");
port = sc.nextInt();

setExecutorPool();
connectToServer();
ConsoleClientLauncher launcher = new ConsoleClientLauncher(host, port);

clientListening = launcher.launchClient();
4 changes: 4 additions & 0 deletions src/main/java/Server/MopeDocumentService.java
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
public class MopeDocumentService implements TextDocumentService {
private ICompilerAdapter compiler;
private static final Logger logger = LoggerFactory.getLogger(MopeDocumentService.class);
private UnsupportedOperationException unsupOpEx = null;

@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams completionParams) {
@@ -42,16 +43,19 @@ public void didOpen(DidOpenTextDocumentParams params) {
@Override
public void didChange(DidChangeTextDocumentParams params) {
// not yet implemented
throw unsupOpEx;
}

@Override
public void didClose(DidCloseTextDocumentParams params) {
// not yet implemented
throw unsupOpEx;
}

@Override
public void didSave(DidSaveTextDocumentParams params) {
// not yet implemented
throw unsupOpEx;
}

@Override
16 changes: 3 additions & 13 deletions src/main/java/Server/MopeLSPServerLauncher.java
Original file line number Diff line number Diff line change
@@ -26,32 +26,23 @@ public class MopeLSPServerLauncher {
private static MopeLSPServer server;
private static ExecutorService executor;
private static Socket socket;
private static Logger logger = LoggerFactory.getLogger(MopeLSPServerLauncher.class);
public static Logger logger = LoggerFactory.getLogger(MopeLSPServerLauncher.class);
private static ConfigObject configObject;

static {
serverSocket = null;
server = null;
configObject = null;
}

public MopeLSPServerLauncher() throws IOException {
configObject = new ConfigObject();
readConfig();
server = new MopeLSPServer(configObject);
serverSocket = new ServerSocket(configObject.port);
}
public static void setExecutorPool() {
executor = Executors.newCachedThreadPool();
}

public void launchServer() {
public static void launchServer() {

System.setProperty(Log4jLoggerAdapter.ROOT_LOGGER_NAME, "TRACE");

logger.info("Server socket listening on port " + configObject.port );
System.out.flush();
//executor = Executors.newCachedThreadPool();
executor = Executors.newCachedThreadPool();
executor.submit(() -> {
while (true) {
socket = serverSocket.accept();
@@ -129,7 +120,6 @@ public static void readConfig() {

public static void main(String[] args) {
try{
setExecutorPool();
MopeLSPServerLauncher launcher = new MopeLSPServerLauncher();
launcher.launchServer();
new Thread(() -> stopFromConsole(server)).start();
21 changes: 14 additions & 7 deletions src/main/java/Server/MopeWorkspaceService.java
Original file line number Diff line number Diff line change
@@ -7,10 +7,14 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static Server.MopeLSPServerLauncher.logger;

public class MopeWorkspaceService implements WorkspaceService {

public String error = "invalid command";
private final ModelicaService modelicaService;
private UnsupportedOperationException unsupOpEx = null;

@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams workspaceSymbolParams) {
return null;
@@ -19,11 +23,13 @@ public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymb
@Override
public void didChangeConfiguration(DidChangeConfigurationParams didChangeConfigurationParams) {
// not yet implemented
throw unsupOpEx;
}

@Override
public void didChangeWatchedFiles(DidChangeWatchedFilesParams didChangeWatchedFilesParams) {
//not yet implemented
throw unsupOpEx;
}

@Override
@@ -36,29 +42,30 @@ public CompletableFuture<Object> executeCommand(ExecuteCommandParams params){
String argument = "";
if(!args.isEmpty()) argument = args.get(0).toString().replaceAll("\"", "");
switch(command){
case "ExecuteCommand":
case "executeCommand":
result = modelicaService.sendExpression(argument);
break;
case "LoadFile":
case "loadFile":
result = modelicaService.loadFile(argument);
break;
case "CheckModel":
case "checkModel":
result = modelicaService.checkModel(argument);
break;
case "AddPath":
case "addPath":
result = modelicaService.addModelicaPath(argument);
break;
case "GetPath":
case "getPath":
result = modelicaService.getModelicaPath();
break;
case "LoadModel":
case "loadModel":
result = modelicaService.loadModel(argument);
break;
case "Version":
case "version":
result = modelicaService.getCompilerVersion();
break;
default:
result = CompletableFuture.completedFuture(error);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really what you want? It is a design choice, but inside a Java environment I would opt for a more rigid approach: When you get an unexpected input, you throw a InputMismatchException.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint!

logger.error("Command is invalid, output is: " + result);
break;
}