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

x33g5p2x  于2022-01-16 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(200)

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

Method.isSynthetic介绍

[英]Returns true if this method is a synthetic method; returns false otherwise.
[中]如果此方法是合成方法,则返回true;否则返回false。

代码示例

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

/**
 * {@inheritDoc}
 */
public boolean isSynthetic() {
  return method.isSynthetic();
}

代码示例来源:origin: google/guava

private static boolean isEqualsDefined(Class<?> cls) {
 try {
  return !cls.getDeclaredMethod("equals", Object.class).isSynthetic();
 } catch (NoSuchMethodException e) {
  return false;
 }
}

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

@Override
public boolean matches(final Method method) {
  return method.isSynthetic();
}

代码示例来源:origin: spring-projects/spring-loaded

public boolean callMethodIsSynthetic(Method m) {
  return m.isSynthetic();
}

代码示例来源:origin: junit-team/junit4

private static boolean isMatchesSafelyMethod(Method method) {
  return "matchesSafely".equals(method.getName())
      && method.getParameterTypes().length == 1
      && !method.isSynthetic();
}

代码示例来源:origin: prestodb/presto

private boolean _isIncludableMemberMethod(Method m)
{
  if (Modifier.isStatic(m.getModifiers())
      // Looks like generics can introduce hidden bridge and/or synthetic methods.
      // I don't think we want to consider those...
      || m.isSynthetic() || m.isBridge()) {
    return false;
  }
  // also, for now we have no use for methods with more than 2 arguments:
  // (2 argument methods for "any setter", fwtw)
  int pcount = m.getParameterTypes().length;
  return (pcount <= 2);
}

代码示例来源:origin: google/j2objc

/**
 * @param method The method to examine.
 * @return true if this method references the relevant type
 */
protected boolean canObtainExpectedTypeFrom(Method method) {
  return method.getName().equals(methodName)
      && method.getParameterTypes().length == expectedNumberOfParameters
      && !method.isSynthetic();
}

代码示例来源:origin: google/j2objc

private static boolean isMatchesSafelyMethod(Method method) {
  return method.getName().equals("matchesSafely")
      && method.getParameterTypes().length == 1
      && !method.isSynthetic();
}

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

private boolean _isIncludableMemberMethod(Method m)
{
  if (Modifier.isStatic(m.getModifiers())
      // Looks like generics can introduce hidden bridge and/or synthetic methods.
      // I don't think we want to consider those...
      || m.isSynthetic() || m.isBridge()) {
    return false;
  }
  // also, for now we have no use for methods with more than 2 arguments:
  // (2 argument methods for "any setter", fwtw)
  int pcount = m.getParameterTypes().length;
  return (pcount <= 2);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Determine whether the given method is declared by the user or at least pointing to
 * a user-declared method.
 * <p>Checks {@link Method#isSynthetic()} (for implementation methods) as well as the
 * {@code GroovyObject} interface (for interface methods; on an implementation class,
 * implementations of the {@code GroovyObject} methods will be marked as synthetic anyway).
 * Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
 * as user-level methods since they are eventually pointing to a user-declared generic method.
 * @param method the method to check
 * @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
 */
public static boolean isUserLevelMethod(Method method) {
  Assert.notNull(method, "Method must not be null");
  return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method)));
}

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
 * @param method The method to examine.
 * @return true if this method references the relevant type
 */
protected boolean canObtainExpectedTypeFrom(Method method) {
  return method.getName().equals(methodName)
      && method.getParameterTypes().length == expectedNumberOfParameters
      && !method.isSynthetic();
}

代码示例来源:origin: Atmosphere/atmosphere

public final static Set<Method> getInheritedPrivateMethod(Class<?> type) {
  Set<Method> result = new HashSet<>();
  Class<?> i = type;
  while (i != null && i != Object.class) {
    for (Method m : i.getDeclaredMethods()) {
      if (!m.isSynthetic()) {
        result.add(m);
      }
    }
    i = i.getSuperclass();
  }
  return result;
}

代码示例来源:origin: hamcrest/JavaHamcrest

/**
 * @param method The method to examine.
 * @return true if this method references the relevant type
 */
private boolean canObtainExpectedTypeFrom(Method method) {
  return method.getName().equals(methodName)
      && method.getParameterTypes().length == expectedNumberOfParameters
      && !method.isSynthetic();
}

代码示例来源:origin: google/guava

