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

io.sundr.adapter.apt.AptAdapter Maven / Gradle / Ivy

There is a newer version: 0.200.0
Show newest version
/*
 * Copyright 2016 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.apt;

import java.util.function.Function;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;

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

public class AptAdapter implements Adapter {

  private final AptContext context;
  private final Function typeAdapterFunction;
  private final Function referenceAdapterFunction;
  private final Function propertyAdapterFunction;
  private final Function methodAdapterFunction;

  private final Function annotationAdapterFunction;
  private final Function typeParamAdapterFunction;

  public AptAdapter(AdapterContext context) {
    this.context = AptContext.create(context);
    this.referenceAdapterFunction = new TypeMirrorToTypeRef(this.context);
    this.annotationAdapterFunction = new AnnotationMirrorToAnnotationRef(this.context, referenceAdapterFunction);
    this.typeParamAdapterFunction = new TypePrameterElementToTypeParamDef(this.context, referenceAdapterFunction);
    this.propertyAdapterFunction = new VariableElementToProperty(this.context, referenceAdapterFunction,
        annotationAdapterFunction);
    this.methodAdapterFunction = new ExecutableElementToMethod(this.context, referenceAdapterFunction, propertyAdapterFunction,
        annotationAdapterFunction);
    this.typeAdapterFunction = new TypeElementToTypeDef(this.context, referenceAdapterFunction, propertyAdapterFunction,
        methodAdapterFunction, annotationAdapterFunction, typeParamAdapterFunction);
  }

  public Function getTypeAdapterFunction() {
    return typeAdapterFunction;
  }

  public Function getReferenceAdapterFunction() {
    return referenceAdapterFunction;
  }

  public Function getPropertyAdapterFunction() {
    return propertyAdapterFunction;
  }

  public Function getMethodAdapterFunction() {
    return methodAdapterFunction;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy