Return a List of TypeMirror for an annotation on a member. This is a
workaround for JDK-6519115, which causes MirroredTypeException to be
thrown rather than MirroredTypesException.
168125
private static List<TypeMirror> getAnnotationClassValues(Element member, Annotation annotation, String annotationMemberName) {
        for (AnnotationMirror annotationMirror : member.getAnnotationMirrors()) {
            if (((TypeElement) annotationMirror.getAnnotationType().asElement()).getQualifiedName().contentEquals(annotation.annotationType().getName())) {
                for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
                    if (entry.getKey().getSimpleName().contentEquals(annotationMemberName)) {
                        @SuppressWarnings({ "unchecked", "rawtypes" })
                        List<AnnotationValue> types = (List) entry.getValue().getValue();
                        TypeMirror[] result = new TypeMirror[types.size()];
                        for (int i = 0; i < types.size(); i++) {
                            result[i] = (TypeMirror) types.get(i).getValue();
                        }
                        return Arrays.asList(result);
                    }
                }
                return Collections.emptyList();
            }
        }

        throw new IllegalStateException(annotation.annotationType().getName() + " not found in " + member);
    }
1299258
public static List<ExecutableElement> getSortedAnnotationMembers(TypeElement annotation) {
    List<ExecutableElement> members = Lists.newArrayList(getMethods(annotation));
    Collections.sort(members, (m1, m2) -> getName(m1).compareTo(getName(m2)));
    return members;
  }
309353
public List<Excerpt> getValueTypeAnnotations() {
    if (valueTypeAnnotations instanceof ImmutableList) {
      valueTypeAnnotations = new ArrayList<>(valueTypeAnnotations);
    }
    return Collections.unmodifiableList(valueTypeAnnotations);
  }
1266980
public static Optional<AnnotationMirror> findAnnotationMirror(
      Element element, QualifiedName annotationClass) {
    return findAnnotationMirror(element, Shading.unshadedName(annotationClass.toString()));
  }
101308
private static List<TypeName> convert(List<? extends TypeMirror> input) {
		List<TypeName> result = new ArrayList<TypeName>();

		for (TypeMirror item : input) {
			result.add(TypeUtility.typeName(item));
		}

		return result;
	}
318733
private Set<JType> findReflectedClasses(final GeneratorContext context, final TypeOracle typeOracle,
            final TreeLogger logger) throws UnableToCompleteException {
        final Set<JType> types = new HashSet<JType>();
        final JPackage[] packages = typeOracle.getPackages();

        // gather all types from wanted packages
        for (final JPackage jPackage : packages) {
            for (final JClassType jType : jPackage.getTypes()) {
                gatherTypes(jType.getErasedType(), types, context, logger);
            }
        }

        // gather all types from explicitely requested packages
        try {
            final ConfigurationProperty reflectionProperties = context.getPropertyOracle()
                    .getConfigurationProperty("gdx.reflect.include");
            for (final String property : reflectionProperties.getValues()) {
                final JClassType type = typeOracle.findType(property);
                if (type != null) {
                    gatherTypes(type.getErasedType(), types, context, logger);
                }
            }
        } catch (final BadPropertyValueException exception) {
            logger.log(Type.ERROR, "Unknown property: " + "gdx.reflect.include", exception);
            throw new UnableToCompleteException();
        }

        gatherTypes(typeOracle.findType("java.util.List").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.util.ArrayList").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.util.HashMap").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.util.Map").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.String").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Boolean").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Byte").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Long").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Character").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Short").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Integer").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Float").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.CharSequence").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Double").getErasedType(), types, context, logger);
        gatherTypes(typeOracle.findType("java.lang.Object").getErasedType(), types, context, logger);

        return types;
    }
19364
private ImmutableList<MemberDefinition> parseAttributeReflectedProperties(
      final PolymerClassDefinition cls) {
    ImmutableList.Builder<MemberDefinition> attrReflectedProps = ImmutableList.builder();

    for (MemberDefinition prop : cls.props) {
      // Generate the setter for readOnly properties.
      if (prop.value.isObjectLit()) {
        Node reflectedValue = NodeUtil.getFirstPropMatchingKey(prop.value, "reflectToAttribute");
        if (reflectedValue != null && reflectedValue.isTrue()) {
          attrReflectedProps.add(prop);
        }
      }
    }

    return attrReflectedProps.build();
  }
1818
@VisibleForTesting
    public static List<IStruct> getAllTraits(IReferenceableInstance entityDefinition,
                                              TypeSystem typeSystem) throws AtlasException {
        List<IStruct> traitInfo = new LinkedList<>();
        for (String traitName : entityDefinition.getTraits()) {
            IStruct trait = entityDefinition.getTrait(traitName);
            String typeName = trait.getTypeName();
            Map<String, Object> valuesMap = trait.getValuesMap();
            traitInfo.add(new Struct(typeName, valuesMap));
            traitInfo.addAll(getSuperTraits(typeName, valuesMap, typeSystem));
        }
        return traitInfo;
    }
369115
@Override
	public Void visitAnnotation(AnnotationMirror a, String p) {
		if (AnnotationAttributeType.INDEXES.getValue().equals(p)) {
			inTasks = true;
		}

		if (inTasks) {
			currentValue = new Pair<List<String>, Boolean>(new ArrayList<String>(), false);
			for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : a.getElementValues().entrySet()) {
				String key = entry.getKey().getSimpleName().toString();
				entry.getValue().accept(this, key);
			}
			indexes.add(currentValue);
		}

		if (AnnotationAttributeType.INDEXES.getValue().equals(p)) {
			inTasks = false;
		}

		return null;
	}
740037
@Override
    public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
        // Android-changed: Uses AnnotatedElements instead.
        return AnnotatedElements.getDirectOrIndirectAnnotationsByType(this, annotationClass);
    }
159759
private static int[] lookupClasses() {
		Class<?> annotationMemberArrayClazz;
		try {
			annotationFactoryClazz = Class.forName("org.apache.harmony.lang.annotation.AnnotationFactory");
			annotationMemberClazz = Class.forName("org.apache.harmony.lang.annotation.AnnotationMember");
			annotationMemberArrayClazz = Class.forName("[Lorg.apache.harmony.lang.annotation.AnnotationMember;");
		} catch (ClassNotFoundException e) {
			return null;
		}

		Field fieldField;
		try {
			elementsField = annotationFactoryClazz.getDeclaredField("elements");
			elementsField.setAccessible(true);

			nameField = annotationMemberClazz.getDeclaredField("name");
			nameField.setAccessible(true);
			valueField = annotationMemberClazz.getDeclaredField("value");
			valueField.setAccessible(true);

			fieldField = DatabaseFieldSample.class.getDeclaredField("field");
		} catch (SecurityException e) {
			return null;
		} catch (NoSuchFieldException e) {
			return null;
		}

		DatabaseField databaseField = fieldField.getAnnotation(DatabaseField.class);
		InvocationHandler proxy = Proxy.getInvocationHandler(databaseField);
		if (proxy.getClass() != annotationFactoryClazz) {
			return null;
		}

		try {
			// this should be an array of AnnotationMember objects
			Object elements = elementsField.get(proxy);
			if (elements == null || elements.getClass() != annotationMemberArrayClazz) {
				return null;
			}

			Object[] elementArray = (Object[]) elements;
			int[] configNums = new int[elementArray.length];

			// build our array of field-numbers that match the AnnotationMember array
			for (int i = 0; i < elementArray.length; i++) {
				String name = (String) nameField.get(elementArray[i]);
				configNums[i] = configFieldNameToNum(name);
			}
			return configNums;
		} catch (IllegalAccessException e) {
			return null;
		}
	}
577965
static TypeMirror getAdaptedType(Elements elements, Types types, DeclaredType adapterType) {
    TypeElement typeAdapterElement = elements.getTypeElement(TYPE_ADAPTER_CLASS_NAME);
    TypeParameterElement param = typeAdapterElement.getTypeParameters().get(0);
    return paramAsMemberOf(types, adapterType, param);
  }
73953
public Set<Class<?>> getTypesAnnotatedWith(final Annotation annotation, boolean honorInherited) {
        Iterable<String> annotated = store.get(index(TypeAnnotationsScanner.class), annotation.annotationType().getName());
        Iterable<Class<?>> filter = filter(forNames(annotated, loaders()), withAnnotation(annotation));
        Iterable<String> classes = getAllAnnotated(names(filter), annotation.annotationType().isAnnotationPresent(Inherited.class), honorInherited);
        return Sets.newHashSet(concat(filter, forNames(filter(classes, not(in(Sets.newHashSet(annotated)))), loaders())));
    }
155682
private String getClassName(final TypeMirror t) {
        String res = null;

        if (t instanceof DeclaredType) {
            final DeclaredType dt = (DeclaredType) t;
            res = ((TypeElement) dt.asElement()).getQualifiedName().toString();
            if (!dt.getTypeArguments().isEmpty()) {
                res += "<";
                boolean first = true;
                for (final TypeMirror tm : dt.getTypeArguments()) {
                    if (first) {
                        first = false;
                    } else {
                        res += ",";
                    }
                    res += getClassName(tm);
                }
                res += ">";
            }

        } else if (t instanceof PrimitiveType) {
            res = ((PrimitiveType) t).toString();
        }

        return res;
    }
290133
<A extends Annotation> A findAnnotation(TypeElement element, Class<A> anno) {

    final A annotation = element.getAnnotation(anno);
    if (annotation != null) {
      return annotation;
    }
    final TypeMirror typeMirror = element.getSuperclass();
    if (typeMirror.getKind() == TypeKind.NONE) {
      return null;
    }
    final TypeElement element1 = (TypeElement)typeUtils.asElement(typeMirror);
    return findAnnotation(element1, anno);
  }
773851
static boolean isRawType(TypeMirror typeMirror) {
    Set<TypeParameterElement> visited = new HashSet<>();
    return typeMirror.accept(CheckRawTypesVisitor.INSTANCE, visited);
  }
698556
private JvmAnnotationReference annotationClassRef(Class<? extends Annotation> type,
			List<? extends JvmTypeReference> values) {
		try {
			final JvmAnnotationReference annot = this._annotationTypesBuilder.annotationRef(type);
			final JvmTypeAnnotationValue annotationValue = this.services.getTypesFactory().createJvmTypeAnnotationValue();
			for (final JvmTypeReference value : values) {
				annotationValue.getValues().add(this.typeBuilder.cloneWithProxies(value));
			}
			annot.getExplicitValues().add(annotationValue);
			return annot;
		} catch (IllegalArgumentException exception) {
			// ignore
		}
		return null;
	}