congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
KFunction
Code IndexAdd Tabnine to your IDE (free)

How to use
KFunction
in
kotlin.reflect

Best Java code snippets using kotlin.reflect.KFunction (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
  if (ctor.getDeclaringClass().isEnum() || !KotlinDetector.isKotlinType(ctor.getDeclaringClass())) {
    return null;
  }
  try {
    KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
    return (function != null ? getParameterNames(function.getParameters()) : null);
  }
  catch (UnsupportedOperationException ex) {
    return null;
  }
}
origin: spring-projects/spring-framework

if (method != null && index == -1) {
  KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
  return (function != null && function.getReturnType().isMarkedNullable());
    List<KParameter> parameters = function.getParameters();
    KParameter parameter = parameters
        .stream()
origin: spring-projects/spring-framework

/**
 * Instantiate a Kotlin class using the provided constructor.
 * @param ctor the constructor of the Kotlin class to instantiate
 * @param args the constructor arguments to apply
 * (use {@code null} for unspecified parameter if needed)
 */
public static <T> T instantiateClass(Constructor<T> ctor, Object... args)
    throws IllegalAccessException, InvocationTargetException, InstantiationException {
  KFunction<T> kotlinConstructor = ReflectJvmMapping.getKotlinFunction(ctor);
  if (kotlinConstructor == null) {
    return ctor.newInstance(args);
  }
  List<KParameter> parameters = kotlinConstructor.getParameters();
  Map<KParameter, Object> argParameters = new HashMap<>(parameters.size());
  Assert.isTrue(args.length <= parameters.size(),
      "Number of provided arguments should be less of equals than number of constructor parameters");
  for (int i = 0 ; i < args.length ; i++) {
    if (!(parameters.get(i).isOptional() && args[i] == null)) {
      argParameters.put(parameters.get(i), args[i]);
    }
  }
  return kotlinConstructor.callBy(argParameters);
}
origin: org.openksavi.sponge/sponge-kotlin

  /**
   * Checks rule event condition by evaluating the defined knowledge base rule method.
   *
   * @param rule rule.
   * @param event event.
   * @return {@code true} if this condition is met.
   */
  @Override
  public boolean condition(Rule rule, Event event) {
    return function.call(rule, event);
  }
}
origin: org.openksavi.sponge/sponge-kotlin

public static String createEventConditionMethodName(KFunction<Boolean> kotlinObject) {
  return kotlinObject.getName();
}
origin: spring-projects/spring-framework

@Override
@Nullable
public String[] getParameterNames(Method method) {
  if (!KotlinDetector.isKotlinType(method.getDeclaringClass())) {
    return null;
  }
  try {
    KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
    return (function != null ? getParameterNames(function.getParameters()) : null);
  }
  catch (UnsupportedOperationException ex) {
    return null;
  }
}
origin: org.springframework/spring-core

if (method != null && index == -1) {
  KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
  return (function != null && function.getReturnType().isMarkedNullable());
    List<KParameter> parameters = function.getParameters();
    KParameter parameter = parameters
        .stream()
origin: org.springframework/spring-beans

/**
 * Instantiate a Kotlin class using the provided constructor.
 * @param ctor the constructor of the Kotlin class to instantiate
 * @param args the constructor arguments to apply
 * (use {@code null} for unspecified parameter if needed)
 */
public static <T> T instantiateClass(Constructor<T> ctor, Object... args)
    throws IllegalAccessException, InvocationTargetException, InstantiationException {
  KFunction<T> kotlinConstructor = ReflectJvmMapping.getKotlinFunction(ctor);
  if (kotlinConstructor == null) {
    return ctor.newInstance(args);
  }
  List<KParameter> parameters = kotlinConstructor.getParameters();
  Map<KParameter, Object> argParameters = new HashMap<>(parameters.size());
  Assert.isTrue(args.length <= parameters.size(),
      "Number of provided arguments should be less of equals than number of constructor parameters");
  for (int i = 0 ; i < args.length ; i++) {
    if (!(parameters.get(i).isOptional() && args[i] == null)) {
      argParameters.put(parameters.get(i), args[i]);
    }
  }
  return kotlinConstructor.callBy(argParameters);
}
origin: org.springframework/spring-core

@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
  if (ctor.getDeclaringClass().isEnum() || !KotlinDetector.isKotlinType(ctor.getDeclaringClass())) {
    return null;
  }
  try {
    KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
    return (function != null ? getParameterNames(function.getParameters()) : null);
  }
  catch (UnsupportedOperationException ex) {
    return null;
  }
}
origin: apache/servicemix-bundles

/**
 * Returns {@literal} whether the given {@link MethodParameter} is nullable. Its declaring method can reference a
 * Kotlin function, property or interface property.
 *
 * @return {@literal true} if {@link MethodParameter} is nullable.
 * @since 2.0.1
 */
static boolean isNullable(MethodParameter parameter) {
  Method method = parameter.getMethod();
  if (method == null) {
    throw new IllegalStateException(String.format("Cannot obtain method from parameter %s!", parameter));
  }
  KFunction<?> kotlinFunction = ReflectJvmMapping.getKotlinFunction(method);
  if (kotlinFunction == null) {
    // Fallback to own lookup because there's no public Kotlin API for that kind of lookup until
    // https://youtrack.jetbrains.com/issue/KT-20768 gets resolved.
    kotlinFunction = findKFunction(method)//
        .orElseThrow(() -> new IllegalArgumentException(
            String.format("Cannot resolve %s to a Kotlin function!", parameter)));
  }
  KType type = parameter.getParameterIndex() == -1 //
      ? kotlinFunction.getReturnType() //
      : kotlinFunction.getParameters().get(parameter.getParameterIndex() + 1).getType();
  return type.isMarkedNullable();
}
origin: org.springframework/spring-core

