Skip to content

Commit

Permalink
Declare UnsupportedPlatformException in method signatures; some Javad…
Browse files Browse the repository at this point in the history
…oc tweaks
  • Loading branch information
jwharm committed Feb 28, 2024
1 parent e5fdd0b commit a9be060
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public TypeSpec generateBuilderClass() {

TypeSpec.Builder builder = TypeSpec.classBuilder("Builder")
.addJavadoc("""
Inner class implementing a builder pattern to construct a GObject with properties
Inner class implementing a builder pattern to construct a GObject with
properties.
@param <B> the type of the Builder that is returned
""")
Expand Down Expand Up @@ -155,14 +156,15 @@ private MethodSpec buildMethod() {
.returns(rt.typeName())
.addJavadoc("""
Finish building the {@code $1L} object. This will call
{@link $2T#withProperties} to create a new
GObject instance, which is then cast to {@code $1L}.
{@link $2T#withProperties} to create a new GObject instance,
which is then cast to {@code $1L}.
@return a new instance of {@code $1L} with the properties
that were set in the Builder object.
""", rt.typeName().simpleName(), GOBJECT);
if (rt instanceof Multiplatform mp && mp.doPlatformCheck())
builder.addJavadoc("@throws $T when run on an unsupported platform",
builder.addException(ClassNames.UNSUPPORTED_PLATFORM_EXCEPTION)
.addJavadoc("@throws $T when run on an unsupported platform",
ClassNames.UNSUPPORTED_PLATFORM_EXCEPTION);

builder.beginControlFlow("try");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ private MethodSpec parentAccessor() {

return MethodSpec.methodBuilder("asParent")
.addJavadoc("""
Returns this instance as if it were its parent type. This is mostly synonymous to the Java
{@code super} keyword, but will set the native typeclass function pointers to the parent
type. When overriding a native virtual method in Java, "chaining up" with
{@code super.methodName()} doesn't work, because it invokes the overridden function pointer
again. To chain up, call {@code asParent().methodName()}. This will call the native function
pointer of this virtual method in the typeclass of the parent type.
Returns this instance as if it were its parent type. This is mostly
synonymous to the Java {@code super} keyword, but will set the native
typeclass function pointers to the parent type. When overriding a native
virtual method in Java, "chaining up" with {@code super.methodName()}
doesn't work, because it invokes the overridden function pointer again.
To chain up, call {@code asParent().methodName()}. This will call the
native function pointer of this virtual method in the typeclass of the
parent type.
""")
.addModifiers(Modifier.PROTECTED)
.returns(cls.typeName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private MethodSpec constructor() {
if (ctor.infoElements().doc() != null) {
String javadoc = new DocGenerator(ctor.infoElements().doc()).generate();
if (ctor.doPlatformCheck())
builder.addJavadoc(javadoc, ClassNames.UNSUPPORTED_PLATFORM_EXCEPTION);
builder.addException(ClassNames.UNSUPPORTED_PLATFORM_EXCEPTION)
.addJavadoc(javadoc, ClassNames.UNSUPPORTED_PLATFORM_EXCEPTION);
else
builder.addJavadoc(javadoc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public MethodSpec generate() {
if (func.infoElements().doc() != null) {
String javadoc = new DocGenerator(func.infoElements().doc()).generate();
if (func instanceof Multiplatform mp && mp.doPlatformCheck())
builder.addJavadoc(javadoc, ClassNames.UNSUPPORTED_PLATFORM_EXCEPTION);
builder.addException(ClassNames.UNSUPPORTED_PLATFORM_EXCEPTION)
.addJavadoc(javadoc, ClassNames.UNSUPPORTED_PLATFORM_EXCEPTION);
else
builder.addJavadoc(javadoc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected MethodSpec getTypeMethod() {
Get the GType of the $L class
@return the GType
""", rt.cType())
""", name())
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(ClassName.get("org.gnome.glib", "Type"))
.addStatement("return $T.getType($S)",
Expand Down

0 comments on commit a9be060

Please sign in to comment.