Use java class in my language

Hi,

i have a problem where i can't find a working solution for. I know this topic was partly already discussed but i don't get it.

I want two things:

1) Use name of java in the same project existing java classes in my language - auto complete.

2) Access the methods of a java class i did write some lines above - even auto complete.

 

Does anyone know an easy solution to embed custom java class and method names into my language?

 

Many regards

0
7 comments

You'll have to create your own reference concepts in your language that target Java ClassConcepts and MethodDeclarations, respectively. In scope rules for the references you'll ensure that only methods from the references classes should be displayed in the completion menu.

Vaclav

 

0
Avatar
Permanently deleted user

Hello Vaclav,

thank you very much for your help. In the mean time i think i made it - but i did used Classifier and BaseMethodDeclarations and without Method filtering until now. Trying now to find out where is the difference to ClassConcepts and MethodDeclarations. 

But until now i just can't reference classes and methods from an other project. I did tried to access some java-classes i did wrote at an intellij project and make them accessible by :

Right click on Solution --> Module Properties --> Common --> Add Model Root --> Java Source Stubs --> Selected folder to directory with .java files in which the classes are placed.

Do you maybe have an idea what jam doing wrong?

Many regards

0
Avatar
Permanently deleted user

Okay. I got it. I made a failure by not adding the dependency for the model which is generated. 

0
Avatar
Permanently deleted user

Okay. I am sorry, but i got one more question. Do you have one hint for me, how i can filter the methods based on the class?

Many regards

0

You'll have to define a reference scope in the Constraints aspect for your method reference concept. The function will retrieve methods of the classes already referred to, perhaps something along these lines:

link {method} 
referent set handler <none>
scope (referenceNode, contextNode, containmentLink, position, linkTarget)->Scope {
nlist<ClassConcept> classes = ...
sequence<node<MethodDeclaration>> targets = classes.selectMany({~it => it.getThisType().getMembers().ofConcept<MethodDeclaration>; });
new ListScope(targets) {
public string getName(node<> child) {
child : INamedConcept.name;
}
};
}
presentation <no presentation>

 

0
Avatar
Permanently deleted user

Hello Vaclav,

thx for the example. It did help me to get it done. But another question did arose, after i did experimented a little bit with mps. 

Is there a simple way to define a "kind of bucket" (e.g. as child, reference or property in my concept) which allows to directly enter base language code? For example first i have some kind of code from my own language and then there is a field where i can write every kind of base language code i want - for example the declaration and initialization of a int variable.

Many regards

0

I'd suggest you try BlockStatement, is is used to hold BaseLanguage statements, e.g. in method bodies.

0

Please sign in to leave a comment.