Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit d88f18a

Browse files
authored
refactor: restructure server packages & include Simple-ML core Jar (#339)
* 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 <lars-reimann@users.noreply.github.com>
1 parent c5e02d8 commit d88f18a

File tree

50 files changed

+1901
-1843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1901
-1843
lines changed

client/src/features/annotatedPackageData/model/InferableAnnotation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
RenameAnnotation,
1515
} from '../../annotations/annotationSlice';
1616

17-
const dataPathPrefix = 'com.larsreimann.api_editor.server.data.';
17+
const dataPathPrefix = 'com.larsreimann.api_editor.model.';
1818

1919
const getDefaultValueTypeSuffix = (type: DefaultType) => {
2020
switch (type) {

gradle.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
javaVersion=17
2-
ktorVersion=1.6.4
3-
logbackVersion=1.2.6
2+
ktorVersion=1.6.6
3+
logbackVersion=1.2.7
4+
xtextVersion=2.26.0.M2
45

56
org.gradle.caching=true
67
kotlin.code.style=official

server/build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
val javaVersion: String by project
22
val ktorVersion: String by project
33
val logbackVersion: String by project
4-
4+
val xtextVersion: String by project
55

66
// Plugins -------------------------------------------------------------------------------------------------------------
77

@@ -22,7 +22,6 @@ java {
2222
}
2323
}
2424

25-
2625
// Dependencies --------------------------------------------------------------------------------------------------------
2726

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

34+
// We can later pull this from Maven Central (or some other repo) once published
35+
implementation(files("lib/de.unibonn.simpleml-1.0.0-SNAPSHOT.jar"))
36+
implementation("org.eclipse.xtext:org.eclipse.xtext:$xtextVersion")
37+
3538
testImplementation(kotlin("test"))
3639
testImplementation("io.kotest:kotest-assertions-core-jvm:5.0.2")
3740
testImplementation("io.ktor:ktor-server-test-host:$ktorVersion")
995 KB
Binary file not shown.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
package com.larsreimann.api_editor.server.file_handling;
1+
package com.larsreimann.api_editor.codegen;
22

3-
import com.larsreimann.api_editor.server.data.AnnotatedPythonClass;
4-
import com.larsreimann.api_editor.server.data.AnnotatedPythonFunction;
3+
import com.larsreimann.api_editor.io.FileBuilder;
4+
import com.larsreimann.api_editor.model.AnnotatedPythonClass;
55

66
import java.util.ArrayList;
77
import java.util.List;
88

9-
class ClassAdapterContentBuilder extends FileBuilder {
9+
public class ClassAdapterContentBuilder extends FileBuilder {
1010
AnnotatedPythonClass pythonClass;
1111

1212
/**
1313
* Constructor for ClassAdapterContentBuilder
1414
*
1515
* @param pythonClass The module whose adapter content should be built
1616
*/
17-
protected ClassAdapterContentBuilder(AnnotatedPythonClass pythonClass) {
17+
public ClassAdapterContentBuilder(AnnotatedPythonClass pythonClass) {
1818
this.pythonClass = pythonClass;
1919
}
2020

@@ -23,7 +23,7 @@ protected ClassAdapterContentBuilder(AnnotatedPythonClass pythonClass) {
2323
*
2424
* @return The string containing the formatted class content
2525
*/
26-
protected String buildClass() {
26+
public String buildClass() {
2727
String formattedClass = "class " + pythonClass.getName() + ":";
2828
if (!pythonClass.getMethods().isEmpty()) {
2929
formattedClass = formattedClass + "\n";
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
package com.larsreimann.api_editor.server.file_handling;
1+
package com.larsreimann.api_editor.codegen;
22

3-
import com.larsreimann.api_editor.server.data.AnnotatedPythonFunction;
4-
import com.larsreimann.api_editor.server.data.AnnotatedPythonParameter;
5-
import com.larsreimann.api_editor.server.data.PythonParameterAssignment;
3+
import com.larsreimann.api_editor.io.FileBuilder;
4+
import com.larsreimann.api_editor.model.AnnotatedPythonFunction;
5+
import com.larsreimann.api_editor.model.AnnotatedPythonParameter;
6+
import com.larsreimann.api_editor.model.PythonParameterAssignment;
67

78
import java.util.ArrayList;
89
import java.util.List;
910
import java.util.Objects;
1011

11-
class FunctionAdapterContentBuilder extends FileBuilder {
12+
public class FunctionAdapterContentBuilder extends FileBuilder {
1213
AnnotatedPythonFunction pythonFunction;
1314

1415
/**
1516
* Constructor for FunctionAdapterContentBuilder
1617
*
1718
* @param pythonFunction The function whose adapter content should be built
1819
*/
19-
protected FunctionAdapterContentBuilder(
20+
public FunctionAdapterContentBuilder(
2021
AnnotatedPythonFunction pythonFunction
2122
) {
2223
this.pythonFunction = pythonFunction;
@@ -27,7 +28,7 @@ protected FunctionAdapterContentBuilder(
2728
*
2829
* @return The string containing the formatted function content
2930
*/
30-
protected String buildFunction() {
31+
public String buildFunction() {
3132
return "def "
3233
+ pythonFunction.getName()
3334
+ "("
@@ -64,13 +65,11 @@ private String buildFunctionParameters() {
6465
formattedFunctionParameters =
6566
formattedFunctionParameters
6667
+ ", /, ";
67-
}
68-
else if(hasNameOnlyParameters) {
68+
} else if (hasNameOnlyParameters) {
6969
formattedFunctionParameters =
7070
formattedFunctionParameters
7171
+ ", /";
72-
}
73-
else {
72+
} else {
7473
formattedFunctionParameters =
7574
formattedFunctionParameters
7675
+ ", /";
@@ -85,8 +84,7 @@ else if(hasNameOnlyParameters) {
8584
if (hasPositionOnlyParameters || hasPositionOrNameParameters) {
8685
formattedFunctionParameters =
8786
formattedFunctionParameters + ", *, ";
88-
}
89-
else {
87+
} else {
9088
formattedFunctionParameters =
9189
formattedFunctionParameters + "*, ";
9290
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
package com.larsreimann.api_editor.server.file_handling;
1+
package com.larsreimann.api_editor.codegen;
22

3-
import com.larsreimann.api_editor.server.data.AnnotatedPythonModule;
3+
import com.larsreimann.api_editor.io.FileBuilder;
4+
import com.larsreimann.api_editor.model.AnnotatedPythonModule;
45

56
import java.util.ArrayList;
67
import java.util.HashSet;
78
import java.util.List;
89
import java.util.Objects;
910

10-
class ModuleAdapterContentBuilder extends FileBuilder {
11+
public class ModuleAdapterContentBuilder extends FileBuilder {
1112
AnnotatedPythonModule pythonModule;
1213

1314
/**
1415
* Constructor for ModuleAdapterContentBuilder
1516
*
1617
* @param pythonModule The module whose adapter content should be built
1718
*/
18-
protected ModuleAdapterContentBuilder(AnnotatedPythonModule pythonModule) {
19+
public ModuleAdapterContentBuilder(AnnotatedPythonModule pythonModule) {
1920
this.pythonModule = pythonModule;
2021
}
2122

@@ -24,7 +25,7 @@ protected ModuleAdapterContentBuilder(AnnotatedPythonModule pythonModule) {
2425
*
2526
* @return The string containing the formatted module content
2627
*/
27-
protected String buildModuleContent() {
28+
public String buildModuleContent() {
2829
String formattedImport = buildNamespace();
2930
String formattedClasses = buildAllClasses();
3031
String formattedFunctions = buildAllFunctions();
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
package com.larsreimann.api_editor.server.file_handling;
1+
package com.larsreimann.api_editor.io;
22

33
import java.text.DecimalFormat;
44
import java.text.DecimalFormatSymbols;
55
import java.util.List;
66
import java.util.Locale;
77

8-
abstract class FileBuilder {
8+
public abstract class FileBuilder {
99
/**
1010
* Returns an indented version of the passed string
1111
*
1212
* @param toIndent The string to be indented
1313
* @return The indented string
1414
*/
15-
String indent(String toIndent) {
15+
protected String indent(String toIndent) {
1616
String INDENTATION = " ";
1717
toIndent = INDENTATION + toIndent;
1818
toIndent = toIndent.replaceAll("\n", "\n" + INDENTATION);
@@ -29,7 +29,7 @@ String indent(String toIndent) {
2929
* elements of the list
3030
* @return The string resulting from joining the list elements
3131
*/
32-
String listToString(
32+
protected String listToString(
3333
List<String> listToConvert, int numberOfNewlines
3434
) {
3535
String delimiter;
@@ -69,9 +69,7 @@ private int countChars(String baseString, char charToCount) {
6969
* @param defaultValue The default value to format
7070
* @return The formatted default value
7171
*/
72-
String buildFormattedDefaultValue(
73-
String defaultValue
74-
) {
72+
protected String buildFormattedDefaultValue(String defaultValue) {
7573
String invalid = "\"###invalid###" + defaultValue.replace("\"", "\\\"") + "###\"";
7674
if (
7775
defaultValue.length() >= 2 &&
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package com.larsreimann.api_editor.server.file_handling;
1+
package com.larsreimann.api_editor.io;
22

3-
import com.larsreimann.api_editor.server.data.AnnotatedPythonModule;
4-
import com.larsreimann.api_editor.server.data.AnnotatedPythonPackage;
3+
import com.larsreimann.api_editor.codegen.ModuleAdapterContentBuilder;
4+
import com.larsreimann.api_editor.codegen.ModuleStubContentBuilder;
5+
import com.larsreimann.api_editor.model.AnnotatedPythonModule;
6+
import com.larsreimann.api_editor.model.AnnotatedPythonPackage;
57
import kotlin.io.FilesKt;
68

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

2123
/**
2224
* Constructor for PackageFileBuilder
23-
* @param pythonPackage The package whose files should be generated
25+
*
26+
* @param pythonPackage The package whose files should be generated
2427
*/
2528
public PackageFileBuilder(AnnotatedPythonPackage pythonPackage) {
2629
this.pythonPackage = pythonPackage;

0 commit comments

Comments
 (0)