use of javax.lang.model.element.Element in project buck by facebook.
the class TreeBackedTypeParameterElementTest method testAccept.
@Test
public void testAccept() throws IOException {
compile("class Foo<T> { }");
TypeParameterElement expectedTypeParameter = elements.getTypeElement("Foo").getTypeParameters().get(0);
Object expectedResult = new Object();
Object actualResult = expectedTypeParameter.accept(new SimpleElementVisitor8<Object, Object>() {
@Override
protected Object defaultAction(Element e, Object o) {
return null;
}
@Override
public Object visitTypeParameter(TypeParameterElement actualTypeParameter, Object o) {
assertSame(expectedTypeParameter, actualTypeParameter);
return o;
}
}, expectedResult);
assertSame(expectedResult, actualResult);
}
use of javax.lang.model.element.Element in project RoboBinding by RoboBinding.
the class ElementWrapperTest method unsupportedElements.
@DataPoints("unsupportedElements")
public static Element[] unsupportedElements() {
Elements elements = compilation.getElements();
PackageElement packageElement = elements.getPackageElement("java.lang");
TypeElement typeElement = elements.getTypeElement(MethodsAndFields.class.getName());
VariableElement variableElement = ElementFilter.fieldsIn(typeElement.getEnclosedElements()).get(0);
return new Element[] { packageElement, variableElement };
}
use of javax.lang.model.element.Element in project RxCache by VictorAlbertos.
the class GetProvidersClass method getMethods.
private List<ProvidersClass.Method> getMethods(Element classElement) throws ValidationException {
List<? extends Element> enclosedElements = classElement.getEnclosedElements();
List<ProvidersClass.Method> methods = new ArrayList<>();
for (Element methodElement : enclosedElements) {
if (!isAnnotatedWithActionable(methodElement))
continue;
if (methodElement.getKind() != ElementKind.METHOD)
continue;
Symbol.MethodSymbol methodSymbol = (Symbol.MethodSymbol) methodElement;
String nameMethod = methodSymbol.getSimpleName().toString();
Type returnType = methodSymbol.getReturnType();
if (!returnType.tsym.toString().equals(TypeName.get(Observable.class).toString())) {
throw new ValidationException(methodSymbol, "Error parsing %s provider. Only Observable<List> type is supported as observable loader", nameMethod);
}
Type enclosingTypeObservable = returnType.getTypeArguments().get(0);
if (!enclosingTypeObservable.tsym.toString().equals(TypeName.get(List.class).toString())) {
throw new ValidationException(methodSymbol, "Error parsing %s provider. Only Observable<List> type is supported as observable loader", nameMethod);
}
List<Symbol.VarSymbol> params = methodSymbol.getParameters();
boolean hasEvictProvider = hasEvictProvider(params);
boolean hasEvictDynamicKey = hasEvictDynamicKey(params);
boolean hasEvictDynamicKeyGroup = hasEvictDynamicKeyGroup(params);
if (!hasEvictProvider && !hasEvictDynamicKey && !hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictProvider && hasEvictDynamicKey) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictProvider && hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictDynamicKey && hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
boolean hasDynamicKey = hasDynamicKey(params);
boolean hasDynamicKeyGroup = hasDynamicKeyGroup(params);
methods.add(new ProvidersClass.Method(nameMethod, methodElement, enclosingTypeObservable, hasDynamicKey, hasDynamicKeyGroup));
}
return methods;
}
use of javax.lang.model.element.Element in project epoxy by airbnb.
the class HashCodeValidator method hasHashCodeInClassHierarchy.
private boolean hasHashCodeInClassHierarchy(TypeElement clazz) {
ExecutableElement methodOnClass = getMethodOnClass(clazz, HASH_CODE_METHOD, typeUtils);
if (methodOnClass == null) {
return false;
}
Element implementingClass = methodOnClass.getEnclosingElement();
if (implementingClass.getSimpleName().toString().equals("Object")) {
// Don't count default implementation on Object class
return false;
}
// correctly :P)
return true;
}
use of javax.lang.model.element.Element 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");
}
}
Aggregations