use of javax.lang.model.type.DeclaredType in project buck by facebook.
the class TreeBackedTypeElementTest method testGetSuperclassNoSuperclassIsObject.
@Test
public void testGetSuperclassNoSuperclassIsObject() throws IOException {
compile("class Foo { }");
TypeElement fooElement = elements.getTypeElement("Foo");
DeclaredType superclass = (DeclaredType) fooElement.getSuperclass();
TypeElement objectElement = elements.getTypeElement("java.lang.Object");
assertSame(objectElement, superclass.asElement());
}
use of javax.lang.model.type.DeclaredType in project buck by facebook.
the class TypeResolverTest method testParameterizedTypeResolves.
@Test
public void testParameterizedTypeResolves() throws IOException {
compile(Joiner.on('\n').join("abstract class Foo extends java.util.ArrayList<java.lang.String> { }", "abstract class Bar extends java.util.ArrayList<java.lang.String> { }"));
TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
TypeElement stringElement = elements.getTypeElement("java.lang.String");
DeclaredType expectedSuperclass = types.getDeclaredType(listElement, stringElement.asType());
TypeElement fooElement = elements.getTypeElement("Foo");
TypeElement barElement = elements.getTypeElement("Bar");
DeclaredType fooSuperclass = (DeclaredType) fooElement.getSuperclass();
DeclaredType barSuperclass = (DeclaredType) barElement.getSuperclass();
assertNotSame(expectedSuperclass, fooSuperclass);
assertSameType(expectedSuperclass, fooSuperclass);
assertSameType(fooSuperclass, barSuperclass);
}
use of javax.lang.model.type.DeclaredType in project RoboBinding by RoboBinding.
the class WrappedTypeElement method firstTypeArgument.
public WrappedTypeElement firstTypeArgument() {
List<? extends TypeMirror> typeArguments = type.getTypeArguments();
DeclaredType firstTypeArgument = (DeclaredType) typeArguments.get(0);
return typeElementOf(firstTypeArgument);
}
use of javax.lang.model.type.DeclaredType in project epoxy by airbnb.
the class HashCodeValidator method validateImplementsHashCode.
private void validateImplementsHashCode(TypeMirror mirror) throws EpoxyProcessorException {
if (TypeName.get(mirror).isPrimitive()) {
return;
}
if (mirror.getKind() == TypeKind.ARRAY) {
validateArrayType((ArrayType) mirror);
return;
}
if (!(mirror instanceof DeclaredType)) {
return;
}
DeclaredType declaredType = (DeclaredType) mirror;
Element element = typeUtils.asElement(mirror);
TypeElement clazz = (TypeElement) element;
if (isIterableType(clazz)) {
validateIterableType(declaredType);
return;
}
if (isAutoValueType(element)) {
return;
}
if (isWhiteListedType(element)) {
return;
}
if (!hasHashCodeInClassHierarchy(clazz)) {
throwError("Attribute does not implement hashCode");
}
}
use of javax.lang.model.type.DeclaredType in project epoxy by airbnb.
the class ProcessorUtils method getEpoxyObjectType.
/**
* Returns the type of the Epoxy model.
* <p>
* Eg for "class MyModel extends EpoxyModel<TextView>" it would return TextView.
*/
static TypeMirror getEpoxyObjectType(TypeElement clazz, Types typeUtils) {
if (clazz.asType().getKind() != TypeKind.DECLARED) {
return null;
}
DeclaredType superclass = (DeclaredType) clazz.getSuperclass();
List<? extends TypeMirror> superTypeArguments = superclass.getTypeArguments();
if (superTypeArguments.isEmpty()) {
return getEpoxyObjectType((TypeElement) typeUtils.asElement(superclass), typeUtils);
}
// should be rare, but it would be nice to handle.
return superTypeArguments.get(0);
}
Aggregations