Java Code Examples for java.lang.annotation.Annotation#getClass()

The following examples show how to use java.lang.annotation.Annotation#getClass() . 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: ConstraintViolationExceptionMapper.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
private String toCode(ConstraintViolation<?> violation) {
	if (violation.getConstraintDescriptor() != null) {
		Annotation annotation = violation.getConstraintDescriptor().getAnnotation();

		if (annotation != null) {
			Class<?> clazz = annotation.getClass();
			Class<?> superclass = annotation.getClass().getSuperclass();
			Class<?>[] interfaces = annotation.getClass().getInterfaces();
			if (superclass == Proxy.class && interfaces.length == 1) {
				clazz = interfaces[0];
			}

			return clazz.getName();
		}
	}
	if (violation.getMessageTemplate() != null) {
		return violation.getMessageTemplate().replace("{", "").replaceAll("}", "");
	}
	return null;
}
 
Example 2
Source File: UiControllerClassMeta.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected Map<String, Object> getControllerAnnotationAttributes(String annotationName, Class<?> screenClass) {
    for (Annotation annotation : screenClass.getAnnotations()) {
        Class<? extends Annotation> annotationClass = annotation.getClass();
        if (!annotationClass.getName().equals(annotationName)) {
            continue;
        }

        Map<String, Object> annotationAttributes = new HashMap<>();
        for (Method method : annotationClass.getDeclaredMethods()) {
            try {
                annotationAttributes.put(method.getName(), method.invoke(annotation));
            } catch (IllegalAccessException | InvocationTargetException e) {
                log.warn("Failed to get '{}#{}' property value for class '{}'",
                        annotationClass.getName(), method.getName(), screenClass.getName(), e);
            }
        }
        return annotationAttributes;
    }
    return Collections.emptyMap();
}
 
Example 3
Source File: PortletParamProducer.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
private String _getParamName(Annotation[] annotations) {

		for (Annotation annotation : annotations) {
			Class<? extends Annotation> annotationClass = annotation.getClass();

			if (CookieParam.class.isAssignableFrom(annotationClass)) {
				CookieParam cookieParam = (CookieParam) annotation;

				return cookieParam.value();
			}

			if (FormParam.class.isAssignableFrom(annotationClass)) {
				FormParam formParam = (FormParam) annotation;

				return formParam.value();
			}

			if (HeaderParam.class.isAssignableFrom(annotationClass)) {
				HeaderParam headerParam = (HeaderParam) annotation;

				return headerParam.value();
			}

			if (QueryParam.class.isAssignableFrom(annotationClass)) {
				QueryParam queryParam = (QueryParam) annotation;

				return queryParam.value();
			}
		}

		return null;
	}
 
Example 4
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
public static SingleInputSemanticProperties getSemanticPropsSingle(
		Set<Annotation> set, TypeInformation<?> inType, TypeInformation<?> outType) {
	if (set == null) {
		return null;
	}
	Iterator<Annotation> it = set.iterator();

	String[] forwarded = null;
	String[] nonForwarded = null;
	String[] read = null;

	while (it.hasNext()) {

		Annotation ann = it.next();

		if (ann instanceof ForwardedFields) {
			forwarded = ((ForwardedFields) ann).value();
		} else if (ann instanceof NonForwardedFields) {
			nonForwarded = ((NonForwardedFields) ann).value();
		} else if (ann instanceof ReadFields) {
			read = ((ReadFields) ann).value();
		} else if (ann instanceof ForwardedFieldsFirst || ann instanceof ForwardedFieldsSecond ||
				ann instanceof NonForwardedFieldsFirst || ann instanceof NonForwardedFieldsSecond ||
				ann instanceof ReadFieldsFirst || ann instanceof ReadFieldsSecond) {
			throw new InvalidSemanticAnnotationException("Annotation " + ann.getClass() + " invalid for single input function.");
		}
	}

	if (forwarded != null || nonForwarded != null || read != null) {
		SingleInputSemanticProperties result = new SingleInputSemanticProperties();
		getSemanticPropsSingleFromString(result, forwarded, nonForwarded, read, inType, outType);
		return result;
	}
	return null;
}
 
