|
|
|
|
|
Re: DomainCompiler in Xtext 2.1 [message #757528 is a reply to message #757526] |
Fri, 18 November 2011 19:08 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: DomainCompiler in Xtext 2.1 [message #758328 is a reply to message #757538] |
Tue, 22 November 2011 18:38 |
Max Goltzsche Messages: 40 Registered: November 2011 |
Member |
|
|
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 18:42] Report message to a moderator
|
|
|
|
Re: DomainCompiler in Xtext 2.1 [message #758333 is a reply to message #758331] |
Tue, 22 November 2011 19:26 |
|
Hi,
StaticMethodsFeatureForTypeProvider uses ExtensionClassNameProvider so its ok if you extend ExtensionClassNameProvider.
the keypoint is (from jans blog)
Quote:Let's write a new extension library class holding the operations as static methods. These methods need to be available at runtime, too, as the generated Java code will call them. That's why it is a good idea to put such extension classes into a separate plug-in org.eclipse.xtext.example.domainmodel.lib.
Quote:If you add the plug-in org.eclipse.xtext.example.domainmodel.lib to the classpath of the project in the runtime workspace, the following domain model should compile
i bet you missed at least the second point
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.04339 seconds