
br.com.objectos.way.flat.FlatContainerProperty Maven / Gradle / Ivy
/*
* Copyright 2016 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.way.flat;
import java.util.List;
import javax.lang.model.element.Modifier;
import br.com.objectos.way.code.SimpleTypeInfo;
import br.com.objectos.way.pojo.plugin.Property;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.MethodSpec.Builder;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
/**
* @author [email protected] (Marcio Endo)
*/
abstract class FlatContainerProperty {
final Property property;
FlatContainerProperty(Property property) {
this.property = property;
}
public static FlatContainerProperty of(Property property) {
SimpleTypeInfo returnTypeInfo = property.returnTypeInfo();
return returnTypeInfo.isInfoOf(List.class)
? ListFlatContainerProperty.of(property, returnTypeInfo)
: SimpleFlatContainerProperty.of(property, returnTypeInfo);
}
public static FlatContainerProperty errorOf(Property property) {
return new Error(property);
}
public void constructor(MethodSpec.Builder constructor) {
constructor
.addParameter(property.returnTypeInfo().typeName(), propertyName())
.addStatement("this.$1L = $1L", propertyName());
}
public void flatReaderVisitor(TypeSpec.Builder visitor) {
visitor.addField(flatReaderVisitorFieldSpec().build());
}
public void visitLineMethodSwitch(MethodSpec.Builder method) {
prefixInfo().visitLineMethodSwitch(method);
}
public abstract void visitLineMethod(MethodSpec.Builder method);
public abstract void writeTo(MethodSpec.Builder method);
FieldSpec.Builder flatReaderVisitorFieldSpec() {
SimpleTypeInfo returnTypeInfo = property.returnTypeInfo();
return FieldSpec.builder(returnTypeInfo.typeName(), property.name(), Modifier.PRIVATE);
}
abstract PrefixInfo prefixInfo();
String propertyName() {
return property.name();
}
TypeName propertyTypeName() {
return property.returnTypeInfo().typeName();
}
private static class Error extends FlatContainerProperty {
public Error(Property property) {
super(property);
}
@Override
public void visitLineMethod(Builder method) {
}
@Override
public void writeTo(Builder method) {
}
@Override
PrefixInfo prefixInfo() {
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy