Skip to content

Commit

Permalink
Merge pull request #254 from AxonFramework/fix/235-popup-exception
Browse files Browse the repository at this point in the history
Move to built-in gutter renderer to prevent exception
  • Loading branch information
CodeDrivenMitch authored Oct 27, 2023
2 parents fc06e94 + 926b703 commit 324f3d9
Show file tree
Hide file tree
Showing 25 changed files with 161 additions and 270 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

pluginGroup=io.axoniq.ide.intellij
pluginName=Axon Framework
pluginVersion=0.8.2
axonVersion=4.7.0
pluginVersion=0.8.3
axonVersion=4.9.0

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild = 231
pluginSinceBuild = 232
pluginUntilBuild = 232.*

# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ClassReferenceHierarcyItem(
private val field: PsiField?,
override val element: PsiElement = field ?: clazz,
val depth: Int
) : PsiElementWrapper {
) : PsiElementWrapper, PsiElement by element {

override fun getIcon(): Icon {
return AxonIcons.Axon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import javax.swing.Icon
* @see Handler
* @see MessageCreator
*/
interface PsiElementWrapper {
interface PsiElementWrapper : PsiElement{
val element: PsiElement


Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) (2010-2023). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.axonframework.intellij.ide.plugin.markers

import com.intellij.codeInsight.navigation.impl.PsiTargetPresentationRenderer
import com.intellij.psi.PsiElement
import org.axonframework.intellij.ide.plugin.api.PsiElementWrapper
import javax.swing.Icon

class AxonNavigationTargetRenderer private constructor() : PsiTargetPresentationRenderer<PsiElement>() {

override fun getContainerText(element: PsiElement): String? {
if (element is PsiElementWrapper) {
return element.renderContainerText()
}
return super.getContainerText(element)
}

override fun getElementText(element: PsiElement): String {
if (element is PsiElementWrapper) {
return element.renderText()
}
return super.getElementText(element)
}

override fun getIcon(element: PsiElement): Icon? {
if (element is PsiElementWrapper) {
return element.getIcon()
}
return super.getIcon(element)
}

companion object {
val INSTANCE = AxonNavigationTargetRenderer()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package org.axonframework.intellij.ide.plugin.markers

import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProvider
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder
import com.intellij.openapi.util.NotNullLazyValue
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiField
import org.axonframework.intellij.ide.plugin.AxonIcons
import org.axonframework.intellij.ide.plugin.api.ClassReferenceHierarcyItem
import org.axonframework.intellij.ide.plugin.api.Entity
import org.axonframework.intellij.ide.plugin.markers.handlers.ValidatingLazyValue
import org.axonframework.intellij.ide.plugin.util.aggregateResolver
import org.axonframework.intellij.ide.plugin.util.creatorResolver
import org.axonframework.intellij.ide.plugin.util.handlerResolver
Expand All @@ -47,29 +47,27 @@ class ClassLineMarkerProvider : LineMarkerProvider {
if (!uElement.isAggregate()) {
val handlers = element.handlerResolver().findHandlersForType(qualifiedName)
if (handlers.isNotEmpty()) {
return AxonNavigationGutterIconRenderer(
icon = AxonIcons.Axon,
popupTitle = "Axon References To This Class",
tooltipText = "Navigate to message handlers and creations",
emptyText = "No references were found",
elements = NotNullLazyValue.createValue {
return NavigationGutterIconBuilder.create(AxonIcons.Axon)
.setPopupTitle("Axon References To This Class")
.setTooltipText("Navigate to message handlers and creations")
.setEmptyPopupText("No references were found")
.setTargets(NotNullLazyValue.lazy {
val publishers = element.creatorResolver().getCreatorsForPayload(qualifiedName)
handlers + publishers
}).createLineMarkerInfo(element)
})
.createLineMarkerInfo(element)
}
}

val owner = element.aggregateResolver().getTopEntityOfEntityWithName(qualifiedName) ?: return null
val items = createHierarchy(owner, null, 0)
if (items.isNotEmpty()) {
return AxonNavigationGutterIconRenderer(
icon = AxonIcons.Axon,
popupTitle = "Related Models",
tooltipText = "Navigate to entities in the same command model hierarchy",
emptyText = "No related entities were found",
elements = ValidatingLazyValue(element) {
items
}).createLineMarkerInfo(element)
return NavigationGutterIconBuilder.create(AxonIcons.Axon)
.setPopupTitle("Related Models")
.setTooltipText("Navigate to entities in the same command model hierarchy")
.setEmptyPopupText("No related entities were found")
.setTargets(NotNullLazyValue.lazy { items })
.createLineMarkerInfo(element)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class AbstractHandlerLineMarkerProvider : LineMarkerProvider {
// Do nothing, IntelliJ does not even want us to log it
return null
}
// We don't want to do anything on errors here. As is shown by Sentry exception catching, the process is error-=prone
// We don't want to do anything on errors here. As is shown by Sentry exception catching, the process is error-prone
// mostly due to Kotlin plugin internals. We don't want to pester the user with it.
// Generally, the issue will resolve itself on the next line marker pass anyway.
logger<AbstractHandlerLineMarkerProvider>().error("Got an exception while analyzing line markers in class {}", e, this::class.java.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.axonframework.intellij.ide.plugin.markers.handlers

import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder
import com.intellij.openapi.util.NotNullLazyValue
import com.intellij.psi.PsiElement
import org.axonframework.intellij.ide.plugin.AxonIcons
import org.axonframework.intellij.ide.plugin.api.MessageHandlerType
import org.axonframework.intellij.ide.plugin.api.MessageType
import org.axonframework.intellij.ide.plugin.markers.AxonNavigationGutterIconRenderer
import org.axonframework.intellij.ide.plugin.markers.AxonNavigationTargetRenderer
import org.axonframework.intellij.ide.plugin.resolving.handlers.types.CommandHandlerInterceptor
import org.axonframework.intellij.ide.plugin.util.creatorResolver
import org.axonframework.intellij.ide.plugin.util.handlerResolver
Expand All @@ -43,16 +45,17 @@ class CommandHandlerMethodLineMarkerProvider : AbstractHandlerLineMarkerProvider
.filterIsInstance<CommandHandlerInterceptor>()

val icon = if (interceptingElements.isNotEmpty()) AxonIcons.HandlerIntercepted else AxonIcons.Handler
return AxonNavigationGutterIconRenderer(
icon = icon,
popupTitle = "Payload Creators",
tooltipText = "Navigate to creators of $payload",
emptyText = "No creators of this message payload were found",
elements = ValidatingLazyValue(element) {
val creatingElements = element.creatorResolver().getCreatorsForPayload(payload)
return NavigationGutterIconBuilder.create(icon)
.setTargets(NotNullLazyValue.lazy {
val creatingElements = element.creatorResolver()
.getCreatorsForPayload(payload)
.distinctBy { it.parentHandler }
interceptingElements + creatingElements
})
.setTargetRenderer { AxonNavigationTargetRenderer.INSTANCE }
.setPopupTitle("Payload Creators")
.setTooltipText("Navigate to creators of $payload")
.setEmptyPopupText("No creators of this message payload were found")
.createLineMarkerInfo(element)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.axonframework.intellij.ide.plugin.markers.handlers

import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder
import com.intellij.openapi.util.NotNullLazyValue
import com.intellij.psi.PsiElement
import org.axonframework.intellij.ide.plugin.AxonIcons
import org.axonframework.intellij.ide.plugin.api.MessageHandlerType
import org.axonframework.intellij.ide.plugin.api.MessageType
import org.axonframework.intellij.ide.plugin.markers.AxonNavigationGutterIconRenderer
import org.axonframework.intellij.ide.plugin.markers.AxonNavigationTargetRenderer
import org.axonframework.intellij.ide.plugin.resolving.handlers.types.CommandHandler
import org.axonframework.intellij.ide.plugin.util.aggregateResolver
import org.axonframework.intellij.ide.plugin.util.handlerResolver
Expand All @@ -48,12 +50,8 @@ class CommandInterceptorLineMarkerProvider : AbstractHandlerLineMarkerProvider()
// An interceptor without payload is fine, default to Object to match all
val actualPayload = payload ?: "java.lang.Object"

return AxonNavigationGutterIconRenderer(
icon = AxonIcons.Interceptor,
popupTitle = "Commands Intercepted",
tooltipText = "Navigate to command handlers that are intercepted",
emptyText = "No intercepted command handlers were found",
elements = ValidatingLazyValue(element) {
return NavigationGutterIconBuilder.create(AxonIcons.Interceptor)
.setTargets(NotNullLazyValue.lazy {
val members = element.aggregateResolver().getEntityAndAllChildrenRecursively(className)
element.handlerResolver().findHandlersForType(actualPayload, MessageType.COMMAND)
.filterIsInstance<CommandHandler>()
Expand All @@ -62,6 +60,10 @@ class CommandInterceptorLineMarkerProvider : AbstractHandlerLineMarkerProvider()
members.any { member -> member.name == name }
}
})
.createLineMarkerInfo(element)
.setTargetRenderer { AxonNavigationTargetRenderer.INSTANCE }
.setPopupTitle("Commands Intercepted")
.setTooltipText("Navigate to command handlers that are intercepted")
.setEmptyPopupText("No intercepted command handlers were found")
.createLineMarkerInfo(element, )
}
}
Loading

0 comments on commit 324f3d9

Please sign in to comment.