本文整理汇总了Java中java.lang.annotation.AnnotationTypeMismatchException类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationTypeMismatchException类的具体用法?Java AnnotationTypeMismatchException怎么用?Java AnnotationTypeMismatchException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationTypeMismatchException类属于java.lang.annotation包,在下文中一共展示了AnnotationTypeMismatchException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
boolean isSuccessfulProcess = true;
for (Element element : roundEnv.getElementsAnnotatedWith(View.class)) {
try {
final ViewElement viewElement = new ViewElement(environment, element);
if (!validator.isViewElementValid(viewElement)) {
isSuccessfulProcess = false;
} else {
environment.addViewElement(viewElement);
}
} catch (AnnotationTypeMismatchException ex) {
environment.error(element, String.format("@%s and @%s annotation attribute values must be self defined constant expressions",
View.class.getSimpleName(), ViewColumn.class.getSimpleName()));
return false;
} catch (Exception e) {
environment.error(element, "View collection error = " + e.getMessage());
e.printStackTrace();
return false;
}
}
return isSuccessfulProcess;
}
示例2: validateValue
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
/**
* Validates contained value against its member definition
* and if ok returns the value.
* Otherwise, if the value type mismatches definition
* or the value itself describes an error,
* throws appropriate exception.
* <br> Note, this method may return null if this element was constructed
* with such value.
*
* @see #rethrowError()
* @see #copyValue()
* @return actual valid value or null if no value
*/
public Object validateValue() throws Throwable {
if (tag == ERROR) {
rethrowError();
}
if (value == NO_VALUE) {
return null;
}
if (elementType == value.getClass()
|| elementType.isInstance(value)) { // nested annotation value
return copyValue();
} else {
throw new AnnotationTypeMismatchException(definingMethod,
value.getClass().getName());
}
}
示例3: validateValue
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
/**
* Validates contained value against its member definition
* and if ok returns the value.
* Otherwise, if the value type mismatches definition
* or the value itself describes an error,
* throws appropriate exception.
* <br> Note, this method may return null if this element was constructed
* with such value.
*
* @see #rethrowError()
* @see #copyValue()
* @return actual valid value or null if no value
*/
public Object validateValue() throws Throwable {
if (tag == ERROR) {
rethrowError();
}
if (value == NO_VALUE) {
return null;
}
if (elementType == value.getClass()
|| elementType.isInstance(value)) { // nested annotation value
return copyValue();
} else {
throw new AnnotationTypeMismatchException(definingMethod,
value.getClass().getName());
}
}
示例4: testSerialization
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
public void testSerialization() throws Exception {
Method m = String.class.getMethod("length");
AnnotationTypeMismatchException original = new AnnotationTypeMismatchException(m, "poop");
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
// AnnotationTypeMismatchException is broken: it's Serializable but has a non-transient
// non-serializable field of type Method.
new ObjectOutputStream(out).writeObject(original);
fail();
} catch (NotSerializableException expected) {
}
}
示例5: test_constructorLjava_lang_reflect_MethodLjava_lang_String
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
/**
* @throws ClassNotFoundException
* @throws SecurityException
* @tests java.lang.annotation.AnnotationTypeMismatchException#AnnotationTypeMismatchException(Method,
* String)
*/
@SuppressWarnings("nls")
public void test_constructorLjava_lang_reflect_MethodLjava_lang_String() throws SecurityException, ClassNotFoundException {
Method[] methods = Class.forName("java.lang.String").getMethods();
Method m = methods[0];
AnnotationTypeMismatchException e = new AnnotationTypeMismatchException(
m, "some type");
assertNotNull("can not instantiate AnnotationTypeMismatchException", e);
assertSame("wrong method name", m, e.element());
assertEquals("wrong found type", "some type", e.foundType());
}
示例6: validate
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
@Override
public void validate() {
if (entityClass == null) {
throw new IllegalArgumentException("testentity class cannot be null");
}
if (!entityClass.isAnnotationPresent(DeepEntity.class)) {
throw new AnnotationTypeMismatchException(null, entityClass.getCanonicalName());
}
super.validate();
/* let's validate fieldNames in @DeepField annotations */
Field[] deepFields = AnnotationUtils.filterDeepFields(entityClass);
Map<String, Cell> colDefs = super.columnDefinitions();
/* colDefs is null if table does not exist. I.E. this configuration will be used as an output configuration
object, and the output table is dynamically created */
if (colDefs == null) {
return;
}
for (Field field : deepFields) {
String annotationFieldName = AnnotationUtils.deepFieldName(field);
if (!colDefs.containsKey(annotationFieldName)) {
throw new DeepNoSuchFieldException("Unknown column name \'" + annotationFieldName + "\' specified for" +
" field " + entityClass.getCanonicalName() + "#" + field.getName() + ". Please, " +
"make sure the field name you specify in @DeepField annotation matches _exactly_ the column " +
"name " +
"in the database");
}
}
}
示例7: test_constructorLjava_lang_reflect_MethodLjava_lang_String
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
/**
* @throws ClassNotFoundException
* @throws SecurityException
* @tests java.lang.annotation.AnnotationTypeMismatchException#AnnotationTypeMismatchException(Method,
* String)
*/
@SuppressWarnings("nls")
public void test_constructorLjava_lang_reflect_MethodLjava_lang_String() throws SecurityException, ClassNotFoundException {
Method[] methods = Class.forName("java.lang.String").getMethods();
Method m = methods[0];
AnnotationTypeMismatchException e = new AnnotationTypeMismatchException(
m, "some type");
assertNotNull("can not instantiate AnnotationTypeMismatchException", e);
assertSame("wrong method name", m, e.element());
assertEquals("wrong found type", "some type", e.foundType());
}
示例8: test_constructorLjava_lang_reflect_MethodLjava_lang_String
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
/**
* @throws ClassNotFoundException
* @throws SecurityException
* @tests java.lang.annotation.AnnotationTypeMismatchException#AnnotationTypeMismatchException(Method,
* String)
*/
@SuppressWarnings("nls")
public void test_constructorLjava_lang_reflect_MethodLjava_lang_String() throws SecurityException, ClassNotFoundException {
Method[] methods = Class.forName("java.lang.String").getMethods();
Method m = methods[0];
AnnotationTypeMismatchException e = new AnnotationTypeMismatchException(
m, "some type");
assertNotNull("can not instanciate AnnotationTypeMismatchException", e);
assertSame("wrong method name", m, e.element());
assertEquals("wrong found type", "some type", e.foundType());
}
示例9: testAnnotationTypeMismatchException
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
@Test(expected = AnnotationTypeMismatchException.class)
@SuppressWarnings("unchecked")
public void testAnnotationTypeMismatchException() throws Throwable {
when(loadedAnnotationValue.resolve()).thenReturn(new Object());
Proxy.getInvocationHandler(AnnotationDescription.AnnotationInvocationHandler.of(getClass().getClassLoader(),
Foo.class,
Collections.<String, AnnotationValue<?, ?>>singletonMap(FOO, annotationValue)))
.invoke(new Object(), Foo.class.getDeclaredMethod("foo"), new Object[0]);
}
示例10: invoke
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
String methodName = method.getName().intern();
if (args == null || args.length == 0)
{
if (methodName == "toString")
{
return toString();
}
else if (methodName == "hashCode")
{
return Integer.valueOf(hashCode());
}
else if (methodName == "annotationType")
{
return type;
}
else
{
Object val = memberValues.get(methodName);
if (val == null)
{
throw new IncompleteAnnotationException(type, methodName);
}
try
{
if (val.getClass().isArray())
val = coerce((Object[])val, method.getReturnType());
}
catch (ArrayStoreException _)
{
throw new AnnotationTypeMismatchException
(method, val.getClass().getName());
}
if (! getBoxedReturnType(method).isInstance(val))
throw (new AnnotationTypeMismatchException
(method, val.getClass().getName()));
return val;
}
}
else if (args.length == 1)
{
if (methodName == "equals")
{
return Boolean.valueOf(equals(proxy, args[0]));
}
}
throw new InternalError("Invalid annotation proxy");
}
示例11: invoke
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
String methodName = method.getName().intern();
if (args == null || args.length == 0)
{
if (methodName == "toString")
{
return toString(type, memberValues);
}
else if (methodName == "hashCode")
{
return Integer.valueOf(hashCode(type, memberValues));
}
else if (methodName == "annotationType")
{
return type;
}
else
{
Object val = memberValues.get(methodName);
if (val == null)
{
throw new IncompleteAnnotationException(type, methodName);
}
if (! getBoxedReturnType(method).isInstance(val))
{
throw new AnnotationTypeMismatchException(method,
val.getClass().getName());
}
if (val.getClass().isArray())
{
val = arrayClone(val);
}
return val;
}
}
else if (args.length == 1)
{
if (methodName == "equals")
{
return Boolean.valueOf(equals(type, memberValues, args[0]));
}
}
throw new InternalError("Invalid annotation proxy");
}
示例12: invoke
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
String methodName = method.getName().intern();
if (args == null || args.length == 0)
{
if (methodName == "toString")
{
return toString(type, memberValues);
}
else if (methodName == "hashCode")
{
return Integer.valueOf(hashCode(type, memberValues));
}
else if (methodName == "annotationType")
{
return type;
}
else
{
Object val = memberValues.get(methodName);
if (val == null)
{
throw new IncompleteAnnotationException(type, methodName);
}
if (! getBoxedReturnType(method).isInstance(val))
{
throw new AnnotationTypeMismatchException(method,
val.getClass().getName());
}
if (val.getClass().isArray())
{
val = arrayClone(val);
}
return val;
}
}
else if (args.length == 1)
{
if (methodName == "equals")
{
return Boolean.valueOf(equals(type, memberValues, args[0]));
}
}
throw new InternalError("Invalid annotation proxy");
}
示例13: testGetters
import java.lang.annotation.AnnotationTypeMismatchException; //导入依赖的package包/类
public void testGetters() throws Exception {
Method m = String.class.getMethod("length");
AnnotationTypeMismatchException ex = new AnnotationTypeMismatchException(m, "poop");
assertSame(m, ex.element());
assertEquals("poop", ex.foundType());
}