Example 5
Source File: WebSocketParam.java    From redkale with Apache License 2.0 5 votes vote down vote up
default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
    Annotation[] annotations = getAnnotations();
    if (annotations == null) return (T[]) Array.newInstance(annotationClass, 0);
    T[] news = (T[]) Array.newInstance(annotationClass, annotations.length);
    int index = 0;
    for (Annotation ann : annotations) {
        if (ann.getClass() == annotationClass) {
            news[index++] = (T) ann;
        }
    }
    if (index < 1) return (T[]) Array.newInstance(annotationClass, 0);
    return Arrays.copyOf(news, index);
}
 
Example 6
Source File: HttpRequest.java    From redkale with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前操作Method上的注解集合
 *
 * @param <T>             注解泛型
 * @param annotationClass 注解类型
 *
 * @return Annotation[]
 */
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
    if (this.annotations == null) return (T[]) Array.newInstance(annotationClass, 0);
    T[] news = (T[]) Array.newInstance(annotationClass, this.annotations.length);
    int index = 0;
    for (Annotation ann : this.annotations) {
        if (ann.getClass() == annotationClass) {
            news[index++] = (T) ann;
        }
    }
    if (index < 1) return (T[]) Array.newInstance(annotationClass, 0);
    return Arrays.copyOf(news, index);
}
 
Example 7
Source File: AccessibleObject.java    From jtransc with Apache License 2.0 5 votes vote down vote up
@JTranscSync
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
	for (Annotation annotation : getDeclaredAnnotations()) {
		if (annotation.getClass() == annotationClass) return (T) annotation;
	}
	return null;
}
 
Example 8
Source File: Class.java    From jtransc with Apache License 2.0 5 votes vote down vote up
@JTranscSync
public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationClass) {
	ArrayList<A> out = new ArrayList<>();
	for (Annotation a : getDeclaredAnnotations()) {
		if (a.getClass() == annotationClass) out.add((A) a);
	}
	return (A[]) out.toArray(new Annotation[0]);
}
 
Example 9
Source File: Class.java    From jtransc with Apache License 2.0 5 votes vote down vote up
@JTranscSync
public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass) {
	for (Annotation a : getDeclaredAnnotations()) {
		if (a.getClass() == annotationClass) return (A) a;
	}
	return null;
}
 
Example 10
Source File: Class.java    From jtransc with Apache License 2.0 5 votes vote down vote up
@JTranscSync
public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) {
	ArrayList<A> out = new ArrayList<>();
	for (Annotation a : getAnnotations()) {
		if (a.getClass() == annotationClass) out.add((A) a);
	}
	return (A[]) out.toArray(new Annotation[0]);
}
 
Example 11
Source File: Reflections.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static boolean isCacheable(Set<Annotation> annotations) {
    for (Annotation qualifier : annotations) {
        Class<?> clazz = qualifier.getClass();
        if (clazz.isAnonymousClass() || (clazz.isMemberClass() && isStatic(clazz))) {
            return false;
        }
    }
    return true;
}
 
Example 12
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
public static SingleInputSemanticProperties getSemanticPropsSingle(
		Set<Annotation> set, TypeInformation<?> inType, TypeInformation<?> outType) {
	if (set == null) {
		return null;
	}
	Iterator<Annotation> it = set.iterator();

	String[] forwarded = null;
	String[] nonForwarded = null;
	String[] read = null;

	while (it.hasNext()) {

		Annotation ann = it.next();

		if (ann instanceof ForwardedFields) {
			forwarded = ((ForwardedFields) ann).value();
		} else if (ann instanceof NonForwardedFields) {
			nonForwarded = ((NonForwardedFields) ann).value();
		} else if (ann instanceof ReadFields) {
			read = ((ReadFields) ann).value();
		} else if (ann instanceof ForwardedFieldsFirst || ann instanceof ForwardedFieldsSecond ||
				ann instanceof NonForwardedFieldsFirst || ann instanceof NonForwardedFieldsSecond ||
				ann instanceof ReadFieldsFirst || ann instanceof ReadFieldsSecond) {
			throw new InvalidSemanticAnnotationException("Annotation " + ann.getClass() + " invalid for single input function.");
		}
	}

	if (forwarded != null || nonForwarded != null || read != null) {
		SingleInputSemanticProperties result = new SingleInputSemanticProperties();
		getSemanticPropsSingleFromString(result, forwarded, nonForwarded, read, inType, outType);
		return result;
	}
	return null;
}
 
