Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public <T> Node<T> addNode0(Type type, Class<?>[] tags, Graph.Factory<? extends
return this.addNode0(type, tags, factory, List.of(), dependencies);
}

public <T> Node<T> addNode0(Type type, Class<?>[] tags, Graph.Factory<? extends T> factory, List<? extends Node<? extends GraphInterceptor<T>>> interceptors, Node<?>... dependencies) {
public <T> Node<T> addNode0(Type type, Class<?>[] tags, Graph.Factory<? extends T> factory, List<? extends Node<? extends GraphInterceptor<? super T>>> interceptors, Node<?>... dependencies) {
var dependenciesList = new ArrayList<NodeImpl<?>>();
for (var dependency : dependencies) {
dependenciesList.add((NodeImpl<?>) dependency);
}
@SuppressWarnings("unchecked")
var interceptorsList = new ArrayList<NodeImpl<? extends GraphInterceptor<T>>>();
for (var interceptor : interceptors) {
interceptorsList.add((NodeImpl<? extends GraphInterceptor<T>>) interceptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,7 @@ public boolean isInterceptable(TypeMirror interceptedType, TypeMirror targetType
if (this.types.isSameType(interceptedType, targetType)) {
return true;
} else if (this.types.isAssignable(targetType, interceptedType)) {
// Check if is AopProxy
var typeMirrorElement = types.asElement(targetType);
var annotation = AnnotationUtils.findAnnotation(typeMirrorElement, CommonClassNames.aopProxy);
if (annotation != null) {
var interceptedTypeElement = types.asElement(interceptedType);
var aopProxyName = NameUtils.generatedType(interceptedTypeElement, "_AopProxy");
var expectedAopProxyCanonicalName = elements.getPackageOf(interceptedTypeElement).toString() + "." + aopProxyName;
return expectedAopProxyCanonicalName.equals(typeMirrorElement.toString());
}
return true;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,7 @@ class ServiceTypesHelper(val resolver: Resolver) {
if (targetType == interceptedType.makeNotNullable()) {
return true
} else if (interceptedType.isAssignableFrom(targetType)) {
val aopProxyAnnotation = targetType.declaration.findAnnotation(CommonClassNames.aopProxy)
val proxyDeclaration = interceptedType.declaration
if (aopProxyAnnotation != null && proxyDeclaration.parentDeclaration != null) {
val aopProxyName = proxyDeclaration.getOuterClassesAsPrefix() + proxyDeclaration.simpleName.asString() + "__AopProxy"
val aopProxyCanonical = proxyDeclaration.packageName.asString() + "." + aopProxyName
return aopProxyCanonical == targetType.declaration.qualifiedName!!.asString()
}
return true
}

return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import ru.tinkoff.kora.application.graph.internal.NodeImpl

class GraphInterceptorTests :AbstractKoraAppProcessorTest() {
class GraphInterceptorTests : AbstractKoraAppProcessorTest() {

@Test
fun interceptor() {
Expand Down Expand Up @@ -106,4 +106,37 @@ class GraphInterceptorTests :AbstractKoraAppProcessorTest() {
draw.init()
Assertions.assertThat((draw.nodes[1] as NodeImpl<*>).interceptors).hasSize(1)
}

@Test
fun interceptorForInterface() {
val draw = compile(
"""
import ru.tinkoff.kora.application.graph.GraphInterceptor

@KoraApp
interface ExampleApplication {

interface TestInterface

class TestClass : TestInterface

class TestRoot

class TestInterceptor : GraphInterceptor<TestInterface> {
override fun init(value: TestInterface) = value

override fun release(value: TestInterface) = value
}

@Root
fun root(testClass: TestClass) = TestRoot()

fun interceptor(): TestInterceptor = TestInterceptor()
}
""".trimIndent(),
)
Assertions.assertThat(draw.nodes).hasSize(3)
draw.init()
Assertions.assertThat((draw.nodes[1] as NodeImpl<*>).interceptors).hasSize(1)
}
}
Loading