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

The following examples show how to use com.sun.tools.javac.code.Attribute. These examples are extracted from open source projects. 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
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void visitArray(Attribute.Array a) {
    // Omit braces from singleton.
    if (a.values.length != 1) sb.append('{');

    boolean first = true;
    for (Attribute elem : a.values) {
        if (first) {
            first = false;
        } else {
            sb.append(", ");
        }
        elem.accept(this);
    }
    // Omit braces from singleton.
    if (a.values.length != 1) sb.append('}');
}
 
Example #2
Source Project: TencentKona-8   Author: Tencent   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void visitArray(Attribute.Array a) {
    // Omit braces from singleton.
    if (a.values.length != 1) sb.append('{');

    boolean first = true;
    for (Attribute elem : a.values) {
        if (first) {
            first = false;
        } else {
            sb.append(", ");
        }
        elem.accept(this);
    }
    // Omit braces from singleton.
    if (a.values.length != 1) sb.append('}');
}
 
Example #3
Source Project: TencentKona-8   Author: Tencent   File: JNIWriter.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 #4
Source Project: manifold   Author: manifold-systems   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 #5
Source Project: lua-for-android   Author: qtiuto   File: ClassReader.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
CompoundAnnotationProxy readCompoundAnnotation() {
    Type t;
    if (currentModule.module_info == currentOwner) {
        int index = poolIdx[nextChar()];
        t = new ProxyType(Arrays.copyOfRange(buf, index + 3, index + 3 + getChar(index + 1)));
    } else {
        t = readTypeOrClassSymbol(nextChar());
    }
    int numFields = nextChar();
    ListBuffer<Pair<Name,Attribute>> pairs = new ListBuffer<>();
    for (int i=0; i<numFields; i++) {
        Name name = readName(nextChar());
        Attribute value = readAttributeValue();
        pairs.append(new Pair<>(name, value));
    }
    return new CompoundAnnotationProxy(t, pairs.toList());
}
 
Example #6
Source Project: lua-for-android   Author: qtiuto   File: Annotate.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Fetches the actual Type that should be the containing annotation.
 */
private Type getContainingType(Attribute.Compound currentAnno,
                               DiagnosticPosition pos,
                               boolean reportError)
{
    Type origAnnoType = currentAnno.type;
    TypeSymbol origAnnoDecl = origAnnoType.tsym;

    // Fetch the Repeatable annotation from the current
    // annotation's declaration, or null if it has none
    Attribute.Compound ca = origAnnoDecl.getAnnotationTypeMetadata().getRepeatable();
    if (ca == null) { // has no Repeatable annotation
        if (reportError)
            log.error(pos, Errors.DuplicateAnnotationMissingContainer(origAnnoType));
        return null;
    }

    return filterSame(extractContainingType(ca, pos, origAnnoDecl),
            origAnnoType);
}
 
Example #7
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JNIWriter.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 #8
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: AnnotationProxyMaker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a map from element names to their values in "dynamic
 * proxy return form".  Includes all elements, whether explicit or
 * defaulted.
 */
private Map<String, Object> getAllReflectedValues() {
    Map<String, Object> res = new LinkedHashMap<String, Object>();

    for (Map.Entry<MethodSymbol, Attribute> entry :
                                              getAllValues().entrySet()) {
        MethodSymbol meth = entry.getKey();
        Object value = generateValue(meth, entry.getValue());
        if (value != null) {
            res.put(meth.name.toString(), value);
        } else {
            // Ignore this element.  May (properly) lead to
            // IncompleteAnnotationException somewhere down the line.
        }
    }
    return res;
}
 
Example #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: DPrinter.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void printObject(String label, Object item, Details details) {
    if (item == null) {
        printNull(label);
    } else if (item instanceof Attribute) {
        printAttribute(label, (Attribute) item);
    } else if (item instanceof Symbol) {
        printSymbol(label, (Symbol) item, details);
    } else if (item instanceof Type) {
        printType(label, (Type) item, details);
    } else if (item instanceof JCTree) {
        printTree(label, (JCTree) item);
    } else if (item instanceof DocTree) {
        printDocTree(label, (DocTree) item);
    } else if (item instanceof List) {
        printList(label, (List) item);
    } else if (item instanceof Name) {
        printName(label, (Name) item);
    } else if (item instanceof Scope) {
        printScope(label, (Scope) item);
    } else {
        printString(label, String.valueOf(item));
    }
}
 
Example #10
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TypeVariableImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #11
Source Project: openjdk-8   Author: bpupadhyaya   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitConstant(Attribute.Constant c) {
    if (c.type.hasTag(BOOLEAN)) {
        // javac represents false and true as integers 0 and 1
        value = Boolean.valueOf(
                        ((Integer)c.value).intValue() != 0);
    } else {
        value = c.value;
    }
}
 
Example #12
Source Project: TencentKona-8   Author: Tencent   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitArray(Attribute.Array a) {
    AnnotationValue vals[] = new AnnotationValue[a.values.length];
    for (int i = 0; i < vals.length; i++) {
        vals[i] = new AnnotationValueImpl(env, a.values[i]);
    }
    value = vals;
}
 
Example #13
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: AnnotatedTypeImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the annotations of this program element.
 * Return an empty array if there are none.
 */
@Override
public AnnotationDesc[] annotations() {
    List<? extends TypeCompound> tas = type.getAnnotationMirrors();
    if (tas == null ||
            tas.isEmpty()) {
        return new AnnotationDesc[0];
    }
    AnnotationDesc res[] = new AnnotationDesc[tas.length()];
    int i = 0;
    for (Attribute.Compound a : tas) {
        res[i++] = new AnnotationDescImpl(env, a);
    }
    return res;
}
 
Example #14
Source Project: TencentKona-8   Author: Tencent   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitConstant(Attribute.Constant c) {
    if (c.type.hasTag(BOOLEAN)) {
        // javac represents false and true as integers 0 and 1
        sb.append(((Integer)c.value).intValue() != 0);
    } else {
        sb.append(FieldDocImpl.constantValueExpression(c.value));
    }
}
 
Example #15
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitArray(Attribute.Array a) {
    AnnotationValue vals[] = new AnnotationValue[a.values.length];
    for (int i = 0; i < vals.length; i++) {
        vals[i] = new AnnotationValueImpl(env, a.values[i]);
    }
    value = vals;
}
 
Example #16
Source Project: openjdk-8-source   Author: keerath   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitConstant(Attribute.Constant c) {
    if (c.type.hasTag(BOOLEAN)) {
        // javac represents false and true as integers 0 and 1
        sb.append(((Integer)c.value).intValue() != 0);
    } else {
        sb.append(FieldDocImpl.constantValueExpression(c.value));
    }
}
 
Example #17
Source Project: TencentKona-8   Author: Tencent   File: AnnotatedTypeImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the annotations of this program element.
 * Return an empty array if there are none.
 */
@Override
public AnnotationDesc[] annotations() {
    List<? extends TypeCompound> tas = type.getAnnotationMirrors();
    if (tas == null ||
            tas.isEmpty()) {
        return new AnnotationDesc[0];
    }
    AnnotationDesc res[] = new AnnotationDesc[tas.length()];
    int i = 0;
    for (Attribute.Compound a : tas) {
        res[i++] = new AnnotationDescImpl(env, a);
    }
    return res;
}
 
Example #18
Source Project: manifold   Author: manifold-systems   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 #19
Source Project: openjdk-8-source   Author: keerath   File: PackageDocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the annotations of this package.
 * 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 #20
Source Project: TencentKona-8   Author: Tencent   File: PackageDocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the annotations of this package.
 * 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 #21
Source Project: TencentKona-8   Author: Tencent   File: ProgramElementDocImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #22
Source Project: TencentKona-8   Author: Tencent   File: DPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void printAttribute(String label, Attribute attr) {
    if (attr == null) {
        printNull(label);
    } else {
        printString(label, attr.getClass().getSimpleName());

        indent(+1);
        attr.accept(attrVisitor);
        indent(-1);
    }
}
 
Example #23
Source Project: openjdk-8-source   Author: keerath   File: ParameterImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the annotations of this parameter.
 * 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 #24
Source Project: manifold   Author: manifold-systems   File: ExtensionTransformer.java    License: Apache License 2.0 5 votes vote down vote up
private void verifyExtensionInterfaces( JCTree.JCClassDecl tree )
{
  if( !hasAnnotation( tree.getModifiers().getAnnotations(), Extension.class ) )
  {
    return;
  }

  outer:
  for( JCExpression iface: tree.getImplementsClause() )
  {
    final Symbol.TypeSymbol ifaceSym = iface.type.tsym;
    if( ifaceSym == _tp.getSymtab().objectType.tsym )
    {
      continue;
    }

    for( Attribute.Compound anno: ifaceSym.getAnnotationMirrors() )
    {
      if( anno.type.toString().equals( Structural.class.getName() ) )
      {
        continue outer;
      }
    }
    // extension interfaces must be structural
    _tp.report( iface, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_ONLY_STRUCTURAL_INTERFACE_ALLOWED_HERE.get( iface.toString() ) );
  }
}
 
Example #25
Source Project: TencentKona-8   Author: Tencent   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 #26
Source Project: manifold   Author: manifold-systems   File: ExtensionTransformer.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isExtensionMethod( Symbol sym )
{
  if( sym instanceof Symbol.MethodSymbol )
  {
    for( Attribute.Compound annotation: sym.getAnnotationMirrors() )
    {
      if( annotation.type.toString().equals( ExtensionMethod.class.getName() ) )
      {
        return true;
      }
    }
  }
  return false;
}
 
Example #27
Source Project: jdk8u60   Author: chenghanpeng   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitConstant(Attribute.Constant c) {
    if (c.type.hasTag(BOOLEAN)) {
        // javac represents false and true as integers 0 and 1
        value = Boolean.valueOf(
                        ((Integer)c.value).intValue() != 0);
    } else {
        value = c.value;
    }
}
 
Example #28
Source Project: lua-for-android   Author: qtiuto   File: ClassReader.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
Attribute.Compound deproxyCompound(CompoundAnnotationProxy a) {
    Type annotationType = resolvePossibleProxyType(a.type);
    ListBuffer<Pair<Symbol.MethodSymbol,Attribute>> buf = new ListBuffer<>();
    for (List<Pair<Name,Attribute>> l = a.values;
         l.nonEmpty();
         l = l.tail) {
        MethodSymbol meth = findAccessMethod(annotationType, l.head.fst);
        buf.append(new Pair<>(meth, deproxy(meth.type.getReturnType(), l.head.snd)));
    }
    return new Attribute.Compound(annotationType, buf.toList());
}
 
Example #29
Source Project: hottub   Author: dsrg-uoft   File: AnnotationValueImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void visitConstant(Attribute.Constant c) {
    if (c.type.hasTag(BOOLEAN)) {
        // javac represents false and true as integers 0 and 1
        value = Boolean.valueOf(
                        ((Integer)c.value).intValue() != 0);
    } else {
        value = c.value;
    }
}
 
Example #30
Source Project: hottub   Author: dsrg-uoft   File: AnnotationDescImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns this annotation's elements and their values.
 * Only those explicitly present in the annotation are
 * included, not those assuming their default values.
 * Returns an empty array if there are none.
 */
public ElementValuePair[] elementValues() {
    List<Pair<MethodSymbol,Attribute>> vals = annotation.values;
    ElementValuePair res[] = new ElementValuePair[vals.length()];
    int i = 0;
    for (Pair<MethodSymbol,Attribute> val : vals) {
        res[i++] = new ElementValuePairImpl(env, val.fst, val.snd);
    }
    return res;
}