java.lang.reflect.Executable.getModifiers()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中java.lang.reflect.Executable.getModifiers()方法的一些代码示例,展示了Executable.getModifiers()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Executable.getModifiers()方法的具体详情如下:
包路径:java.lang.reflect.Executable
类名称:Executable
方法名:getModifiers

Executable.getModifiers介绍

暂无

代码示例

代码示例来源:origin: AxonFramework/AxonFramework

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;
}

代码示例来源:origin: org.seedstack.shed/shed

/**
 * 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;
}

代码示例来源:origin: com.github.markusmo3.urm/urm-core

public boolean isStatic() {
  return Modifier.isStatic(executable.getModifiers());
}

代码示例来源:origin: com.github.markusmo3.urm/urm-core

public boolean isAbstract() {
  return Modifier.isAbstract(executable.getModifiers());
}

代码示例来源:origin: com.github.zerkseez/generic-reflection

@Override
protected int doGetModifiers() {
  return getExecutable().getModifiers();
}

代码示例来源:origin: com.github.markusmo3.urm/urm-core

public Visibility getVisibility() {
  return TypeUtils.getVisibility(executable.getModifiers());
}

代码示例来源:origin: org.graalvm.truffle/truffle-api

static boolean isAccessible(Executable method) {
  return Modifier.isPublic(method.getModifiers()) && Modifier.isPublic(method.getDeclaringClass().getModifiers());
}

代码示例来源:origin: com.oracle.truffle/truffle-api

static boolean isAccessible(Executable method) {
  return Modifier.isPublic(method.getModifiers()) && Modifier.isPublic(method.getDeclaringClass().getModifiers());
}

代码示例来源:origin: io.airlift/parameternames

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);
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

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;
}

代码示例来源:origin: org.axonframework/axon-core

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;
}

代码示例来源:origin: org.axonframework/axon-messaging

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;
}

代码示例来源:origin: com.oracle.substratevm/library-support

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);
}

代码示例来源:origin: com.oracle.substratevm/svm

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);
  }
}

代码示例来源:origin: com.oracle.substratevm/library-support

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;
  });
}

代码示例来源:origin: kasonyang/kalang

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);

代码示例来源:origin: com.oracle.substratevm/library-support

@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;
}

相关文章