Java Code Examples for com.sun.tools.javac.code.Attribute#Compound

The following examples show how to use com.sun.tools.javac.code.Attribute#Compound . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@DefinedBy(Api.LANGUAGE_MODEL)
public Map<MethodSymbol, Attribute> getElementValuesWithDefaults(
                                                    AnnotationMirror a) {
    Attribute.Compound anno = cast(Attribute.Compound.class, a);
    DeclaredType annotype = a.getAnnotationType();
    Map<MethodSymbol, Attribute> valmap = anno.getElementValues();

    for (ExecutableElement ex :
             methodsIn(annotype.asElement().getEnclosedElements())) {
        MethodSymbol meth = (MethodSymbol) ex;
        Attribute defaultValue = meth.getDefaultValue();
        if (defaultValue != null && !valmap.containsKey(meth)) {
            valmap.put(meth, defaultValue);
        }
    }
    return valmap;
}
 
Example 2
Source Project: manifold   File: ManAttr_8.java    License: Apache License 2.0 6 votes vote down vote up
private Type getFragmentValueType( Attribute.Compound attribute )
{
  String type = null;
  for( com.sun.tools.javac.util.Pair<Symbol.MethodSymbol, Attribute> pair: attribute.values )
  {
    Name argName = pair.fst.getSimpleName();
    if( argName.toString().equals( "type" ) )
    {
      type = (String)pair.snd.getValue();
    }
  }

  if( type != null )
  {
    Symbol.ClassSymbol fragValueSym = IDynamicJdk.instance().getTypeElement( JavacPlugin.instance().getContext(), getEnv().toplevel, type );
    if( fragValueSym != null )
    {
      return fragValueSym.type;
    }
  }

  return null;
}
 
Example 3
private <T extends Attribute.Compound> T makeContainerAnnotation(List<T> toBeReplaced,
        AnnotationContext<T> ctx, Symbol sym, boolean isTypeParam)
{
    // Process repeated annotations
    T validRepeated =
            processRepeatedAnnotations(toBeReplaced, ctx, sym, isTypeParam);

    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()),
                      Errors.InvalidRepeatableAnnotationRepeatedAndContainerPresent(manualContainer.first().type.tsym));
        }
    }

    // A null return will delete the Placeholder
    return validRepeated;
}
 
Example 4
private boolean needsHeader(ClassSymbol c, boolean checkNestedClasses) {
    if (c.isLocal() || (c.flags() & Flags.SYNTHETIC) != 0)
        return false;

    for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
        if (i.sym.kind == Kinds.MTH && (i.sym.flags() & Flags.NATIVE) != 0)
            return true;
        for (Attribute.Compound a: i.sym.getDeclarationAttributes()) {
            if (a.type.tsym == syms.nativeHeaderType.tsym)
                return true;
        }
    }
    if (checkNestedClasses) {
        for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
            if ((i.sym.kind == Kinds.TYP) && needsHeader(((ClassSymbol) i.sym), true))
                return true;
        }
    }
    return false;
}
 
Example 5
/**
 * Get the annotations of this program element.
 * Return an empty array if there are none.
 */
public AnnotationDesc[] annotations() {
    if (!type.isAnnotated()) {
        return new AnnotationDesc[0];
    }
    List<? extends TypeCompound> tas = type.getAnnotationMirrors();
    AnnotationDesc res[] = new AnnotationDesc[tas.length()];
    int i = 0;
    for (Attribute.Compound a : tas) {
        res[i++] = new AnnotationDescImpl(env, a);
    }
    return res;
}
 
Example 6
/**
 * Get the annotations of this program element.
 * Return an empty array if there are none.
 */
public AnnotationDesc[] annotations() {
    if (!type.isAnnotated()) {
        return new AnnotationDesc[0];
    }
    List<? extends TypeCompound> tas = type.getAnnotationMirrors();
    AnnotationDesc res[] = new AnnotationDesc[tas.length()];
    int i = 0;
    for (Attribute.Compound a : tas) {
        res[i++] = new AnnotationDescImpl(env, a);
    }
    return res;
}
 
Example 7
/** Extract the actual Type to be used for a containing annotation. */
private Type extractContainingType(Attribute.Compound ca,
                                   DiagnosticPosition pos,
                                   TypeSymbol annoDecl)
{
    // The next three checks check that the Repeatable annotation
    // on the declaration of the annotation type that is repeating is
    // valid.

    // Repeatable must have at least one element
    if (ca.values.isEmpty()) {
        log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl));
        return null;
    }
    Pair<MethodSymbol,Attribute> p = ca.values.head;
    Name name = p.fst.name;
    if (name != names.value) { // should contain only one element, named "value"
        log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl));
        return null;
    }
    if (!(p.snd instanceof Attribute.Class)) { // check that the value of "value" is an Attribute.Class
        log.error(pos, Errors.InvalidRepeatableAnnotation(annoDecl));
        return null;
    }

    return ((Attribute.Class)p.snd).getValue();
}
 
