Allows to collect all fields which can be used for scripting.

@param annotatedClass class to be processed, must not be null
@return container which contains all found items
15517
protected BinFieldContainer collectAnnotatedFields(final Class<?> annotatedClass) {
    final Bin defautBin = annotatedClass.getAnnotation(Bin.class);
    final DslBinCustom defaultBinCustom = annotatedClass.getAnnotation(DslBinCustom.class);

    final BinFieldContainer result;
    if (defautBin != null) {
      result = new BinFieldContainer(annotatedClass, defautBin, true, null);
    } else if (defaultBinCustom != null) {
      result = new BinFieldContainer(annotatedClass, defaultBinCustom, true, null);
    } else {
      result = new BinFieldContainer(annotatedClass, null);
    }

    final Class<?> superclazz = annotatedClass.getSuperclass();

    if (superclazz != null && superclazz != Object.class) {
      final BinFieldContainer parentFields = collectAnnotatedFields(superclazz);
      if (!parentFields.fields.isEmpty()) {
        result.addAllFromContainer(parentFields);
      }
    }

    for (final Field f : annotatedClass.getDeclaredFields()) {
      if ((f.getModifiers() & (Modifier.NATIVE | Modifier.STATIC | Modifier.FINAL | Modifier.PRIVATE | Modifier.TRANSIENT)) == 0) {
        final Bin fieldBinAnno = f.getAnnotation(Bin.class);
        final DslBinCustom fieldBinCustomAnno = f.getAnnotation(DslBinCustom.class);

        if (fieldBinAnno != null || defautBin != null || defaultBinCustom != null || fieldBinCustomAnno != null) {
          validateAnnotatedField(defautBin, fieldBinAnno, defaultBinCustom, fieldBinCustomAnno, f);

          final Class<?> type = f.getType().isArray() ? f.getType().getComponentType() : f.getType();
          if (type.isPrimitive() || type == String.class) {
            if (fieldBinAnno != null || fieldBinCustomAnno != null) {
              if (fieldBinAnno != null) {
                result.addBinField(fieldBinAnno, true, f);
              } else {
                result.addBinCustomField(fieldBinCustomAnno, true, f);
              }
            } else {
              if (defautBin != null) {
                result.addBinField(defautBin, false, f);
              } else {
                result.addBinCustomField(defaultBinCustom, false, f);
              }
            }
          } else {
            final BinFieldContainer container = collectAnnotatedFields(type);
            if (!container.fields.isEmpty()) {
              if (fieldBinAnno != null) {
                container.bin = fieldBinAnno;
                container.fieldLocalAnnotation = true;
              } else if (fieldBinCustomAnno != null) {
                container.binCustom = fieldBinCustomAnno;
                container.fieldLocalAnnotation = true;
              }
              container.field = f;
              result.addContainer(container);
            }
          }
        }
      }
    }

    result.sort();

    if (!result.fields.isEmpty()) {
      result.addContainer(BinFieldContainer.END_STRUCT);
    }

    return result;
  }
1128295
public static <A extends Annotation> A getAnnotation(Object objectOrClass, Class<A> annotationClass) {
    Class<?> initialClass = objectOrClass instanceof Class<?> ? (Class<?>) objectOrClass : objectOrClass.getClass();
    
    for (Class<?> aClass = initialClass; aClass != null; aClass = aClass.getSuperclass()) {
      A result = aClass.getAnnotation(annotationClass);
      if (result != null) {
        return result;
      }
    }

    for (Class<?> anInterface : (List<Class<?>>) ClassUtils.getAllInterfaces(initialClass)) {
      A result = anInterface.getAnnotation(annotationClass);
      if (result != null) {
        return result;
      }
    }

    return null;
  }
432091
private Object generateObject(final Field field,
                                  final GenContainer container,
                                  final Map<Field, Long> enumerateMap,
                                  final Set<Field> nullableFields,
                                  final int currentEmbeddedDepth) {
        final IGenerator generator = genStorage.getGenInstance(container.getGeneratorClass());
        final Annotation annotation = container.getMarker();

        Object generated;

        if (EmbeddedGenerator.class.equals(container.getGeneratorClass())) {
            generated = generateEmbeddedObject(annotation, field, nullableFields, currentEmbeddedDepth);
        } else if (enumerateMap.containsKey(field)) {
            generated = generateEnumerateObject(field, enumerateMap);
        } else if (container.isComplex()) {
            // If complexGen can generate embedded objects
            // And not handling it like BasicComplexGenerator, you are StackOverFlowed
            generated = ((IComplexGenerator) generator).generate(annotation, field, genStorage, currentEmbeddedDepth);
        } else {
            generated = generator.generate();
        }

        final Object casted = castObject(generated, field.getType());
        if (casted == null)
            nullableFields.add(field);

        return casted;
    }
