public TypeParamRefBuilder(TypeParamRef instance, Boolean validationEnabled) { this.fluent = this; this.withName(instance.getName()); this.withDimensions(instance.getDimensions()); this.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
public boolean isAssignableFrom(TypeRef ref) { return this.equals(ref); } }
private static final Set<TypeParamDef> extractParameters(ClassRef classRef) { final Set<TypeParamDef> result = new LinkedHashSet<TypeParamDef>(); final Set<TypeParamRef> refs = new LinkedHashSet<TypeParamRef>(); ClassRef ignored = new ClassRefBuilder(classRef).accept(new TypeParamDefColletor(result)).accept(new TypeParamRefColletor(refs)).build(); for (TypeParamRef typeParamRef : refs) { result.add(new TypeParamDefBuilder().withName(typeParamRef.getName()).withAttributes(typeParamRef.getAttributes()).build()); } return result; }
private static TypeRef getKeyForValue(Map<TypeRef, TypeParamDef> map, TypeRef value) { for (Map.Entry<TypeRef, TypeParamDef> entry : map.entrySet()) { if (value instanceof TypeParamRef && ((TypeParamRef) value).getName().equals(entry.getValue().getName())) { return entry.getKey(); } } return null; //throw new IllegalStateException("Key not found for value:[" + value +"]."); }
/** * Checks if a {@link TypeRef} is an array. * @param type The type to check. * @return True if its an array.B */ public static boolean isArray(TypeRef type) { if (type instanceof ClassRef) { return ((ClassRef)type).getDimensions() > 0; } else if (type instanceof PrimitiveRef) { return ((PrimitiveRef)type).getDimensions() > 0; } else if (type instanceof TypeParamRef) { return ((TypeParamRef)type).getDimensions() > 0; } else { return false; } }
private static final Set<TypeParamDef> extractParameters(TypeDef typeDef) { final Set<TypeParamDef> result = new LinkedHashSet<TypeParamDef>(); final Set<TypeParamRef> refs = new LinkedHashSet<TypeParamRef>(); TypeDef ignored = new TypeDefBuilder(typeDef).accept(new TypeParamDefColletor(result)).accept(new TypeParamRefColletor(refs)).build(); for (TypeParamRef typeParamRef : refs) { result.add(new TypeParamDefBuilder().withName(typeParamRef.getName()).withAttributes(typeParamRef.getAttributes()).build()); } return result; }
private static boolean containsValue(Map<TypeRef, TypeParamDef> map, TypeRef value) { for (Map.Entry<TypeRef, TypeParamDef> entry : map.entrySet()) { if (value instanceof TypeParamRef && ((TypeParamRef) value).getName().equals(entry.getValue().getName())) { return true; } } return false; }
public TypeParamRefBuilder(TypeParamRefFluent<?> fluent, TypeParamRef instance, Boolean validationEnabled) { this.fluent = fluent; fluent.withName(instance.getName()); fluent.withDimensions(instance.getDimensions()); fluent.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
public static Set<String> allGenericsOf(TypeRef type) { Set<String> result = new HashSet<String>(); if (type instanceof ClassRef) { for (TypeRef ref : ((ClassRef)type).getArguments()) { if (ref instanceof TypeParamRef) { result.add(((TypeParamRef)ref).getName()); } } } return result; }
public void visit(ClassRefBuilder builder) { List<TypeRef> unwrappedArguments = new ArrayList<TypeRef>(); for (TypeRef argument : builder.getArguments()) { TypeRef key = getKeyForValue(GENERIC_MAPPINGS, argument); if (TRANSPARENT_REF.equals(key)) { continue; } else if (key != null) { unwrappedArguments.add(key); } else if (argument instanceof ClassRef) { unwrappedArguments.add(new ClassRefBuilder((ClassRef)argument).accept(UNWRAP_CLASSREF_VISITOR).build()); } else { unwrappedArguments.add(argument); } } builder.withArguments(unwrappedArguments); } };
public TypeParamRefFluentImpl(TypeParamRef instance){ this.withName(instance.getName()); this.withDimensions(instance.getDimensions()); this.withAttributes(instance.getAttributes()); }
public static TypeParamDef getParameterDefinition(TypeRef typeRef, Collection<TypeParamDef> parameters) { String name; if (typeRef instanceof ClassRef) { name = ((ClassRef)typeRef).getName(); } else if (typeRef instanceof TypeParamRef) { name = ((TypeParamRef)typeRef).getName(); } else if (typeRef instanceof PrimitiveRef) { name = ((PrimitiveRef)typeRef).getName(); } else { name = typeRef.toString(); } for (TypeParamDef parameter : parameters) { if (parameter.getName().equals(name)) { return parameter; } } return null; }