|
|
|
|
|
|
|
Re: Best way to extend Xtend? [message #813518 is a reply to message #813384] |
Mon, 05 March 2012 11:15 |
|
Hi!
Extending Xtend works actually quite well (but Jan is right about the limited syntactic possibilites). Here is my grammar:
grammar org.jnario.spec.Spec with org.eclipse.xtend.core.Xtend
import "http www jnario org /jnario/spec/Spec"
import "http www eclipse org /xtend" as xtend
import "http www eclipse org /xtext/xbase/Xbase" as xbase
import "http www eclipse org /xtext/common/JavaVMTypes" as types
import "http www jnario org /Jnario"
...
XPrimaryExpression returns xbase::XExpression:
XConstructorCall |
XBlockExpression |
XSwitchExpression |
XFeatureCall |
XLiteral |
XIfExpression |
XForLoopExpression |
XWhileExpression |
XDoWhileExpression |
XThrowExpression |
XReturnExpression |
XTryCatchFinallyExpression |
XParenthesizedExpression |
Assertion |
Matcher;
I have defined my metamodel in a separate ecore file. Further things you need to do:
- Import org.eclipse.xtend.core & org.eclipse.xtext.xbase as projects with source folders into your workspace. This is necessary to make the EcoreGenerator find the generated custom classes.
- Patch the EcoreGenerator (custom classes in Xtend use a different naming scheme):
// GenerateSpec.mwe2
component = org.jnario.PatchedEcoreGenerator {
genModel = "platform:/resource/${projectName}/model/Spec.genmodel"
srcPath ="platform:/resource/${projectName}/src"
srcPath ="platform:/resource/org.eclipse.xtext.common.types/src"
srcPath ="platform:/resource/org.eclipse.xtext.xbase/src"
srcPath ="platform:/resource/org.eclipse.xtend.core/src"
srcPath ="platform:/resource/org.jnario/src"
}
and the patched EcoreGenerator:
package org.jnario;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.mwe2.ecore.EcoreGenerator;
import com.google.common.base.Function;
public class PatchedEcoreGenerator extends EcoreGenerator {
private boolean customClasses;
protected final class PatchedMapper implements Function<String, String> {
public String apply(String from) {
if (from.startsWith("org.eclipse.emf.ecore"))
return null;
for(String srcPath: srcPaths) {
URI createURI = URI.createURI(srcPath+"/"+from.replace('.', '/')+"Custom.java");
String customClassName = from+"Custom";
if (URIConverter.INSTANCE.exists(createURI, null)) {
return customClassName;
}
createURI = URI.createURI(srcPath+"/"+from.replace('.', '/')+"ImplCustom.java");
if (URIConverter.INSTANCE.exists(createURI, null)) {
return customClassName;
}
if (from.endsWith("Impl") && customClasses) {
generate(from,customClassName,createURI);
return customClassName;
}
}
return null;
}
}
@Override
public void setGenerateCustomClasses(boolean generateCustomClasses) {
customClasses = generateCustomClasses;
super.setGenerateCustomClasses(generateCustomClasses);
}
}
This works for me so far. It is actually not necessary to copy a lot infrastructure. The only thing you need to do is to copy the runtime and ui module from xtend.
Hope that helps.
Sebastian
P.S. I had to change the imported package URIs as I am not allowed to post any links in messages...
|
|
|
|
|
|
Re: Best way to extend Xtend? [message #976730 is a reply to message #819131] |
Thu, 08 November 2012 20:14 |
Iuzuz Denker Messages: 2 Registered: November 2012 |
Junior Member |
|
|
Hello Xtend-frieds,
I also want to extend Xtend and try out some ideas. But some things has been changed since last message (at least the URLs) and the guidance seems not to work any more. I must say I am an Xtext beginner.
Steps, I tried:
- Installed a new Eclipse with Xtext
- Created a new Xtext project (=4 projects)
- Changed the with-clause to "with org.eclipse.xtend.core.Xtend" -> can't resolve the grammar
- Added to the project org.xtext.example.mydsl a manifest dependence to ...xtend.core -> the error disappear
- added to the .mwe2 file:
registerGeneratedEPackage = "org.eclipse.xtend.core.xtend.XtendPackage"
registerGenModelFile = "platform:/resource/org.eclipse.xtend.core/model/Xtend.genmodel"
- "Generate Xtext Artifacts" (on the .xtext file) -> Successful (with the download)
After the (successful) generating there is a compile error in th ..ui project:
Quote:The project was not built since its build path is incomplete. Cannot find the class file for
org.eclipse.xtend.core.services.XtendGrammarAccess$ImportElements. Fix the build path then try building this project
- Added to the project org.xtext.example.mydsl.ui a manifest dependences to all ..xtend.. and ..xbase.. (without .source)
I get 6 erroros, the base seems to be, the package
org.eclipse.xtend.core.ui and the class are not in the classpath
org.eclipse.xtend.core.ui.contentassist.XtendProposalProvider
But if I ctrl-click on it, it is found in one of the dependences.
Have any one a suggestion?
What do I make wrong?
Thanks, Iuzuz
[Updated on: Thu, 08 November 2012 21:19] Report message to a moderator
|
|
|
Re: Best way to extend Xtend? [message #976805 is a reply to message #976730] |
Thu, 08 November 2012 21:37 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Iuzuz,
it might be that the generated package is wrong. The
XtendProposalProvider is in xtend.ide.contentassist and not in core.ui..
I'm afraid you'll have to adapt that manually
Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 08.11.12 21:28, schrieb Iuzuz Denker:
> Hello Xtend-frieds,
> I also want to extend Xtend and try out some ideas. But some things has
> been changed since last message (at least the URLs) and the guidance
> seems not to work any more. I must say I am an Xtext beginner.
>
> Steps, I tried:
>
>
> Installed a new Eclipse with Xtext
> Created a new Xtext project (=4 projects)
> Changed the with-clause to "with org.eclipse.xtend.core.Xtend" -> can't
> resolve the grammar
> Added to the project org.xtext.example.mydsl a manifest dependence to
> ...xtend.core -> the error disappear
> added to the .mwe2 file:
> registerGeneratedEPackage = "org.eclipse.xtend.core.xtend.XtendPackage"
> registerGenModelFile =
> "platform:/resource/org.eclipse.xtend.core/model/Xtend.genmodel"
>
> "Generate Xtext Artifacts" (on the .xtext file) -> Successful (with the
> download)
>
>
> After the (successful) generating there is a compile error in th ..ui
> project:
> Quote:
>> The project was not built since its build path is incomplete. Cannot
>> find the class file for
>> org.eclipse.xtend.core.services.XtendGrammarAccess$ImportElements. Fix
>> the build path then try building this project
>
>
>
> Added to the project org.xtext.example.mydsl a manifest dependences to
> all ..xtend.. and ..xbase.. (without .source)
>
> I get 6 erroros, the base seems to be, the package
> org.eclipse.xtend.core.ui and the class are not in the classpath
> org.eclipse.xtend.core.ui.contentassist.XtendProposalProvider
>
> But if I ctrl-click on it, it is found in one of the dependences.
>
> Have any one a suggestion?
> What do I make wrong?
>
> Thanks, Iuzuz
|
|
|
|
Powered by
FUDForum. Page generated in 0.05503 seconds