Example 8
public void visitCompound(Attribute.Compound c) {
    try {
        Class<? extends Annotation> nested =
            returnClass.asSubclass(Annotation.class);
        value = generateAnnotation(c, nested);
    } catch (ClassCastException ex) {
        value = null;   // indicates a type mismatch
    }
}
 
Example 9
Source Project: manifold   File: ExtensionTransformer.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("WeakerAccess")
public static boolean isJailbreakSymbol( Symbol sym )
{
  if( sym == null )
  {
    return false;
  }

  SymbolMetadata metadata = sym.getMetadata();
  if( metadata == null || (metadata.isTypesEmpty() && metadata.isEmpty()) )
  {
    return false;
  }

  List<Attribute.TypeCompound> typeAttributes = metadata.getTypeAttributes();
  if( !typeAttributes.isEmpty() )
  {
    return typeAttributes.stream()
      .anyMatch( attr -> attr.type.toString().equals( Jailbreak.class.getTypeName() ) );
  }

  List<Attribute.Compound> attributes = metadata.getDeclarationAttributes();
  if( !attributes.isEmpty() )
  {
    return attributes.stream()
      .anyMatch( attr -> attr.type.toString().equals( Jailbreak.class.getTypeName() ) );
  }
  return false;
}
 
Example 10
public void visitCompound(Attribute.Compound c) {
    try {
        Class<? extends Annotation> nested =
            returnClass.asSubclass(Annotation.class);
        value = generateAnnotation(c, nested);
    } catch (ClassCastException ex) {
        value = null;   // indicates a type mismatch
    }
}
 
Example 11
Source Project: manifold   File: TypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isStructuralInterface( TypeProcessor tp, Symbol sym )
{
  if( sym == null )
  {
    return false;
  }

  if( (!sym.isInterface() || !sym.hasAnnotations()) && !(sym instanceof Symbol.TypeVariableSymbol) )
  {
    return false;
  }

  // use the raw type
  Type type = tp.getTypes().erasure( sym.type );
  sym = type.tsym;
  if( !sym.isInterface() || !sym.hasAnnotations() )
  {
    return false;
  }

  for( Attribute.Compound annotation : sym.getAnnotationMirrors() )
  {
    if( annotation.type.toString().equals( Structural.class.getName() ) )
    {
      return true;
    }
  }
  return false;
}
 
Example 12
/**
 * Get the annotations of this program element.
 * Return an empty array if there are none.
 */
public AnnotationDesc[] annotations() {
    AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
    int i = 0;
    for (Attribute.Compound a : sym.getRawAttributes()) {
        res[i++] = new AnnotationDescImpl(env, a);
    }
    return res;
}
 
Example 13
/**
 * Get the annotations of this program element.
 * Return an empty array if there are none.
 */
public AnnotationDesc[] annotations() {
    AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
    int i = 0;
    for (Attribute.Compound a : sym.getRawAttributes()) {
        res[i++] = new AnnotationDescImpl(env, a);
    }
    return res;
}
 
Example 14
Source Project: jdk8u60   File: DPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitCompound(Attribute.Compound a) {
    if (a instanceof Attribute.TypeCompound) {
        Attribute.TypeCompound ta = (Attribute.TypeCompound) a;
        // consider a custom printer?
        printObject("position", ta.position, Details.SUMMARY);
    }
    printObject("synthesized", a.isSynthesized(), Details.SUMMARY);
    printList("values", a.values);
    visitAttribute(a);
}
 
Example 15
public void visitCompound(Attribute.Compound c) {
    value = new AnnotationDescImpl(env, c);
}
 
Example 16
AnnotationDescImpl(DocEnv env, Attribute.Compound annotation) {
    this.env = env;
    this.annotation = annotation;
}
 
Example 17
public void visitCompound(Attribute.Compound c) {
    value = new AnnotationDescImpl(env, c);
}
 
Example 18
AnnotationDescImpl(DocEnv env, Attribute.Compound annotation) {
    this.env = env;
    this.annotation = annotation;
}
 
Example 19
public void visitCompound(Attribute.Compound c) {
    sb.append(new AnnotationDescImpl(env, c));
}
 
Example 20
public void visitCompound(Attribute.Compound c) {
    value = new AnnotationDescImpl(env, c);
}