Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
refactor: restructure server packages & include Simple-ML core Jar (#339
Browse files Browse the repository at this point in the history
)

* refactor: clean class stub builder (1)

* refactor: server package structure

* refactor: use Simple-ML creators to create functions

* refactor: include recent changes

* refactor: include recent changes

* build: don't change version of kotest

* fix: regression

* style: use static imports

* style: import enum constants

* fix: data path prefix in client

* fix: linter errors

* style: apply automatic fixes of linters

* test: remove duplicate test

Co-authored-by: lars-reimann <[email protected]>
  • Loading branch information
lars-reimann and lars-reimann authored Dec 17, 2021
1 parent c5e02d8 commit d88f18a
Show file tree
Hide file tree
Showing 50 changed files with 1,901 additions and 1,843 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
RenameAnnotation,
} from '../../annotations/annotationSlice';

const dataPathPrefix = 'com.larsreimann.api_editor.server.data.';
const dataPathPrefix = 'com.larsreimann.api_editor.model.';

const getDefaultValueTypeSuffix = (type: DefaultType) => {
switch (type) {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
javaVersion=17
ktorVersion=1.6.4
logbackVersion=1.2.6
ktorVersion=1.6.6
logbackVersion=1.2.7
xtextVersion=2.26.0.M2

org.gradle.caching=true
kotlin.code.style=official
7 changes: 5 additions & 2 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
val javaVersion: String by project
val ktorVersion: String by project
val logbackVersion: String by project

val xtextVersion: String by project

// Plugins -------------------------------------------------------------------------------------------------------------

Expand All @@ -22,7 +22,6 @@ java {
}
}


// Dependencies --------------------------------------------------------------------------------------------------------

dependencies {
Expand All @@ -32,6 +31,10 @@ dependencies {
implementation("io.ktor:ktor-server-host-common:$ktorVersion")
implementation("io.ktor:ktor-server-netty:$ktorVersion")

// We can later pull this from Maven Central (or some other repo) once published
implementation(files("lib/de.unibonn.simpleml-1.0.0-SNAPSHOT.jar"))
implementation("org.eclipse.xtext:org.eclipse.xtext:$xtextVersion")

testImplementation(kotlin("test"))
testImplementation("io.kotest:kotest-assertions-core-jvm:5.0.2")
testImplementation("io.ktor:ktor-server-test-host:$ktorVersion")
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.larsreimann.api_editor.server.file_handling;
package com.larsreimann.api_editor.codegen;

import com.larsreimann.api_editor.server.data.AnnotatedPythonClass;
import com.larsreimann.api_editor.server.data.AnnotatedPythonFunction;
import com.larsreimann.api_editor.io.FileBuilder;
import com.larsreimann.api_editor.model.AnnotatedPythonClass;

import java.util.ArrayList;
import java.util.List;

class ClassAdapterContentBuilder extends FileBuilder {
public class ClassAdapterContentBuilder extends FileBuilder {
AnnotatedPythonClass pythonClass;

/**
* Constructor for ClassAdapterContentBuilder
*
* @param pythonClass The module whose adapter content should be built
*/
protected ClassAdapterContentBuilder(AnnotatedPythonClass pythonClass) {
public ClassAdapterContentBuilder(AnnotatedPythonClass pythonClass) {
this.pythonClass = pythonClass;
}

Expand All @@ -23,7 +23,7 @@ protected ClassAdapterContentBuilder(AnnotatedPythonClass pythonClass) {
*
* @return The string containing the formatted class content
*/
protected String buildClass() {
public String buildClass() {
String formattedClass = "class " + pythonClass.getName() + ":";
if (!pythonClass.getMethods().isEmpty()) {
formattedClass = formattedClass + "\n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package com.larsreimann.api_editor.server.file_handling;
package com.larsreimann.api_editor.codegen;

import com.larsreimann.api_editor.server.data.AnnotatedPythonFunction;
import com.larsreimann.api_editor.server.data.AnnotatedPythonParameter;
import com.larsreimann.api_editor.server.data.PythonParameterAssignment;
import com.larsreimann.api_editor.io.FileBuilder;
import com.larsreimann.api_editor.model.AnnotatedPythonFunction;
import com.larsreimann.api_editor.model.AnnotatedPythonParameter;
import com.larsreimann.api_editor.model.PythonParameterAssignment;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

class FunctionAdapterContentBuilder extends FileBuilder {
public class FunctionAdapterContentBuilder extends FileBuilder {
AnnotatedPythonFunction pythonFunction;

/**
* Constructor for FunctionAdapterContentBuilder
*
* @param pythonFunction The function whose adapter content should be built
*/
protected FunctionAdapterContentBuilder(
public FunctionAdapterContentBuilder(
AnnotatedPythonFunction pythonFunction
) {
this.pythonFunction = pythonFunction;
Expand All @@ -27,7 +28,7 @@ protected FunctionAdapterContentBuilder(
*
* @return The string containing the formatted function content
*/
protected String buildFunction() {
public String buildFunction() {
return "def "
+ pythonFunction.getName()
+ "("
Expand Down Expand Up @@ -64,13 +65,11 @@ private String buildFunctionParameters() {
formattedFunctionParameters =
formattedFunctionParameters
+ ", /, ";
}
else if(hasNameOnlyParameters) {
} else if (hasNameOnlyParameters) {
formattedFunctionParameters =
formattedFunctionParameters
+ ", /";
}
else {
} else {
formattedFunctionParameters =
formattedFunctionParameters
+ ", /";
Expand All @@ -85,8 +84,7 @@ else if(hasNameOnlyParameters) {
if (hasPositionOnlyParameters || hasPositionOrNameParameters) {
formattedFunctionParameters =
formattedFunctionParameters + ", *, ";
}
else {
} else {
formattedFunctionParameters =
formattedFunctionParameters + "*, ";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.larsreimann.api_editor.server.file_handling;
package com.larsreimann.api_editor.codegen;

import com.larsreimann.api_editor.server.data.AnnotatedPythonModule;
import com.larsreimann.api_editor.io.FileBuilder;
import com.larsreimann.api_editor.model.AnnotatedPythonModule;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;

class ModuleAdapterContentBuilder extends FileBuilder {
public class ModuleAdapterContentBuilder extends FileBuilder {
AnnotatedPythonModule pythonModule;

/**
* Constructor for ModuleAdapterContentBuilder
*
* @param pythonModule The module whose adapter content should be built
*/
protected ModuleAdapterContentBuilder(AnnotatedPythonModule pythonModule) {
public ModuleAdapterContentBuilder(AnnotatedPythonModule pythonModule) {
this.pythonModule = pythonModule;
}

Expand All @@ -24,7 +25,7 @@ protected ModuleAdapterContentBuilder(AnnotatedPythonModule pythonModule) {
*
* @return The string containing the formatted module content
*/
protected String buildModuleContent() {
public String buildModuleContent() {
String formattedImport = buildNamespace();
String formattedClasses = buildAllClasses();
String formattedFunctions = buildAllFunctions();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.larsreimann.api_editor.server.file_handling;
package com.larsreimann.api_editor.io;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.List;
import java.util.Locale;

abstract class FileBuilder {
public abstract class FileBuilder {
/**
* Returns an indented version of the passed string
*
* @param toIndent The string to be indented
* @return The indented string
*/
String indent(String toIndent) {
protected String indent(String toIndent) {
String INDENTATION = " ";
toIndent = INDENTATION + toIndent;
toIndent = toIndent.replaceAll("\n", "\n" + INDENTATION);
Expand All @@ -29,7 +29,7 @@ String indent(String toIndent) {
* elements of the list
* @return The string resulting from joining the list elements
*/
String listToString(
protected String listToString(
List<String> listToConvert, int numberOfNewlines
) {
String delimiter;
Expand Down Expand Up @@ -69,9 +69,7 @@ private int countChars(String baseString, char charToCount) {
* @param defaultValue The default value to format
* @return The formatted default value
*/
String buildFormattedDefaultValue(
String defaultValue
) {
protected String buildFormattedDefaultValue(String defaultValue) {
String invalid = "\"###invalid###" + defaultValue.replace("\"", "\\\"") + "###\"";
if (
defaultValue.length() >= 2 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.larsreimann.api_editor.server.file_handling;
package com.larsreimann.api_editor.io;

import com.larsreimann.api_editor.server.data.AnnotatedPythonModule;
import com.larsreimann.api_editor.server.data.AnnotatedPythonPackage;
import com.larsreimann.api_editor.codegen.ModuleAdapterContentBuilder;
import com.larsreimann.api_editor.codegen.ModuleStubContentBuilder;
import com.larsreimann.api_editor.model.AnnotatedPythonModule;
import com.larsreimann.api_editor.model.AnnotatedPythonPackage;
import kotlin.io.FilesKt;

import java.io.BufferedWriter;
Expand All @@ -20,7 +22,8 @@ public class PackageFileBuilder {

/**
* Constructor for PackageFileBuilder
* @param pythonPackage The package whose files should be generated
*
* @param pythonPackage The package whose files should be generated
*/
public PackageFileBuilder(AnnotatedPythonPackage pythonPackage) {
this.pythonPackage = pythonPackage;
Expand Down
Loading

0 comments on commit d88f18a

Please sign in to comment.