@@ -35,7 +35,7 @@ import javax.swing.Icon as JIcon
3535class TypeMappingPackageLineMarker : RelatedItemLineMarkerProvider () {
3636 private val log: Logger = LoggerFactory .getLogger(this .javaClass.name)
3737
38- class Renderer () : PsiTargetPresentationRenderer<PsiElement>() {
38+ class Renderer (private val userDataKey : Key < String > ) : PsiTargetPresentationRenderer<PsiElement>() {
3939
4040 override fun getContainerText (element : PsiElement ): String? {
4141 return getSymbolContainerText(element)
@@ -55,7 +55,7 @@ class TypeMappingPackageLineMarker : RelatedItemLineMarkerProvider() {
5555 }
5656
5757 val moduleLocation = getModuleLocation(element)
58- val packageLocation = element.getUserData(PACKAGE_LOCATION_USER_KEY )
58+ val packageLocation = element.getUserData(userDataKey )
5959 val locationText = if (packageLocation == null ) {
6060 moduleLocation?.text
6161 } else {
@@ -74,13 +74,15 @@ class TypeMappingPackageLineMarker : RelatedItemLineMarkerProvider() {
7474 }
7575 }
7676
77- class GotoPackage (element : PsiDirectory ): GotoRelatedItem(element, Goto .I18n .GROUP ) {
77+ class GotoPackage (element : PsiDirectory , private val userDataKey : Key <String >):
78+ GotoRelatedItem (element, Goto .I18n .GROUP ) {
79+
7880 override fun getCustomName (): String {
7981 return " ${getSymbolPresentableText(this .element!! )} "
8082 }
8183
8284 override fun getCustomContainerName (): String {
83- val loc = element!! .getUserData(PACKAGE_LOCATION_USER_KEY )!!
85+ val loc = element!! .getUserData(userDataKey )!!
8486 val pkg = getSymbolContainerText(element!! )!!
8587 return " $pkg - $loc "
8688 }
@@ -94,16 +96,31 @@ class TypeMappingPackageLineMarker : RelatedItemLineMarkerProvider() {
9496 if (! isMapping)
9597 return
9698
97- if (element.text != PACKAGE_KEY )
98- return
99+ if (element.text == PACKAGE_NAME_KEY ) {
100+ val info = createLineMarkerInfo(element, PACKAGE_NAME_USER_KEY )
101+ if (info != null ) {
102+ result.add(info)
103+ }
104+ }
99105
100- val info = createLineMarkerInfo(element)
101- ? : return
106+ if (element.text == PACKAGE_BASE_KEY ) {
107+ // todo check package-names parent key
108+ val info = createLineMarkerInfo(element, PACKAGE_NAMES_BASE_USER_KEY )
109+ if (info != null ) {
110+ result.add(info)
111+ }
112+ }
102113
103- result.add(info)
114+ if (element.text == PACKAGE_LOCATION_KEY ) {
115+ // todo check package-names parent key
116+ val info = createLineMarkerInfo(element, PACKAGE_NAMES_LOCATION_USER_KEY )
117+ if (info != null ) {
118+ result.add(info)
119+ }
120+ }
104121 }
105122
106- private fun createLineMarkerInfo (packageKey : PsiElement ): RelatedItemLineMarkerInfo <* >? {
123+ private fun createLineMarkerInfo (packageKey : PsiElement , userDataKey : Key < String > ): RelatedItemLineMarkerInfo <* >? {
107124 val packageKeyValue = packageKey.parent
108125 if (packageKeyValue !is YAMLKeyValue )
109126 return null
@@ -115,7 +132,7 @@ class TypeMappingPackageLineMarker : RelatedItemLineMarkerProvider() {
115132 val pkgDirs = service<TargetPackageService >()
116133 .findPackageDirs(pkgName, module)
117134
118- val targets = addLocations(pkgDirs)
135+ val targets = addLocations(pkgDirs, userDataKey )
119136 if (targets.isEmpty()) {
120137 log.warn(" found no targets!" )
121138 return null
@@ -125,16 +142,16 @@ class TypeMappingPackageLineMarker : RelatedItemLineMarkerProvider() {
125142 .create<PsiDirectory >(
126143 Icon .`package`,
127144 { listOf (it) },
128- { listOf (GotoPackage (it)) })
145+ { listOf (GotoPackage (it, userDataKey )) })
129146 .setTooltipText(I18n .TOOLTIP_TEXT )
130147 .setPopupTitle(I18n .POPUP_TITLE )
131148 .setTargets(targets)
132- .setTargetRenderer { Renderer () }
149+ .setTargetRenderer { Renderer (userDataKey ) }
133150
134151 return builder.createLineMarkerInfo(packageKey)
135152 }
136153
137- private fun addLocations (pkgDirs : List <PsiDirectory >): List <PsiDirectory > {
154+ private fun addLocations (pkgDirs : List <PsiDirectory >, userDataKey : Key < String > ): List <PsiDirectory > {
138155 if (pkgDirs.size < 2 ) {
139156 return pkgDirs
140157 }
@@ -158,7 +175,7 @@ class TypeMappingPackageLineMarker : RelatedItemLineMarkerProvider() {
158175 return pkgDirs
159176 .map {
160177 it.putUserData(
161- PACKAGE_LOCATION_USER_KEY ,
178+ userDataKey ,
162179 it.virtualFile.path.drop(commonPrefix.length).dropLast(commonSuffix.length)
163180 )
164181 it
@@ -188,8 +205,13 @@ class TypeMappingPackageLineMarker : RelatedItemLineMarkerProvider() {
188205 }
189206
190207 companion object {
191- const val PACKAGE_KEY = " package-name"
208+ const val PACKAGE_NAME_KEY = " package-name"
209+ const val PACKAGE_NAMES_KEY = " package-names"
210+ const val PACKAGE_BASE_KEY = " base"
211+ const val PACKAGE_LOCATION_KEY = " location"
192212 }
193213}
194214
195- private val PACKAGE_LOCATION_USER_KEY : Key <String > = Key .create(" openapiprocessor.package-location" )
215+ private val PACKAGE_NAME_USER_KEY : Key <String > = Key .create(" openapiprocessor.package-name" )
216+ private val PACKAGE_NAMES_BASE_USER_KEY : Key <String > = Key .create(" openapiprocessor.package-names.base" )
217+ private val PACKAGE_NAMES_LOCATION_USER_KEY : Key <String > = Key .create(" openapiprocessor.package-names.location" )
0 commit comments