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
24 changed files
with
369 additions
and
426 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,74 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 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.Locale; | ||
|
||
/** | ||
* Primitive types that are convertible with {@code boolean}. | ||
* | ||
* @author squid233 | ||
* @see Convert | ||
* @since 0.1.0 | ||
*/ | ||
public enum AsBool { | ||
/** | ||
* {@code char} type | ||
*/ | ||
CHAR(char.class), | ||
/** | ||
* {@code byte} type | ||
*/ | ||
BYTE(byte.class), | ||
/** | ||
* {@code short} type | ||
*/ | ||
SHORT(short.class), | ||
/** | ||
* {@code int} type | ||
*/ | ||
INT(int.class), | ||
/** | ||
* {@code long} type | ||
*/ | ||
LONG(long.class), | ||
/** | ||
* {@code float} type | ||
*/ | ||
FLOAT(float.class), | ||
/** | ||
* {@code double} type | ||
*/ | ||
DOUBLE(double.class), | ||
; | ||
|
||
private final Class<?> javaClass; | ||
|
||
AsBool(Class<?> javaClass) { | ||
this.javaClass = javaClass; | ||
} | ||
|
||
/// {@return the class of this type} | ||
public Class<?> javaClass() { | ||
return javaClass; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name().toLowerCase(Locale.ROOT); | ||
} | ||
} |
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,80 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 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 overrun.marshal.internal.Constants; | ||
|
||
import java.lang.constant.*; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.reflect.AnnotatedElement; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Parameter; | ||
import java.util.Optional; | ||
|
||
/** | ||
* @author squid233 | ||
* @since 0.1.0 | ||
*/ | ||
public record ConvertedClassType( | ||
Class<?> javaClass, | ||
Class<?> downcallClass | ||
) implements Constable { | ||
public static ConvertedClassType returnType(Method method) { | ||
return of(method, method.getReturnType()); | ||
} | ||
|
||
public static ConvertedClassType parameterType(Parameter parameter) { | ||
return of(parameter, parameter.getType()); | ||
} | ||
|
||
private static ConvertedClassType of(AnnotatedElement element, Class<?> type) { | ||
Convert convert = element.getAnnotation(Convert.class); | ||
if (type == boolean.class && convert != null) { | ||
return new ConvertedClassType(type, convert.value().javaClass()); | ||
} | ||
return new ConvertedClassType(type, type); | ||
} | ||
|
||
@Override | ||
public Optional<Desc> describeConstable() { | ||
return Optional.of(new Desc(ClassDesc.ofDescriptor(javaClass.descriptorString()), ClassDesc.ofDescriptor(downcallClass.descriptorString()))); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (javaClass == downcallClass) { | ||
return javaClass.getSimpleName(); | ||
} | ||
return downcallClass.getSimpleName() + "<from " + javaClass.getSimpleName() + ">"; | ||
} | ||
|
||
public static final class Desc extends DynamicConstantDesc<ConvertedClassType> { | ||
private final ClassDesc javaClass; | ||
private final ClassDesc downcallClass; | ||
|
||
public Desc(ClassDesc javaClass, ClassDesc downcallClass) { | ||
super(Constants.BSM_DowncallFactory_createExtendedClassType, ConstantDescs.DEFAULT_NAME, Constants.CD_ConvertedClassType, javaClass, downcallClass); | ||
this.javaClass = javaClass; | ||
this.downcallClass = downcallClass; | ||
} | ||
|
||
@Override | ||
public ConvertedClassType resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException { | ||
return new ConvertedClassType(javaClass.resolveConstantDesc(lookup), downcallClass.resolveConstantDesc(lookup)); | ||
} | ||
} | ||
} |
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.