示例#1
1
  /*
   * Replace Placeholders for repeating annotations with their containers
   */
  private <T extends Attribute.Compound> void complete(Annotate.AnnotateRepeatedContext<T> ctx) {
    Log log = ctx.log;
    Env<AttrContext> env = ctx.env;
    JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
    try {
      // TODO: can we reduce duplication in the following branches?
      if (ctx.isTypeCompound) {
        Assert.check(!isTypesEmpty());

        if (isTypesEmpty()) {
          return;
        }

        List<Attribute.TypeCompound> result = List.nil();
        for (Attribute.TypeCompound a : getTypeAttributes()) {
          if (a instanceof Placeholder) {
            @SuppressWarnings("unchecked")
            Placeholder<Attribute.TypeCompound> ph = (Placeholder<Attribute.TypeCompound>) a;
            Attribute.TypeCompound replacement = replaceOne(ph, ph.getRepeatedContext());

            if (null != replacement) {
              result = result.prepend(replacement);
            }
          } else {
            result = result.prepend(a);
          }
        }

        type_attributes = result.reverse();

        Assert.check(Annotations.this.getTypePlaceholders().isEmpty());
      } else {
        Assert.check(!pendingCompletion());

        if (isEmpty()) {
          return;
        }

        List<Attribute.Compound> result = List.nil();
        for (Attribute.Compound a : getDeclarationAttributes()) {
          if (a instanceof Placeholder) {
            @SuppressWarnings("unchecked")
            Attribute.Compound replacement = replaceOne((Placeholder<T>) a, ctx);

            if (null != replacement) {
              result = result.prepend(replacement);
            }
          } else {
            result = result.prepend(a);
          }
        }

        attributes = result.reverse();

        Assert.check(Annotations.this.getPlaceholders().isEmpty());
      }
    } finally {
      log.useSource(oldSource);
    }
  }
示例#2
0
  public Placeholder getTextType() {
    CTPlaceholder ph = getCTPlaceholder();
    if (ph == null) return null;

    int val = ph.getType().intValue();
    return Placeholder.values()[val - 1];
  }
示例#3
0
  private <T extends Attribute.Compound> T replaceOne(
      Placeholder<T> placeholder, Annotate.AnnotateRepeatedContext<T> ctx) {
    Log log = ctx.log;

    // Process repeated annotations
    T validRepeated = ctx.processRepeatedAnnotations(placeholder.getPlaceholderFor(), sym);

    if (validRepeated != null) {
      // Check that the container isn't manually
      // present along with repeated instances of
      // its contained annotation.
      ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym);
      if (manualContainer != null) {
        log.error(
            ctx.pos.get(manualContainer.first()),
            "invalid.repeatable.annotation.repeated.and.container.present",
            manualContainer.first().type.tsym);
      }
    }

    // A null return will delete the Placeholder
    return validRepeated;
  }