@Override public String getQualifiedNameWithGenerics() { String result = type.toString(); if (origin instanceof Importer<?>) { return Types.rebuildGenericNameWithArrays(((Importer<?>) origin).resolveType(result), this); } return result; }
@Override public String getQualifiedNameWithGenerics() { String result = type.toString(); if (origin instanceof Importer<?>) { return Types.rebuildGenericNameWithArrays(((Importer<?>) origin).resolveType(result), this); } return result; }
@Override public FieldSource<O> setType(String typeName) { O origin = getOrigin(); Type<O> innerType = new TypeImpl<O>(origin, null, typeName); Import imprt = getOrigin().addImport(innerType); String resolvedType = (imprt != null) ? Types.rebuildGenericNameWithArrays(imprt.getSimpleName(), innerType) : typeName; if (Types.isJavaLang(resolvedType)) { resolvedType = Types.toSimpleName(typeName); } org.eclipse.jdt.core.dom.Type fieldType = TypeImpl.fromString(resolvedType, this.ast); field.setType(fieldType); return this; }
@Override public FieldSource<O> setType(String typeName) { O origin = getOrigin(); Type<O> innerType = new TypeImpl<O>(origin, null, typeName); Import imprt = getOrigin().addImport(innerType); String resolvedType = (imprt != null) ? Types.rebuildGenericNameWithArrays(imprt.getSimpleName(), innerType) : typeName; if (Types.isJavaLang(resolvedType)) { resolvedType = Types.toSimpleName(typeName); } org.eclipse.jdt.core.dom.Type fieldType = TypeImpl.fromString(resolvedType, this.ast); field.setType(fieldType); return this; }
@SuppressWarnings("unchecked") @Override public ParameterSource<O> addParameter(String type, String name) { String resolvedType = type; if (!hasTypeVariable(type) && getOrigin().requiresImport(type)) { Type<?> innerType = new TypeImpl<O>(getOrigin(), null, type); Import imprt = getOrigin().addImport(innerType); resolvedType = imprt != null ? Types.rebuildGenericNameWithArrays(imprt.getSimpleName(), innerType) : Types.toSimpleName(type); } String stub = "public class Stub { public void method( " + resolvedType + " " + name + " ) {} }"; JavaClassSource temp = (JavaClassSource) Roaster.parse(stub); List<MethodSource<JavaClassSource>> methods = temp.getMethods(); List<VariableDeclaration> astParameters = ((MethodDeclaration) methods.get(0).getInternal()).parameters(); ParameterSource<O> param = null; for (VariableDeclaration declaration : astParameters) { VariableDeclaration copy = (VariableDeclaration) ASTNode.copySubtree(method.getAST(), declaration); method.parameters().add(copy); param = new ParameterImpl<O>(parent, copy); } return param; }
@SuppressWarnings("unchecked") @Override public ParameterSource<O> addParameter(String type, String name) { String resolvedType = type; if (!hasTypeVariable(type) && getOrigin().requiresImport(type)) { Type<?> innerType = new TypeImpl<O>(getOrigin(), null, type); Import imprt = getOrigin().addImport(innerType); resolvedType = imprt != null ? Types.rebuildGenericNameWithArrays(imprt.getSimpleName(), innerType) : Types.toSimpleName(type); } String stub = "public class Stub { public void method( " + resolvedType + " " + name + " ) {} }"; JavaClassSource temp = (JavaClassSource) Roaster.parse(stub); List<MethodSource<JavaClassSource>> methods = temp.getMethods(); List<VariableDeclaration> astParameters = ((MethodDeclaration) methods.get(0).getInternal()).parameters(); ParameterSource<O> param = null; for (VariableDeclaration declaration : astParameters) { VariableDeclaration copy = (VariableDeclaration) ASTNode.copySubtree(method.getAST(), declaration); method.parameters().add(copy); param = new ParameterImpl<O>(parent, copy); } return param; }