use of javax.lang.model.type.TypeMirror in project qpid-broker-j by apache.
the class AttributeAnnotationValidator method checkMethodReturnTypeIsNumberOrDate.
private void checkMethodReturnTypeIsNumberOrDate(final TypeElement annotationElement, final ExecutableElement methodElement) {
TypeMirror numberType = elementUtils.getTypeElement("java.lang.Number").asType();
TypeMirror dateType = elementUtils.getTypeElement("java.util.Date").asType();
if (!typeUtils.isAssignable(methodElement.getReturnType(), numberType) && !typeUtils.isSameType(methodElement.getReturnType(), dateType)) {
messager.printMessage(Diagnostic.Kind.ERROR, "@" + annotationElement.getSimpleName() + " return type does not extend java.lang.Number" + " and is not java.util.Date : " + methodElement.getReturnType().toString(), methodElement);
}
}
use of javax.lang.model.type.TypeMirror in project qpid-broker-j by apache.
the class OperationAnnotationValidator method checkInterfaceExtendsConfiguredObject.
public void checkInterfaceExtendsConfiguredObject(final TypeElement annotationElement, final Element e) {
Types typeUtils = processingEnv.getTypeUtils();
TypeMirror configuredObjectType = getErasure("org.apache.qpid.server.model.ConfiguredObject");
TypeElement parent = (TypeElement) e.getEnclosingElement();
if (!typeUtils.isAssignable(typeUtils.erasure(parent.asType()), configuredObjectType)) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@" + annotationElement.getSimpleName() + " can only be applied to methods within an interface which extends " + configuredObjectType.toString() + " which does not apply to " + parent.asType().toString(), e);
}
}
use of javax.lang.model.type.TypeMirror in project react4j by react4j.
the class ProcessorUtil method enumerateMethods.
private static void enumerateMethods(@Nonnull final TypeElement scope, @Nonnull final Types typeUtils, @Nonnull final TypeElement element, @Nonnull final Map<String, ExecutableElement> methods) {
final TypeMirror superclass = element.getSuperclass();
if (TypeKind.NONE != superclass.getKind()) {
enumerateMethods(scope, typeUtils, (TypeElement) ((DeclaredType) superclass).asElement(), methods);
}
for (final TypeMirror interfaceType : element.getInterfaces()) {
final TypeElement interfaceElement = (TypeElement) ((DeclaredType) interfaceType).asElement();
enumerateMethods(scope, typeUtils, interfaceElement, methods);
}
for (final Element member : element.getEnclosedElements()) {
if (member.getKind() == ElementKind.METHOD) {
final ExecutableType methodType = (ExecutableType) typeUtils.asMemberOf((DeclaredType) scope.asType(), member);
methods.put(member.getSimpleName() + methodType.toString(), (ExecutableElement) member);
}
}
}
use of javax.lang.model.type.TypeMirror in project butterknife by JakeWharton.
the class ButterKnifeProcessor method isSubtypeOfType.
static boolean isSubtypeOfType(TypeMirror typeMirror, String otherType) {
if (isTypeEqual(typeMirror, otherType)) {
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 butterknife by JakeWharton.
the class ButterKnifeProcessor method parseResourceColor.
private void parseResourceColor(Element element, Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames) {
boolean hasError = false;
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
// Verify that the target type is int or ColorStateList.
boolean isColorStateList = false;
TypeMirror elementType = element.asType();
if (COLOR_STATE_LIST_TYPE.equals(elementType.toString())) {
isColorStateList = true;
} else if (elementType.getKind() != TypeKind.INT) {
error(element, "@%s field type must be 'int' or 'ColorStateList'. (%s.%s)", BindColor.class.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName());
hasError = true;
}
// Verify common generated code restrictions.
hasError |= isInaccessibleViaGeneratedCode(BindColor.class, "fields", element);
hasError |= isBindingInWrongPackage(BindColor.class, element);
if (hasError) {
return;
}
// Assemble information on the field.
String name = element.getSimpleName().toString();
int id = element.getAnnotation(BindColor.class).value();
QualifiedId qualifiedId = elementToQualifiedId(element, id);
BindingSet.Builder builder = getOrCreateBindingBuilder(builderMap, enclosingElement);
builder.addResource(new FieldResourceBinding(getId(qualifiedId), name, isColorStateList ? FieldResourceBinding.Type.COLOR_STATE_LIST : FieldResourceBinding.Type.COLOR));
erasedTargetNames.add(enclosingElement);
}
Aggregations