private MethodCommandMessageHandlingMember(MessageHandlingMember<T> delegate, Map<String, Object> annotationAttributes) { super(delegate); this.routingKey = "".equals(annotationAttributes.get("routingKey")) ? null : (String) annotationAttributes.get("routingKey"); Executable executable = delegate.unwrap(Executable.class).orElseThrow(() -> new AxonConfigurationException( "The @CommandHandler annotation must be put on an Executable (either directly or as Meta " + "Annotation)")); if ("".equals(annotationAttributes.get("commandName"))) { commandName = delegate.payloadType().getName(); } else { commandName = (String) annotationAttributes.get("commandName"); } final boolean factoryMethod = executable instanceof Method && Modifier.isStatic(executable.getModifiers()); if (factoryMethod && !executable.getDeclaringClass().isAssignableFrom(((Method)executable).getReturnType())) { throw new AxonConfigurationException("static @CommandHandler methods must declare a return value " + "which is equal to or a subclass of the declaring time"); } isFactoryHandler = executable instanceof Constructor || factoryMethod; }
/** * Checks if a candidate class has the specified modifier. * * @param modifier the modifier to check for. * @return the predicate. */ public static <T extends Executable> Predicate<T> executableModifierIs(final int modifier) { return candidate -> (candidate.getModifiers() & modifier) != 0; }
public boolean isStatic() { return Modifier.isStatic(executable.getModifiers()); }
public boolean isAbstract() { return Modifier.isAbstract(executable.getModifiers()); }
@Override protected int doGetModifiers() { return getExecutable().getModifiers(); }
public Visibility getVisibility() { return TypeUtils.getVisibility(executable.getModifiers()); }
static boolean isAccessible(Executable method) { return Modifier.isPublic(method.getModifiers()) && Modifier.isPublic(method.getDeclaringClass().getModifiers()); }
static boolean isAccessible(Executable method) { return Modifier.isPublic(method.getModifiers()) && Modifier.isPublic(method.getDeclaringClass().getModifiers()); }
ParameterNameClassVisitor(Executable executable) { super(Opcodes.ASM5); methodName = executable instanceof Constructor ? "<init>" : executable.getName(); parameterTypes = Arrays.stream(executable.getParameterTypes()) .map(Type::getType) .collect(toList()); this.methodVisitor = new ParameterNameMethodVisitor(isStatic(executable.getModifiers()), parameterTypes); }
private Set<ConstrainedExecutable> getMetaData(Executable[] executableElements) { Set<ConstrainedExecutable> executableMetaData = newHashSet(); for ( Executable executable : executableElements ) { // HV-172; ignoring synthetic methods (inserted by the compiler), as they can't have any constraints // anyway and possibly hide the actual method with the same signature in the built meta model if ( Modifier.isStatic( executable.getModifiers() ) || executable.isSynthetic() ) { continue; } executableMetaData.add( findExecutableMetaData( executable ) ); } return executableMetaData; }
private MethodCommandMessageHandlingMember(MessageHandlingMember<T> delegate, Map<String, Object> annotationAttributes) { super(delegate); this.routingKey = "".equals(annotationAttributes.get("routingKey")) ? null : (String) annotationAttributes.get("routingKey"); Executable executable = delegate.unwrap(Executable.class).orElseThrow(() -> new AxonConfigurationException( "The @CommandHandler annotation must be put on an Executable (either directly or as Meta " + "Annotation)")); if ("".equals(annotationAttributes.get("commandName"))) { commandName = delegate.payloadType().getName(); } else { commandName = (String) annotationAttributes.get("commandName"); } final boolean factoryMethod = executable instanceof Method && Modifier.isStatic(executable.getModifiers()); if (factoryMethod && !executable.getDeclaringClass().isAssignableFrom(((Method)executable).getReturnType())) { throw new AxonConfigurationException("static @CommandHandler methods must declare a return value " + "which is equal to or a subclass of the declaring time"); } isFactoryHandler = executable instanceof Constructor || factoryMethod; }
private MethodCommandMessageHandlingMember(MessageHandlingMember<T> delegate, Map<String, Object> annotationAttributes) { super(delegate); this.routingKey = "".equals(annotationAttributes.get("routingKey")) ? null : (String) annotationAttributes.get("routingKey"); Executable executable = delegate.unwrap(Executable.class).orElseThrow(() -> new AxonConfigurationException( "The @CommandHandler annotation must be put on an Executable (either directly or as Meta " + "Annotation)")); if ("".equals(annotationAttributes.get("commandName"))) { commandName = delegate.payloadType().getName(); } else { commandName = (String) annotationAttributes.get("commandName"); } final boolean factoryMethod = executable instanceof Method && Modifier.isStatic(executable.getModifiers()); if (factoryMethod && !executable.getDeclaringClass().isAssignableFrom(((Method)executable).getReturnType())) { throw new AxonConfigurationException("static @CommandHandler methods must declare a return value " + "which is equal to or a subclass of the declaring time"); } isFactoryHandler = executable instanceof Constructor || factoryMethod; }
public JNIJavaCallWrapperMethod(Executable reflectMethod, CallVariant callVariant, boolean nonVirtual, MetaAccessProvider metaAccess, NativeLibraries nativeLibs) { assert !nonVirtual || !Modifier.isStatic(reflectMethod.getModifiers()); this.declaringClass = metaAccess.lookupJavaType(JNIJavaCallWrappers.class); this.constantPool = JNIJavaCallWrappers.getConstantPool(metaAccess); this.reflectMethod = reflectMethod; this.nativeLibs = nativeLibs; this.callVariant = callVariant; this.nonVirtual = nonVirtual; this.targetMethod = metaAccess.lookupJavaMethod(reflectMethod); this.signature = createSignature(metaAccess); }
private ResolvedJavaMethod findOriginalMethod(Executable annotatedMethod, Class<?> originalClass) { TargetElement targetElementAnnotation = lookupAnnotation(annotatedMethod, TargetElement.class); String originalName = ""; if (targetElementAnnotation != null) { originalName = targetElementAnnotation.name(); if (!isIncluded(targetElementAnnotation, originalClass, annotatedMethod)) { return null; } } if (originalName.length() == 0) { originalName = annotatedMethod.getName(); } try { if (annotatedMethod instanceof Method && !originalName.equals(TargetElement.CONSTRUCTOR_NAME)) { Class<?>[] originalParams = interceptParameterTypes(annotatedMethod.getParameterTypes()); Method originalMethod = originalClass.getDeclaredMethod(originalName, originalParams); guarantee(Modifier.isStatic(annotatedMethod.getModifiers()) == Modifier.isStatic(originalMethod.getModifiers()), "Static modifier mismatch: %s, %s", annotatedMethod, originalMethod); return metaAccess.lookupJavaMethod(originalMethod); } else { guarantee(!Modifier.isStatic(annotatedMethod.getModifiers()), "Constructor Alias method %s must not be static", annotatedMethod); Class<?>[] originalParams = interceptParameterTypes(annotatedMethod.getParameterTypes()); Constructor<?> originalMethod = originalClass.getDeclaredConstructor(originalParams); return metaAccess.lookupJavaMethod(originalMethod); } } catch (NoSuchMethodException ex) { throw UserError.abort("could not find target method: " + annotatedMethod); } }
private void addMethod(Executable method, DuringAnalysisAccessImpl access) { JNIAccessibleClass jniClass = addClass(method.getDeclaringClass(), access); JNIAccessibleMethodDescriptor descriptor = JNIAccessibleMethodDescriptor.of(method); jniClass.addMethodIfAbsent(descriptor, d -> { MetaAccessProvider wrappedMetaAccess = access.getMetaAccess().getWrapped(); JNIJavaCallWrapperMethod varargsCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VARARGS, false, wrappedMetaAccess, nativeLibraries); JNIJavaCallWrapperMethod arrayCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.ARRAY, false, wrappedMetaAccess, nativeLibraries); JNIJavaCallWrapperMethod valistCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VA_LIST, false, wrappedMetaAccess, nativeLibraries); Stream<JNIJavaCallWrapperMethod> wrappers = Stream.of(varargsCallWrapper, arrayCallWrapper, valistCallWrapper); JNIJavaCallWrapperMethod varargsNonvirtualCallWrapper = null; JNIJavaCallWrapperMethod arrayNonvirtualCallWrapper = null; JNIJavaCallWrapperMethod valistNonvirtualCallWrapper = null; if (!Modifier.isStatic(method.getModifiers()) && !Modifier.isAbstract(method.getModifiers())) { varargsNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VARARGS, true, wrappedMetaAccess, nativeLibraries); arrayNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.ARRAY, true, wrappedMetaAccess, nativeLibraries); valistNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VA_LIST, true, wrappedMetaAccess, nativeLibraries); wrappers = Stream.concat(wrappers, Stream.of(varargsNonvirtualCallWrapper, arrayNonvirtualCallWrapper, valistNonvirtualCallWrapper)); } JNIAccessibleMethod jniMethod = new JNIAccessibleMethod(method.getModifiers(), jniClass, varargsCallWrapper, arrayCallWrapper, valistCallWrapper, varargsNonvirtualCallWrapper, arrayNonvirtualCallWrapper, valistNonvirtualCallWrapper); wrappers.forEach(wrapper -> { AnalysisMethod analysisWrapper = access.getUniverse().lookup(wrapper); access.getBigBang().addRootMethod(analysisWrapper); analysisWrapper.registerAsEntryPoint(jniMethod); // ensures C calling convention }); return jniMethod; }); }
mType = getType(((Method) m).getGenericReturnType(), gTypeMap , ((Method) m).getReturnType(), nullable); mName = m.getName(); mModifier = m.getModifiers(); } else if (m instanceof Constructor) { mName = "<init>"; mModifier = m.getModifiers();// | Modifier.STATIC; } else { throw Exceptions.unexceptedValue(m);
@CEntryPoint(exceptionHandler = JNIExceptionHandlerReturnNullWord.class) @CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class) static JNIMethodId FromReflectedMethod(JNIEnvironment env, JNIObjectHandle methodHandle) { JNIMethodId methodId = WordFactory.nullPointer(); if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) { Executable method = JNIObjectHandles.getObject(methodHandle); if (method != null) { boolean isStatic = Modifier.isStatic(method.getModifiers()); JNIAccessibleMethodDescriptor descriptor = JNIAccessibleMethodDescriptor.of(method); methodId = JNIReflectionDictionary.singleton().getMethodID(method.getDeclaringClass(), descriptor, isStatic); } } return methodId; }