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

br.com.objectos.auto.Unsupported Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015 Objectos, Fábrica de Software LTDA.
 *
 * 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 br.com.objectos.auto;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import br.com.objectos.code.AccessInfo;
import br.com.objectos.code.AutoMethodInfo;
import br.com.objectos.code.ConstructorInfo;
import br.com.objectos.code.MethodInfo;
import br.com.objectos.code.ModifierInfo;
import br.com.objectos.code.TypeInfo;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;

/**
 * @author [email protected] (Patricia Nascimento)
 */
abstract class Unsupported {

  final ClassName className;
  final List constructorInfoList;
  final List methodInfoList;
  final TypeName superTypeName;
  final TypeInfo typeInfo;

  public Unsupported(ClassName className,
                     List constructorInfoList,
                     List methodInfoList,
                     TypeName superTypeName,
                     TypeInfo typeInfo) {
    this.className = className;
    this.constructorInfoList = constructorInfoList;
    this.methodInfoList = methodInfoList;
    this.superTypeName = superTypeName;
    this.typeInfo = typeInfo;
  }

  public static Unsupported code(TypeInfo typeInfo) {
    String suffix = "Unsupported";
    ClassName className = typeInfo.classNameSuffix(suffix);

    List constructorInfoList = typeInfo.constructorInfoStream()
        .filter(c -> !c.hasAccessInfo(AccessInfo.PRIVATE))
        .collect(Collectors.toList());

    Stream typeStream = typeInfo.methodInfoStream();
    Stream objectStream = AutoMethodInfo.objectMethodStream();
    List methodInfoList = Stream.concat(typeStream, objectStream)
        .filter(MethodInfo.distinctSignature())
        .filter(m -> !m.hasAccessInfo(AccessInfo.PRIVATE))
        .filter(m -> !m.hasModifierInfo(ModifierInfo.FINAL))
        .filter(m -> !m.hasModifierInfo(ModifierInfo.STATIC))
        .collect(Collectors.toList());

    TypeName superTypeName = typeInfo.typeName();
    return typeInfo.isClass()
        ? new UnsupportedClass(className, constructorInfoList, methodInfoList, superTypeName, typeInfo)
        : new UnsupportedInterface(className, constructorInfoList, methodInfoList, superTypeName, typeInfo);
  }

  public JavaFile get() {
    UnsupportedType type = type();
    TypeSpec typeSpec = type.get();
    return typeInfo.toJavaFile(typeSpec);
  }

  UnsupportedConstructor constructor() {
    return new UnsupportedConstructor(this);
  }

  UnsupportedMethod method() {
    return new UnsupportedMethod(this);
  }

  abstract UnsupportedType type();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy