All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sundr.adapter.reflect.ReflectionAdapter Maven / Gradle / Ivy

/**
 * Copyright 2015 The original authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
**/

package io.sundr.adapter.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;

import io.sundr.adapter.api.Adapter;
import io.sundr.adapter.api.AdapterContext;
import io.sundr.model.Property;
import io.sundr.model.TypeDef;
import io.sundr.model.TypeRef;

public class ReflectionAdapter implements Adapter {

  private final AdapterContext context;
  private final Function typeAdapterFunction;
  private final Function referenceAdapterFunction;
  private final Function propertyAdapterFunction;
  private final Function methodAdapterFunction;
  private final Set references = new HashSet<>();

  @Override
  public Function getTypeAdapterFunction() {
    return typeAdapterFunction;
  }

  public ReflectionAdapter(AdapterContext context) {
    this.context = context;
    this.referenceAdapterFunction = new TypeToTypeRef(references);
    this.typeAdapterFunction = new ClassToTypeDef(context, references, referenceAdapterFunction,
        new TypeToTypeParamDef(referenceAdapterFunction),
        new AnnotationClassToAnnotationRef(referenceAdapterFunction),
        new ClassToKind());
    this.propertyAdapterFunction = null;
    this.methodAdapterFunction = null;
  }

  public Function getReferenceAdapterFunction() {
    return referenceAdapterFunction;
  }

  public Function getPropertyAdapterFunction() {
    return propertyAdapterFunction;
  }

  public Function getMethodAdapterFunction() {
    return methodAdapterFunction;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy