Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/io/vertx/codegen/ClassModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ protected void checkConstantType(VariableElement elem, TypeInfo type, TypeMirror
if (isLegalNonCallableReturnType(type, allowAnyJavaType)) {
return;
}
// Workaround for Kotlin companion objects.
// https://github.com/vert-x3/vertx-lang-kotlin/issues/93
if (type.getName().equalsIgnoreCase(modelElt.getQualifiedName().toString() + "." + type.getSimpleName())) {
return;
}
throw new GenException(elem, "type " + type + " is not legal for use for a constant type in code generation");
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/java/io/vertx/test/codegen/ClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,15 @@ public void testImplPackage() throws Exception {
}

@Test
public void testInterfaceWithKotlinCompanionObject() throws Exception {
ClassModel model = new GeneratorHelper().generateClass(InterfaceWithCompanionObject.class);
}

@Test(expected = GenException.class)
public void testInterfaceUnrelatedCompanionObject() throws Exception {
ClassModel model = new GeneratorHelper().generateClass(InterfaceWithUnrelatedCompanionClass.class);
}

public void testJsonMapper() throws Exception {
ClassModel model = new GeneratorHelper().generateClass(WithMyPojo.class);
assertFalse(model.getAnnotations().isEmpty());
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/io/vertx/test/codegen/testapi/Companion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.vertx.test.codegen.testapi;

public final class Companion {
static final Companion $$INSTANCE;

public final void create() {
}

static {
Companion var0 = new Companion();
$$INSTANCE = var0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.vertx.test.codegen.testapi;

import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;

/**
* @author Richard Gomez
*/
@VertxGen
public interface InterfaceWithCompanionObject {

InterfaceWithCompanionObject.Companion Companion = InterfaceWithCompanionObject.Companion.$$INSTANCE;

@GenIgnore
public static final class Companion {
static final InterfaceWithCompanionObject.Companion $$INSTANCE;

public final void create() {
}

static {
InterfaceWithCompanionObject.Companion var0 = new InterfaceWithCompanionObject.Companion();
$$INSTANCE = var0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.vertx.test.codegen.testapi;

import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;

/**
* @author Richard Gomez
*/
@VertxGen
public interface InterfaceWithUnrelatedCompanionClass {
Companion CompanionField = Companion.$$INSTANCE;
}