private static String getBindingKey(TypeVariable type) { StringBuilder sb = new StringBuilder(); sb.append('T'); sb.append(type.identifier()); sb.append(type.bounds().stream().map(BindingKeyUtils::getGeneralTypeBindingKey).collect(Collectors.joining(":"))); sb.append(';'); return sb.toString(); }
TypeVariable copyType(int boundIndex, Type bound) { if (boundIndex > bounds.length) { throw new IllegalArgumentException("Bound index outside of bounds"); } Type[] bounds = this.bounds.clone(); bounds[boundIndex] = bound; return new TypeVariable(name, bounds, annotationArray()); }
String toString(boolean simple) { StringBuilder builder = new StringBuilder(); appendAnnotations(builder); builder.append(name); // FIXME - revist this logic if (!simple && bounds.length > 0 && !(bounds.length == 1 && ClassType.OBJECT_TYPE.equals(bounds[0]))) { builder.append(" extends ").append(bounds[0].toString(true)); for (int i = 1; i < bounds.length; i++) { builder.append(" & ").append(bounds[i].toString(true)); } } return builder.toString(); }
private TypeVariable resolveBounds(Type type) { TypeVariable typeVariable = type.asTypeVariable(); Type[] bounds = typeVariable.boundArray(); for (int i = 0; i < bounds.length; i++) { Type newType = resolveType(bounds[i]); if (newType != null && newType != bounds[i]) { typeVariable = typeVariable.copyType(i, newType); } } return typeVariable; }
case TYPE_VARIABLE: { TypeVariable typeVariable = type.asTypeVariable(); addString(typeVariable.identifier()); addTypeList(typeVariable.boundArray()); break;
/** * @param i * @return * @throws SerianalyzerException */ static String makeSignature ( MethodInfo i, boolean fix ) throws SerianalyzerException { StringBuilder sb = new StringBuilder(); sb.append('('); ClassInfo declaringImpl = i.declaringClass(); if ( fix && "<init>".equals(i.name()) && declaringImpl.nestingType() == NestingType.INNER ) { //$NON-NLS-1$ // there seems to be some sort of bug, missing the the outer instance parameter in the constructor if ( !Modifier.isStatic(declaringImpl.flags()) ) { org.jboss.jandex.Type enclosingClass = org.jboss.jandex.Type.create(declaringImpl.enclosingClass(), Kind.CLASS); org.jboss.jandex.Type firstArg = i.parameters().size() > 0 ? i.parameters().get(0) : null; if ( firstArg instanceof TypeVariable ) { firstArg = firstArg.asTypeVariable().bounds().get(0); } if ( firstArg == null || !firstArg.equals(enclosingClass) ) { sb.append(toString(enclosingClass)); } } } for ( org.jboss.jandex.Type p : i.parameters() ) { sb.append(toString(p)); } sb.append(')'); sb.append(toString(i.returnType())); return sb.toString(); }
private void resolveTypeList(ArrayList<Type> list) { int size = list.size(); for (int i = 0; i < size; i++) { Type type = resolveType(list.get(i)); if (type != null) { list.set(i, type); typeParameters.put(type.asTypeVariable().identifier(), type.asTypeVariable()); } } }
@Override Type copyType(AnnotationInstance[] newAnnotations) { return new TypeVariable(name, bounds, newAnnotations); }
@Override public String name() { return getType().name().toString(); }
TypeParameterBoundTypeTarget boundTarget = target.asTypeParameterBound(); type = getTypeParameters(enclosingTarget)[boundTarget.position()] .asTypeVariable().boundArray()[boundTarget.boundPosition()]; break;
case TYPE_VARIABLE: TypeVariable typeVariable = type.asTypeVariable(); stream.writePackedU32(positionOf(typeVariable.identifier())); writeReferenceOrFull(stream, typeVariable.boundArray()); break; case UNRESOLVED_TYPE_VARIABLE:
if (boundIndex >= type.boundArray().length) { return; type = type.copyType(boundIndex, resolveTypePath(type.boundArray()[boundIndex], typeAnnotationState)); types[index] = intern(type); setTypeParameters(target, intern(types));
return toString( ( (TypeVariable) p ).bounds().get(0));
private Type parseTypeParameter() { int start = pos; String signature = this.signature; if (signature.charAt(start) == '>') { pos++; return null; } int bound = advancePast(':'); String name = names.intern(signature.substring(start, bound)); ArrayList<Type> bounds = new ArrayList<Type>(); // Class bound has an optional reference type if (signature.charAt(pos) != ':') { bounds.add(parseReferenceType()); } // Interface bounds are none to many, with a required reference type while (signature.charAt(pos) == ':') { pos++; bounds.add(parseReferenceType()); } TypeVariable type = new TypeVariable(name, bounds.toArray(new Type[bounds.size()])); typeParameters.put(name, type); return type; }
Type[] bounds = readTypeListReference(stream); AnnotationInstance[] annotations = readAnnotations(stream, null); return new TypeVariable(identifier, bounds, annotations);