540780
public Annotation buildAnnotation(final Class<?> annoClass, final AnnotationInfo info) throws AnnotationReadException {
        
        final Map<String, Object> defaultValues = new HashMap<>();
        for(Method method : annoClass.getMethods()) {
            final Object defaultValue = method.getDefaultValue();
            if(defaultValue != null) {
                defaultValues.put(method.getName(), defaultValue);
            }
        }
        
        final Map<String, Object> xmlValues = new HashMap<>();
        for(String key : info.getAttributeKeys()) {
            try {
                Object value = Ognl.getValue(info.getAttribute(key), ognlContext, new Object());
                xmlValues.put(key, value);
            } catch(OgnlException e) {
                throw new AnnotationReadException(String.format("fail annotation attribute %s with ognl.", key), e);
            }
        }
        
        ClassLoader loader = classLoader;
        if(loader == null){
            loader = Thread.currentThread().getContextClassLoader();
        }
        
        Object obj = Proxy.newProxyInstance(loader, new Class[]{annoClass},
                new InvocationHandler() {
                    @Override
                    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                        String name = method.getName();
                        if (name.equals("annotationType")) {
                            return annoClass;
                        } else if(xmlValues.containsKey(name)){
                            return xmlValues.get(name);
                        } else {
                            return defaultValues.get(name);
                        }
                    }
        });
        
        return (Annotation) obj;
    }
1107734
public <A extends Annotation> boolean hasAnnotation(final Field field, final Class<A> annClass) {
        return getAnnotation(field, annClass) != null;
    }
1208527
public static Collection<Method> findAnnotatedMethods(Class<?> type, Class<? extends Annotation> annotation)
    {
        List<Method> result = new ArrayList<>();

        // gather all publicly available methods
        // this returns everything, even if it's declared in a parent
        for (Method method : type.getMethods()) {
            // skip methods that are used internally by the vm for implementing covariance, etc
            if (method.isSynthetic() || method.isBridge() || isStatic(method.getModifiers())) {
                continue;
            }

            // look for annotations recursively in super-classes or interfaces
            Method managedMethod = findAnnotatedMethod(
                    type,
                    annotation,
                    method.getName(),
                    method.getParameterTypes());
            if (managedMethod != null) {
                result.add(managedMethod);
            }
        }

        return result;
    }
465150
private static Class<? extends Annotation> getContainer(Class<? extends Annotation> annoType) {
        // Since we can not refer to java.lang.annotation.Repeatable until we are
        // bootstrapping with java 8 we need to get the Repeatable annotation using
        // reflective invocations instead of just using its type and element method.
        if (REPEATABLE_CLASS != null &&
            VALUE_ELEMENT_METHOD != null) {
            // Get the Repeatable instance on the annotations declaration
            Annotation repeatable = (Annotation)annoType.getAnnotation(REPEATABLE_CLASS);
            if (repeatable != null) {
                try {
                    // Get the value element, it should be a class
                    // indicating the containing annotation type
                    @SuppressWarnings("unchecked")
                    Class<? extends Annotation> containerType = (Class)VALUE_ELEMENT_METHOD.invoke(repeatable);
                    if (containerType == null)
                        return null;

                    return containerType;
                } catch (ClassCastException | IllegalAccessException | InvocationTargetException e) {
                    return null;
                }
            }
        }
        return null;
    }
165761
protected Set<Class<? extends Annotation>> getSupportedAnnotationClasses() {
		Set<Class<? extends Annotation>> annotations = new LinkedHashSet<Class<? extends Annotation>>();
		annotations.add(BindType.class);		

		return annotations;
	}
867240
public <A extends Annotation> A annotation(Class<A> annotationClass) {
        return field.getAnnotation(annotationClass);
    }
73898
public static <T extends Annotation> T getAnnotation(final Class<?> componentClass,
		final Class<T> annotationClass)
	{
		T annotation = componentClass.getAnnotation(annotationClass);
		if (annotation != null)
		{
			return annotation;
		}
		for (final Class<?> ifc : componentClass.getInterfaces())
		{
			annotation = getAnnotation(ifc, annotationClass);
			if (annotation != null)
			{
				return annotation;
			}
		}
		if (!Annotation.class.isAssignableFrom(componentClass))
		{
			for (final Annotation ann : componentClass.getAnnotations())
			{
				annotation = getAnnotation(ann.annotationType(), annotationClass);
				if (annotation != null)
				{
					return annotation;
				}
			}
		}
		final Class<?> superClass = componentClass.getSuperclass();
		if (superClass == null || superClass.equals(Object.class))
		{
			return null;
		}
		return getAnnotation(superClass, annotationClass);
	}
315871
private Collection<Field> getDeclaredFields() {
      final LinkedList<Field> declaredFields = new LinkedList<>(Arrays.asList(clazz.getDeclaredFields()));
      for (Class<?> c = clazz.getSuperclass(); c != null; c = c.getSuperclass()) {
         // support fields from MappedSuperclass(es).
         // Do not support ambiguous annotation. Spec says:
         // "A mapped superclass has no separate table defined for it".
         if (c.getAnnotation(MappedSuperclass.class) != null) {
            if (c.getAnnotation(Table.class) == null) {
               declaredFields.addAll(Arrays.asList(c.getDeclaredFields()));
            }
            else {
               throw new RuntimeException("Class " + c.getName() + " annotated with @MappedSuperclass cannot also have @Table annotation");
            }
         }
      }
      return declaredFields;
   }
1345237
protected static <A> A _getAnnotation(Class<A> annotationClass, Class endpointClass) {
        return annotationClass.cast(endpointClass.getAnnotation(annotationClass));
    }
837699
public DockerContainerObjectBuilder<T> withContainerObjectClass(Class<T> containerObjectClass) {
        if (containerObjectClass == null) {
            throw new IllegalArgumentException("container object class cannot be null");
        }
        this.containerObjectClass = containerObjectClass;

        //First we check if this ContainerObject is defining a @CubeDockerFile in static method
        final List<Method> methodsWithCubeDockerFile =
            ReflectionUtil.getMethodsWithAnnotation(containerObjectClass, CubeDockerFile.class);

        if (methodsWithCubeDockerFile.size() > 1) {
            throw new IllegalArgumentException(
                String.format(
                    "More than one %s annotation found and only one was expected. Methods where annotation was found are: %s",
                    CubeDockerFile.class.getSimpleName(), methodsWithCubeDockerFile));
        }

        classHasMethodWithCubeDockerFile = !methodsWithCubeDockerFile.isEmpty();
        classDefinesCubeDockerFile = containerObjectClass.isAnnotationPresent(CubeDockerFile.class);
        classDefinesImage = containerObjectClass.isAnnotationPresent(Image.class);

        if (classHasMethodWithCubeDockerFile) {
            methodWithCubeDockerFile = methodsWithCubeDockerFile.get(0);
            boolean isMethodStatic = Modifier.isStatic(methodWithCubeDockerFile.getModifiers());
            boolean methodHasNoArguments = methodWithCubeDockerFile.getParameterCount() == 0;
            boolean methodReturnsAnArchive = Archive.class.isAssignableFrom(methodWithCubeDockerFile.getReturnType());
            if (!isMethodStatic || !methodHasNoArguments || !methodReturnsAnArchive) {
                throw new IllegalArgumentException(
                    String.format("Method %s annotated with %s is expected to be static, no args and return %s.",
                        methodWithCubeDockerFile, CubeDockerFile.class.getSimpleName(), Archive.class.getSimpleName()));
            }
        }

        // User has defined @CubeDockerfile on the class and a method
        if (classHasMethodWithCubeDockerFile && classDefinesCubeDockerFile) {
            throw new IllegalArgumentException(
                String.format(
                    "More than one %s annotation found and only one was expected. Both class and method %s has the annotation.",
                    CubeDockerFile.class.getSimpleName(), methodWithCubeDockerFile));
        }

        // User has defined @CubeDockerfile and @Image
        if ((classHasMethodWithCubeDockerFile || classDefinesCubeDockerFile) && classDefinesImage) {
            throw new IllegalArgumentException(
                String.format("Container Object %s has defined %s annotation and %s annotation together.",
                    containerObjectClass.getSimpleName(), Image.class.getSimpleName(),
                    CubeDockerFile.class.getSimpleName()));
        }

        // User has not defined either @CubeDockerfile or @Image
        if (!classDefinesCubeDockerFile && !classDefinesImage && !classHasMethodWithCubeDockerFile) {
            throw new IllegalArgumentException(
                String.format("Container Object %s is not annotated with either %s or %s annotations.",
                    containerObjectClass.getName(), CubeDockerFile.class.getSimpleName(), Image.class.getSimpleName()));
        }

        return this;
    }
233083
@Override
    public <T> Collection<T> all(Class<T> serviceClass) {

        if (serviceClass == null) {
            throw new IllegalArgumentException("ServiceClass must be provided");
        }

        return createInstances(serviceClass, load(serviceClass));
    }
830461
@Override
    public  <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
        return AnnotationUtils.getAnnotation(target, annotationClass);
    }
1366442
public synchronized Set<Class<?>> getTypesAnnotatedWith(final Class<? extends Annotation> annotation) {
        Assert.requireNonNull(annotation, "annotation");
        return reflections.getTypesAnnotatedWith(annotation);
    }
335490
public List<MappedField> getFieldsAnnotatedWith(final Class<? extends Annotation> clazz) {
        final List<MappedField> results = new ArrayList<MappedField>();
        for (final MappedField mf : persistenceFields) {
            if (mf.hasAnnotation(clazz)) {
                results.add(mf);
            }
        }
        return results;
    }