2

I want to generate an interface with non-default methods. For this purpose I'm using the JvmTypesBuilder.

The code

meth.toMethod(meth.name, meth.returnType)[]

generates for example

public default int meth();

Trying it with

meth.toMethod(meth.name, meth.returnType)[
   it.^default = false
]

doesn't change anything.

Setting it abstract works

meth.toMethod(meth.name, meth.returnType)[
  it.abstract = true
]

but then I get a method like

public abstract int meth();

what I don't want either.

Is there any way using JvmTypesBuilder and generate a method without default or abstract keywords?

public int meth();

I'm using Eclipse 4.5.1 for DSL Developer

Mino
  • 23
  • 3

2 Answers2

0

Please make sure that you put the method into an interface and not into a class. E.g. please set the interface flag on the JvmGenericType to true. That should do the trick.

Sebastian Zarnekow
  • 6,609
  • 20
  • 23
0

What do you expect to be generated? A method can either have an implementation (default) or not (abstract). In fact, without any modifiers, an interface method is implicitly abstract.

interface MyInterface
{
    public abstract void foo();
}

compiles to exactly the same bytecode as

interface MyInterface
{
    public void foo();
}
Clashsoft
  • 11,553
  • 5
  • 40
  • 79
  • I know that, but you second code is shorter and better to read. It's only a question fo readability and appearance. I expected another behavior of JvmTypesBuilder. – Mino Oct 20 '15 at 15:48
  • In that case, it is just a matter of prettyprinting. – Clashsoft Oct 20 '15 at 16:09