Exemplo n.º 1
0
 /**
  * Returns return parameter label as a string, string parametrized with a style mask.
  *
  * @param style the mask that indicates which element to display
  * @return a string containing the return parameter type
  */
 private static String getReturnTypeAsString(
     Operation operation, Collection<String> displayValue) {
   boolean displayType =
       displayValue.contains(ICustomAppearance.DISP_RT_TYPE)
           || displayValue.contains(ICustomAppearance.DISP_TYPE);
   boolean displayMultiplicity =
       displayValue.contains(ICustomAppearance.DISP_RT_MULTIPLICITY)
           || displayValue.contains(ICustomAppearance.DISP_MULTIPLICITY);
   StringBuffer label = new StringBuffer("");
   // Retrieve the return parameter (assume to be unique if defined)
   Parameter returnParameter = getReturnParameter(operation);
   // Create the string for the return type
   if (returnParameter == null) {
     // no-operation: label = ""
   } else if (!displayType && !displayMultiplicity) {
     // no-operation: label = ""
   } else {
     label.append(": ");
     if (displayType) {
       label.append(TypedElementUtil.getTypeAsString(returnParameter));
     }
     if (displayMultiplicity) {
       label.append(MultiplicityElementUtil.getMultiplicityAsString(returnParameter));
     }
   }
   return label.toString();
 }
  /**
   * Returns the string used to represent this parameter
   *
   * @param parameter a parameter
   * @return the string used to represent this parameter
   */
  public static String getLabel(Parameter parameter) {
    StringBuffer buffer = new StringBuffer();
    // visibility
    buffer.append(" "); // $NON-NLS-1$
    buffer.append(NamedElementUtil.getVisibilityAsSign(parameter));

    // direction
    buffer.append(" "); // $NON-NLS-1$
    buffer.append(parameter.getDirection().getLiteral());

    // name
    buffer.append(" "); // $NON-NLS-1$
    if (parameter.getName() != null) {
      buffer.append(parameter.getName());
    }

    // type
    if (parameter.getType() != null) {
      EList<Namespace> namespaces = parameter.allNamespaces();
      buffer.append(
          " : "
              + getTypeLabel(
                  parameter.getType(), namespaces.get(namespaces.size() - 1))); // $NON-NLS-1$
    } else {
      buffer.append(" : " + TypeUtil.UNDEFINED_TYPE_NAME); // $NON-NLS-1$
    }

    // multiplicity -> do not display [1]
    String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter);
    if (!multiplicity.trim().equals("[1]")) { // $NON-NLS-1$
      buffer.append(multiplicity);
    }

    // default value
    if (parameter.getDefault() != null) {
      buffer.append(" = "); // $NON-NLS-1$
      buffer.append(parameter.getDefault());
    }

    // property modifiers
    buffer.append(ParameterUtil.getModifiersAsString(parameter, false));
    buffer.append(getEffectAsString(parameter));
    return buffer.toString();
  }
Exemplo n.º 3
0
 public static String getCustomLabel(
     Message e, int paramIndex, Parameter parameter, Collection<String> displayValue) {
   StringBuffer buffer = new StringBuffer();
   // visibility
   buffer.append(" ");
   if (displayValue.contains(ICustomAppearance.DISP_VISIBILITY)) {
     buffer.append(NamedElementUtil.getVisibilityAsSign(parameter));
   }
   // direction property
   if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_DIRECTION)) {
     buffer.append(" ");
     buffer.append(parameter.getDirection().getLiteral());
   }
   boolean showEqualMark = false;
   // name
   if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_NAME)) {
     buffer.append(" ");
     String name = StringHelper.trimToEmpty(parameter.getName());
     if (name.trim().length() > 0) {
       showEqualMark = true;
     }
     buffer.append(name);
   }
   if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_TYPE)) {
     // type
     if (parameter.getType() != null) {
       buffer.append(": " + StringHelper.trimToEmpty(parameter.getType().getName()));
     } else {
       buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
     }
     showEqualMark = true;
   }
   if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_MULTIPLICITY)) {
     // multiplicity -> do not display [1]
     String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter);
     buffer.append(multiplicity);
   }
   if (displayValue.contains(ICustomAppearance.DISP_DERIVE)) {
     String value = getValue(e, paramIndex, parameter);
     if (value != null) {
       if (showEqualMark) {
         buffer.append(" = ");
       }
       buffer.append(value);
     }
   } else if (displayValue.contains(ICustomAppearance.DISP_PARAMETER_DEFAULT)) {
     // default value
     if (parameter.getDefault() != null) {
       if (showEqualMark) {
         buffer.append(" = ");
       }
       buffer.append(parameter.getDefault());
     }
   }
   if (displayValue.contains(ICustomAppearance.DISP_MODIFIERS)) {
     boolean multiLine = displayValue.contains(ICustomAppearance.DISP_MULTI_LINE);
     // property modifiers
     String modifiers = ParameterUtil.getModifiersAsString(parameter, multiLine);
     if (!modifiers.equals("")) {
       if (multiLine) {
         buffer.append("\n");
       }
       buffer.append(modifiers);
     }
   }
   return buffer.toString();
 }