use of javax.lang.model.type.ExecutableType in project react4j by react4j.
the class Generator method buildPropMethod.
private static MethodSpec.Builder buildPropMethod(@Nonnull final ComponentDescriptor descriptor, @Nonnull final PropDescriptor prop) {
final ExecutableElement methodElement = prop.getMethod();
final ExecutableType methodType = prop.getMethodType();
final TypeMirror returnType = methodType.getReturnType();
final MethodSpec.Builder method = MethodSpec.methodBuilder(methodElement.getSimpleName().toString()).returns(TypeName.get(returnType));
ProcessorUtil.copyTypeParameters(methodType, method);
ProcessorUtil.copyAccessModifiers(methodElement, method);
ProcessorUtil.copyDocumentedAnnotations(methodElement, method);
method.addAnnotation(Override.class);
final String name = prop.getName();
if (descriptor.isArezComponent()) {
final AnnotationSpec.Builder annotation = AnnotationSpec.builder(OBSERVABLE_ANNOTATION_CLASSNAME).addMember("name", "$S", name).addMember("expectSetter", "false");
method.addAnnotation(annotation.build());
}
final Element propType = prop.getPropType();
if (null != propType && descriptor.isArezComponent() && ElementKind.CLASS == propType.getKind()) {
if (null != ProcessorUtil.findAnnotationByType(propType, Constants.AREZ_COMPONENT_ANNOTATION_CLASSNAME)) {
method.addAnnotation(AnnotationSpec.builder(AREZ_DEPENDENCY_CLASSNAME).build());
}
}
final String convertMethodName = getConverter(returnType, methodElement, "Prop");
final String key = "child".equals(name) ? "children" : name;
if (null == ProcessorUtil.findAnnotationByType(methodElement, Constants.NONNULL_ANNOTATION_CLASSNAME)) {
method.addStatement("return props().has( $S ) ? props().getAny( $S ).$N() : null", key, key, convertMethodName);
} else {
method.addStatement("return props().getAny( $S ).$N()", key, convertMethodName);
}
return method;
}
use of javax.lang.model.type.ExecutableType in project lombok by rzwitserloot.
the class HandleDelegate method addMethodBindings.
public void addMethodBindings(List<MethodSig> signatures, ClassType ct, JavacTypes types, Set<String> banList) throws DelegateRecursion {
TypeSymbol tsym = ct.asElement();
if (tsym == null)
return;
for (Symbol member : tsym.getEnclosedElements()) {
for (Compound am : member.getAnnotationMirrors()) {
String name = null;
try {
name = am.type.tsym.flatName().toString();
} catch (Exception ignore) {
}
if ("lombok.Delegate".equals(name) || "lombok.experimental.Delegate".equals(name)) {
throw new DelegateRecursion(ct.tsym.name.toString(), member.name.toString());
}
}
if (member.getKind() != ElementKind.METHOD)
continue;
if (member.isStatic())
continue;
if (member.isConstructor())
continue;
ExecutableElement exElem = (ExecutableElement) member;
if (!exElem.getModifiers().contains(Modifier.PUBLIC))
continue;
ExecutableType methodType = (ExecutableType) types.asMemberOf(ct, member);
String sig = printSig(methodType, member.name, types);
// If add returns false, it was already in there
if (!banList.add(sig))
continue;
boolean isDeprecated = (member.flags() & DEPRECATED) != 0;
signatures.add(new MethodSig(member.name, methodType, isDeprecated, exElem));
}
if (ct.supertype_field instanceof ClassType)
addMethodBindings(signatures, (ClassType) ct.supertype_field, types, banList);
if (ct.interfaces_field != null)
for (Type iface : ct.interfaces_field) {
if (iface instanceof ClassType)
addMethodBindings(signatures, (ClassType) iface, types, banList);
}
}
use of javax.lang.model.type.ExecutableType in project mapstruct by mapstruct.
the class TypeFactory method getReturnType.
public Type getReturnType(DeclaredType includingType, Accessor accessor) {
Type type;
TypeMirror accessorType = getMethodType(includingType, accessor.getElement());
if (isExecutableType(accessorType)) {
type = getType(((ExecutableType) accessorType).getReturnType());
} else {
type = getType(accessorType);
}
return type;
}
use of javax.lang.model.type.ExecutableType in project st-js by st-js.
the class JavaNodes method getEnclosingType.
/**
* <p>getEnclosingType.</p>
*
* @param type a {@link javax.lang.model.type.TypeMirror} object.
* @return a {@link javax.lang.model.type.DeclaredType} object.
*/
public static DeclaredType getEnclosingType(TypeMirror type) {
if (!(type instanceof DeclaredType)) {
return null;
}
DeclaredType declaredType = (DeclaredType) type;
TypeMirror enclosingType = declaredType.asElement().getEnclosingElement().asType();
if (enclosingType instanceof ExecutableType) {
// get the type that encloses this method
enclosingType = declaredType.asElement().getEnclosingElement().getEnclosingElement().asType();
}
if (enclosingType instanceof DeclaredType) {
return (DeclaredType) enclosingType;
}
return null;
}
use of javax.lang.model.type.ExecutableType in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method retrievePrototypeMethods.
private List<SourceMethod> retrievePrototypeMethods(TypeElement mapperTypeElement, MapperConfiguration mapperConfig) {
if (mapperConfig.config() == null) {
return Collections.emptyList();
}
TypeElement typeElement = asTypeElement(mapperConfig.config());
List<SourceMethod> methods = new ArrayList<SourceMethod>();
for (ExecutableElement executable : getAllEnclosedExecutableElements(elementUtils, typeElement)) {
ExecutableType methodType = typeFactory.getMethodType(mapperConfig.config(), executable);
List<Parameter> parameters = typeFactory.getParameters(methodType, executable);
boolean containsTargetTypeParameter = SourceMethod.containsTargetTypeParameter(parameters);
// prototype methods don't have prototypes themselves
List<SourceMethod> prototypeMethods = Collections.emptyList();
SourceMethod method = getMethodRequiringImplementation(methodType, executable, parameters, containsTargetTypeParameter, mapperConfig, prototypeMethods, mapperTypeElement);
if (method != null) {
methods.add(method);
}
}
return methods;
}
Aggregations