use of javax.lang.model.type.TypeMirror in project buck by facebook.
the class TreeBackedTypeParameterElementTest method testSuperclassBoundedTypeParameter.
@Test
public void testSuperclassBoundedTypeParameter() throws IOException {
compile("class Foo<T extends java.lang.CharSequence> { }");
TypeMirror charSequenceType = elements.getTypeElement("java.lang.CharSequence").asType();
TypeElement fooElement = elements.getTypeElement("Foo");
List<? extends TypeParameterElement> typeParameters = fooElement.getTypeParameters();
assertSame(1, typeParameters.size());
TypeParameterElement typeParam = typeParameters.get(0);
List<? extends TypeMirror> bounds = typeParam.getBounds();
assertSame(1, bounds.size());
assertSameType(charSequenceType, bounds.get(0));
}
use of javax.lang.model.type.TypeMirror in project buck by facebook.
the class TreeBackedTypesTest method testIsSameTypeJavacTypeTopLevelNoGenerics.
@Test
public void testIsSameTypeJavacTypeTopLevelNoGenerics() throws IOException {
initCompiler();
TypeElement objectElement = elements.getTypeElement("java.lang.Object");
TypeMirror objectTypeMirror = types.getDeclaredType(objectElement);
TypeMirror objectTypeMirror2 = types.getDeclaredType(objectElement);
assertSameType(objectTypeMirror, objectTypeMirror2);
}
use of javax.lang.model.type.TypeMirror in project RoboBinding by RoboBinding.
the class TypeMirrorWrapperTest method unsupportedTypeMirrors.
@DataPoints("unsupportedTypeMirrors")
public static TypeMirror[] unsupportedTypeMirrors() {
Types types = compilation.getTypes();
NullType nullType = types.getNullType();
NoType noneType = types.getNoType(TypeKind.NONE);
return new TypeMirror[] { nullType, noneType };
}
use of javax.lang.model.type.TypeMirror in project epoxy by airbnb.
the class ProcessorUtils method isSubtypeOfType.
static boolean isSubtypeOfType(TypeMirror typeMirror, String otherType) {
if (otherType.equals(typeMirror.toString())) {
return true;
}
if (typeMirror.getKind() != TypeKind.DECLARED) {
return false;
}
DeclaredType declaredType = (DeclaredType) typeMirror;
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.size() > 0) {
StringBuilder typeString = new StringBuilder(declaredType.asElement().toString());
typeString.append('<');
for (int i = 0; i < typeArguments.size(); i++) {
if (i > 0) {
typeString.append(',');
}
typeString.append('?');
}
typeString.append('>');
if (typeString.toString().equals(otherType)) {
return true;
}
}
Element element = declaredType.asElement();
if (!(element instanceof TypeElement)) {
return false;
}
TypeElement typeElement = (TypeElement) element;
TypeMirror superType = typeElement.getSuperclass();
if (isSubtypeOfType(superType, otherType)) {
return true;
}
for (TypeMirror interfaceType : typeElement.getInterfaces()) {
if (isSubtypeOfType(interfaceType, otherType)) {
return true;
}
}
return false;
}
use of javax.lang.model.type.TypeMirror in project epoxy by airbnb.
the class EpoxyProcessor method addCreateHolderMethodIfNeeded.
/**
* If the model is a holder and doesn't implement the "createNewHolder" method we can generate a
* default implementation by getting the class type and creating a new instance of it.
*/
private void addCreateHolderMethodIfNeeded(TypeElement originalClassElement, List<MethodSpec> methods) {
if (!isEpoxyModelWithHolder(originalClassElement)) {
return;
}
MethodSpec createHolderMethod = MethodSpec.methodBuilder(CREATE_NEW_HOLDER_METHOD_NAME).addAnnotation(Override.class).addModifiers(Modifier.PROTECTED).build();
if (implementsMethod(originalClassElement, createHolderMethod, typeUtils)) {
return;
}
TypeMirror epoxyObjectType = getEpoxyObjectType(originalClassElement, typeUtils);
if (epoxyObjectType == null) {
logError("Return type for createNewHolder method could not be found. (class: %s)", originalClassElement.getSimpleName());
return;
}
createHolderMethod = createHolderMethod.toBuilder().returns(TypeName.get(epoxyObjectType)).addStatement("return new $T()", epoxyObjectType).build();
methods.add(createHolderMethod);
}
Aggregations