User: nel Date: 20 Jun 24 23:02 Revision: 41240cad956f4148291c28c4c25775de27cc874e Summary: fix: #2316 (#2317) TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9333&personal=false Index: src/main/kotlin/platform/sponge/inspection/SpongeInjectionInspection.kt =================================================================== --- src/main/kotlin/platform/sponge/inspection/SpongeInjectionInspection.kt (revision 4bb60870ed26865a53d9c7375ef4b2eba04df967) +++ src/main/kotlin/platform/sponge/inspection/SpongeInjectionInspection.kt (revision 41240cad956f4148291c28c4c25775de27cc874e) @@ -244,11 +244,13 @@ ) } } - "ninja.leaping.configurate.loader.ConfigurationLoader" -> { + "ninja.leaping.configurate.loader.ConfigurationLoader", + "org.spongepowered.configurate.reference.ConfigurationReference", + "org.spongepowered.configurate.loader.ConfigurationLoader" -> { if (defaultConfig == null) { holder.registerProblem( variable.nameIdentifier ?: variable, - "Injected ConfigurationLoader must be annotated with @DefaultConfig.", + "Injected ${classType.name} must be annotated with @DefaultConfig.", ProblemHighlightType.GENERIC_ERROR, AddAnnotationFix(SpongeConstants.DEFAULT_CONFIG_ANNOTATION, annotationsOwner), ) @@ -257,7 +259,7 @@ if (configDir != null) { holder.registerProblem( configDir, - "Injected ConfigurationLoader cannot be annotated with @ConfigDir.", + "Injected ${classType.name} cannot be annotated with @ConfigDir.", ProblemHighlightType.GENERIC_ERROR, QuickFixFactory.getInstance().createDeleteFix(configDir, "Remove @ConfigDir"), ) @@ -267,7 +269,7 @@ val ref = classType.reference holder.registerProblem( ref, - "Injected ConfigurationLoader must have a generic parameter.", + "Injected ${classType.name} must have a generic parameter.", ProblemHighlightType.GENERIC_ERROR, MissingConfLoaderTypeParamFix(ref), ) @@ -275,14 +277,17 @@ classType.parameters.firstOrNull()?.let { param -> val paramType = param as? PsiClassReferenceType ?: return@let val paramTypeFQName = paramType.fullQualifiedName ?: return@let - if (paramTypeFQName != "ninja.leaping.configurate.commented.CommentedConfigurationNode") { + if ( + paramTypeFQName != "ninja.leaping.configurate.commented.CommentedConfigurationNode" && + paramTypeFQName != "org.spongepowered.configurate.CommentedConfigurationNode" + ) { val ref = param.reference holder.registerProblem( ref, "Injected ConfigurationLoader generic parameter must be " + "CommentedConfigurationNode.", ProblemHighlightType.GENERIC_ERROR, - WrongConfLoaderTypeParamFix(ref), + WrongConfLoaderTypeParamFix(classType.className, ref), ) } } @@ -371,7 +376,8 @@ } } - class WrongConfLoaderTypeParamFix(ref: PsiJavaCodeReferenceElement) : LocalQuickFixOnPsiElement(ref) { + class WrongConfLoaderTypeParamFix(private val clazzName: String, param: PsiJavaCodeReferenceElement) : + LocalQuickFixOnPsiElement(param) { override fun getFamilyName(): String = name @@ -379,7 +385,11 @@ override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) { val newRef = JavaPsiFacade.getElementFactory(project).createReferenceFromText( - "ninja.leaping.configurate.commented.CommentedConfigurationNode", + when (clazzName) { + "ninja.leaping.configurate.loader.ConfigurationLoader" -> + "ninja.leaping.configurate.commented.CommentedConfigurationNode" + else -> { "org.spongepowered.configurate.CommentedConfigurationNode" } + }, startElement, ) startElement.replace(newRef) @@ -393,11 +403,23 @@ override fun getText(): String = "Insert generic parameter" override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) { - val newRef = JavaPsiFacade.getElementFactory(project).createReferenceFromText( + val newRef: PsiElement = if ( + JavaPsiFacade.getInstance(project) + .findPackage("ninja.leaping.configurate") != null + ) { + JavaPsiFacade.getElementFactory(project).createReferenceFromText( - "ninja.leaping.configurate.loader.ConfigurationLoader" + - "", + "ninja.leaping.configurate.loader.ConfigurationLoader" + + "", - startElement, + startElement - ) + ) + } else { + JavaPsiFacade.getElementFactory(project).createReferenceFromText( + "org.spongepowered.configurate.loader.ConfigurationLoader" + + "", + startElement + ) + } + startElement.replace(newRef) } }