Ejemplo n.º 1
0
 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());
   }
 }
Ejemplo n.º 2
0
 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);
   }
 }
Ejemplo n.º 3
0
  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;
  }
Ejemplo n.º 4
0
 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));
 }
Ejemplo n.º 5
0
  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));
  }