/*
* 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.ITypeBinding;
import org.eclipse.jdt.core.dom.TypeParameter;
import br.com.objectos.way.base.WayIterable;
import br.com.objectos.way.base.WayIterables;
import com.google.common.base.Function;
import com.google.common.base.Optional;
/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
class TypeParameterWrapper {
public static final Function<TypeParameter, TypeParameterWrapper> WRAP = new Function<TypeParameter, TypeParameterWrapper>() {
@Override
public TypeParameterWrapper apply(TypeParameter input) {
return new TypeParameterWrapper(input);
}
};
public static final Function<TypeParameterWrapper, SimpleTypeInfo> TO_SIMPLE_TYPE_INFO = new Function<TypeParameterWrapper, SimpleTypeInfo>() {
@Override
public SimpleTypeInfo apply(TypeParameterWrapper input) {
return input.toSimpleTypeInfo();
}
};
private final TypeParameter type;
private TypeParameterWrapper(TypeParameter type) {
this.type = type;
}
public static WayIterable<TypeParameterWrapper> wrapAll(Iterable<TypeParameter> typeParameterList) {
return WayIterables.from(typeParameterList)
.transform(WRAP);
}
public SimpleTypeInfo toSimpleTypeInfo() {
SimpleTypeInfo res = new SimpleTypeInfoBuilder().build();
ITypeBinding binding = type.resolveBinding();
if (binding != null) {
res = ITypeBindingWrapper.wrapperOf(binding)
.toSimpleTypeInfo();
}
return res;
}
private class SimpleTypeInfoBuilder implements SimpleTypeInfo.Builder {
@Override
public SimpleTypeInfo build() {
return new SimpleTypeInfoPojo(this);
}
@Override
public Optional<PackageInfo> getPackageInfo() {
return Optional.absent();
}
@Override
public String getName() {
return type.getName()
.getIdentifier();
}
}
}