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;
}
use of javax.lang.model.type.ExecutableType in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method getMethod.
private SourceMethod getMethod(TypeElement usedMapper, ExecutableElement method, TypeElement mapperToImplement, MapperConfiguration mapperConfig, List<SourceMethod> prototypeMethods) {
ExecutableType methodType = typeFactory.getMethodType((DeclaredType) usedMapper.asType(), method);
List<Parameter> parameters = typeFactory.getParameters(methodType, method);
Type returnType = typeFactory.getReturnType(methodType);
boolean methodRequiresImplementation = method.getModifiers().contains(Modifier.ABSTRACT);
boolean containsTargetTypeParameter = SourceMethod.containsTargetTypeParameter(parameters);
// add method with property mappings if an implementation needs to be generated
if ((usedMapper.equals(mapperToImplement)) && methodRequiresImplementation) {
return getMethodRequiringImplementation(methodType, method, parameters, containsTargetTypeParameter, mapperConfig, prototypeMethods, mapperToImplement);
} else // otherwise add reference to existing mapper method
if (isValidReferencedMethod(parameters) || isValidFactoryMethod(method, parameters, returnType) || isValidLifecycleCallbackMethod(method, returnType)) {
return getReferencedMethod(usedMapper, methodType, method, mapperToImplement, parameters);
} else {
return null;
}
}
use of javax.lang.model.type.ExecutableType in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method getMethodRequiringImplementation.
private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, ExecutableElement method, List<Parameter> parameters, boolean containsTargetTypeParameter, MapperConfiguration mapperConfig, List<SourceMethod> prototypeMethods, TypeElement mapperToImplement) {
Type returnType = typeFactory.getReturnType(methodType);
List<Type> exceptionTypes = typeFactory.getThrownTypes(methodType);
List<Parameter> sourceParameters = Parameter.getSourceParameters(parameters);
List<Parameter> contextParameters = Parameter.getContextParameters(parameters);
Parameter targetParameter = extractTargetParameter(parameters);
Type resultType = selectResultType(returnType, targetParameter);
boolean isValid = checkParameterAndReturnType(method, sourceParameters, targetParameter, contextParameters, resultType, returnType, containsTargetTypeParameter);
if (!isValid) {
return null;
}
ParameterProvidedMethods contextProvidedMethods = retrieveLifecycleMethodsFromContext(contextParameters, mapperToImplement, mapperConfig);
return new SourceMethod.Builder().setExecutable(method).setParameters(parameters).setReturnType(returnType).setExceptionTypes(exceptionTypes).setMappings(getMappings(method)).setIterableMapping(IterableMapping.fromPrism(IterableMappingPrism.getInstanceOn(method), method, messager, typeUtils)).setMapMapping(MapMapping.fromPrism(MapMappingPrism.getInstanceOn(method), method, messager, typeUtils)).setBeanMapping(BeanMapping.fromPrism(BeanMappingPrism.getInstanceOn(method), method, messager, typeUtils)).setValueMappings(getValueMappings(method)).setTypeUtils(typeUtils).setMessager(messager).setTypeFactory(typeFactory).setMapperConfiguration(mapperConfig).setPrototypeMethods(prototypeMethods).setContextProvidedMethods(contextProvidedMethods).build();
}
use of javax.lang.model.type.ExecutableType in project react4j by react4j.
the class BuilderGenerator method buildStaticStepMethodMethod.
@Nonnull
private static MethodSpec buildStaticStepMethodMethod(@Nonnull final ProcessingEnvironment processingEnv, @Nonnull final ViewDescriptor descriptor, @Nonnull final Step step, @Nonnull final StepMethod stepMethod) {
final MethodSpec.Builder method = MethodSpec.methodBuilder(stepMethod.getName()).addAnnotation(GeneratorUtil.NONNULL_CLASSNAME);
method.addModifiers(Modifier.STATIC);
if (descriptor.getDeclaredType().asElement().getModifiers().contains(Modifier.PUBLIC)) {
method.addModifiers(Modifier.PUBLIC);
}
GeneratorUtil.copyTypeParameters(descriptor.getElement(), method);
if (stepMethod.isBuildIntrinsic()) {
method.addStatement("return newBuilder().build()");
} else {
final TypeName type = stepMethod.getType();
final ParameterSpec.Builder parameter = ParameterSpec.builder(type, stepMethod.getName(), Modifier.FINAL);
final ExecutableElement inputMethod = stepMethod.getMethod();
if (null != inputMethod) {
GeneratorUtil.copyWhitelistedAnnotations(inputMethod, parameter);
final ExecutableType methodType = stepMethod.getMethodType();
assert null != methodType;
SuppressWarningsUtil.addSuppressWarningsIfRequired(processingEnv, parameter, methodType.getReturnType());
} else if (stepMethod.isChildrenStreamIntrinsic()) {
parameter.addAnnotation(GeneratorUtil.NONNULL_CLASSNAME);
}
if (type instanceof ArrayTypeName) {
method.varargs();
}
method.addParameter(parameter.build());
final String infix = asTypeArgumentsInfix(descriptor.getDeclaredType());
if (infix.isEmpty()) {
// No type parameters
method.addStatement("return newBuilder().$N( $N )", stepMethod.getName(), stepMethod.getName());
} else {
method.addStatement("return $T." + infix + "newBuilder().$N( $N )", descriptor.getBuilderClassName(), stepMethod.getName(), stepMethod.getName());
}
}
configureStepMethodReturns(descriptor, method, step, stepMethod.getStepMethodType());
return method.build();
}
Aggregations