Example 13
Source File: Reflections.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static boolean isCacheable(Annotation[] annotations) {
    for (Annotation qualifier : annotations) {
        Class<?> clazz = qualifier.getClass();
        if (clazz.isAnonymousClass() || (clazz.isMemberClass() && isStatic(clazz))) {
            return false;
        }
    }
    return true;
}
 
Example 14
Source File: TypeDescriptor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private boolean annotationEquals(Annotation ann, Annotation otherAnn) {
	// Annotation.equals is reflective and pretty slow, so let's check identity and proxy type first.
	return (ann == otherAnn || (ann.getClass() == otherAnn.getClass() && ann.equals(otherAnn)));
}
 
Example 15
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
public static DualInputSemanticProperties getSemanticPropsDual(
		Set<Annotation> set, TypeInformation<?> inType1, TypeInformation<?> inType2, TypeInformation<?> outType) {
	if (set == null) {
		return null;
	}
	Iterator<Annotation> it = set.iterator();

	String[] forwardedFirst = null;
	String[] forwardedSecond = null;
	String[] nonForwardedFirst = null;
	String[] nonForwardedSecond = null;
	String[] readFirst = null;
	String[] readSecond = null;

	while (it.hasNext()) {
		Annotation ann = it.next();

		if (ann instanceof ForwardedFieldsFirst) {
			forwardedFirst = ((ForwardedFieldsFirst) ann).value();
		} else if (ann instanceof ForwardedFieldsSecond) {
			forwardedSecond = ((ForwardedFieldsSecond) ann).value();
		} else if (ann instanceof NonForwardedFieldsFirst) {
			nonForwardedFirst = ((NonForwardedFieldsFirst) ann).value();
		} else if (ann instanceof NonForwardedFieldsSecond) {
			nonForwardedSecond = ((NonForwardedFieldsSecond) ann).value();
		} else if (ann instanceof ReadFieldsFirst) {
			readFirst = ((ReadFieldsFirst) ann).value();
		} else if (ann instanceof ReadFieldsSecond) {
			readSecond = ((ReadFieldsSecond) ann).value();
		} else if (ann instanceof ForwardedFields || ann instanceof NonForwardedFields || ann instanceof ReadFields) {
			throw new InvalidSemanticAnnotationException("Annotation " + ann.getClass() + " invalid for dual input function.");
		}
	}

	if (forwardedFirst != null || nonForwardedFirst != null || readFirst != null ||
			forwardedSecond != null || nonForwardedSecond != null || readSecond != null) {
		DualInputSemanticProperties result = new DualInputSemanticProperties();
		getSemanticPropsDualFromString(result, forwardedFirst, forwardedSecond,
			nonForwardedFirst, nonForwardedSecond, readFirst, readSecond, inType1, inType2, outType);
		return result;
	}
	return null;
}
 
Example 16
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
public static DualInputSemanticProperties getSemanticPropsDual(
		Set<Annotation> set, TypeInformation<?> inType1, TypeInformation<?> inType2, TypeInformation<?> outType) {
	if (set == null) {
		return null;
	}
	Iterator<Annotation> it = set.iterator();

	String[] forwardedFirst = null;
	String[] forwardedSecond = null;
	String[] nonForwardedFirst = null;
	String[] nonForwardedSecond = null;
	String[] readFirst = null;
	String[] readSecond = null;

	while (it.hasNext()) {
		Annotation ann = it.next();

		if (ann instanceof ForwardedFieldsFirst) {
			forwardedFirst = ((ForwardedFieldsFirst) ann).value();
		} else if (ann instanceof ForwardedFieldsSecond) {
			forwardedSecond = ((ForwardedFieldsSecond) ann).value();
		} else if (ann instanceof NonForwardedFieldsFirst) {
			nonForwardedFirst = ((NonForwardedFieldsFirst) ann).value();
		} else if (ann instanceof NonForwardedFieldsSecond) {
			nonForwardedSecond = ((NonForwardedFieldsSecond) ann).value();
		} else if (ann instanceof ReadFieldsFirst) {
			readFirst = ((ReadFieldsFirst) ann).value();
		} else if (ann instanceof ReadFieldsSecond) {
			readSecond = ((ReadFieldsSecond) ann).value();
		} else if (ann instanceof ForwardedFields || ann instanceof NonForwardedFields || ann instanceof ReadFields) {
			throw new InvalidSemanticAnnotationException("Annotation " + ann.getClass() + " invalid for dual input function.");
		}
	}

	if (forwardedFirst != null || nonForwardedFirst != null || readFirst != null ||
			forwardedSecond != null || nonForwardedSecond != null || readSecond != null) {
		DualInputSemanticProperties result = new DualInputSemanticProperties();
		getSemanticPropsDualFromString(result, forwardedFirst, forwardedSecond,
			nonForwardedFirst, nonForwardedSecond, readFirst, readSecond, inType1, inType2, outType);
		return result;
	}
	return null;
}
 
Example 17
Source File: SemanticPropUtil.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public static DualInputSemanticProperties getSemanticPropsDual(
		Set<Annotation> set, TypeInformation<?> inType1, TypeInformation<?> inType2, TypeInformation<?> outType) {
	if (set == null) {
		return null;
	}
	Iterator<Annotation> it = set.iterator();

	String[] forwardedFirst = null;
	String[] forwardedSecond = null;
	String[] nonForwardedFirst = null;
	String[] nonForwardedSecond = null;
	String[] readFirst = null;
	String[] readSecond = null;

	while (it.hasNext()) {
		Annotation ann = it.next();

		if (ann instanceof ForwardedFieldsFirst) {
			forwardedFirst = ((ForwardedFieldsFirst) ann).value();
		} else if (ann instanceof ForwardedFieldsSecond) {
			forwardedSecond = ((ForwardedFieldsSecond) ann).value();
		} else if (ann instanceof NonForwardedFieldsFirst) {
			nonForwardedFirst = ((NonForwardedFieldsFirst) ann).value();
		} else if (ann instanceof NonForwardedFieldsSecond) {
			nonForwardedSecond = ((NonForwardedFieldsSecond) ann).value();
		} else if (ann instanceof ReadFieldsFirst) {
			readFirst = ((ReadFieldsFirst) ann).value();
		} else if (ann instanceof ReadFieldsSecond) {
			readSecond = ((ReadFieldsSecond) ann).value();
		} else if (ann instanceof ForwardedFields || ann instanceof NonForwardedFields || ann instanceof ReadFields) {
			throw new InvalidSemanticAnnotationException("Annotation " + ann.getClass() + " invalid for dual input function.");
		}
	}

	if (forwardedFirst != null || nonForwardedFirst != null || readFirst != null ||
			forwardedSecond != null || nonForwardedSecond != null || readSecond != null) {
		DualInputSemanticProperties result = new DualInputSemanticProperties();
		getSemanticPropsDualFromString(result, forwardedFirst, forwardedSecond,
			nonForwardedFirst, nonForwardedSecond, readFirst, readSecond, inType1, inType2, outType);
		return result;
	}
	return null;
}
 
Example 18
Source File: WebSocketParam.java    From redkale with Apache License 2.0 4 votes vote down vote up
default <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
    for (Annotation ann : getAnnotations()) {
        if (ann.getClass() == annotationClass) return (T) ann;
    }
    return null;
}
 
Example 19
Source File: TypeDescriptor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private boolean annotationEquals(Annotation ann, Annotation otherAnn) {
	// Annotation.equals is reflective and pretty slow, so let's check identity and proxy type first.
	return (ann == otherAnn || (ann.getClass() == otherAnn.getClass() && ann.equals(otherAnn)));
}
 
Example 20
Source File: ParamConverterProviderImpl.java    From portals-pluto with Apache License 2.0 3 votes vote down vote up
private String _getParamName(Annotation[] annotations) {

		for (Annotation annotation : annotations) {

			Class<? extends Annotation> annotationClass = annotation.getClass();

			if (CookieParam.class.isAssignableFrom(annotationClass)) {
				CookieParam cookieParam = (CookieParam) annotation;

				return cookieParam.value();
			}

			if (FormParam.class.isAssignableFrom(annotationClass)) {
				FormParam formParam = (FormParam) annotation;

				return formParam.value();
			}

			if (HeaderParam.class.isAssignableFrom(annotationClass)) {
				HeaderParam headerParam = (HeaderParam) annotation;

				return headerParam.value();
			}

			if (QueryParam.class.isAssignableFrom(annotationClass)) {
				QueryParam queryParam = (QueryParam) annotation;

				return queryParam.value();
			}
		}

		return null;
	}