Esempio n. 1
0
 protected void transform(final XtendField source, final JvmGenericType container) {
   super.transform(source, container);
   Set<EObject> _jvmElements = this._iJvmModelAssociations.getJvmElements(source);
   EObject _head = IterableExtensions.<EObject>head(_jvmElements);
   final JvmField field = ((JvmField) _head);
   boolean _equals = Objects.equal(field, null);
   if (_equals) {
     return;
   }
   JvmVisibility _visibility = field.getVisibility();
   boolean _equals_1 = Objects.equal(_visibility, JvmVisibility.PRIVATE);
   if (_equals_1) {
     field.setVisibility(JvmVisibility.DEFAULT);
   }
   boolean _isExtension = source.isExtension();
   if (_isExtension) {
     field.setVisibility(JvmVisibility.PUBLIC);
     EList<JvmAnnotationReference> _annotations = field.getAnnotations();
     JvmAnnotationReference _annotation =
         this.jvmTypesBuilder.toAnnotation(source, org.jnario.runner.Extension.class);
     this.jvmTypesBuilder.<JvmAnnotationReference>operator_add(_annotations, _annotation);
   }
 }
 protected void transform(XtendField source, JvmGenericType container) {
   if ((source.isExtension() || source.getName() != null) && source.getType() != null) {
     JvmField field = typesFactory.createJvmField();
     field.setSimpleName(computeFieldName(source, container));
     container.getMembers().add(field);
     associator.associatePrimary(source, field);
     field.setVisibility(source.getVisibility());
     field.setStatic(source.isStatic());
     field.setType(cloneWithProxies(source.getType()));
     jvmTypesBuilder.translateAnnotationsTo(source.getAnnotationInfo().getAnnotations(), field);
     jvmTypesBuilder.setDocumentation(field, jvmTypesBuilder.getDocumentation(source));
     jvmTypesBuilder.setInitializer(field, source.getInitialValue());
   }
 }
  @Test
  public void testGenerateWithExpressionContext() throws Exception {
    EDataType dataType = EcorePackage.eINSTANCE.getEBigDecimal();

    EPackage pkg = helper.createPackage("tests");
    EClass clazz = helper.createClass(pkg, "NumericTests");
    helper.addAttribute(clazz, dataType, "a");

    EObject instance = helper.createInstance(clazz);

    XtextResourceSet resourceSet =
        expressionFactory.getInjector().getInstance(XtextResourceSet.class);
    Resource resource = resourceSet.createResource(URI.createURI("__synthetic.testData.expr"));
    resource.getContents().add(instance);

    // TODO could use TypeReferences getTypeForName() instead JvmTypesBuilder newTypeRef() ..

    Injector injector = expressionFactory.getInjector();
    JvmTypesBuilder jvmTypesBuilder = injector.getInstance(JvmTypesBuilder.class);
    JvmTypeReferenceBuilder.Factory factory =
        injector.getInstance(JvmTypeReferenceBuilder.Factory.class);
    JvmTypeReferenceBuilder jvmTypeReferenceBuilder =
        factory.create(instance.eResource().getResourceSet());

    JvmGenericType type = jvmTypesBuilder.toClass(instance, "tests.NumericTests");
    resource.getContents().add(type);

    JvmField field =
        jvmTypesBuilder.toField(
            instance,
            "a",
            jvmTypeReferenceBuilder.typeRef(
                dataType.getInstanceClassName() /*"java.math.BigDecimal"*/));
    field.setVisibility(JvmVisibility.PUBLIC);
    type.getMembers().add(field);

    ExpressionContext context = new ExpressionContext(resource);
    context.setType(jvmTypeReferenceBuilder.typeRef(Boolean.TYPE));
    context.addVariable("t", jvmTypeReferenceBuilder.typeRef(type));

    checkGeneration(
        "t.a == 5",
        Boolean.TYPE,
        context,
        "com.google.common.base.Objects.equal(t.a, new java.math.BigDecimal(\"5\"))");
  }