Пример #1
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);
   }
 }
Пример #2
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;
  }