@Override
@Nullable
public String[] getParameterNames(Method method) {
  if (!KotlinDetector.isKotlinType(method.getDeclaringClass())) {
    return null;
  }
  try {
    KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
    return (function != null ? getParameterNames(function.getParameters()) : null);
  }
  catch (UnsupportedOperationException ex) {
    return null;
  }
}
origin: com.github.XDean/spring-annotation

/**
 * Check whether the specified {@link MethodParameter} represents a nullable Kotlin type or an
 * optional parameter (with a default value in the Kotlin declaration).
 */
public static boolean isOptional(MethodParameter param) {
 Method method = param.getMethod();
 Constructor<?> ctor = param.getConstructor();
 int index = param.getParameterIndex();
 if (method != null && index == -1) {
  KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
  return (function != null && function.getReturnType().isMarkedNullable());
 } else {
  KFunction<?> function = null;
  if (method != null) {
   function = ReflectJvmMapping.getKotlinFunction(method);
  } else if (ctor != null) {
   function = ReflectJvmMapping.getKotlinFunction(ctor);
  }
  if (function != null) {
   List<KParameter> parameters = function.getParameters();
   KParameter parameter = parameters
     .stream()
     .filter(p -> KParameter.Kind.VALUE.equals(p.getKind()))
     .collect(Collectors.toList())
     .get(index);
   return (parameter.getType().isMarkedNullable() || parameter.isOptional());
  }
 }
 return false;
}
origin: apache/servicemix-bundles

/**
 * @param publicCopyMethod Compiler-generated public {@code copy} method accepting all properties.
 * @param syntheticCopyMethod Compiler-generated synthetic {@code copy$default} variant of the copy method accepting
 *          the original instance and defaulting masks.
 */
private KotlinCopyMethod(Method publicCopyMethod, Method syntheticCopyMethod) {
  this.publicCopyMethod = publicCopyMethod;
  this.syntheticCopyMethod = syntheticCopyMethod;
  this.copyFunction = ReflectJvmMapping.getKotlinFunction(publicCopyMethod);
  this.parameterCount = copyFunction.getParameters().size();
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

if (method != null && index == -1) {
  KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
  return (function != null && function.getReturnType().isMarkedNullable());
    List<KParameter> parameters = function.getParameters();
    KParameter parameter = parameters
        .stream()
origin: apache/servicemix-bundles

  static int findIndex(KFunction<?> function, String parameterName) {
    for (KParameter parameter : function.getParameters()) {
      if (parameterName.equals(parameter.getName())) {
        return parameter.getIndex();
      }
    }
    return -1;
  }
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
  if (ctor.getDeclaringClass().isEnum() || !KotlinDetector.isKotlinType(ctor.getDeclaringClass())) {
    return null;
  }
  try {
    KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
    return (function != null ? getParameterNames(function.getParameters()) : null);
  }
  catch (UnsupportedOperationException ex) {
    return null;
  }
}
origin: apache/servicemix-bundles

@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
  if (ctor.getDeclaringClass().isEnum() || !KotlinDetector.isKotlinType(ctor.getDeclaringClass())) {
    return null;
  }
  try {
    KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
    return (function != null ? getParameterNames(function.getParameters()) : null);
  }
  catch (UnsupportedOperationException ex) {
    return null;
  }
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

@Override
@Nullable
public String[] getParameterNames(Method method) {
  if (!KotlinDetector.isKotlinType(method.getDeclaringClass())) {
    return null;
  }
  try {
    KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
    return (function != null ? getParameterNames(function.getParameters()) : null);
  }
  catch (UnsupportedOperationException ex) {
    return null;
  }
}
origin: apache/servicemix-bundles

@SuppressWarnings("unchecked")
private static Optional<Method> findPublicCopyMethod(Method defaultKotlinMethod) {
  Class<?> type = defaultKotlinMethod.getDeclaringClass();
  KClass<?> kotlinClass = JvmClassMappingKt.getKotlinClass(type);
  KFunction<?> primaryConstructor = KClasses.getPrimaryConstructor(kotlinClass);
  if (primaryConstructor == null) {
    return Optional.empty();
  }
  List<KParameter> constructorArguments = primaryConstructor.getParameters() //
      .stream() //
      .filter(it -> it.getKind() == Kind.VALUE) //
      .collect(Collectors.toList());
  return Arrays.stream(type.getDeclaredMethods()).filter(it -> it.getName().equals("copy") //
      && !it.isSynthetic() //
      && !Modifier.isStatic(it.getModifiers()) //
      && it.getReturnType().equals(type) //
      && it.getParameterCount() == constructorArguments.size()) //
      .filter(it -> {
        KFunction<?> kotlinFunction = ReflectJvmMapping.getKotlinFunction(it);
        if (kotlinFunction == null) {
          return false;
        }
        return parameterMatches(constructorArguments, kotlinFunction);
      }).findFirst();
}
origin: apache/servicemix-bundles

@Override
@Nullable
public String[] getParameterNames(Method method) {
  if (!KotlinDetector.isKotlinType(method.getDeclaringClass())) {
    return null;
  }
  try {
    KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
    return (function != null ? getParameterNames(function.getParameters()) : null);
  }
  catch (UnsupportedOperationException ex) {
    return null;
  }
}
kotlin.reflectKFunction

Most used methods

  • getParameters
  • getReturnType
  • callBy
  • call
  • getName
  • isExternal
  • isInfix
  • isInline
  • isOperator
  • isSuspend

Popular in Java

  • Start an intent from android
  • getResourceAsStream (ClassLoader)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getSystemService (Context)
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now