/** * <p>Checks if one <code>Class</code> can be assigned to a variable of * another <code>Class</code>.</p> * * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, * this method takes into account widenings of primitive classes and * <code>null</code>s.</p> * * <p>Primitive widenings allow an int to be assigned to a long, float or * double. This method returns the correct result for these cases.</p> * * <p><code>Null</code> may be assigned to any reference type. This method * will return <code>true</code> if <code>null</code> is passed in and the * toClass is non-primitive.</p> * * <p>Specifically, this method tests whether the type represented by the * specified <code>Class</code> parameter can be converted to the type * represented by this <code>Class</code> object via an identity conversion * widening primitive or widening reference conversion. See * <em><a href="http://java.sun.com/docs/books/jls/">The Java Language Specification</a></em>, * sections 5.1.1, 5.1.2 and 5.1.4 for details.</p> * * @param cls the Class to check, may be null * @param toClass the Class to try to assign into, returns false if null * @return <code>true</code> if assignment possible */ public static boolean isAssignable(Class cls, Class toClass) { return isAssignable(cls, toClass, false); }
return isAssignable(classArray, toClassArray, false);
private static boolean shouldKeep(Class<?> type, Object extension, @Nullable ExtensionMatcher matcher) { return ClassUtils.isAssignable(extension.getClass(), type) && (matcher == null || matcher.accept(extension)); } }
if (destClass.isInterface() && ClassUtils.isAssignable(srcClass, destClass)) {
if (isAssignable(classArray[i], toClassArray[i], autoboxing) == false) { return false;
public boolean accept(Object extension) { return extension.equals(Foo.class) || ClassUtils.isAssignable(Foo.class, extension.getClass()) || ClassUtils.isAssignable(FooProvider.class, extension.getClass()); } }
if (methods[i].getName().equals(methodName)) { if (ClassUtils.isAssignable(parameterTypes, methods[i] .getParameterTypes(), true)) {
if (ClassUtils.isAssignable(parameterTypes, ctors[i].getParameterTypes(), true)) {
|| ClassUtils.wrapperToPrimitive(c) != null) { errorStr.append(offsetStr).append(name + ": [" + p + "]\n"); } else if (ClassUtils.isAssignable(c, Iterable.class)) { errorStr.append(offsetStr).append(name + " is an iterable\n"); Iterator<?> i1 = ((Iterable<?>)p).iterator(); dumpObject(errorStr, name + "[" + i + "]", Array.get(p, i), t, level + 1); } else if (ClassUtils.isAssignable(c, Map.class)) { Map<?,?> c1 = (Map<?,?>)p; errorStr.append(offsetStr).append(name + " is a map\n");
final Class<?> type = customizerConfig.getValue().getClass(); return m.getName().equals(customizerConfig.getKey()) && m.getParameters().length <= 1 && ClassUtils.isAssignable(type, m.getParameters()[0].getType(), true); }).findFirst() .orElseThrow(() -> new IllegalStateException("Could not find builder method '" + customizerConfig.getKey() + "' on " + builderClazz.getCanonicalName()));
@Override public boolean supports(Class<?> aClass) { return ClassUtils.isAssignable(aClass, DataConnection.class); } }
/** * Tests whether this converter can handle a conversion to the given * target class. * * @param clazz the desired target class of the conversion * @return a flag whether this conversion is supported */ public boolean canHandleConverter(Class<?> clazz) { return ClassUtils.isAssignable(clazz, targetClass); } }
/** * Helper method for comparing the classes of a method parameter. Depending * on the exact match flag either a strict comparison or a test for * assignment compatibility is performed. * * @param methodParamCls the class of the method parameter * @param argCls the class of the argument * @param exactMatch the exact match flag * @return a flag whether the classes are compatible */ private static boolean compareParameterClasses(Class<?> methodParamCls, Class<?> argCls, boolean exactMatch) { return exactMatch ? methodParamCls.equals(argCls) : ClassUtils .isAssignable(argCls, methodParamCls); }
@Override public final boolean accept(Object extension) { return ClassUtils.isAssignable(extension.getClass(), Sensor.class) && acceptSensor((Sensor) extension) || ClassUtils.isAssignable(extension.getClass(), org.sonar.api.batch.sensor.Sensor.class); }
private boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) { boolean keep = (ClassUtils.isAssignable(extension.getClass(), type) || (org.sonar.api.batch.Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class))) && (matcher == null || matcher.accept(extension)); if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) { keep = ((CheckProject) extension).shouldExecuteOnProject(project); } return keep; } }
private static boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) { boolean keep = (ClassUtils.isAssignable(extension.getClass(), type) || (org.sonar.api.batch.Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class))) && (matcher == null || matcher.accept(extension)); if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) { keep = ((CheckProject) extension).shouldExecuteOnProject(project); } return keep; } }
private static boolean shouldKeep(Class<?> type, Object extension, @Nullable ExtensionMatcher matcher) { return ClassUtils.isAssignable(extension.getClass(), type) && (matcher == null || matcher.accept(extension)); } }
protected String getDisplayName(Object obj, int mode) { if ((ClassUtils.isAssignable(obj.getClass(), Number.class, true))) { return FormattersManager.getFormatter(obj).format(obj); } if (obj instanceof INamedThing) { INamedThing nt = (INamedThing) obj; return nt.getDisplayName(mode); } return String.valueOf(obj); }
private void registerInstruction(String instructionName, String targetNamespace, String className) throws ConfigurationException { Class clazz; try { clazz = Class.forName(className); if (!ClassUtils.isAssignable(clazz, Instruction.class)) throw new ConfigurationException("Class '" + className + "' is not assignable to " + "o.a.c.template.jxtg.script.event.StartInstruction "); Constructor constructor = clazz.getConstructor(INSTRUCTION_CONSTRUCTOR_PARAMS); String instructionKey = instructionKey(instructionName, targetNamespace); this.instructions.put(instructionKey, constructor); } catch (Exception e) { if (e instanceof ConfigurationException) throw (ConfigurationException) e; else throw new ConfigurationException("unable to register instruction", e); } }
/** * Handle {@link Call}-annotated methods. * @param pjp The wrapped method * @return The result of the service call as configured by {@link Call}. * @throws Throwable No exception/error is handled in aspect. */ @Around("@annotation(org.talend.daikon.annotation.Call)") public Object call(ProceedingJoinPoint pjp) throws Throwable { MethodSignature ms = (MethodSignature) pjp.getSignature(); Method m = ms.getMethod(); final Call callAnnotation = AnnotationUtils.getAnnotation(m, Call.class); if (callAnnotation != null) { final Object[] args = pjp.getArgs(); if (!callAnnotation.using().equals(DefaultHystrixCommand.class)) { if (!ClassUtils.isAssignable(callAnnotation.service(), DefaultService.class) || StringUtils.isEmpty(callAnnotation.operation())) { LOGGER.warn("Method '{}' use custom invocation but also sets service and operation name", m.getName()); } return handleCustomExecution(callAnnotation, args); } else { return handleServiceForward(callAnnotation, args); } } return pjp.proceed(); }