use of javax.lang.model.type.WildcardType in project mapstruct by mapstruct.
the class Type method isWildCardExtendsBound.
public boolean isWildCardExtendsBound() {
boolean result = false;
if (typeMirror.getKind() == TypeKind.WILDCARD) {
WildcardType wildcardType = (WildcardType) typeMirror;
result = wildcardType.getExtendsBound() != null;
}
return result;
}
use of javax.lang.model.type.WildcardType in project javapoet by square.
the class AbstractTypesTest method wildcardMirrorSuperType.
@Test
public void wildcardMirrorSuperType() throws Exception {
Types types = getTypes();
Elements elements = getElements();
TypeMirror string = elements.getTypeElement(String.class.getName()).asType();
WildcardType wildcard = types.getWildcardType(null, string);
TypeName type = TypeName.get(wildcard);
assertThat(type.toString()).isEqualTo("? super java.lang.String");
}
use of javax.lang.model.type.WildcardType in project javapoet by square.
the class AbstractTypesTest method wildcardMirrorExtendsType.
@Test
public void wildcardMirrorExtendsType() throws Exception {
Types types = getTypes();
Elements elements = getElements();
TypeMirror charSequence = elements.getTypeElement(CharSequence.class.getName()).asType();
WildcardType wildcard = types.getWildcardType(charSequence, null);
TypeName type = TypeName.get(wildcard);
assertThat(type.toString()).isEqualTo("? extends java.lang.CharSequence");
}
use of javax.lang.model.type.WildcardType in project j2objc by google.
the class NameUtil method buildTypeSignature.
private void buildTypeSignature(TypeMirror type, StringBuilder sb) {
switch(type.getKind()) {
case BOOLEAN:
case BYTE:
case CHAR:
case DOUBLE:
case FLOAT:
case INT:
case LONG:
case SHORT:
case VOID:
sb.append(TypeUtil.getBinaryName(type));
break;
case ARRAY:
sb.append('[');
buildTypeSignature(((ArrayType) type).getComponentType(), sb);
break;
case DECLARED:
buildDeclaredType((DeclaredType) type, sb);
sb.append(';');
break;
case TYPEVAR:
buildTypeVariable((TypeVariable) type, sb);
break;
case INTERSECTION:
sb.append("&{");
for (TypeMirror bound : ((IntersectionType) type).getBounds()) {
buildTypeSignature(bound, sb);
}
sb.append('}');
break;
case WILDCARD:
TypeMirror upperBound = ((WildcardType) type).getExtendsBound();
TypeMirror lowerBound = ((WildcardType) type).getSuperBound();
if (upperBound != null) {
sb.append('+');
buildTypeSignature(upperBound, sb);
} else if (lowerBound != null) {
sb.append('-');
buildTypeSignature(lowerBound, sb);
} else {
sb.append('*');
}
break;
default:
throw new AssertionError("Unexpected type kind: " + type.getKind());
}
}
use of javax.lang.model.type.WildcardType in project j2objc by google.
the class SignatureGenerator method genTypeSignature.
// TODO(kstanger): Figure out if this can replace TypeUtil.getSignatureName().
private void genTypeSignature(TypeMirror type, StringBuilder sb) {
switch(type.getKind()) {
case BOOLEAN:
case BYTE:
case CHAR:
case DOUBLE:
case FLOAT:
case INT:
case LONG:
case SHORT:
case VOID:
sb.append(TypeUtil.getBinaryName(type));
break;
case ARRAY:
// ArrayTypeSignature ::= "[" TypSignature.
sb.append('[');
genTypeSignature(((ArrayType) type).getComponentType(), sb);
break;
case DECLARED:
String typeName = elementUtil.getBinaryName(TypeUtil.asTypeElement(type));
if (!TypeUtil.isStubType(typeName)) {
// ClassTypeSignature ::= "L" {Ident "/"} Ident
// OptTypeArguments {"." Ident OptTypeArguments} ";".
sb.append('L');
sb.append(typeName.replace('.', '/'));
genOptTypeArguments(((DeclaredType) type).getTypeArguments(), sb);
sb.append(';');
}
break;
case TYPEVAR:
// TypeVariableSignature ::= "T" Ident ";".
sb.append('T');
sb.append(ElementUtil.getName(((TypeVariable) type).asElement()));
sb.append(';');
break;
case WILDCARD:
// TypeArgument ::= (["+" | "-"] FieldTypeSignature) | "*".
TypeMirror upperBound = ((WildcardType) type).getExtendsBound();
TypeMirror lowerBound = ((WildcardType) type).getSuperBound();
if (upperBound != null) {
sb.append('+');
genTypeSignature(upperBound, sb);
} else if (lowerBound != null) {
sb.append('-');
genTypeSignature(lowerBound, sb);
} else {
sb.append('*');
}
break;
default:
throw new AssertionError("Unexpected type kind: " + type.getKind());
}
}
Aggregations