mirror of
https://github.com/apple/pkl.git
synced 2026-01-16 16:36:59 +01:00
Initial commit
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.codegen.java
|
||||
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.listDirectoryEntries
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import org.pkl.commons.cli.CliBaseOptions
|
||||
import org.pkl.commons.readString
|
||||
|
||||
class CliJavaCodeGeneratorTest {
|
||||
|
||||
private val dollar = "$"
|
||||
|
||||
@Test
|
||||
fun `module inheritance`(@TempDir tempDir: Path) {
|
||||
val module1 =
|
||||
PklModule(
|
||||
"org.mod1",
|
||||
"""
|
||||
open module org.mod1
|
||||
|
||||
pigeon: Person
|
||||
|
||||
class Person {
|
||||
name: String
|
||||
age: Int
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
val module2 =
|
||||
PklModule(
|
||||
"org.mod2",
|
||||
"""
|
||||
module org.mod2
|
||||
|
||||
extends "mod1.pkl"
|
||||
|
||||
parrot: Person
|
||||
"""
|
||||
)
|
||||
|
||||
val module1File = module1.writeToDisk(tempDir.resolve("org/mod1.pkl"))
|
||||
val module2File = module2.writeToDisk(tempDir.resolve("org/mod2.pkl"))
|
||||
val outputDir = tempDir.resolve("output")
|
||||
|
||||
val generator =
|
||||
CliJavaCodeGenerator(
|
||||
CliJavaCodeGeneratorOptions(
|
||||
CliBaseOptions(listOf(module1File.toUri(), module2File.toUri())),
|
||||
outputDir
|
||||
)
|
||||
)
|
||||
|
||||
generator.run()
|
||||
|
||||
val javaDir = outputDir.resolve("java")
|
||||
|
||||
val moduleJavaFiles = javaDir.resolve("org").listDirectoryEntries()
|
||||
assertThat(moduleJavaFiles.map { it.fileName.toString() })
|
||||
.containsExactlyInAnyOrder("Mod1.java", "Mod2.java")
|
||||
|
||||
val module1JavaFile = javaDir.resolve("org/Mod1.java")
|
||||
assertContains(
|
||||
"""
|
||||
|public class Mod1 {
|
||||
| public final @NonNull Person pigeon;
|
||||
""",
|
||||
module1JavaFile.readString()
|
||||
)
|
||||
|
||||
val module2JavaFile = javaDir.resolve("org/Mod2.java")
|
||||
assertContains(
|
||||
"""
|
||||
|public final class Mod2 extends Mod1 {
|
||||
| public final Mod1. @NonNull Person parrot;
|
||||
""",
|
||||
module2JavaFile.readString()
|
||||
)
|
||||
val resourcesDir = outputDir.resolve("resources/META-INF/org/pkl/config/java/mapper/classes/")
|
||||
|
||||
val module1PropertiesFile = resourcesDir.resolve("org.mod1.properties")
|
||||
|
||||
assertContains(
|
||||
"""
|
||||
org.pkl.config.java.mapper.org.mod1\#Person=org.Mod1${dollar}Person
|
||||
org.pkl.config.java.mapper.org.mod1\#ModuleClass=org.Mod1
|
||||
"""
|
||||
.trimIndent(),
|
||||
module1PropertiesFile.readString()
|
||||
)
|
||||
|
||||
val module2PropertiesFile = resourcesDir.resolve("org.mod2.properties")
|
||||
|
||||
assertContains(
|
||||
"""
|
||||
org.pkl.config.java.mapper.org.mod2\#ModuleClass=org.Mod2
|
||||
"""
|
||||
.trimIndent(),
|
||||
module2PropertiesFile.readString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `class name clashes`(@TempDir tempDir: Path) {
|
||||
val module1 =
|
||||
PklModule(
|
||||
"org.mod1",
|
||||
"""
|
||||
module org.mod1
|
||||
|
||||
class Person {
|
||||
name: String
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
val module2 =
|
||||
PklModule(
|
||||
"org.mod2",
|
||||
"""
|
||||
module org.mod2
|
||||
|
||||
import "mod1.pkl"
|
||||
|
||||
person1: mod1.Person
|
||||
person2: Person
|
||||
|
||||
class Person {
|
||||
age: Int
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
val module1PklFile = module1.writeToDisk(tempDir.resolve("org/mod1.pkl"))
|
||||
val module2PklFile = module2.writeToDisk(tempDir.resolve("org/mod2.pkl"))
|
||||
val outputDir = tempDir.resolve("output")
|
||||
|
||||
val generator =
|
||||
CliJavaCodeGenerator(
|
||||
CliJavaCodeGeneratorOptions(
|
||||
CliBaseOptions(listOf(module1PklFile.toUri(), module2PklFile.toUri())),
|
||||
outputDir
|
||||
)
|
||||
)
|
||||
|
||||
generator.run()
|
||||
|
||||
val module2JavaFile = outputDir.resolve("java/org/Mod2.java")
|
||||
assertContains(
|
||||
"""
|
||||
|public final class Mod2 {
|
||||
| public final Mod1. @NonNull Person person1;
|
||||
|
|
||||
| public final @NonNull Person person2;
|
||||
""",
|
||||
module2JavaFile.readString()
|
||||
)
|
||||
}
|
||||
|
||||
private fun assertContains(part: String, code: String) {
|
||||
val trimmedPart = part.trim().trimMargin()
|
||||
if (!code.contains(trimmedPart)) {
|
||||
// check for equality to get better error output (ide diff dialog)
|
||||
assertThat(code).isEqualTo(trimmedPart)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.codegen.java
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.net.URI
|
||||
import javax.tools.*
|
||||
|
||||
class CompilationFailedException(msg: String) : RuntimeException(msg)
|
||||
|
||||
object InMemoryJavaCompiler {
|
||||
fun compile(sourceFiles: Map<String, String>): Map<String, Class<*>> {
|
||||
val compiler = ToolProvider.getSystemJavaCompiler()
|
||||
val diagnosticsCollector = DiagnosticCollector<JavaFileObject>()
|
||||
val fileManager =
|
||||
InMemoryFileManager(compiler.getStandardFileManager(diagnosticsCollector, null, null))
|
||||
val sourceObjects =
|
||||
sourceFiles.map { (filename, contents) -> ReadableSourceFileObject(filename, contents) }
|
||||
val task = compiler.getTask(null, fileManager, diagnosticsCollector, null, null, sourceObjects)
|
||||
val result = task.call()
|
||||
if (!result) {
|
||||
throw CompilationFailedException(
|
||||
buildString {
|
||||
appendLine("Compilation failed. Error(s):")
|
||||
for (diagnostic in diagnosticsCollector.diagnostics) {
|
||||
appendLine(diagnostic.getMessage(null))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
val loader = ClassFileObjectLoader(fileManager.outputFiles)
|
||||
return fileManager.outputFiles.mapValues { loader.loadClass(it.key) }
|
||||
}
|
||||
}
|
||||
|
||||
private class ClassFileObjectLoader(val fileObjects: Map<String, WritableBinaryFileObject>) :
|
||||
ClassLoader(ClassFileObjectLoader::class.java.classLoader) {
|
||||
|
||||
override fun findClass(name: String): Class<*> {
|
||||
val obj = fileObjects[name]
|
||||
if (obj == null || obj.kind != JavaFileObject.Kind.CLASS) {
|
||||
throw ClassNotFoundException(name)
|
||||
}
|
||||
val array = obj.out.toByteArray()
|
||||
return defineClass(name, array, 0, array.size)
|
||||
}
|
||||
}
|
||||
|
||||
private class ReadableSourceFileObject(path: String, private val contents: String) :
|
||||
SimpleJavaFileObject(URI(path), JavaFileObject.Kind.SOURCE) {
|
||||
|
||||
override fun openInputStream(): InputStream = contents.byteInputStream()
|
||||
|
||||
override fun getCharContent(ignoreEncodingErrors: Boolean): CharSequence = contents
|
||||
}
|
||||
|
||||
private class WritableBinaryFileObject(className: String, kind: JavaFileObject.Kind) :
|
||||
SimpleJavaFileObject(URI("/${className.replace(".", "/")}.${kind.extension}"), kind) {
|
||||
val out = ByteArrayOutputStream()
|
||||
|
||||
override fun openOutputStream(): OutputStream = out
|
||||
}
|
||||
|
||||
private class InMemoryFileManager(delegate: JavaFileManager) :
|
||||
ForwardingJavaFileManager<JavaFileManager>(delegate) {
|
||||
|
||||
val outputFiles = mutableMapOf<String, WritableBinaryFileObject>()
|
||||
|
||||
override fun getJavaFileForOutput(
|
||||
location: JavaFileManager.Location,
|
||||
className: String,
|
||||
kind: JavaFileObject.Kind,
|
||||
sibling: FileObject
|
||||
): JavaFileObject {
|
||||
|
||||
return WritableBinaryFileObject(className, kind).also { outputFiles[className] = it }
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.codegen.java
|
||||
|
||||
import java.nio.file.Path
|
||||
import org.pkl.commons.createParentDirectories
|
||||
import org.pkl.commons.writeString
|
||||
|
||||
data class PklModule(val name: String, val content: String) {
|
||||
fun writeToDisk(path: Path): Path {
|
||||
return path.createParentDirectories().writeString(content)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package my;
|
||||
|
||||
import java.lang.Object;
|
||||
import java.lang.Override;
|
||||
import java.lang.String;
|
||||
import java.lang.StringBuilder;
|
||||
import java.util.Objects;
|
||||
import org.pkl.config.java.mapper.Named;
|
||||
import org.pkl.config.java.mapper.NonNull;
|
||||
import org.pkl.core.DataSize;
|
||||
import org.pkl.core.Duration;
|
||||
|
||||
public final class Mod {
|
||||
private Mod() {
|
||||
}
|
||||
|
||||
private static void appendProperty(StringBuilder builder, String name, Object value) {
|
||||
builder.append("\n ").append(name).append(" = ");
|
||||
String[] lines = Objects.toString(value).split("\n");
|
||||
builder.append(lines[0]);
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
builder.append("\n ").append(lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class GenerateGetters {
|
||||
private final boolean urgent;
|
||||
|
||||
private final @NonNull String url;
|
||||
|
||||
private final @NonNull DataSize diskSize;
|
||||
|
||||
private final @NonNull Duration ETA;
|
||||
|
||||
private final @NonNull String _package;
|
||||
|
||||
public GenerateGetters(@Named("urgent") boolean urgent, @Named("url") @NonNull String url,
|
||||
@Named("diskSize") @NonNull DataSize diskSize, @Named("ETA") @NonNull Duration ETA,
|
||||
@Named("package") @NonNull String _package) {
|
||||
this.urgent = urgent;
|
||||
this.url = url;
|
||||
this.diskSize = diskSize;
|
||||
this.ETA = ETA;
|
||||
this._package = _package;
|
||||
}
|
||||
|
||||
public boolean isUrgent() {
|
||||
return urgent;
|
||||
}
|
||||
|
||||
public GenerateGetters withUrgent(boolean urgent) {
|
||||
return new GenerateGetters(urgent, url, diskSize, ETA, _package);
|
||||
}
|
||||
|
||||
public @NonNull String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public GenerateGetters withUrl(@NonNull String url) {
|
||||
return new GenerateGetters(urgent, url, diskSize, ETA, _package);
|
||||
}
|
||||
|
||||
public @NonNull DataSize getDiskSize() {
|
||||
return diskSize;
|
||||
}
|
||||
|
||||
public GenerateGetters withDiskSize(@NonNull DataSize diskSize) {
|
||||
return new GenerateGetters(urgent, url, diskSize, ETA, _package);
|
||||
}
|
||||
|
||||
public @NonNull Duration getETA() {
|
||||
return ETA;
|
||||
}
|
||||
|
||||
public GenerateGetters withETA(@NonNull Duration ETA) {
|
||||
return new GenerateGetters(urgent, url, diskSize, ETA, _package);
|
||||
}
|
||||
|
||||
public @NonNull String getPackage() {
|
||||
return _package;
|
||||
}
|
||||
|
||||
public GenerateGetters withPackage(@NonNull String _package) {
|
||||
return new GenerateGetters(urgent, url, diskSize, ETA, _package);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (this.getClass() != obj.getClass()) return false;
|
||||
GenerateGetters other = (GenerateGetters) obj;
|
||||
if (!Objects.equals(this.urgent, other.urgent)) return false;
|
||||
if (!Objects.equals(this.url, other.url)) return false;
|
||||
if (!Objects.equals(this.diskSize, other.diskSize)) return false;
|
||||
if (!Objects.equals(this.ETA, other.ETA)) return false;
|
||||
if (!Objects.equals(this._package, other._package)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(this.urgent);
|
||||
result = 31 * result + Objects.hashCode(this.url);
|
||||
result = 31 * result + Objects.hashCode(this.diskSize);
|
||||
result = 31 * result + Objects.hashCode(this.ETA);
|
||||
result = 31 * result + Objects.hashCode(this._package);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(300);
|
||||
builder.append(GenerateGetters.class.getSimpleName()).append(" {");
|
||||
appendProperty(builder, "urgent", this.urgent);
|
||||
appendProperty(builder, "url", this.url);
|
||||
appendProperty(builder, "diskSize", this.diskSize);
|
||||
appendProperty(builder, "ETA", this.ETA);
|
||||
appendProperty(builder, "_package", this._package);
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package my;
|
||||
|
||||
import java.lang.Object;
|
||||
import java.lang.Override;
|
||||
import java.lang.String;
|
||||
import java.lang.StringBuilder;
|
||||
import java.util.Objects;
|
||||
import org.pkl.config.java.mapper.Named;
|
||||
import org.pkl.config.java.mapper.NonNull;
|
||||
import org.pkl.core.Duration;
|
||||
|
||||
public final class Mod {
|
||||
private Mod() {
|
||||
}
|
||||
|
||||
private static void appendProperty(StringBuilder builder, String name, Object value) {
|
||||
builder.append("\n ").append(name).append(" = ");
|
||||
String[] lines = Objects.toString(value).split("\n");
|
||||
builder.append(lines[0]);
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
builder.append("\n ").append(lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class Foo {
|
||||
protected final long one;
|
||||
|
||||
protected Foo(@Named("one") long one) {
|
||||
this.one = one;
|
||||
}
|
||||
|
||||
public long getOne() {
|
||||
return one;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (this.getClass() != obj.getClass()) return false;
|
||||
Foo other = (Foo) obj;
|
||||
if (!Objects.equals(this.one, other.one)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(this.one);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(100);
|
||||
builder.append(Foo.class.getSimpleName()).append(" {");
|
||||
appendProperty(builder, "one", this.one);
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class None extends Foo {
|
||||
public None(@Named("one") long one) {
|
||||
super(one);
|
||||
}
|
||||
|
||||
public None withOne(long one) {
|
||||
return new None(one);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Bar extends None {
|
||||
protected final String two;
|
||||
|
||||
public Bar(@Named("one") long one, @Named("two") String two) {
|
||||
super(one);
|
||||
this.two = two;
|
||||
}
|
||||
|
||||
public Bar withOne(long one) {
|
||||
return new Bar(one, two);
|
||||
}
|
||||
|
||||
public String getTwo() {
|
||||
return two;
|
||||
}
|
||||
|
||||
public Bar withTwo(String two) {
|
||||
return new Bar(one, two);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (this.getClass() != obj.getClass()) return false;
|
||||
Bar other = (Bar) obj;
|
||||
if (!Objects.equals(this.one, other.one)) return false;
|
||||
if (!Objects.equals(this.two, other.two)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(this.one);
|
||||
result = 31 * result + Objects.hashCode(this.two);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(150);
|
||||
builder.append(Bar.class.getSimpleName()).append(" {");
|
||||
appendProperty(builder, "one", this.one);
|
||||
appendProperty(builder, "two", this.two);
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Baz extends Bar {
|
||||
private final @NonNull Duration three;
|
||||
|
||||
public Baz(@Named("one") long one, @Named("two") String two,
|
||||
@Named("three") @NonNull Duration three) {
|
||||
super(one, two);
|
||||
this.three = three;
|
||||
}
|
||||
|
||||
public Baz withOne(long one) {
|
||||
return new Baz(one, two, three);
|
||||
}
|
||||
|
||||
public Baz withTwo(String two) {
|
||||
return new Baz(one, two, three);
|
||||
}
|
||||
|
||||
public @NonNull Duration getThree() {
|
||||
return three;
|
||||
}
|
||||
|
||||
public Baz withThree(@NonNull Duration three) {
|
||||
return new Baz(one, two, three);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (this.getClass() != obj.getClass()) return false;
|
||||
Baz other = (Baz) obj;
|
||||
if (!Objects.equals(this.one, other.one)) return false;
|
||||
if (!Objects.equals(this.two, other.two)) return false;
|
||||
if (!Objects.equals(this.three, other.three)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(this.one);
|
||||
result = 31 * result + Objects.hashCode(this.two);
|
||||
result = 31 * result + Objects.hashCode(this.three);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(200);
|
||||
builder.append(Baz.class.getSimpleName()).append(" {");
|
||||
appendProperty(builder, "one", this.one);
|
||||
appendProperty(builder, "two", this.two);
|
||||
appendProperty(builder, "three", this.three);
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package my;
|
||||
|
||||
import java.lang.Object;
|
||||
import java.lang.Override;
|
||||
import java.lang.String;
|
||||
import java.lang.StringBuilder;
|
||||
import java.util.Objects;
|
||||
import org.pkl.config.java.mapper.Named;
|
||||
import org.pkl.config.java.mapper.NonNull;
|
||||
|
||||
/**
|
||||
* module comment.
|
||||
* *emphasized* `code`.
|
||||
*/
|
||||
public final class Mod {
|
||||
/**
|
||||
* module property comment.
|
||||
* *emphasized* `code`.
|
||||
*/
|
||||
public final @NonNull Person pigeon;
|
||||
|
||||
public Mod(@Named("pigeon") @NonNull Person pigeon) {
|
||||
this.pigeon = pigeon;
|
||||
}
|
||||
|
||||
public Mod withPigeon(@NonNull Person pigeon) {
|
||||
return new Mod(pigeon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (this.getClass() != obj.getClass()) return false;
|
||||
Mod other = (Mod) obj;
|
||||
if (!Objects.equals(this.pigeon, other.pigeon)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(this.pigeon);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(100);
|
||||
builder.append(Mod.class.getSimpleName()).append(" {");
|
||||
appendProperty(builder, "pigeon", this.pigeon);
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void appendProperty(StringBuilder builder, String name, Object value) {
|
||||
builder.append("\n ").append(name).append(" = ");
|
||||
String[] lines = Objects.toString(value).split("\n");
|
||||
builder.append(lines[0]);
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
builder.append("\n ").append(lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* class comment.
|
||||
* *emphasized* `code`.
|
||||
*/
|
||||
public static final class Person {
|
||||
/**
|
||||
* class property comment.
|
||||
* *emphasized* `code`.
|
||||
*/
|
||||
public final @NonNull String name;
|
||||
|
||||
public Person(@Named("name") @NonNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Person withName(@NonNull String name) {
|
||||
return new Person(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (this.getClass() != obj.getClass()) return false;
|
||||
Person other = (Person) obj;
|
||||
if (!Objects.equals(this.name, other.name)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(this.name);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(100);
|
||||
builder.append(Person.class.getSimpleName()).append(" {");
|
||||
appendProperty(builder, "name", this.name);
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
package my;
|
||||
|
||||
import java.lang.Object;
|
||||
import java.lang.Override;
|
||||
import java.lang.String;
|
||||
import java.lang.StringBuilder;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import org.pkl.config.java.mapper.Named;
|
||||
import org.pkl.config.java.mapper.NonNull;
|
||||
import org.pkl.core.DataSize;
|
||||
import org.pkl.core.DataSizeUnit;
|
||||
import org.pkl.core.Duration;
|
||||
import org.pkl.core.DurationUnit;
|
||||
import org.pkl.core.Pair;
|
||||
|
||||
public final class Mod {
|
||||
private Mod() {
|
||||
}
|
||||
|
||||
private static void appendProperty(StringBuilder builder, String name, Object value) {
|
||||
builder.append("\n ").append(name).append(" = ");
|
||||
String[] lines = Objects.toString(value).split("\n");
|
||||
builder.append(lines[0]);
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
builder.append("\n ").append(lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PropertyTypes {
|
||||
public final boolean _boolean;
|
||||
|
||||
public final long _int;
|
||||
|
||||
public final double _float;
|
||||
|
||||
public final @NonNull String string;
|
||||
|
||||
public final @NonNull Duration duration;
|
||||
|
||||
public final @NonNull DurationUnit durationUnit;
|
||||
|
||||
public final @NonNull DataSize dataSize;
|
||||
|
||||
public final @NonNull DataSizeUnit dataSizeUnit;
|
||||
|
||||
public final String nullable;
|
||||
|
||||
public final String nullable2;
|
||||
|
||||
public final @NonNull Pair<Object, Object> pair;
|
||||
|
||||
public final @NonNull Pair<@NonNull String, @NonNull Other> pair2;
|
||||
|
||||
public final @NonNull Collection<Object> coll;
|
||||
|
||||
public final @NonNull Collection<@NonNull Other> coll2;
|
||||
|
||||
public final @NonNull List<Object> list;
|
||||
|
||||
public final @NonNull List<@NonNull Other> list2;
|
||||
|
||||
public final @NonNull Set<Object> set;
|
||||
|
||||
public final @NonNull Set<@NonNull Other> set2;
|
||||
|
||||
public final @NonNull Map<Object, Object> map;
|
||||
|
||||
public final @NonNull Map<@NonNull String, @NonNull Other> map2;
|
||||
|
||||
public final @NonNull Map<Object, Object> container;
|
||||
|
||||
public final @NonNull Map<@NonNull String, @NonNull Other> container2;
|
||||
|
||||
public final @NonNull Other other;
|
||||
|
||||
public final @NonNull Pattern regex;
|
||||
|
||||
public final Object any;
|
||||
|
||||
public final @NonNull Object nonNull;
|
||||
|
||||
public final @NonNull Direction _enum;
|
||||
|
||||
public PropertyTypes(@Named("boolean") boolean _boolean, @Named("int") long _int,
|
||||
@Named("float") double _float, @Named("string") @NonNull String string,
|
||||
@Named("duration") @NonNull Duration duration,
|
||||
@Named("durationUnit") @NonNull DurationUnit durationUnit,
|
||||
@Named("dataSize") @NonNull DataSize dataSize,
|
||||
@Named("dataSizeUnit") @NonNull DataSizeUnit dataSizeUnit,
|
||||
@Named("nullable") String nullable, @Named("nullable2") String nullable2,
|
||||
@Named("pair") @NonNull Pair<Object, Object> pair,
|
||||
@Named("pair2") @NonNull Pair<@NonNull String, @NonNull Other> pair2,
|
||||
@Named("coll") @NonNull Collection<Object> coll,
|
||||
@Named("coll2") @NonNull Collection<@NonNull Other> coll2,
|
||||
@Named("list") @NonNull List<Object> list,
|
||||
@Named("list2") @NonNull List<@NonNull Other> list2, @Named("set") @NonNull Set<Object> set,
|
||||
@Named("set2") @NonNull Set<@NonNull Other> set2,
|
||||
@Named("map") @NonNull Map<Object, Object> map,
|
||||
@Named("map2") @NonNull Map<@NonNull String, @NonNull Other> map2,
|
||||
@Named("container") @NonNull Map<Object, Object> container,
|
||||
@Named("container2") @NonNull Map<@NonNull String, @NonNull Other> container2,
|
||||
@Named("other") @NonNull Other other, @Named("regex") @NonNull Pattern regex,
|
||||
@Named("any") Object any, @Named("nonNull") @NonNull Object nonNull,
|
||||
@Named("enum") @NonNull Direction _enum) {
|
||||
this._boolean = _boolean;
|
||||
this._int = _int;
|
||||
this._float = _float;
|
||||
this.string = string;
|
||||
this.duration = duration;
|
||||
this.durationUnit = durationUnit;
|
||||
this.dataSize = dataSize;
|
||||
this.dataSizeUnit = dataSizeUnit;
|
||||
this.nullable = nullable;
|
||||
this.nullable2 = nullable2;
|
||||
this.pair = pair;
|
||||
this.pair2 = pair2;
|
||||
this.coll = coll;
|
||||
this.coll2 = coll2;
|
||||
this.list = list;
|
||||
this.list2 = list2;
|
||||
this.set = set;
|
||||
this.set2 = set2;
|
||||
this.map = map;
|
||||
this.map2 = map2;
|
||||
this.container = container;
|
||||
this.container2 = container2;
|
||||
this.other = other;
|
||||
this.regex = regex;
|
||||
this.any = any;
|
||||
this.nonNull = nonNull;
|
||||
this._enum = _enum;
|
||||
}
|
||||
|
||||
public PropertyTypes withBoolean(boolean _boolean) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withInt(long _int) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withFloat(double _float) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withString(@NonNull String string) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withDuration(@NonNull Duration duration) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withDurationUnit(@NonNull DurationUnit durationUnit) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withDataSize(@NonNull DataSize dataSize) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withDataSizeUnit(@NonNull DataSizeUnit dataSizeUnit) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withNullable(String nullable) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withNullable2(String nullable2) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withPair(@NonNull Pair<Object, Object> pair) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withPair2(@NonNull Pair<@NonNull String, @NonNull Other> pair2) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withColl(@NonNull Collection<Object> coll) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withColl2(@NonNull Collection<@NonNull Other> coll2) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withList(@NonNull List<Object> list) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withList2(@NonNull List<@NonNull Other> list2) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withSet(@NonNull Set<Object> set) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withSet2(@NonNull Set<@NonNull Other> set2) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withMap(@NonNull Map<Object, Object> map) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withMap2(@NonNull Map<@NonNull String, @NonNull Other> map2) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withContainer(@NonNull Map<Object, Object> container) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withContainer2(@NonNull Map<@NonNull String, @NonNull Other> container2) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withOther(@NonNull Other other) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withRegex(@NonNull Pattern regex) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withAny(Object any) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withNonNull(@NonNull Object nonNull) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
public PropertyTypes withEnum(@NonNull Direction _enum) {
|
||||
return new PropertyTypes(_boolean, _int, _float, string, duration, durationUnit, dataSize, dataSizeUnit, nullable, nullable2, pair, pair2, coll, coll2, list, list2, set, set2, map, map2, container, container2, other, regex, any, nonNull, _enum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (this.getClass() != obj.getClass()) return false;
|
||||
PropertyTypes other = (PropertyTypes) obj;
|
||||
if (!Objects.equals(this._boolean, other._boolean)) return false;
|
||||
if (!Objects.equals(this._int, other._int)) return false;
|
||||
if (!Objects.equals(this._float, other._float)) return false;
|
||||
if (!Objects.equals(this.string, other.string)) return false;
|
||||
if (!Objects.equals(this.duration, other.duration)) return false;
|
||||
if (!Objects.equals(this.durationUnit, other.durationUnit)) return false;
|
||||
if (!Objects.equals(this.dataSize, other.dataSize)) return false;
|
||||
if (!Objects.equals(this.dataSizeUnit, other.dataSizeUnit)) return false;
|
||||
if (!Objects.equals(this.nullable, other.nullable)) return false;
|
||||
if (!Objects.equals(this.nullable2, other.nullable2)) return false;
|
||||
if (!Objects.equals(this.pair, other.pair)) return false;
|
||||
if (!Objects.equals(this.pair2, other.pair2)) return false;
|
||||
if (!Objects.equals(this.coll, other.coll)) return false;
|
||||
if (!Objects.equals(this.coll2, other.coll2)) return false;
|
||||
if (!Objects.equals(this.list, other.list)) return false;
|
||||
if (!Objects.equals(this.list2, other.list2)) return false;
|
||||
if (!Objects.equals(this.set, other.set)) return false;
|
||||
if (!Objects.equals(this.set2, other.set2)) return false;
|
||||
if (!Objects.equals(this.map, other.map)) return false;
|
||||
if (!Objects.equals(this.map2, other.map2)) return false;
|
||||
if (!Objects.equals(this.container, other.container)) return false;
|
||||
if (!Objects.equals(this.container2, other.container2)) return false;
|
||||
if (!Objects.equals(this.other, other.other)) return false;
|
||||
if (!Objects.equals(this.regex.pattern(), other.regex.pattern())) return false;
|
||||
if (!Objects.equals(this.any, other.any)) return false;
|
||||
if (!Objects.equals(this.nonNull, other.nonNull)) return false;
|
||||
if (!Objects.equals(this._enum, other._enum)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(this._boolean);
|
||||
result = 31 * result + Objects.hashCode(this._int);
|
||||
result = 31 * result + Objects.hashCode(this._float);
|
||||
result = 31 * result + Objects.hashCode(this.string);
|
||||
result = 31 * result + Objects.hashCode(this.duration);
|
||||
result = 31 * result + Objects.hashCode(this.durationUnit);
|
||||
result = 31 * result + Objects.hashCode(this.dataSize);
|
||||
result = 31 * result + Objects.hashCode(this.dataSizeUnit);
|
||||
result = 31 * result + Objects.hashCode(this.nullable);
|
||||
result = 31 * result + Objects.hashCode(this.nullable2);
|
||||
result = 31 * result + Objects.hashCode(this.pair);
|
||||
result = 31 * result + Objects.hashCode(this.pair2);
|
||||
result = 31 * result + Objects.hashCode(this.coll);
|
||||
result = 31 * result + Objects.hashCode(this.coll2);
|
||||
result = 31 * result + Objects.hashCode(this.list);
|
||||
result = 31 * result + Objects.hashCode(this.list2);
|
||||
result = 31 * result + Objects.hashCode(this.set);
|
||||
result = 31 * result + Objects.hashCode(this.set2);
|
||||
result = 31 * result + Objects.hashCode(this.map);
|
||||
result = 31 * result + Objects.hashCode(this.map2);
|
||||
result = 31 * result + Objects.hashCode(this.container);
|
||||
result = 31 * result + Objects.hashCode(this.container2);
|
||||
result = 31 * result + Objects.hashCode(this.other);
|
||||
result = 31 * result + Objects.hashCode(this.regex);
|
||||
result = 31 * result + Objects.hashCode(this.any);
|
||||
result = 31 * result + Objects.hashCode(this.nonNull);
|
||||
result = 31 * result + Objects.hashCode(this._enum);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(1400);
|
||||
builder.append(PropertyTypes.class.getSimpleName()).append(" {");
|
||||
appendProperty(builder, "_boolean", this._boolean);
|
||||
appendProperty(builder, "_int", this._int);
|
||||
appendProperty(builder, "_float", this._float);
|
||||
appendProperty(builder, "string", this.string);
|
||||
appendProperty(builder, "duration", this.duration);
|
||||
appendProperty(builder, "durationUnit", this.durationUnit);
|
||||
appendProperty(builder, "dataSize", this.dataSize);
|
||||
appendProperty(builder, "dataSizeUnit", this.dataSizeUnit);
|
||||
appendProperty(builder, "nullable", this.nullable);
|
||||
appendProperty(builder, "nullable2", this.nullable2);
|
||||
appendProperty(builder, "pair", this.pair);
|
||||
appendProperty(builder, "pair2", this.pair2);
|
||||
appendProperty(builder, "coll", this.coll);
|
||||
appendProperty(builder, "coll2", this.coll2);
|
||||
appendProperty(builder, "list", this.list);
|
||||
appendProperty(builder, "list2", this.list2);
|
||||
appendProperty(builder, "set", this.set);
|
||||
appendProperty(builder, "set2", this.set2);
|
||||
appendProperty(builder, "map", this.map);
|
||||
appendProperty(builder, "map2", this.map2);
|
||||
appendProperty(builder, "container", this.container);
|
||||
appendProperty(builder, "container2", this.container2);
|
||||
appendProperty(builder, "other", this.other);
|
||||
appendProperty(builder, "regex", this.regex);
|
||||
appendProperty(builder, "any", this.any);
|
||||
appendProperty(builder, "nonNull", this.nonNull);
|
||||
appendProperty(builder, "_enum", this._enum);
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Other {
|
||||
public final @NonNull String name;
|
||||
|
||||
public Other(@Named("name") @NonNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Other withName(@NonNull String name) {
|
||||
return new Other(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (this.getClass() != obj.getClass()) return false;
|
||||
Other other = (Other) obj;
|
||||
if (!Objects.equals(this.name, other.name)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
result = 31 * result + Objects.hashCode(this.name);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(100);
|
||||
builder.append(Other.class.getSimpleName()).append(" {");
|
||||
appendProperty(builder, "name", this.name);
|
||||
builder.append("\n}");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Direction {
|
||||
NORTH("north"),
|
||||
|
||||
EAST("east"),
|
||||
|
||||
SOUTH("south"),
|
||||
|
||||
WEST("west");
|
||||
|
||||
private String value;
|
||||
|
||||
private Direction(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user