Issues while importing Java project

Hi,

I am currently importing the Jest library (https://github.com/searchbox-io/Jest) in MPS.  I have a few issues which I couldn't solve.

 

Concrete method call of generic method

IntelliJ

MPS

The ImmutableMap class of Google's Guava library allows to customize the type of the "of-method" Is there any way to express this in MPS? The type checker accepts the call only when I add a cast to Map<string, Object> but this results in a compilation error.

 

Check if Java annotation is present
The call isAnnotationPresent() is only accepted by the type checker if I add "getClass()", but this results also in an error while compiling. How do I express this in the correct way?

Error: io/searchbox/action/AbstractAction.java : The method isAnnotationPresent(Class<? extends Annotation>) in the type AccessibleObject is not applicable for the arguments (Class<capture#2-of ? extends Class>) (line: 96)

 

 

Compatibility problems for method call parameters


While compiling, at every point in the code where jestClient.execute() is called an error occurs. The generated code however looks just like the original Java Code in IntelliJ.

 

Error: io/searchbox/client/config/discovery/NodeCheckerTest.java : The method execute(Action<T>) in the type JestClient is not applicable for the arguments (Action) (line: 167)

 

Erasure Failure (I don't know how to title this error)

I fixed this error with a workaround, but I just wanted to let you know, that this particular erasure didn't work for me. MPS didn't allow me to write "operationPath()" after builder. Only after casting builder in the concrete classes it was possible to call "operationPath()".

 

Best regards

Moritz Fey

 

2 comments

Hi

In the first one, your MPS code isn't identical to java code, as the 'of' method doesn't have generic arguments attached

<String, Object>of(...)

You can add those by hitting '>' on the left of 'of' I think. Or something like that.

 

Regarding the others, I think those are just bugs in our java (baseLanguage) implementation. And I suggest you file them as bugs.

Also keep in mind, that in some cases you could try to ignore the errors MPS reports, and generate the source code anyway. The generated java source will be accepted by the java compiler, if it really is correct.

That doens't always work of course, like in your case with Cat.CatBuilder where you can't enter the code in the first place. By the way, why do you cast to individual sub-classes instead of casting to Cat.CatBuilder itself?

Also, when filing those bugs, I would title the CatBuilder one 'Additional bound of a generic paramter is ignored'. I think erasure isn't relevant here.

0

Hi Daniil,

thank you very much for answering!

I tried '<' instead of '>' so it obviously didn't work for me.

 

I thought I tried to cast to Cat.CatBuilder and it didn't work. Now I tried it again and it worked!

 

I am now going to check if the generated code is identical with the java sources.

 

Thanks again

Moritz

0

Please sign in to leave a comment.