예제 #1
0
  /**
   * Returns a sorted (canonical) MetaData parameter list.
   *
   * <p>Don't change this method without considering its use in SignatureEvaluator.java
   */
  public static String getSortedMetaDataParamString(MetaDataNode node) {
    final Set<Value> params = new TreeSet<Value>(metaDataValueComparator);
    final StringBuilder parameters = new StringBuilder(32);

    if (node.getValues() != null) {
      for (int i = 0, length = node.getValues().length; i < length; i++) {
        params.add(node.getValues()[i]);
      }

      final Iterator<Value> iter = params.iterator();
      parameters.append('(');
      while (iter.hasNext()) {
        final Object v = iter.next();

        if (v instanceof KeyValuePair) {
          final KeyValuePair pair = (KeyValuePair) v;
          parameters.append(pair.key).append("=\"").append(pair.obj).append('"');
        } else {
          assert (v instanceof KeylessValue);
          parameters.append('"').append(((KeylessValue) v).obj).append('"');
        }

        if (iter.hasNext()) {
          parameters.append(",");
        }
      }
      parameters.append(')');
    }

    return parameters.toString();
  }
예제 #2
0
  public Value evaluate(Context context, MetaDataNode node) {
    if ("Style".equals(node.getId())) {
      if (NodeMagic.isClassDefinition(node)) {
        processStyle(context, node);
      } else {
        context.localizedError2(node.pos(), new StyleMustAnnotateAClass());
      }
    }

    return null;
  }
예제 #3
0
  public static void removeMetaData(DefinitionNode definitionNode, String id) {
    StatementListNode metaData = definitionNode.metaData;

    if ((metaData != null) && (metaData.items != null)) {
      Iterator iterator = metaData.items.iterator();

      while (iterator.hasNext()) {
        MetaDataNode metaDataNode = (MetaDataNode) iterator.next();
        if ((metaDataNode.getId() != null) && metaDataNode.getId().equals(id)) {
          iterator.remove();
        }
      }
    }
  }
예제 #4
0
  /** add style into unit-wide list */
  private void registerStyle(Context context, MetaDataNode metaDataNode, String name, MetaData md) {
    try {
      unit.styles.addStyle(name, md, unit.getSource());
    } catch (StyleConflictException e) {
      context.localizedWarning2(metaDataNode.pos(), e);

      if (Trace.error) e.printStackTrace();
    }
  }
예제 #5
0
  private void processStyle(Context context, MetaDataNode metaDataNode) {
    MetaData metaData = new MetaData(metaDataNode);
    String styleName = metaData.getValue("name");
    String typeName = metaData.getValue("type");

    if (styleName == null) {
      // preilly: we should report this earlier in the process.
      context.localizedError2(metaDataNode.pos(), new StyleHasMissingName());
    }

    if (typeName != null) {
      unit.expressions.add(NameFormatter.toMultiName(typeName));
    }

    registerStyle(context, metaDataNode, styleName, metaData);
  }