Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the link between creators and parent handlers #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@ enum class AxonAnnotation(val annotationName: String) {
AGGREGATE_MEMBER("org.axonframework.modelling.command.AggregateMember"),
ROUTING_KEY("org.axonframework.commandhandling.RoutingKey"),
ENTITY_ID("org.axonframework.modelling.command.EntityId"),
PROCESSING_GROUP("org.axonframework.config.ProcessingGroup")
PROCESSING_GROUP("org.axonframework.config.ProcessingGroup"),
SAGA("org.axonframework.config.ProcessingGroup")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this refer to the sage annotation instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore, what does this change have to do with the PR's intent of removing the link between creators and parent handlers?

;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,12 +27,5 @@ interface MessageCreator : PsiElementWrapper {
* it's the payload type.
*/
val payload: String

/**
* The parent handler that published the message. For example, if this MessageCreator represents an event
* created by a CommandHandler, the parentHandler will be that CommandHandler.
* The same applied for commands created by a SagaEventHandler, among others.
*/
val parentHandler: Handler?
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@ package org.axonframework.intellij.ide.plugin.api

import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import org.axonframework.intellij.ide.plugin.util.containingClassname
import org.axonframework.intellij.ide.plugin.util.toViewText
import org.jetbrains.uast.UMethod
import org.jetbrains.uast.getParentOfType
import org.jetbrains.uast.toUElement
Expand All @@ -40,7 +40,7 @@ interface PsiElementWrapper {
fun renderText(): String {
val methodParent = element.toUElement()?.getParentOfType<UMethod>()
if (methodParent != null) {
return methodParent.containingClassname() + "." + methodParent.name
return methodParent.toViewText()
}

if (element is PsiClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ClassLineMarkerProvider : LineMarkerProvider {
if (handlers.isNotEmpty()) {
return AxonNavigationGutterIconRenderer(
icon = AxonIcons.Axon,
popupTitle = "Axon References To This Class",
popupTitle = "Axon References To $qualifiedName",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bug fix you've sneaked into this PR.

tooltipText = "Navigate to message handlers and creations",
emptyText = "No references were found",
elements = NotNullLazyValue.createValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class CommandHandlerMethodLineMarkerProvider : AbstractHandlerLineMarkerProvider
emptyText = "No creators of this message payload were found",
elements = ValidatingLazyValue(element) {
val creatingElements = element.creatorResolver().getCreatorsForPayload(payload)
.distinctBy { it.parentHandler }
interceptingElements + creatingElements
})
.createLineMarkerInfo(element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class CommonHandlerMethodLineMarkerProvider : AbstractHandlerLineMarkerProvider(
emptyText = "No creators of this message payload were found",
elements = ValidatingLazyValue(element) {
element.creatorResolver().getCreatorsForPayload(payload)
.distinctBy { it.parentHandler }
}).createLineMarkerInfo(element)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class DeadlineHandlerMethodLineMarkerProvider : AbstractHandlerLineMarkerProvide
emptyText = "No deadline schedule invocations could be found",
elements = ValidatingLazyValue(element) {
element.deadlineReferenceResolver().findByDeadlineName(deadlineName)
.distinctBy { it.parentHandler }
}).createLineMarkerInfo(element)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,6 @@ import org.axonframework.intellij.ide.plugin.resolving.creators.DefaultMessageCr
import org.axonframework.intellij.ide.plugin.util.axonScope
import org.axonframework.intellij.ide.plugin.util.createCachedValue
import org.axonframework.intellij.ide.plugin.util.deadlineMethodResolver
import org.axonframework.intellij.ide.plugin.util.findParentHandlers
import org.axonframework.intellij.ide.plugin.util.toQualifiedName
import org.jetbrains.uast.UCallExpression
import org.jetbrains.uast.evaluateString
Expand Down Expand Up @@ -117,10 +116,6 @@ class DeadlineManagerReferenceResolver(val project: Project) {
}

private fun createCreators(payload: String, element: PsiElement): List<MessageCreator> {
val parentHandlers = element.findParentHandlers()
if (parentHandlers.isEmpty()) {
return listOf(DefaultMessageCreator(element, payload, null))
}
return parentHandlers.map { DefaultMessageCreator(element, payload, it) }
return listOf(DefaultMessageCreator(element, payload, true))
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,15 +17,13 @@
package org.axonframework.intellij.ide.plugin.resolving

import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.search.searches.MethodReferencesSearch
import com.intellij.psi.util.CachedValue
import org.axonframework.intellij.ide.plugin.api.MessageCreator
import org.axonframework.intellij.ide.plugin.resolving.creators.DefaultMessageCreator
import org.axonframework.intellij.ide.plugin.util.areAssignable
import org.axonframework.intellij.ide.plugin.util.axonScope
import org.axonframework.intellij.ide.plugin.util.createCachedValue
import org.axonframework.intellij.ide.plugin.util.findParentHandlers
import org.axonframework.intellij.ide.plugin.util.handlerResolver
import org.axonframework.intellij.ide.plugin.util.javaFacade
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -74,17 +72,9 @@ class MessageCreationResolver(private val project: Project) {
val methods = clazz.constructors + clazz.methods.filter { it.name.contains("build", ignoreCase = true) }
methods
.flatMap { MethodReferencesSearch.search(it, project.axonScope(), true) }
.flatMap { ref -> createCreators(typeFqn, ref.element) }
.map { ref -> DefaultMessageCreator(ref.element, typeFqn, false) }
.distinct()
}
}
}

private fun createCreators(payload: String, element: PsiElement): List<MessageCreator> {
val parentHandlers = element.findParentHandlers()
if (parentHandlers.isEmpty()) {
return listOf(DefaultMessageCreator(element, payload, null))
}
return parentHandlers.map { DefaultMessageCreator(element, payload, it) }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,8 +18,8 @@ package org.axonframework.intellij.ide.plugin.resolving.creators

import com.intellij.psi.PsiElement
import org.axonframework.intellij.ide.plugin.AxonIcons
import org.axonframework.intellij.ide.plugin.api.Handler
import org.axonframework.intellij.ide.plugin.api.MessageCreator
import org.jetbrains.kotlin.idea.core.util.getLineNumber
import javax.swing.Icon

/**
Expand All @@ -34,7 +34,7 @@ import javax.swing.Icon
data class DefaultMessageCreator(
override val element: PsiElement,
override val payload: String,
override val parentHandler: Handler?,
val isDeadline: Boolean = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR now seems to implement more than just removal of linked parent handlers to creators. Was that intended?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of the previous answer, having something called "default message creator" have a concept of whether it's a deadline makes it less default to me. I'd more so think you'd be dealing with a specific DeadlineMessageCreator in this case.

) : MessageCreator {

/**
Expand All @@ -45,9 +45,13 @@ data class DefaultMessageCreator(
}

override fun renderText(): String {
if (parentHandler != null) {
return parentHandler.renderText()
return super.renderText() + ":" + element.getLineNumber()
}

override fun renderContainerText(): String? {
if (isDeadline) {
return payload
}
return super.renderText()
return null
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@ import org.axonframework.intellij.ide.plugin.util.toQualifiedName
/**
* Searches for any event handlers that are not part of the aggregate model.
*
* @see org.axonframework.intellij.ide.plugin.handlers.types.EventHandler
* @see org.axonframework.intellij.ide.plugin.resolving.handlers.types.EventHandler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a documentation fix you've sneaked into this PR.

*/
class EventHandlerSearcher : AbstractHandlerSearcher(MessageHandlerType.EVENT) {
override fun createMessageHandler(method: PsiMethod, annotation: PsiClass?): Handler? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@ import com.intellij.psi.PsiMethod
import org.axonframework.intellij.ide.plugin.api.Handler
import org.axonframework.intellij.ide.plugin.api.MessageHandlerType
import org.axonframework.intellij.ide.plugin.util.toShortName
import org.axonframework.intellij.ide.plugin.util.toViewText

/**
* Represents a method being able to handle a command.
Expand All @@ -34,6 +35,10 @@ data class CommandHandler(
) : Handler {
override val handlerType: MessageHandlerType = MessageHandlerType.COMMAND

override fun renderText(): String {
return element.toViewText()
}

override fun renderContainerText(): String {
return componentName.toShortName()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@ import com.intellij.psi.PsiMethod
import org.axonframework.intellij.ide.plugin.AxonIcons
import org.axonframework.intellij.ide.plugin.api.Handler
import org.axonframework.intellij.ide.plugin.api.MessageHandlerType
import org.axonframework.intellij.ide.plugin.util.toShortName
import org.axonframework.intellij.ide.plugin.util.toViewText
import javax.swing.Icon

/**
Expand All @@ -37,11 +37,11 @@ data class CommandHandlerInterceptor(
override val handlerType: MessageHandlerType = MessageHandlerType.COMMAND_INTERCEPTOR

override fun renderText(): String {
return "Command Interceptor of ${componentName.toShortName()}"
return element.toViewText()
}

override fun renderContainerText(): String {
return element.name
return "Command interceptor"
}

override fun getIcon(): Icon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ package org.axonframework.intellij.ide.plugin.resolving.handlers.types
import com.intellij.psi.PsiMethod
import org.axonframework.intellij.ide.plugin.api.Handler
import org.axonframework.intellij.ide.plugin.api.MessageHandlerType
import org.axonframework.intellij.ide.plugin.util.toViewText

/**
* Represents a method being able to a deadline message. Invoked when a deadline expires.
Expand All @@ -33,6 +34,6 @@ data class DeadlineHandler(
override val handlerType: MessageHandlerType = MessageHandlerType.DEADLINE

override fun renderText(): String {
return "Deadline $deadlineName"
return element.toViewText()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@ package org.axonframework.intellij.ide.plugin.resolving.handlers.types
import com.intellij.psi.PsiMethod
import org.axonframework.intellij.ide.plugin.api.Handler
import org.axonframework.intellij.ide.plugin.api.MessageHandlerType
import org.axonframework.intellij.ide.plugin.util.containingClassname
import org.axonframework.intellij.ide.plugin.util.toViewText

/**
* Represents a method being able to handle an event. There are more specific event handlers (`EventSourcingHandler` and
Expand All @@ -40,7 +40,7 @@ data class EventHandler(
override val handlerType: MessageHandlerType = MessageHandlerType.EVENT

override fun renderText(): String {
return element.containingClassname().ifEmpty { "Event Processor" }
return element.toViewText()
}

override fun renderContainerText(): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@ package org.axonframework.intellij.ide.plugin.resolving.handlers.types
import com.intellij.psi.PsiMethod
import org.axonframework.intellij.ide.plugin.api.Handler
import org.axonframework.intellij.ide.plugin.api.MessageHandlerType
import org.axonframework.intellij.ide.plugin.util.toShortName
import org.axonframework.intellij.ide.plugin.util.toViewText

/**
* Represents a method being able to handle an event for sourcing an aggregate.
Expand All @@ -35,6 +35,10 @@ data class EventSourcingHandler(
override val handlerType: MessageHandlerType = MessageHandlerType.EVENT_SOURCING

override fun renderText(): String {
return "EventSourcingHandler " + entity.toShortName()
return element.toViewText()
}

override fun renderContainerText(): String {
return "EventSourcingHandler"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022. Axon Framework
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@ package org.axonframework.intellij.ide.plugin.resolving.handlers.types
import com.intellij.psi.PsiMethod
import org.axonframework.intellij.ide.plugin.api.Handler
import org.axonframework.intellij.ide.plugin.api.MessageHandlerType
import org.axonframework.intellij.ide.plugin.util.containingClassname
import org.axonframework.intellij.ide.plugin.util.toViewText

/**
* Represents a method being able to handle a query.
Expand All @@ -35,7 +35,7 @@ data class QueryHandler(
override val handlerType: MessageHandlerType = MessageHandlerType.QUERY

override fun renderText(): String {
return "${element.containingClassname()}.${element.name}"
return element.toViewText()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am certainly not deep enough into this stuff to understand how this solves the predicament of this PR. Would you care to explain this?

}

override fun renderContainerText(): String {
Expand Down
Loading