Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wadoon committed Oct 20, 2024
1 parent 77f8834 commit 8c33e8c
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 314 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ subprojects {
version = rootProject.version

java {
sourceCompatibility = 17
targetCompatibility = 17
sourceCompatibility = 22
targetCompatibility = 22
}

repositories {
Expand Down Expand Up @@ -111,8 +111,8 @@ subprojects {
tasks.withType(JavaCompile) {
// Setting UTF-8 as the java source encoding.
options.encoding = "UTF-8"
// Setting the release to Java 17
options.release = 17
// Setting the release to Java 22
options.release = 22
}

tasks.withType(Javadoc) {
Expand Down
4 changes: 2 additions & 2 deletions keyext.api.doc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
implementation(project(":keyext.api"))
implementation("com.github.javaparser:javaparser-core:3.25.5")
implementation("com.github.javaparser:javaparser-symbol-solver-core:3.25.5")
implementation("com.github.javaparser:javaparser-symbol-solver-core:3.26.1")
implementation("info.picocli:picocli:4.7.6")
}
190 changes: 0 additions & 190 deletions keyext.api.doc/src/main/java/DocGen.java

This file was deleted.

107 changes: 107 additions & 0 deletions keyext.api.doc/src/main/java/org/key_project/key/api/doc/DocGen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.key_project.key.api.doc;/* This file is part of KeY - https://key-project.org
* KeY is licensed under the GNU General Public License Version 2
* SPDX-License-Identifier: GPL-2.0-only */

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Comparator;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
* @author Alexander Weigl
* @version 1 (29.10.23)
*/
public class DocGen implements Supplier<String> {
private final Metamodel.KeyApi metamodel;
private PrintWriter out;

public DocGen(Metamodel.KeyApi metamodel) {
this.metamodel = metamodel;
}

@Override
public String get() {
final StringWriter target = new StringWriter();
try (var out = new PrintWriter(target)) {
this.out = out;
printHeader();

out.format("## Types%n");
metamodel.types()
.stream().sorted(Comparator.comparing(Metamodel.Type::name))
.forEach(this::printType);

out.format("## Endpoints%n");
metamodel.endpoints()
.stream().sorted(Comparator.comparing(Metamodel.Endpoint::name))
.forEach(this::endpoints);
printFooter();
}
return target.toString();
}

private void printFooter() {

}

private void printHeader() {


}

private void endpoints(Metamodel.Endpoint endpoint) {
var direction = switch (endpoint) {
case Metamodel.ServerRequest sr -> "client -> server";
case Metamodel.ClientRequest sr -> "server -> client";
case Metamodel.ServerNotification sr -> "client ~~> server";
case Metamodel.ClientNotification sr -> "server ~~> client";
};

out.format("### %s (`%s`) %n%n", endpoint.name(), direction);
out.format("```%n");
var args = endpoint.args();
final var a = args.stream()
.map(it -> "%s : %s".formatted(it.name(), it.type()))
.collect(Collectors.joining(", "));
switch (endpoint) {
case Metamodel.ServerRequest sr -> out.format("Server.%s( %s ) -> %s%n", endpoint.name(), a, sr.returnType().name());
case Metamodel.ClientRequest sr -> out.format("Client.%s( %s ) -> %s%n", endpoint.name(), a, sr.returnType().name());
case Metamodel.ServerNotification _ -> out.format("Server.%s( %s ) **async**%n", endpoint.name(), a);
case Metamodel.ClientNotification _ -> out.format("Client.%s( %s ) **async**%n", endpoint.name(), a);
default -> {
}
}
out.format("```%n");

out.println(endpoint.documentation());
out.println();
}

private void printType(Metamodel.Type type) {
out.format("### Type: %s%n", type.name());
if (type instanceof Metamodel.ObjectType ot) {
out.format("""
```
type %s {
%s
}
```
""".formatted(type.name(),
ot.fields().stream().sorted(Comparator.comparing(Metamodel.Field::name))
.map(it -> "\t%s : %s".formatted(it.name(), it.type()))
.collect(Collectors.joining("\n"))));
}

if (type instanceof Metamodel.EnumType et) {
out.format("""
```
enum %s { %s }
```
""".formatted(type.name(), String.join(", ", et.values())));
out.format(type.documentation());
}
out.format(type.documentation());
out.println();
}
}
Loading

0 comments on commit 8c33e8c

Please sign in to comment.