private static ImmutableList<Method> getAnnotatedMethodsNotCached(Class<?> clazz) {
 Set<? extends Class<?>> supertypes = TypeToken.of(clazz).getTypes().rawTypes();
 Map<MethodIdentifier, Method> identifiers = Maps.newHashMap();
 for (Class<?> supertype : supertypes) {
  for (Method method : supertype.getDeclaredMethods()) {
   if (method.isAnnotationPresent(Subscribe.class) && !method.isSynthetic()) {
    // TODO(cgdecker): Should check for a generic parameter type and error out
    Class<?>[] parameterTypes = method.getParameterTypes();
    checkArgument(
      parameterTypes.length == 1,
      "Method %s has @Subscribe annotation but has %s parameters."
        + "Subscriber methods must have exactly 1 parameter.",
      method,
      parameterTypes.length);
    MethodIdentifier ident = new MethodIdentifier(method);
    if (!identifiers.containsKey(ident)) {
     identifiers.put(ident, method);
    }
   }
  }
 }
 return ImmutableList.copyOf(identifiers.values());
}

代码示例来源:origin: cucumber/cucumber-jvm

private Method getAcceptMethod(Class<? extends StepdefBody> bodyClass) {
  List<Method> acceptMethods = new ArrayList<>();
  for (Method method : bodyClass.getDeclaredMethods()) {
    if (!method.isBridge() && !method.isSynthetic() && "accept".equals(method.getName())) {
      acceptMethods.add(method);
    }
  }
  if (acceptMethods.size() != 1) {
    throw new IllegalStateException(format(
      "Expected single 'accept' method on body class, found '%s'", acceptMethods));
  }
  return acceptMethods.get(0);
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Determine whether the given method is declared by the user or at least pointing to
 * a user-declared method.
 * <p>Checks {@link Method#isSynthetic()} (for implementation methods) as well as the
 * {@code GroovyObject} interface (for interface methods; on an implementation class,
 * implementations of the {@code GroovyObject} methods will be marked as synthetic anyway).
 * Note that, despite being synthetic, bridge methods ({@link Method#isBridge()}) are considered
 * as user-level methods since they are eventually pointing to a user-declared generic method.
 * @param method the method to check
 * @return {@code true} if the method can be considered as user-declared; [@code false} otherwise
 */
public static boolean isUserLevelMethod(Method method) {
  Assert.notNull(method, "Method must not be null");
  return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method)));
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

protected boolean _isIncludableMethod(Method m, MethodFilter filter)
{
  if (filter != null && !filter.includeMethod(m)) {
    return false;
  }
  /* 07-Apr-2009, tatu: Looks like generics can introduce hidden
   *   bridge and/or synthetic methods. I don't think we want to
   *   consider those...
   */
  if (m.isSynthetic() || m.isBridge()) {
    return false;
  }
  return true;
}

代码示例来源:origin: google/guava

private ImmutableList<Method> getVisibleMethods(Class<?> cls) {
  // Don't use cls.getPackage() because it does nasty things like reading
  // a file.
  String visiblePackage = Reflection.getPackageName(cls);
  ImmutableList.Builder<Method> builder = ImmutableList.builder();
  for (Class<?> type : TypeToken.of(cls).getTypes().rawTypes()) {
   if (!Reflection.getPackageName(type).equals(visiblePackage)) {
    break;
   }
   for (Method method : type.getDeclaredMethods()) {
    if (!method.isSynthetic() && isVisible(method)) {
     builder.add(method);
    }
   }
  }
  return builder.build();
 }
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns whether the method given is a getter method we should serialize /
 * deserialize to the service. The method must begin with "get" or "is",
 * have no arguments, belong to a class that declares its table, and not be
 * marked ignored.
 */
private static boolean isRelevantGetter(Method m) {
  return (m.getName().startsWith("get") || m.getName().startsWith("is"))
      && m.getParameterTypes().length == 0
      && ! (m.isBridge() || m.isSynthetic())
      && isDocumentType(m.getDeclaringClass())
      && !ReflectionUtils.getterOrFieldHasAnnotation(m, DynamoDBIgnore.class);
}

代码示例来源:origin: prestodb/presto

private static ImmutableList<Method> getAnnotatedMethodsNotCached(Class<?> clazz) {
 Set<? extends Class<?>> supertypes = TypeToken.of(clazz).getTypes().rawTypes();
 Map<MethodIdentifier, Method> identifiers = Maps.newHashMap();
 for (Class<?> supertype : supertypes) {
  for (Method method : supertype.getDeclaredMethods()) {
   if (method.isAnnotationPresent(Subscribe.class) && !method.isSynthetic()) {
    // TODO(cgdecker): Should check for a generic parameter type and error out
    Class<?>[] parameterTypes = method.getParameterTypes();
    checkArgument(
      parameterTypes.length == 1,
      "Method %s has @Subscribe annotation but has %s parameters."
        + "Subscriber methods must have exactly 1 parameter.",
      method,
      parameterTypes.length);
    MethodIdentifier ident = new MethodIdentifier(method);
    if (!identifiers.containsKey(ident)) {
     identifiers.put(ident, method);
    }
   }
  }
 }
 return ImmutableList.copyOf(identifiers.values());
}

相关文章

微信公众号

最新文章

更多