protected void transform(XtendConstructor source, JvmGenericType container) {
   JvmConstructor constructor = typesFactory.createJvmConstructor();
   container.getMembers().add(constructor);
   associator.associatePrimary(source, constructor);
   JvmVisibility visibility = source.getVisibility();
   constructor.setSimpleName(container.getSimpleName());
   constructor.setVisibility(visibility);
   for (XtendParameter parameter : source.getParameters()) {
     JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
     jvmParam.setName(parameter.getName());
     jvmParam.setParameterType(cloneWithProxies(parameter.getParameterType()));
     constructor.getParameters().add(jvmParam);
     associator.associate(parameter, jvmParam);
   }
   copyAndFixTypeParameters(source.getTypeParameters(), constructor);
   for (JvmTypeReference exception : source.getExceptions()) {
     constructor.getExceptions().add(cloneWithProxies(exception));
   }
   jvmTypesBuilder.translateAnnotationsTo(
       source.getAnnotationInfo().getAnnotations(), constructor);
   associator.associateLogicalContainer(source.getExpression(), constructor);
   jvmTypesBuilder.setDocumentation(constructor, jvmTypesBuilder.getDocumentation(source));
 }
 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());
   }
 }
 protected void addDefaultConstructor(XtendClass source, JvmGenericType target) {
   boolean declaredConstructor = false;
   for (XtendMember member : source.getMembers()) {
     if (member instanceof XtendConstructor) {
       declaredConstructor = true;
       break;
     }
   }
   if (!declaredConstructor) {
     JvmConstructor constructor = typesFactory.createJvmConstructor();
     target.getMembers().add(constructor);
     associator.associatePrimary(source, constructor);
     constructor.setSimpleName(source.getName());
     constructor.setVisibility(JvmVisibility.PUBLIC);
   }
 }
  protected JvmGenericType transform(XtendClass source, boolean prelinkingPhase) {
    JvmGenericType inferredJvmType = typesFactory.createJvmGenericType();
    source.eResource().getContents().add(inferredJvmType);
    associator.associatePrimary(source, inferredJvmType);
    inferredJvmType.setPackageName(source.getPackageName());
    inferredJvmType.setSimpleName(source.getName());
    inferredJvmType.setVisibility(JvmVisibility.PUBLIC);
    if (!prelinkingPhase) {
      JvmAnnotationType annotation =
          (JvmAnnotationType) typeReferences.findDeclaredType(SuppressWarnings.class, source);
      if (annotation != null) {
        JvmAnnotationReference suppressWarnings = typesFactory.createJvmAnnotationReference();
        suppressWarnings.setAnnotation(annotation);
        JvmStringAnnotationValue annotationValue = typesFactory.createJvmStringAnnotationValue();
        annotationValue.getValues().add("all");
        suppressWarnings.getValues().add(annotationValue);
        inferredJvmType.getAnnotations().add(suppressWarnings);
      }
      addDefaultConstructor(source, inferredJvmType);
      if (source.getExtends() == null) {
        JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
        if (typeRefToObject != null) inferredJvmType.getSuperTypes().add(typeRefToObject);
      } else {
        inferredJvmType.getSuperTypes().add(cloneWithProxies(source.getExtends()));
      }
      for (JvmTypeReference intf : source.getImplements()) {
        inferredJvmType.getSuperTypes().add(cloneWithProxies(intf));
      }
      copyAndFixTypeParameters(source.getTypeParameters(), inferredJvmType);
      for (XtendMember member : source.getMembers()) {
        if (member instanceof XtendField
            || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)
            || member instanceof XtendConstructor) {
          transform(member, inferredJvmType);
        }
      }
      appendSyntheticDispatchMethods(source, inferredJvmType);
      computeInferredReturnTypes(inferredJvmType);
      jvmTypesBuilder.translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
      jvmTypesBuilder.setDocumentation(inferredJvmType, jvmTypesBuilder.getDocumentation(source));

      nameClashResolver.resolveNameClashes(inferredJvmType);
    }
    return inferredJvmType;
  }
 /**
  * @return a {@link JvmOperation} with common denominator argument types of all given operations
  */
 protected JvmOperation deriveGenericDispatchOperationSignature(
     List<JvmOperation> sortedOperations, JvmGenericType target) {
   if (sortedOperations.isEmpty()) return null;
   final Iterator<JvmOperation> iterator = sortedOperations.iterator();
   JvmOperation first = iterator.next();
   JvmOperation result = typesFactory.createJvmOperation();
   target.getMembers().add(result);
   for (int i = 0; i < first.getParameters().size(); i++) {
     JvmFormalParameter parameter = typesFactory.createJvmFormalParameter();
     result.getParameters().add(parameter);
     parameter.setParameterType(getTypeProxy(parameter));
     JvmFormalParameter parameter2 = first.getParameters().get(i);
     parameter.setName(parameter2.getName());
   }
   jvmTypesBuilder.setBody(result, compileStrategies.forDispatcher(result, sortedOperations));
   JvmVisibility commonVisibility = null;
   boolean isFirst = true;
   boolean allStatic = true;
   for (JvmOperation jvmOperation : sortedOperations) {
     Iterable<XtendFunction> xtendFunctions =
         filter(associations.getSourceElements(jvmOperation), XtendFunction.class);
     for (XtendFunction func : xtendFunctions) {
       JvmVisibility xtendVisibility =
           func.eIsSet(Xtend2Package.Literals.XTEND_FUNCTION__VISIBILITY)
               ? func.getVisibility()
               : null;
       if (isFirst) {
         commonVisibility = xtendVisibility;
         isFirst = false;
       } else if (commonVisibility != xtendVisibility) {
         commonVisibility = null;
       }
       associator.associate(func, result);
       if (!func.isStatic()) allStatic = false;
     }
     for (JvmTypeReference declaredException : jvmOperation.getExceptions())
       result.getExceptions().add(cloneWithProxies(declaredException));
   }
   if (commonVisibility == null) result.setVisibility(JvmVisibility.PUBLIC);
   else result.setVisibility(commonVisibility);
   result.setStatic(allStatic);
   return result;
 }
 protected void copyAndFixTypeParameters(
     List<JvmTypeParameter> typeParameters, JvmTypeParameterDeclarator target) {
   for (JvmTypeParameter typeParameter : typeParameters) {
     final JvmTypeParameter clonedTypeParameter = cloneWithProxies(typeParameter);
     target.getTypeParameters().add(clonedTypeParameter);
     boolean upperBoundSeen = false;
     for (JvmTypeConstraint constraint : clonedTypeParameter.getConstraints()) {
       if (constraint instanceof JvmUpperBound) {
         upperBoundSeen = true;
         break;
       }
     }
     if (!upperBoundSeen) {
       JvmUpperBound upperBound = typesFactory.createJvmUpperBound();
       upperBound.setTypeReference(typeReferences.getTypeForName(Object.class, typeParameter));
       clonedTypeParameter.getConstraints().add(upperBound);
     }
     associator.associate(typeParameter, clonedTypeParameter);
   }
 }
  protected void transform(XtendFunction source, JvmGenericType container) {
    JvmOperation operation = typesFactory.createJvmOperation();
    container.getMembers().add(operation);
    associator.associatePrimary(source, operation);
    String sourceName = source.getName();
    JvmVisibility visibility = source.getVisibility();
    if (source.isDispatch()) {
      if (!source.eIsSet(Xtend2Package.Literals.XTEND_FUNCTION__VISIBILITY))
        visibility = JvmVisibility.PROTECTED;
      sourceName = "_" + sourceName;
    }
    operation.setSimpleName(sourceName);
    operation.setVisibility(visibility);
    operation.setStatic(source.isStatic());
    for (XtendParameter parameter : source.getParameters()) {
      JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
      jvmParam.setName(parameter.getName());
      jvmParam.setParameterType(cloneWithProxies(parameter.getParameterType()));
      operation.getParameters().add(jvmParam);
      associator.associate(parameter, jvmParam);
      jvmTypesBuilder.translateAnnotationsTo(parameter.getAnnotations(), jvmParam);
    }
    JvmTypeReference returnType = null;
    if (source.getReturnType() != null) {
      returnType = cloneWithProxies(source.getReturnType());
    } else {
      returnType = getTypeProxy(operation);
    }
    operation.setReturnType(returnType);
    copyAndFixTypeParameters(source.getTypeParameters(), operation);
    for (JvmTypeReference exception : source.getExceptions()) {
      operation.getExceptions().add(cloneWithProxies(exception));
    }
    jvmTypesBuilder.translateAnnotationsTo(source.getAnnotationInfo().getAnnotations(), operation);
    CreateExtensionInfo createExtensionInfo = source.getCreateExtensionInfo();
    if (createExtensionInfo != null) {
      JvmTypeReference arrayList =
          typeReferences.getTypeForName(ArrayList.class, container, typeReferences.wildCard());
      JvmTypeReference hashMap =
          typeReferences.getTypeForName(
              HashMap.class, container, arrayList, cloneWithProxies(returnType));

      JvmField cacheVar =
          jvmTypesBuilder.toField(
              source, CREATE_CHACHE_VARIABLE_PREFIX + source.getName(), hashMap);
      cacheVar.setFinal(true);
      jvmTypesBuilder.setInitializer(cacheVar, compileStrategies.forCacheVariable(container));
      container.getMembers().add(cacheVar);

      JvmOperation initializer = typesFactory.createJvmOperation();
      container.getMembers().add(initializer);
      initializer.setSimpleName(CREATE_INITIALIZER_PREFIX + source.getName());
      initializer.setVisibility(JvmVisibility.PRIVATE);
      initializer.setReturnType(typeReferences.getTypeForName(Void.TYPE, source));
      for (JvmTypeReference exception : source.getExceptions()) {
        initializer.getExceptions().add(cloneWithProxies(exception));
      }

      jvmTypesBuilder.setBody(
          operation, compileStrategies.forCacheMethod(createExtensionInfo, cacheVar, initializer));

      // the first parameter is the created object
      JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
      jvmParam.setName(createExtensionInfo.getName());
      jvmParam.setParameterType(getTypeProxy(createExtensionInfo.getCreateExpression()));
      initializer.getParameters().add(jvmParam);
      associator.associate(createExtensionInfo, jvmParam);

      // add all others
      for (XtendParameter parameter : source.getParameters()) {
        jvmParam = typesFactory.createJvmFormalParameter();
        jvmParam.setName(parameter.getName());
        jvmParam.setParameterType(cloneWithProxies(parameter.getParameterType()));
        initializer.getParameters().add(jvmParam);
        associator.associate(parameter, jvmParam);
      }
      associator.associate(source, initializer);
      associator.associateLogicalContainer(createExtensionInfo.getCreateExpression(), operation);
      associator.associateLogicalContainer(source.getExpression(), initializer);
    } else {
      associator.associateLogicalContainer(source.getExpression(), operation);
    }
    jvmTypesBuilder.setDocumentation(operation, jvmTypesBuilder.getDocumentation(source));
  }