generated from Over-Run/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
994 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2023 Overrun Organization | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
|
||
package overrun.marshal.gen; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Annotation | ||
* | ||
* @author squid233 | ||
* @since 0.1.0 | ||
*/ | ||
public final class AnnotationSpec implements Spec { | ||
private final String type; | ||
private final Map<String, String> arguments = new LinkedHashMap<>(); | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param type type | ||
*/ | ||
public AnnotationSpec(String type) { | ||
this.type = type; | ||
} | ||
|
||
/** | ||
* Add a argument | ||
* | ||
* @param name name | ||
* @param value value | ||
*/ | ||
public void addArgument(String name, String value) { | ||
arguments.put(name, value); | ||
} | ||
|
||
/** | ||
* Also runs the action | ||
* | ||
* @param consumer the action | ||
* @return this | ||
*/ | ||
public AnnotationSpec also(Consumer<AnnotationSpec> consumer) { | ||
consumer.accept(this); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void append(StringBuilder builder, int indent) { | ||
builder.append('@').append(type); | ||
if (!arguments.isEmpty()) { | ||
builder.append('('); | ||
if (arguments.size() == 1 && "value".equals(arguments.keySet().stream().findFirst().orElse(null))) { | ||
builder.append(arguments.get("value")); | ||
} else { | ||
builder.append(arguments.entrySet().stream() | ||
.map(e -> e.getKey() + " = " + e.getValue()) | ||
.collect(Collectors.joining(", "))); | ||
} | ||
builder.append(')'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2023 Overrun Organization | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
|
||
package overrun.marshal.gen; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* catch clause | ||
* | ||
* @author squid233 | ||
* @since 0.1.0 | ||
*/ | ||
public final class CatchClause implements Spec, StatementBlock { | ||
private final String type; | ||
private final String name; | ||
private final List<Spec> statements = new ArrayList<>(); | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param type exception type | ||
* @param name variable name | ||
*/ | ||
public CatchClause(String type, String name) { | ||
this.type = type; | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Add a statement | ||
* | ||
* @param spec statement | ||
*/ | ||
@Override | ||
public void addStatement(Spec spec) { | ||
statements.add(spec); | ||
} | ||
|
||
/** | ||
* {@return name} | ||
*/ | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void append(StringBuilder builder, int indent) { | ||
final String indentString = Spec.indentString(indent); | ||
builder.append("catch (").append(type).append(' ').append(name).append(") {\n"); | ||
statements.forEach(spec -> spec.append(builder, indent + 4)); | ||
builder.append(indentString).append('}'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.