DomainCompiler in Xtext 2.1 [message #757492] |
Fri, 18 November 2011 11:06  |
Eclipse User |
|
|
|
Hi,
I try to reproduce, in Xtext 2.1, the Jan's blog Xtext 2.0 example.
I have created a DomainmodelTypeProvider class and bound it in the DomainmodelRuntimeModule.
I have also created a DomainmodelCompiler class but I don't find where it can be bound in Xtext 2.1. I don't find where XbaseCompiler is bound to Guice...
Can you help me ?
Thanks for your answer.
|
|
|
|
|
|
|
Re: DomainCompiler in Xtext 2.1 [message #757528 is a reply to message #757526] |
Fri, 18 November 2011 14:08   |
Eclipse User |
|
|
|
So this is what works for me
public class DomainmodelRuntimeModule extends AbstractDomainmodelRuntimeModule {
@Override
public Class<? extends IValueConverterService> bindIValueConverterService() {
return DomainmodelValueConverterService.class;
}
@Override
public Class<? extends ITypeProvider> bindITypeProvider() {
return DomainModelTypeProvider.class;
}
public Class<? extends XbaseCompiler> bindXbaseCompiler() {
return DomainModelCompiler.class;
}
}
@Singleton
public class DomainModelTypeProvider extends XbaseTypeProvider {
@Override
protected JvmTypeReference type(XExpression expression, JvmTypeReference rawExpectation, boolean rawType) {
if (expression instanceof DecimalLiteral) {
return _type((DecimalLiteral) expression, rawExpectation, rawType);
}
return super.type(expression, rawExpectation, rawType);
}
protected JvmTypeReference _type(DecimalLiteral literal, JvmTypeReference rawExpectation, boolean rawType) {
return getTypeReferences().getTypeForName(Double.class,
literal);
}
}
*/
public class DomainModelCompiler extends XbaseCompiler {
protected void _toJavaExpression(DecimalLiteral expr, IAppendable b) {
b.append(expr.getIntPart() + "." + expr.getDecimalPart());
}
protected void _toJavaStatement(DecimalLiteral expr, IAppendable b, boolean isReferenced) {
generateComment(expr, b, isReferenced);
}
}
~Christian
|
|
|
|
Re: DomainCompiler in Xtext 2.1 [message #758328 is a reply to message #757538] |
Tue, 22 November 2011 13:38   |
Eclipse User |
|
|
|
Hey,
now, I understand the topic of the thread^^.
I try to add operators using xtext 2.1.1 like in this article: http://koehnlein.blogspot.com/2011/07/extending-xbase.html
Instead of the extending StaticMethodsFeatureForTypeProvider I extend ExtensionClassNameProvider:
@Singleton
public class UclExtensionClassNameProvider extends ExtensionClassNameProvider {
@Override
protected Collection<String> computeLiteralClassNames() {
Collection<String> result = super.computeLiteralClassNames();
result.add(DoubleLiteral.class.getName());
return result;
}
@Override
protected Multimap<Class<?>, Class<?>> simpleComputeExtensionClasses() {
Multimap<Class<?>, Class<?>> extensions = super.simpleComputeExtensionClasses();
extensions.put(Double.class, MathExtensions.class);
return extensions;
}
}
... and bind it in the RuntimeModule:
public Class<? extends ExtensionClassNameProvider> bindExtensionClassNameProvider() {
return UclExtensionClassNameProvider.class;
}
MathExtensions class:
public class MathExtensions {
public static Double operator_plus(Double x, Double y) {
return x + y;
}
public static Double operator_minus(Double x, Double y) {
return x - y;
}
public static Double operator_multiply(Double x, Double y) {
return x * y;
}
public static Double operator_divide(Double x, Double y) {
return x / y;
}
}
When I debug StaticMethodsFeatureForTypeProvider.getVisibleTypesContainingStaticMethods() result the MathExtensions for Double types is returned correctly. Also returned by default is the Comparable extension but I neither can use my MathExtensions nor any default ones like '<' or '=='.
What am I doing wrong.
regards,
Max
[Updated on: Tue, 22 November 2011 13:42] by Moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05325 seconds