br.com.objectos.ui.html.Naming 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.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.ui.html.annotation.Spec;
import br.com.objectos.way.code.Code;
import br.com.objectos.way.code.MethodInfo;
import br.com.objectos.way.code.TypeInfo;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
/**
* @author [email protected] (Marcio Endo)
*/
@Pojo
abstract class Naming implements Testable {
abstract ClassName className();
abstract ClassName specClassName();
abstract ClassName elementClassName();
Naming() {
}
public static NamingBuilder builder() {
return new NamingBuilderPojo();
}
public static Naming of(TypeInfo typeInfo) {
ClassName specClassName = typeInfo.className();
return Naming.builder()
.className(typeInfo.annotationInfo(Spec.class)
.flatMap(info -> info.stringValue("className"))
.map(s -> specClassName.peerClass(s))
.get())
.specClassName(specClassName)
.elementClassName(typeInfo.interfaceTypeInfoAnnotatedWith(ElementSpec.class)
.flatMap(info -> info.annotationInfo(br.com.objectos.ui.html.annotation.ClassName.class))
.flatMap(info -> info.stringValue("value"))
.map(s -> specClassName.peerClass(s))
.get())
.build();
}
public String classSimpleName() {
return className().simpleName();
}
public ClassName elementMethodClassName(MethodInfo methodInfo) {
String name = methodInfo.annotationInfo(br.com.objectos.ui.html.annotation.ClassName.class)
.flatMap(annotationInfo -> annotationInfo.stringValue("value"))
.orElse(methodInfo.name());
return className().peerClass(Code.upperCaseFirstChar(name));
}
public String elementSimpleName() {
return elementClassName().simpleName();
}
public TypeName protoTypeName(ClassName className) {
String simpleName = className.simpleName();
ClassName rawName = className.peerClass(simpleName + "Proto");
return ParameterizedTypeName.get(rawName, className);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy