/** * {@inheritDoc} */ public boolean isLocalType() { return type.isLocalClass(); }
public static boolean callIsLocalClass(Class thiz) { return thiz.isLocalClass(); }
@Override @Nullable Class<?> getOwnerType(Class<?> rawType) { if (rawType.isLocalClass()) { return null; } else { return rawType.getEnclosingClass(); } } };
private void checkNotLocal(Field field) { if(field.getType().isLocalClass()) { throw new MockitoException("the type '" + field.getType().getSimpleName() + "' is a local class."); } }
@NullableDecl @Override Class<?> getOwnerType(Class<?> rawType) { if (rawType.isLocalClass()) { return null; } else { return rawType.getEnclosingClass(); } } };
@Nullable @Override Class<?> getOwnerType(Class<?> rawType) { if (rawType.isLocalClass()) { return null; } else { return rawType.getEnclosingClass(); } } };
@Override @NullableDecl Class<?> getOwnerType(Class<?> rawType) { if (rawType.isLocalClass()) { return null; } else { return rawType.getEnclosingClass(); } } };
private void checkNotLocal(Field field) { if(field.getType().isLocalClass()) { throw new MockitoException("the type '" + field.getType().getSimpleName() + "' is a local class."); } }
public static <T> T newInstance(Object bean, String propertyName, Class<T> clazz) { try { return clazz.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException("The " + bean.getClass().getSimpleName() + "'s " + propertyName + " (" + clazz.getName() + ") does not have a public no-arg constructor" // Inner classes include local, anonymous and non-static member classes + ((clazz.isLocalClass() || clazz.isAnonymousClass() || clazz.isMemberClass()) && !Modifier.isStatic(clazz.getModifiers()) ? " because it is an inner class." : "."), e); } }
@NullableDecl @Override Class<?> getOwnerType(Class<?> rawType) { if (rawType.isLocalClass()) { return null; } else { return rawType.getEnclosingClass(); } } };
/** * Check if the class is acceptable as a JAX-RS provider or resource. * <p/> * Method returns {@code false} if the class is either * <ul> * <li>abstract</li> * <li>interface</li> * <li>annotation</li> * <li>primitive</li> * <li>local class</li> * <li>non-static member class</li> * </ul> * * @param c class to be checked. * @return {@code true} if the class is an acceptable JAX-RS provider or * resource, {@code false} otherwise. */ public static boolean isAcceptable(Class<?> c) { return !((c.getModifiers() & Modifier.ABSTRACT) != 0 || c.isPrimitive() || c.isAnnotation() || c.isInterface() || c.isLocalClass() || (c.isMemberClass() && (c.getModifiers() & Modifier.STATIC) == 0)); }
/** * Check if the class is acceptable as a JAX-RS provider or resource. * <p/> * Method returns {@code false} if the class is either * <ul> * <li>abstract</li> * <li>interface</li> * <li>annotation</li> * <li>primitive</li> * <li>local class</li> * <li>non-static member class</li> * </ul> * * @param c class to be checked. * @return {@code true} if the class is an acceptable JAX-RS provider or * resource, {@code false} otherwise. */ public static boolean isAcceptable(Class<?> c) { return !((c.getModifiers() & Modifier.ABSTRACT) != 0 || c.isPrimitive() || c.isAnnotation() || c.isInterface() || c.isLocalClass() || (c.isMemberClass() && (c.getModifiers() & Modifier.STATIC) == 0)); }
private Class<?> checkSecurity(Class<?> clazz) throws ClassNotFoundException { Class<?> target = clazz; while (target.isArray()) { target = target.getComponentType(); } while (target.isAnonymousClass() || target.isLocalClass()) { target = target.getEnclosingClass(); } if (!target.isPrimitive()) { if (!isTrustedType(target)) { throw new ClassNotFoundException("Forbidden " + clazz + "! " + "This class is not trusted to be deserialized under the current configuration. " + "Please refer to the documentation for more information on how to configure trusted classes."); } } return clazz; }
/** Validating instance creator that ensures the supplier type is static or top-level */ public static <T> T newInstance(Class<T> type, ClassLoader loader) { assertThat(type) .withFailMessage(type + " should be a static member class") .satisfies(c -> { assertThat(c.isLocalClass()).isFalse(); assertThat(Modifier.isPublic(c.getModifiers())).isFalse(); }); try { Class<T> classToInstantiate = (Class<T>) loader.loadClass(type.getName()); Constructor<T> ctor = classToInstantiate.getDeclaredConstructor(); ctor.setAccessible(true); return ctor.newInstance(); } catch (ReflectiveOperationException e) { throw new IllegalStateException(e); } }
/** * 计算ClassType * * @param targetClass 目标类 * @return 计算出的ClassType */ public static int computeClassType(Class<?> targetClass) { int type = 0; if (targetClass.isAnnotation()) type |= TYPE_ANNOTATION; if (targetClass.isAnonymousClass()) type |= TYPE_ANONYMOUS; if (targetClass.isArray()) type |= TYPE_ARRAY; if (targetClass.isEnum()) type |= TYPE_ENUM; if (targetClass.isInterface()) type |= TYPE_INTERFACE; if (targetClass.isLocalClass()) type |= TYPE_LOCAL; if (targetClass.isMemberClass()) type |= TYPE_MEMBER; if (targetClass.isPrimitive()) type |= TYPE_PRIMITIVE; if (targetClass.isSynthetic()) type |= TYPE_SYNTHETIC; return type; }
throw new IllegalArgumentException("Cannot serialize anonymous class " + rawType.getName()); if (rawType.isLocalClass()) { throw new IllegalArgumentException("Cannot serialize local class " + rawType.getName());
@Override public boolean test(Class<?> candidate) { // Please do not collapse the following into a single statement. if (isPrivate(candidate)) { return false; } if (isAbstract(candidate)) { return false; } if (candidate.isLocalClass()) { return false; } if (candidate.isAnonymousClass()) { return false; } return !isInnerClass(candidate); }
private <T> void validateClass(Class<T> entityClass) { if (entityClass.isAnonymousClass() || entityClass.isLocalClass()) { throw new IllegalArgumentException(entityClass.getName() + " is not publically accessable.");
private <T> void validateClass(Class<T> entityClass) { if (entityClass.isAnonymousClass() || entityClass.isLocalClass()) { throw new IllegalArgumentException(entityClass.getName() + " is not publically accessable.");
private String drawClassInfo() { final CodeSource cs = clazz.getProtectionDomain().getCodeSource(); final TTable tTable = new TTable(new TTable.ColumnDefine[]{ new TTable.ColumnDefine(50, TTable.Align.RIGHT), new TTable.ColumnDefine(80, TTable.Align.LEFT) }) .addRow("class-info", tranClassName(clazz)) .addRow("code-source", getCodeSource(cs)) .addRow("name", tranClassName(clazz)) .addRow("isInterface", clazz.isInterface()) .addRow("isAnnotation", clazz.isAnnotation()) .addRow("isEnum", clazz.isEnum()) .addRow("isAnonymousClass", clazz.isAnonymousClass()) .addRow("isArray", clazz.isArray()) .addRow("isLocalClass", clazz.isLocalClass()) .addRow("isMemberClass", clazz.isMemberClass()) .addRow("isPrimitive", clazz.isPrimitive()) .addRow("isSynthetic", clazz.isSynthetic()) .addRow("simple-name", clazz.getSimpleName()) .addRow("modifier", tranModifier(clazz.getModifiers())) .addRow("annotation", drawAnnotation()) .addRow("interfaces", drawInterface()) .addRow("super-class", drawSuperClass()) .addRow("class-loader", drawClassLoader()); if (isPrintField) { tTable.addRow("fields", drawField()); } return tTable.padding(1).rendering(); }