/*
* 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 org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import br.com.objectos.way.base.Testables;
import com.google.common.base.Optional;
/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
class FieldInfoPojo implements FieldInfo {
private final SimpleTypeInfo simpleTypeInfo;
private final String name;
public FieldInfoPojo(Builder builder) {
simpleTypeInfo = builder.getSimpleTypeInfo();
name = builder.getName();
}
@Override
public boolean isEqual(FieldInfo o) {
FieldInfoPojo that = o.toPojo();
return Testables.isEqualHelper()
.equal(this.simpleTypeInfo, that.simpleTypeInfo)
.equal(this.name, that.name)
.result();
}
@Override
public FieldDeclaration toFieldDeclaration(AST ast) {
VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(name));
FieldDeclaration field = ast.newFieldDeclaration(fragment);
field.setType(simpleTypeInfo.toType(ast));
return field;
}
@Override
public Optional<ImportInfo> toImportInfo() {
return simpleTypeInfo.toImportInfo();
}
@Override
public FieldInfoPojo toPojo() {
return this;
}
@Override
public SimpleName toSimpleName(AST ast) {
return ast.newSimpleName(name);
}
}