use of javax.lang.model.type.ExecutableType in project arez by arez.
the class ComponentDescriptor method buildRepository.
/**
* Build the enhanced class for the component.
*/
@Nonnull
TypeSpec buildRepository(@Nonnull final Types typeUtils) throws ArezProcessorException {
assert null != _repositoryExtensions;
final TypeElement element = getElement();
final ClassName arezType = ClassName.get(getPackageName(), getArezClassName());
final TypeSpec.Builder builder = TypeSpec.classBuilder(getRepositoryName()).addTypeVariables(ProcessorUtil.getTypeArgumentsAsNames(asDeclaredType()));
builder.addAnnotation(AnnotationSpec.builder(Generated.class).addMember("value", "$S", ArezProcessor.class.getName()).build());
final boolean addSingletonAnnotation = "ENABLE".equals(_repositoryInjectConfig) || ("AUTODETECT".equals(_repositoryInjectConfig) && _injectClassesPresent);
final AnnotationSpec.Builder arezComponent = AnnotationSpec.builder(ClassName.bestGuess(Constants.COMPONENT_ANNOTATION_CLASSNAME));
if (!addSingletonAnnotation) {
arezComponent.addMember("nameIncludesId", "false");
}
if (!"AUTODETECT".equals(_repositoryInjectConfig)) {
arezComponent.addMember("inject", "$T.$N", GeneratorUtil.INJECTIBLE_CLASSNAME, _repositoryInjectConfig);
}
if (!"AUTODETECT".equals(_repositoryDaggerConfig)) {
arezComponent.addMember("dagger", "$T.$N", GeneratorUtil.INJECTIBLE_CLASSNAME, _repositoryDaggerConfig);
}
builder.addAnnotation(arezComponent.build());
if (addSingletonAnnotation) {
builder.addAnnotation(GeneratorUtil.SINGLETON_CLASSNAME);
}
builder.superclass(ParameterizedTypeName.get(GeneratorUtil.ABSTRACT_REPOSITORY_CLASSNAME, getIdType().box(), ClassName.get(element), ClassName.get(getPackageName(), getRepositoryName())));
_repositoryExtensions.forEach(e -> builder.addSuperinterface(TypeName.get(e.asType())));
ProcessorUtil.copyAccessModifiers(element, builder);
builder.addModifiers(Modifier.ABSTRACT);
// Add the default access, no-args constructor
builder.addMethod(MethodSpec.constructorBuilder().build());
// Add the factory method
builder.addMethod(buildFactoryMethod());
for (final ExecutableElement constructor : ProcessorUtil.getConstructors(element)) {
final ExecutableType methodType = (ExecutableType) typeUtils.asMemberOf((DeclaredType) _element.asType(), constructor);
builder.addMethod(buildRepositoryCreate(constructor, methodType, arezType));
}
if (null != _componentId) {
builder.addMethod(buildFindByIdMethod());
builder.addMethod(buildGetByIdMethod());
}
return builder.build();
}
use of javax.lang.model.type.ExecutableType in project arez by arez.
the class ComponentDescriptor method buildConstructors.
/**
* Build all constructors as they appear on the ArezComponent class.
* Arez Observable fields are populated as required and parameters are passed up to superclass.
*/
private void buildConstructors(@Nonnull final TypeSpec.Builder builder, @Nonnull final Types typeUtils) {
final boolean requiresDeprecatedSuppress = hasDeprecatedElements();
for (final ExecutableElement constructor : ProcessorUtil.getConstructors(getElement())) {
final ExecutableType methodType = (ExecutableType) typeUtils.asMemberOf((DeclaredType) _element.asType(), constructor);
builder.addMethod(buildConstructor(constructor, methodType, requiresDeprecatedSuppress));
}
}
use of javax.lang.model.type.ExecutableType in project arez by arez.
the class ProcessorUtil method processMethod.
private static void processMethod(@Nonnull final Elements elementUtils, @Nonnull final Types typeUtils, @Nonnull final TypeElement typeElement, @Nonnull final Map<String, ArrayList<ExecutableElement>> methods, @Nonnull final ExecutableElement method) {
final ExecutableType methodType = (ExecutableType) typeUtils.asMemberOf((DeclaredType) typeElement.asType(), method);
final String key = method.getSimpleName().toString();
final ArrayList<ExecutableElement> elements = methods.computeIfAbsent(key, k -> new ArrayList<>());
boolean found = false;
final int size = elements.size();
for (int i = 0; i < size; i++) {
final ExecutableElement executableElement = elements.get(i);
if (method.equals(executableElement)) {
found = true;
break;
} else if (isSubsignature(typeUtils, typeElement, methodType, executableElement)) {
if (!isAbstractInterfaceMethod(method)) {
elements.set(i, method);
}
found = true;
break;
} else if (elementUtils.overrides(method, executableElement, typeElement)) {
elements.set(i, method);
found = true;
break;
}
}
if (!found) {
elements.add(method);
}
}
use of javax.lang.model.type.ExecutableType in project arez by arez.
the class ProcessorUtil method isSubsignature.
private static boolean isSubsignature(@Nonnull final Types typeUtils, @Nonnull final TypeElement typeElement, @Nonnull final ExecutableType methodType, @Nonnull final ExecutableElement candidate) {
final ExecutableType candidateType = (ExecutableType) typeUtils.asMemberOf((DeclaredType) typeElement.asType(), candidate);
final boolean isEqual = methodType.equals(candidateType);
final boolean isSubsignature = typeUtils.isSubsignature(methodType, candidateType);
return isSubsignature || isEqual;
}
use of javax.lang.model.type.ExecutableType in project ceylon by eclipse.
the class P method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!ran) {
ran = true;
ExecutableElement m = getFirstMethodIn("C");
System.err.println("method: " + m);
TypeMirror type = (DeclaredType) m.getParameters().get(0).asType();
System.err.println("parameters[0]: " + type);
if (!isParameterized(type))
throw new AssertionError(type);
type = ((ExecutableType) m.asType()).getParameterTypes().get(0);
System.err.println("parameterTypes[0]: " + type);
if (!isParameterized(type))
throw new AssertionError(type);
System.err.println();
}
return true;
}
Aggregations