use of com.google.j2objc.annotations.OnDealloc in project j2objc by google.
the class DestructorGenerator method getOnDeallocMethodDeclaration.
private static MethodDeclaration getOnDeallocMethodDeclaration(AbstractTypeDeclaration typeDeclaration) {
List<MethodDeclaration> onDeallocMethodDeclarations = ImmutableList.copyOf(Iterables.filter(Iterables.transform(typeDeclaration.getBodyDeclarations(), bodyDeclaration -> {
if (!(bodyDeclaration instanceof MethodDeclaration)) {
return null;
}
MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
ExecutableElement executableElement = methodDeclaration.getExecutableElement();
if (!ElementUtil.hasAnnotation(executableElement, OnDealloc.class)) {
return null;
}
if (!executableElement.getModifiers().contains(Modifier.PRIVATE)) {
ErrorUtil.error(methodDeclaration, "@OnDealloc method must be private.");
return null;
}
if (executableElement.getModifiers().contains(Modifier.STATIC)) {
ErrorUtil.error(methodDeclaration, "@OnDealloc method must be non-static.");
return null;
}
if (!TypeUtil.isVoid(executableElement.getReturnType())) {
ErrorUtil.error(methodDeclaration, "@OnDealloc method must return void.");
return null;
}
if (!executableElement.getParameters().isEmpty()) {
ErrorUtil.error(methodDeclaration, "@OnDealloc method must have no parameters.");
return null;
}
return methodDeclaration;
}), Predicates.notNull()));
int size = onDeallocMethodDeclarations.size();
if (size > 1) {
ErrorUtil.error("There can be at most one @OnDealloc method.");
return null;
}
return size == 0 ? null : onDeallocMethodDeclarations.get(0);
}
Aggregations