private static BuildMetaClass cloneToBuildMetaClass(MetaClass clazz) {
return cloneToBuildMetaClass(clazz, null);
}
private static BuildMetaClass cloneToBuildMetaClass(MetaClass clazz, MetaParameterizedType parameterizedType) {
BuildMetaClass buildMetaClass = new BuildMetaClass(Context.create(), clazz.getFullyQualifiedName());
buildMetaClass.setReifiedFormOf(clazz);
buildMetaClass.setAbstract(clazz.isAbstract());
buildMetaClass.setFinal(clazz.isFinal());
buildMetaClass.setStatic(clazz.isStatic());
buildMetaClass.setInterface(clazz.isInterface());
buildMetaClass.setInterfaces(Arrays.asList(clazz.getInterfaces()));
buildMetaClass.setScope(GenUtil.scopeOf(clazz));
buildMetaClass.setSuperClass(clazz.getSuperClass());
for (MetaTypeVariable typeVariable : clazz.getTypeParameters()) {
buildMetaClass.addTypeVariable(typeVariable);
}
if (parameterizedType != null) {
buildMetaClass.setParameterizedType(parameterizedType);
}
else {
buildMetaClass.setParameterizedType(clazz.getParameterizedType());
}
for (MetaField field : clazz.getDeclaredFields()) {
BuildMetaField bmf = new ShadowBuildMetaField(buildMetaClass, EmptyStatement.INSTANCE,
GenUtil.scopeOf(field), field.getType(), field.getName(), field);
bmf.setFinal(field.isFinal());
bmf.setStatic(field.isStatic());
bmf.setVolatile(field.isVolatile());
bmf.setTransient(field.isTransient());
buildMetaClass.addField(bmf);
}
for (MetaConstructor c : clazz.getDeclaredConstructors()) {
BuildMetaConstructor newConstructor = new BuildMetaConstructor(buildMetaClass, EmptyStatement.INSTANCE,
GenUtil.scopeOf(c),
DefParameters.from(c));
newConstructor.setReifiedFormOf(c);
buildMetaClass.addConstructor(newConstructor);
}
for (MetaMethod method : clazz.getDeclaredMethods()) {
MetaClass returnType = method.getReturnType();
if (method.getGenericReturnType() instanceof MetaTypeVariable) {
MetaTypeVariable typeVariable = (MetaTypeVariable) method.getGenericReturnType();
MetaClass tVarVal = getTypeVariableValue(typeVariable, buildMetaClass);
if (tVarVal != null) {
returnType = tVarVal;
}
}
List<Parameter> parameters = new ArrayList<Parameter>();
int i = 0;
for (MetaParameter parm : method.getParameters()) {
MetaClass parmType = null;
if (method.getGenericParameterTypes() != null) {
if (method.getGenericParameterTypes()[i] instanceof MetaTypeVariable) {
MetaTypeVariable typeVariable = (MetaTypeVariable) method.getGenericParameterTypes()[i];
MetaClass tVarVal = getTypeVariableValue(typeVariable, buildMetaClass);
if (tVarVal != null) {
parmType = tVarVal;
}
}
}
if (parmType == null) {
parmType = parm.getType();
}
parameters.add(Parameter.of(parmType, parm.getName()));
i++;
}
BuildMetaMethod newMethod = new ShadowBuildMetaMethod(buildMetaClass, EmptyStatement.INSTANCE,
GenUtil.scopeOf(method), GenUtil.modifiersOf(method), method.getName(), returnType,
method.getGenericReturnType(),
DefParameters.fromParameters(parameters), ThrowsDeclaration.of(method.getCheckedExceptions()), method);
newMethod.setReifiedFormOf(method);
buildMetaClass.addMethod(newMethod);
}
return buildMetaClass;
}