br.com.objectos.ui.html.ProtoNaming Maven / Gradle / Ivy
/*
* 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.ui.html;
import br.com.objectos.way.pojo.Pojo;
import br.com.objectos.way.testable.Testable;
import br.com.objectos.ui.html.annotation.ElementSpec;
import br.com.objectos.way.code.TypeInfo;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.TypeVariableName;
/**
* @author [email protected] (Marcio Endo)
*/
@Pojo
abstract class ProtoNaming implements Testable {
abstract ClassName elementClassName();
abstract TypeVariableName typeVariableName();
abstract TypeVariableName protoTypeVariableName();
abstract TypeName superclassTypeName();
ProtoNaming() {
}
public static ProtoNamingBuilder builder() {
return new ProtoNamingBuilderPojo();
}
public static ProtoNaming of(TypeInfo typeInfo) {
ClassName className = typeInfo.className();
ClassName elementClassName = typeInfo.interfaceTypeInfoAnnotatedWith(ElementSpec.class)
.flatMap(info -> info.annotationInfo(br.com.objectos.ui.html.annotation.ClassName.class))
.flatMap(info -> info.stringValue("value"))
.map(s -> className.peerClass(s))
.get();
TypeVariableName typeVariableName = TypeVariableName.get("E");
return ProtoNaming.builder()
.elementClassName(elementClassName)
.typeVariableName(typeVariableName)
.protoTypeVariableName(TypeVariableName.get("E", Element.class))
.superclassTypeName(ParameterizedTypeName.get(elementClassName, typeVariableName))
.build();
}
public JavaFile generate(TypeSpec type) {
String packageName = elementClassName().packageName();
return JavaFile.builder(packageName, type)
.skipJavaLangImports(true)
.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy