
br.com.objectos.way.code.ParameterInfo Maven / Gradle / Ivy
/*
* Copyright 2014 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.code;
import java.util.Collections;
import java.util.List;
import br.com.objectos.way.pojo.Pojo;
import br.com.objectos.way.testable.Equality;
import br.com.objectos.way.testable.Testable;
import br.com.objectos.way.testable.Tester;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.TypeName;
/**
* @author [email protected] (Marcio Endo)
*/
@Pojo
public abstract class ParameterInfo
implements
CanGenerateCompilationError,
HasAnnotationInfoList,
Testable {
public abstract Index index();
@Override
public abstract List annotationInfoList();
public abstract SimpleTypeInfo simpleTypeInfo();
public abstract String name();
ParameterInfo() {
}
public static ParameterInfoBuilder newPojo() {
return new ParameterInfoBuilderPojo();
}
@Override
public Equality isEqualTo(Object that) {
return Tester.of(ParameterInfo.class)
.add("index", o -> o.index())
.add("annotationInfoList", o -> o.annotationInfoList())
.add("simpleTypeInfo", o -> o.simpleTypeInfo())
.add("name", o -> o.name())
.test(this, that);
}
public boolean isInfoOf(Class> type) {
return simpleTypeInfo().isInfoOf(type);
}
public FieldInfo toFieldInfo() {
return FieldInfo.newPojo()
.annotationInfoList(Collections. emptyList())
.simpleTypeInfo(simpleTypeInfo())
.name(name())
.build();
}
public IndexedParameterInfo toIndexedParameterInfo(int index, int total) {
return new IndexedParameterInfoBuilder(index, total).build();
}
@Override
public String toString() {
return simpleTypeInfo().getDeclaredName() + " " + name();
}
@Override
public void compilationError(String message) {
}
public ParameterInfoFieldWriter fieldWriter() {
return new ParameterInfoFieldWriter(this);
}
public ParameterSpec parameterSpec() {
TypeName type = simpleTypeInfo().typeName();
return ParameterSpec.builder(type, name())
.build();
}
void addName(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy