com.sun.tools.javac.code.Attribute Java Examples
The following examples show how to use
com.sun.tools.javac.code.Attribute.
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 File: DPrinter.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #2
Source File: JNIWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #3
Source File: ClassReader.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #4
Source File: Annotate.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 #5
Source File: AnnotationValueImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #6
Source File: JNIWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #7
Source File: AnnotationValueImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 #8
Source File: AnnotationProxyMaker.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * 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 File: ManAttr_8.java From manifold with Apache License 2.0 | 6 votes |
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 #10
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 5 votes |
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 #11
Source File: AnnotatedTypeImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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 #12
Source File: AnnotationValueImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 #13
Source File: AnnotationValueImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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 #14
Source File: AnnotationValueImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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 #15
Source File: AnnotationValueImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
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 #16
Source File: ClassReader.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #17
Source File: ProgramElementDocImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 #18
Source File: AnnotationDescImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #19
Source File: DPrinter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 #20
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 5 votes |
private JCTree replaceStringLiteral( JCTree.JCLiteral tree ) { String literal = (String)tree.getValue(); if( !literal.contains( FragmentProcessor.FRAGMENT_START ) || !literal.contains( FragmentProcessor.FRAGMENT_END ) ) { return tree; } JCTree.JCClassDecl enclosingClass = getEnclosingClass( tree ); CharSequence source = ManParserFactory.getSource( enclosingClass.sym.sourcefile ); CharSequence chars = source.subSequence( tree.pos().getStartPosition(), tree.pos().getEndPosition( ((JCTree.JCCompilationUnit)_tp.getCompilationUnit()).endPositions ) ); FragmentProcessor.Fragment fragment = FragmentProcessor.instance().parseFragment( tree.pos().getStartPosition(), chars.toString(), chars.length() > 3 && chars.charAt( 1 ) == '"' ? TEXT_BLOCK_LITERAL : DOUBLE_QUOTE_LITERAL ); if( fragment != null ) { String fragClass = enclosingClass.sym.packge().toString() + '.' + fragment.getName(); Symbol.ClassSymbol fragSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), fragClass ); for( Attribute.Compound annotation: fragSym.getAnnotationMirrors() ) { if( annotation.type.toString().equals( FragmentValue.class.getName() ) ) { return replaceStringLiteral( fragSym, tree, annotation ); } } } return tree; }
Example #21
Source File: Annotate.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Attribute getAnnotationEnumValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) { Type result = attr.attribTree(tree, env, annotationValueInfo(expectedElementType)); Symbol sym = TreeInfo.symbol(tree); if (sym == null || TreeInfo.nonstaticSelect(tree) || sym.kind != VAR || (sym.flags() & Flags.ENUM) == 0) { log.error(tree.pos(), Errors.EnumAnnotationMustBeEnumConstant); return new Attribute.Error(result.getOriginalType()); } VarSymbol enumerator = (VarSymbol) sym; return new Attribute.Enum(expectedElementType, enumerator); }
Example #22
Source File: TypeVariableImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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 #23
Source File: ProgramElementDocImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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 #24
Source File: ProgramElementDocImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 #25
Source File: ParameterImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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 #26
Source File: PackageDocImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 #27
Source File: ClassReader.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
List<Attribute.Compound> deproxyCompoundList(List<CompoundAnnotationProxy> pl) { // also must fill in types!!!! ListBuffer<Attribute.Compound> buf = new ListBuffer<>(); for (List<CompoundAnnotationProxy> l = pl; l.nonEmpty(); l=l.tail) { buf.append(deproxyCompound(l.head)); } return buf.toList(); }
Example #28
Source File: SrcClassUtil.java From manifold with Apache License 2.0 | 5 votes |
private SrcType makeSrcType( Type type, Symbol symbol, TargetType targetType, int index ) { SrcType srcType; List<Attribute.TypeCompound> annotationMirrors = type.getAnnotationMirrors(); if( annotationMirrors != null && !annotationMirrors.isEmpty() ) { String unannotatedType = isJava8() ? ReflectUtil.method( type, "unannotatedType" ).invoke().toString() : ReflectUtil.method( type, "cloneWithMetadata", ReflectUtil.type( "com.sun.tools.javac.code.TypeMetadata" ) ) .invoke( ReflectUtil.field( "com.sun.tools.javac.code.TypeMetadata", "EMPTY" ).getStatic() ).toString(); srcType = new SrcType( unannotatedType ); } else { srcType = new SrcType( typeNoAnnotations( type ) ); } SymbolMetadata metadata = symbol.getMetadata(); if( metadata == null || metadata.isTypesEmpty() ) { return srcType; } List<Attribute.TypeCompound> typeAttributes = metadata.getTypeAttributes(); if( typeAttributes.isEmpty() ) { return null; } java.util.List<Attribute.TypeCompound> targetedTypeAttrs = typeAttributes.stream() .filter( attr -> attr.getPosition().type == targetType && isTargetIndex( targetType, attr, index ) ) .collect( Collectors.toList() ); annotateType( srcType, targetedTypeAttrs ); return srcType; }
Example #29
Source File: AnnotationProxyMaker.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
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 #30
Source File: AnnotationValueImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
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)); } }