Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Substitution#createTypeFromTemplate return type #1464

Merged
merged 3 commits into from
Jul 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/spoon/template/Substitution.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,18 @@ public static <T extends Template<?>> void insertAll(CtType<?> targetType, T tem
* @param templateParameters
* the substitution parameters
*/
public static <T> CtType<T> createTypeFromTemplate(String qualifiedTypeName, CtType<T> templateOfType, Map<String, Object> templateParameters) {
@SuppressWarnings("unchecked")
public static <T extends CtType<?>> T createTypeFromTemplate(String qualifiedTypeName, CtType<?> templateOfType, Map<String, Object> templateParameters) {
final Factory f = templateOfType.getFactory();
CtTypeReference<T> typeRef = f.Type().createReference(qualifiedTypeName);
CtPackage targetPackage = f.Package().getOrCreate(typeRef.getPackage().getSimpleName());
final Map<String, Object> extendedParams = new HashMap<String, Object>(templateParameters);
extendedParams.put(templateOfType.getSimpleName(), typeRef);
List<CtType<T>> generated = new SubstitutionVisitor(f, extendedParams).substitute(templateOfType.clone());
for (CtType<T> ctType : generated) {
List<CtType<?>> generated = (List) new SubstitutionVisitor(f, extendedParams).substitute(templateOfType.clone());
for (CtType<?> ctType : generated) {
targetPackage.addType(ctType);
}
return typeRef.getTypeDeclaration();
return (T) typeRef.getTypeDeclaration();
}

/**
Expand Down Expand Up @@ -207,7 +208,6 @@ public static void insertAllMethods(CtType<?> targetType, Template<?> template)
* the model of source template
*/
static void insertAllMethods(CtType<?> targetType, Template<?> template, CtClass<?> sourceClass) {

Set<CtMethod<?>> methodsOfTemplate = sourceClass.getFactory().Type().get(Template.class).getMethods();
// insert all the methods
for (CtMethod<?> m : sourceClass.getMethods()) {
Expand Down