From d1a52976a3972bd161d01286961dd775820efe6b Mon Sep 17 00:00:00 2001 From: Dmitry Kichinsky Date: Fri, 13 Feb 2026 00:01:59 +0100 Subject: [PATCH] [gradle] IDEA-357140 Migrate Gradle Java Plugin descriptors to V2: properties module GitOrigin-RevId: ac7bb2e345150f6d60c5d261ad98619ed4a8c871 --- .idea/modules.xml | 1 + build/bazel-generated-file-list.txt | 1 + plugins/gradle/java/BUILD.bazel | 4 +- .../src/GradleGroovyElementFeatureProvider.kt | 4 +- plugins/gradle/java/intellij.gradle.java.iml | 3 +- .../java/intellij.gradle.java.tests.iml | 1 + plugins/gradle/java/properties/BUILD.bazel | 34 +++++++++++ .../intellij.gradle.java.properties.iml | 27 +++++++++ .../intellij.gradle.java.properties.xml | 26 +++++++++ .../GradleRedundantKotlinStdLibInspection.kt | 11 ++-- .../GradleImplicitPropertyUsageProvider.kt | 6 +- .../GradlePropertyReferencesSearcher.java | 4 +- .../service}/GradleExtensionsContributor.kt | 56 +++++++------------ .../src/util}/properties.kt | 10 +++- .../META-INF/gradle-groovy-integration.xml | 1 - .../gradle-properties-integration.xml | 15 ----- .../gradle/java/resources/META-INF/plugin.xml | 9 +-- .../GradleDslInspectionProvider.kt | 2 +- ...eprecatedConfigurationInspectionVisitor.kt | 4 +- .../completion/GradleCompletionConsumer.kt | 4 +- ...dleVersionCatalogGotoDeclarationHandler.kt | 2 +- .../GradleArtifactHandlerContributor.kt | 2 +- .../GradleDependencyHandlerContributor.kt | 2 +- .../GradleExtensionsContributorUtil.kt | 37 ++++++++++++ .../GradleProjectExtensionContributor.kt | 2 +- .../GradleProjectMembersContributor.kt | 2 +- .../resolve/GradleTaskContainerContributor.kt | 2 +- .../gradle/java/src/service/resolve/util.kt | 11 ++-- ...adleRedundantKotlinStdLibInspectionTest.kt | 2 +- .../kotlin.gradle.scripting.k2/BUILD.bazel | 1 + .../intellij.kotlin.gradle.scripting.iml | 1 + .../RedundantKotlinStdLibInspectionTest.kt | 2 +- 32 files changed, 190 insertions(+), 99 deletions(-) create mode 100644 plugins/gradle/java/properties/BUILD.bazel create mode 100644 plugins/gradle/java/properties/intellij.gradle.java.properties.iml create mode 100644 plugins/gradle/java/properties/resources/intellij.gradle.java.properties.xml rename plugins/gradle/java/{ => properties}/src/codeInspection/GradleRedundantKotlinStdLibInspection.kt (65%) rename plugins/gradle/java/{ => properties}/src/findUsages/GradleImplicitPropertyUsageProvider.kt (80%) rename plugins/gradle/java/{ => properties}/src/findUsages/GradlePropertyReferencesSearcher.java (96%) rename plugins/gradle/java/{src/service/resolve => properties/src/service}/GradleExtensionsContributor.kt (74%) rename plugins/gradle/java/{src/service/resolve => properties/src/util}/properties.kt (74%) delete mode 100644 plugins/gradle/java/resources/META-INF/gradle-properties-integration.xml create mode 100644 plugins/gradle/java/src/service/resolve/GradleExtensionsContributorUtil.kt diff --git a/.idea/modules.xml b/.idea/modules.xml index 3feb2195d2a0..7c3028e0db86 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -465,6 +465,7 @@ + diff --git a/build/bazel-generated-file-list.txt b/build/bazel-generated-file-list.txt index 187619622a2e..f00d30d26617 100644 --- a/build/bazel-generated-file-list.txt +++ b/build/bazel-generated-file-list.txt @@ -1002,6 +1002,7 @@ plugins/gradle/java/groovy plugins/gradle/java/groovy/ml plugins/gradle/java/groovy/toml plugins/gradle/java/performance +plugins/gradle/java/properties plugins/gradle/java/toml plugins/gradle/jps-plugin plugins/gradle/kotlin/tests diff --git a/plugins/gradle/java/BUILD.bazel b/plugins/gradle/java/BUILD.bazel index ecc6d90ef2fe..00958f35df38 100644 --- a/plugins/gradle/java/BUILD.bazel +++ b/plugins/gradle/java/BUILD.bazel @@ -53,8 +53,6 @@ jvm_library( "//libraries/xstream", "//plugins/groovy/groovy-psi:psi", "//java/execution/openapi:java-execution", - "//plugins/properties/properties-psi-api:psi", - "//plugins/properties/properties-psi-impl:backend-psi", "//jps/model-impl", "//platform/statistics", "//platform/core-ui", @@ -73,6 +71,7 @@ jvm_library( "//java/debugger/shared", "//platform/eel-provider", "//platform/execution", + "//plugins/properties/properties-psi-impl:backend-psi", ], exports = ["//plugins/gradle:gradle-common"], runtime_deps = ["@lib//ant/lib:ant"] @@ -172,6 +171,7 @@ jvm_library( "//plugins/gradle/java/toml", "//plugins/gradle/java/groovy", "//plugins/gradle/java/groovy/toml", + "//plugins/gradle/java/properties", ], runtime_deps = [":java-tests"] ) diff --git a/plugins/gradle/java/groovy/ml/src/GradleGroovyElementFeatureProvider.kt b/plugins/gradle/java/groovy/ml/src/GradleGroovyElementFeatureProvider.kt index 68a7fb0a843e..26880a94b4e9 100644 --- a/plugins/gradle/java/groovy/ml/src/GradleGroovyElementFeatureProvider.kt +++ b/plugins/gradle/java/groovy/ml/src/GradleGroovyElementFeatureProvider.kt @@ -10,7 +10,7 @@ import com.intellij.psi.OriginInfoAwareElement import org.jetbrains.plugins.gradle.service.resolve.GradleArtifactHandlerContributor import org.jetbrains.plugins.gradle.service.resolve.GradleDependencyHandlerContributor import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionProperty -import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributor +import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributorUtil import org.jetbrains.plugins.gradle.service.resolve.GradleGroovyProperty import org.jetbrains.plugins.gradle.service.resolve.GradleNamedDomainCollectionContributor import org.jetbrains.plugins.gradle.service.resolve.GradleTaskContainerContributor @@ -22,7 +22,7 @@ class GradleGroovyElementFeatureProvider : ElementFeatureProvider { ARTIFACT_HANDLER(GradleArtifactHandlerContributor.ARTIFACTS_ORIGIN_INFO), DEPENDENCY_NOTATION(GradleDependencyHandlerContributor.DEPENDENCY_NOTATION), USER_CONTRIBUTED_PROPERTY(GradleGroovyProperty.EXTENSION_PROPERTY), - PROPERTIES_FILE_PROPERTY(GradleExtensionsContributor.PROPERTIES_FILE_ORIGINAL_INFO), + PROPERTIES_FILE_PROPERTY(GradleExtensionsContributorUtil.PROPERTIES_FILE_ORIGINAL_INFO), NAMED_DOMAIN_DECLARATION(GradleNamedDomainCollectionContributor.NAMED_DOMAIN_DECLARATION), GRADLE_CONTRIBUTED_PROPERTY(GradleExtensionProperty.GRADLE_EXTENSION_PROPERTY), TASK_METHOD(GradleTaskContainerContributor.GRADLE_TASK_INFO), diff --git a/plugins/gradle/java/intellij.gradle.java.iml b/plugins/gradle/java/intellij.gradle.java.iml index 39c4fb43bee4..5a68bf2a2509 100644 --- a/plugins/gradle/java/intellij.gradle.java.iml +++ b/plugins/gradle/java/intellij.gradle.java.iml @@ -49,8 +49,6 @@ - - @@ -69,5 +67,6 @@ + \ No newline at end of file diff --git a/plugins/gradle/java/intellij.gradle.java.tests.iml b/plugins/gradle/java/intellij.gradle.java.tests.iml index e39e477caa51..503a261af38f 100644 --- a/plugins/gradle/java/intellij.gradle.java.tests.iml +++ b/plugins/gradle/java/intellij.gradle.java.tests.iml @@ -68,5 +68,6 @@ + \ No newline at end of file diff --git a/plugins/gradle/java/properties/BUILD.bazel b/plugins/gradle/java/properties/BUILD.bazel new file mode 100644 index 000000000000..dad27ee0776a --- /dev/null +++ b/plugins/gradle/java/properties/BUILD.bazel @@ -0,0 +1,34 @@ +### auto-generated section `build intellij.gradle.java.properties` start +load("@rules_jvm//:jvm.bzl", "jvm_library", "resourcegroup") + +resourcegroup( + name = "properties_resources", + srcs = glob(["resources/**/*"]), + strip_prefix = "resources" +) + +jvm_library( + name = "properties", + module_name = "intellij.gradle.java.properties", + visibility = ["//visibility:public"], + srcs = glob(["src/**/*.kt", "src/**/*.java", "src/**/*.form"], allow_empty = True), + resources = [":properties_resources"], + deps = [ + "@lib//:kotlin-stdlib", + "@lib//:jetbrains-annotations", + "//plugins/properties/properties-psi-api:psi", + "//plugins/properties/properties-psi-impl:backend-psi", + "//plugins/gradle/java", + "//platform/core-api:core", + "//platform/core-impl", + "//platform/util", + "//platform/analysis-api:analysis", + "//platform/indexing-api:indexing", + "//plugins/groovy/groovy-psi:psi", + "//java/java-psi-api:psi", + "//java/java-psi-impl:psi-impl", + "//platform/util:util-ui", + "//platform/projectModel-api:projectModel", + ] +) +### auto-generated section `build intellij.gradle.java.properties` end \ No newline at end of file diff --git a/plugins/gradle/java/properties/intellij.gradle.java.properties.iml b/plugins/gradle/java/properties/intellij.gradle.java.properties.iml new file mode 100644 index 000000000000..6aa9fa06ac56 --- /dev/null +++ b/plugins/gradle/java/properties/intellij.gradle.java.properties.iml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/gradle/java/properties/resources/intellij.gradle.java.properties.xml b/plugins/gradle/java/properties/resources/intellij.gradle.java.properties.xml new file mode 100644 index 000000000000..ad4f9e9dc20c --- /dev/null +++ b/plugins/gradle/java/properties/resources/intellij.gradle.java.properties.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/gradle/java/src/codeInspection/GradleRedundantKotlinStdLibInspection.kt b/plugins/gradle/java/properties/src/codeInspection/GradleRedundantKotlinStdLibInspection.kt similarity index 65% rename from plugins/gradle/java/src/codeInspection/GradleRedundantKotlinStdLibInspection.kt rename to plugins/gradle/java/properties/src/codeInspection/GradleRedundantKotlinStdLibInspection.kt index 18c32300ef20..28194ec604e8 100644 --- a/plugins/gradle/java/src/codeInspection/GradleRedundantKotlinStdLibInspection.kt +++ b/plugins/gradle/java/properties/src/codeInspection/GradleRedundantKotlinStdLibInspection.kt @@ -1,11 +1,12 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.gradle.codeInspection +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.gradle.java.properties.codeInspection import com.intellij.codeInspection.LocalInspectionTool import com.intellij.codeInspection.ProblemsHolder +import com.intellij.gradle.java.properties.util.gradlePropertiesStream import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiFile -import org.jetbrains.plugins.gradle.service.resolve.gradlePropertiesStream +import org.jetbrains.plugins.gradle.codeInspection.GradleDslInspectionProvider class GradleRedundantKotlinStdLibInspection : LocalInspectionTool() { override fun isAvailableForFile(file: PsiFile): Boolean { @@ -16,13 +17,13 @@ class GradleRedundantKotlinStdLibInspection : LocalInspectionTool() { if (kotlinStdlibDefaultDependencyProp == "false") return false val language = file.language - val inspectionProvider = GradleDslInspectionProvider.INSTANCE.forLanguage(language) ?: return false + val inspectionProvider = GradleDslInspectionProvider.Companion.INSTANCE.forLanguage(language) ?: return false return inspectionProvider.isRedundantKotlinStdLibInspectionAvailable(file) } override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { val language = holder.file.language - val inspectionProvider = GradleDslInspectionProvider.INSTANCE.forLanguage(language) ?: return PsiElementVisitor.EMPTY_VISITOR + val inspectionProvider = GradleDslInspectionProvider.Companion.INSTANCE.forLanguage(language) ?: return PsiElementVisitor.EMPTY_VISITOR return inspectionProvider.getRedundantKotlinStdLibInspectionVisitor(holder, isOnTheFly) } } \ No newline at end of file diff --git a/plugins/gradle/java/src/findUsages/GradleImplicitPropertyUsageProvider.kt b/plugins/gradle/java/properties/src/findUsages/GradleImplicitPropertyUsageProvider.kt similarity index 80% rename from plugins/gradle/java/src/findUsages/GradleImplicitPropertyUsageProvider.kt rename to plugins/gradle/java/properties/src/findUsages/GradleImplicitPropertyUsageProvider.kt index 4117cf52077f..065abe0d842f 100644 --- a/plugins/gradle/java/src/findUsages/GradleImplicitPropertyUsageProvider.kt +++ b/plugins/gradle/java/properties/src/findUsages/GradleImplicitPropertyUsageProvider.kt @@ -1,11 +1,11 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.gradle.findUsages +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.gradle.java.properties.findUsages import com.intellij.lang.properties.codeInspection.unused.ImplicitPropertyUsageProvider import com.intellij.lang.properties.psi.PropertiesFile import com.intellij.lang.properties.psi.Property import com.intellij.util.asSafely -import org.jetbrains.plugins.gradle.service.resolve.gradlePropertiesStream +import com.intellij.gradle.java.properties.util.gradlePropertiesStream class GradleImplicitPropertyUsageProvider : ImplicitPropertyUsageProvider { diff --git a/plugins/gradle/java/src/findUsages/GradlePropertyReferencesSearcher.java b/plugins/gradle/java/properties/src/findUsages/GradlePropertyReferencesSearcher.java similarity index 96% rename from plugins/gradle/java/src/findUsages/GradlePropertyReferencesSearcher.java rename to plugins/gradle/java/properties/src/findUsages/GradlePropertyReferencesSearcher.java index 442f8db62409..252a67fa63c6 100644 --- a/plugins/gradle/java/src/findUsages/GradlePropertyReferencesSearcher.java +++ b/plugins/gradle/java/properties/src/findUsages/GradlePropertyReferencesSearcher.java @@ -1,5 +1,5 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.gradle.findUsages; +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.gradle.java.properties.findUsages; import com.intellij.lang.properties.psi.Property; import com.intellij.openapi.application.QueryExecutorBase; diff --git a/plugins/gradle/java/src/service/resolve/GradleExtensionsContributor.kt b/plugins/gradle/java/properties/src/service/GradleExtensionsContributor.kt similarity index 74% rename from plugins/gradle/java/src/service/resolve/GradleExtensionsContributor.kt rename to plugins/gradle/java/properties/src/service/GradleExtensionsContributor.kt index 86c7371ca556..7b58dac4e4ce 100644 --- a/plugins/gradle/java/src/service/resolve/GradleExtensionsContributor.kt +++ b/plugins/gradle/java/properties/src/service/GradleExtensionsContributor.kt @@ -1,45 +1,46 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.gradle.service.resolve +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.gradle.java.properties.service +import com.intellij.gradle.java.properties.util.gradlePropertiesStream import com.intellij.icons.AllIcons import com.intellij.lang.properties.IProperty -import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.psi.CommonClassNames import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiClass import com.intellij.psi.PsiClassType import com.intellij.psi.PsiElement -import com.intellij.psi.PsiElementFactory -import com.intellij.psi.PsiSubstitutor import com.intellij.psi.PsiType import com.intellij.psi.ResolveState import com.intellij.psi.scope.PsiScopeProcessor import com.intellij.psi.util.InheritanceUtil -import icons.GradleIcons import org.jetbrains.annotations.ApiStatus -import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames.GRADLE_API_PROJECT -import org.jetbrains.plugins.gradle.settings.GradleExtensionsSettings -import org.jetbrains.plugins.gradle.settings.GradleExtensionsSettings.GradleExtensionsData +import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames +import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributorUtil +import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributorUtil.Companion.PROPERTIES_FILE_ORIGINAL_INFO +import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributorUtil.Companion.getExtensionsFor +import org.jetbrains.plugins.gradle.service.resolve.GradleGroovyProperty +import org.jetbrains.plugins.gradle.service.resolve.GradleProjectAwareType +import org.jetbrains.plugins.gradle.service.resolve.getAccessorsForAllCatalogs +import org.jetbrains.plugins.gradle.service.resolve.getVersionCatalogAccessor import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor -import org.jetbrains.plugins.groovy.lang.resolve.api.GroovyPropertyBase import org.jetbrains.plugins.groovy.lang.resolve.getName import org.jetbrains.plugins.groovy.lang.resolve.processors.inference.type import org.jetbrains.plugins.groovy.lang.resolve.shouldProcessProperties -import javax.swing.Icon @ApiStatus.Internal class GradleExtensionsContributor : NonCodeMembersContributor() { override fun getClassNames(): Collection { - return listOf(GradleCommonClassNames.GRADLE_API_EXTRA_PROPERTIES_EXTENSION, GRADLE_API_PROJECT) + return listOf(GradleCommonClassNames.GRADLE_API_EXTRA_PROPERTIES_EXTENSION, GradleCommonClassNames.GRADLE_API_PROJECT) } override fun processDynamicElements(qualifierType: PsiType, aClass: PsiClass?, processor: PsiScopeProcessor, place: PsiElement, - state: ResolveState) { + state: ResolveState + ) { if (qualifierType !is GradleProjectAwareType && !InheritanceUtil.isInheritor(qualifierType, GradleCommonClassNames.GRADLE_API_EXTRA_PROPERTIES_EXTENSION)) return if (!processor.shouldProcessProperties()) return val file = place.containingFile @@ -64,7 +65,8 @@ class GradleExtensionsContributor : NonCodeMembersContributor() { private fun processPropertiesFromFile(aClass: PsiClass?, processor: PsiScopeProcessor, place: PsiElement, - state: ResolveState) : Set { + state: ResolveState + ) : Set { if (aClass == null) { return emptySet() } @@ -104,47 +106,27 @@ class GradleExtensionsContributor : NonCodeMembersContributor() { return newProperty } - - class StaticVersionCatalogProperty(place: PsiElement, name: String, val clazz: PsiClass) : GroovyPropertyBase(name, place) { - override fun getPropertyType(): PsiType { - return PsiElementFactory.getInstance(project).createType(clazz, PsiSubstitutor.EMPTY) - } - - override fun getIcon(flags: Int): Icon? { - return GradleIcons.Gradle - } - } - fun processPropertiesFromCatalog(name: String?, place: PsiElement, processor: PsiScopeProcessor, state: ResolveState) : Set? { if (name == null) { // this case is possible when only a part of a catalog name is written and autocomplete is triggered return processAllCatalogsOfBuild(place, processor, state) } val accessor = getVersionCatalogAccessor(place, name) ?: return emptySet() - val element = StaticVersionCatalogProperty(place, name, accessor) + val element = GradleExtensionsContributorUtil.Companion.StaticVersionCatalogProperty(place, name, accessor) if (!processor.execute(element, state)) { return null // to stop processing } return setOf(name) } - fun getExtensionsFor(psiElement: PsiElement): GradleExtensionsData? { - val project = psiElement.project - val virtualFile = psiElement.containingFile?.originalFile?.virtualFile ?: return null - val module = ProjectFileIndex.getInstance(project).getModuleForFile(virtualFile) - return GradleExtensionsSettings.getInstance(project).getExtensionsFor(module) - } - - const val PROPERTIES_FILE_ORIGINAL_INFO : String = "by gradle.properties" - private fun processAllCatalogsOfBuild(place: PsiElement, processor: PsiScopeProcessor, state: ResolveState): Set? { val catalogNameToAccessor: Map = getAccessorsForAllCatalogs(place) catalogNameToAccessor.forEach { (catalogName, accessor) -> - if (!processor.execute(StaticVersionCatalogProperty(place, catalogName, accessor), state)) { + if (!processor.execute(GradleExtensionsContributorUtil.Companion.StaticVersionCatalogProperty(place, catalogName, accessor), state)) { return null // to stop processing } } return catalogNameToAccessor.keys } } -} +} \ No newline at end of file diff --git a/plugins/gradle/java/src/service/resolve/properties.kt b/plugins/gradle/java/properties/src/util/properties.kt similarity index 74% rename from plugins/gradle/java/src/service/resolve/properties.kt rename to plugins/gradle/java/properties/src/util/properties.kt index db8030a5e190..7c9137ca3a16 100644 --- a/plugins/gradle/java/src/service/resolve/properties.kt +++ b/plugins/gradle/java/properties/src/util/properties.kt @@ -1,13 +1,15 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.gradle.service.resolve +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.gradle.java.properties.util import com.intellij.lang.properties.psi.PropertiesFile +import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VfsUtil import com.intellij.psi.PsiElement import com.intellij.psi.util.PsiUtilCore import com.intellij.util.asSafely import org.jetbrains.plugins.gradle.properties.GradlePropertiesFile +import org.jetbrains.plugins.gradle.service.resolve.module import org.jetbrains.plugins.gradle.util.GradleConstants.GRADLE_PROPERTIES_FILE_NAME import java.nio.file.Path @@ -21,3 +23,7 @@ private fun Path.getGradlePropertiesFile(project: Project): PropertiesFile? { val file = VfsUtil.findFile(this, false)?.findChild(GRADLE_PROPERTIES_FILE_NAME) return file?.let { PsiUtilCore.getPsiFile(project, it) }.asSafely() } + +internal fun PsiElement.getRootGradleProjectPath() : String? { + return ExternalSystemApiUtil.getExternalRootProjectPath(module) +} \ No newline at end of file diff --git a/plugins/gradle/java/resources/META-INF/gradle-groovy-integration.xml b/plugins/gradle/java/resources/META-INF/gradle-groovy-integration.xml index ebbdb8446963..96fe01fa6b85 100644 --- a/plugins/gradle/java/resources/META-INF/gradle-groovy-integration.xml +++ b/plugins/gradle/java/resources/META-INF/gradle-groovy-integration.xml @@ -98,7 +98,6 @@ - diff --git a/plugins/gradle/java/resources/META-INF/gradle-properties-integration.xml b/plugins/gradle/java/resources/META-INF/gradle-properties-integration.xml deleted file mode 100644 index b83be67e3ec5..000000000000 --- a/plugins/gradle/java/resources/META-INF/gradle-properties-integration.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/plugins/gradle/java/resources/META-INF/plugin.xml b/plugins/gradle/java/resources/META-INF/plugin.xml index ef7bff29c788..c0cc011b49e7 100644 --- a/plugins/gradle/java/resources/META-INF/plugin.xml +++ b/plugins/gradle/java/resources/META-INF/plugin.xml @@ -18,7 +18,6 @@ org.intellij.groovy - com.intellij.properties @@ -31,6 +30,7 @@ + messages.GradleInspectionBundle @@ -177,12 +177,5 @@ implementationClass="org.jetbrains.plugins.gradle.codeInspection.GradleAvoidDependencyNamedArgumentsNotationInspection" isInternal="true"/> - diff --git a/plugins/gradle/java/src/codeInspection/GradleDslInspectionProvider.kt b/plugins/gradle/java/src/codeInspection/GradleDslInspectionProvider.kt index e6583bd57be1..ab1664831490 100644 --- a/plugins/gradle/java/src/codeInspection/GradleDslInspectionProvider.kt +++ b/plugins/gradle/java/src/codeInspection/GradleDslInspectionProvider.kt @@ -46,7 +46,7 @@ interface GradleDslInspectionProvider { fun getAvoidDependencyNamedArgumentsNotationInspectionVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor /** - * @see GradleRedundantKotlinStdLibInspection + * @see com.intellij.gradle.java.properties.codeInspection.GradleRedundantKotlinStdLibInspection */ fun isRedundantKotlinStdLibInspectionAvailable(file: PsiFile): Boolean fun getRedundantKotlinStdLibInspectionVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor diff --git a/plugins/gradle/java/src/codeInspection/groovy/GroovyDeprecatedConfigurationInspectionVisitor.kt b/plugins/gradle/java/src/codeInspection/groovy/GroovyDeprecatedConfigurationInspectionVisitor.kt index 47a1c05df6ba..274972d024bc 100644 --- a/plugins/gradle/java/src/codeInspection/groovy/GroovyDeprecatedConfigurationInspectionVisitor.kt +++ b/plugins/gradle/java/src/codeInspection/groovy/GroovyDeprecatedConfigurationInspectionVisitor.kt @@ -7,7 +7,7 @@ import com.intellij.codeInspection.ProblemsHolder import com.intellij.util.containers.map2Array import org.jetbrains.plugins.gradle.codeInspection.GradleInspectionBundle import org.jetbrains.plugins.gradle.service.resolve.DECLARATION_ALTERNATIVES -import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributor +import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributorUtil import org.jetbrains.plugins.groovy.intentions.GrReplaceMethodCallQuickFix import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression @@ -19,7 +19,7 @@ class GroovyDeprecatedConfigurationInspectionVisitor(val holder: ProblemsHolder) val resolved = referenceExpression.resolve() ?: return val alternatives = resolved.getUserData(DECLARATION_ALTERNATIVES)?.takeIf { it.isNotEmpty() } ?: return - val knownConfigurations = GradleExtensionsContributor.getExtensionsFor(referenceExpression)?.configurations?.keys ?: emptyList() + val knownConfigurations = GradleExtensionsContributorUtil.getExtensionsFor(referenceExpression)?.configurations?.keys ?: emptyList() val descriptor = InspectionManager.getInstance(referenceExpression.project) .createProblemDescriptor( diff --git a/plugins/gradle/java/src/service/completion/GradleCompletionConsumer.kt b/plugins/gradle/java/src/service/completion/GradleCompletionConsumer.kt index 05fc532558bc..4ae089de6cc6 100644 --- a/plugins/gradle/java/src/service/completion/GradleCompletionConsumer.kt +++ b/plugins/gradle/java/src/service/completion/GradleCompletionConsumer.kt @@ -14,7 +14,7 @@ import com.intellij.util.lazyPub import org.jetbrains.plugins.gradle.codeInspection.groovy.DelegationHierarchy import org.jetbrains.plugins.gradle.codeInspection.groovy.getDelegationHierarchy import org.jetbrains.plugins.gradle.codeInspection.groovy.getDelegationSourceCaller -import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributor +import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributorUtil import org.jetbrains.plugins.groovy.lang.completion.api.GroovyCompletionConsumer import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField import kotlin.math.absoluteValue @@ -33,7 +33,7 @@ class GradleCompletionConsumer(position: PsiElement, val delegate: GroovyComplet GradleLookupWeigher.setGradleCompletionPriority(newElement, GradleLookupWeigher.DEFAULT_COMPLETION_PRIORITY - 1) delegate.consume(newElement) } - else if (psi is GrLightField && psi.originInfo == GradleExtensionsContributor.PROPERTIES_FILE_ORIGINAL_INFO) { + else if (psi is GrLightField && psi.originInfo == GradleExtensionsContributorUtil.PROPERTIES_FILE_ORIGINAL_INFO) { val property = psi.navigationElement.asSafely() ?: return delegate.consume(element) val value = property.value val newElement = element.modify { withTailText("=$value").withTypeText(psi.type.presentableText, true) } diff --git a/plugins/gradle/java/src/service/navigation/GradleVersionCatalogGotoDeclarationHandler.kt b/plugins/gradle/java/src/service/navigation/GradleVersionCatalogGotoDeclarationHandler.kt index 49d71c1430be..0698c50ce487 100644 --- a/plugins/gradle/java/src/service/navigation/GradleVersionCatalogGotoDeclarationHandler.kt +++ b/plugins/gradle/java/src/service/navigation/GradleVersionCatalogGotoDeclarationHandler.kt @@ -15,7 +15,7 @@ import com.intellij.util.asSafely import org.jetbrains.plugins.gradle.service.project.CommonGradleProjectResolverExtension import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionProperty -import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributor.Companion.StaticVersionCatalogProperty +import org.jetbrains.plugins.gradle.service.resolve.GradleExtensionsContributorUtil.Companion.StaticVersionCatalogProperty import org.jetbrains.plugins.gradle.util.GradleConstants import org.jetbrains.plugins.gradle.util.getCapitalizedAccessorName import org.jetbrains.plugins.groovy.intentions.style.inference.resolve diff --git a/plugins/gradle/java/src/service/resolve/GradleArtifactHandlerContributor.kt b/plugins/gradle/java/src/service/resolve/GradleArtifactHandlerContributor.kt index e42f87035d64..50a3d866f8b1 100644 --- a/plugins/gradle/java/src/service/resolve/GradleArtifactHandlerContributor.kt +++ b/plugins/gradle/java/src/service/resolve/GradleArtifactHandlerContributor.kt @@ -33,7 +33,7 @@ class GradleArtifactHandlerContributor : NonCodeMembersContributor() { if (clazz == null) return if (!processor.shouldProcessMethods()) return - val data = GradleExtensionsContributor.getExtensionsFor(place) ?: return + val data = GradleExtensionsContributorUtil.getExtensionsFor(place) ?: return val methodName = processor.getName(state) val manager = place.manager val objectVarargType = PsiEllipsisType(getJavaLangObject(place)) diff --git a/plugins/gradle/java/src/service/resolve/GradleDependencyHandlerContributor.kt b/plugins/gradle/java/src/service/resolve/GradleDependencyHandlerContributor.kt index bdccabab14ef..28261c1164cb 100644 --- a/plugins/gradle/java/src/service/resolve/GradleDependencyHandlerContributor.kt +++ b/plugins/gradle/java/src/service/resolve/GradleDependencyHandlerContributor.kt @@ -39,7 +39,7 @@ class GradleDependencyHandlerContributor : NonCodeMembersContributor() { if (clazz == null) return if (!processor.shouldProcessMethods()) return - val data = GradleExtensionsContributor.getExtensionsFor(place) ?: return + val data = GradleExtensionsContributorUtil.getExtensionsFor(place) ?: return val methodName = processor.getName(state) val manager = place.manager val objectVarargType = PsiEllipsisType(TypesUtil.getJavaLangObject(place)) diff --git a/plugins/gradle/java/src/service/resolve/GradleExtensionsContributorUtil.kt b/plugins/gradle/java/src/service/resolve/GradleExtensionsContributorUtil.kt new file mode 100644 index 000000000000..0eaad9218149 --- /dev/null +++ b/plugins/gradle/java/src/service/resolve/GradleExtensionsContributorUtil.kt @@ -0,0 +1,37 @@ +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.gradle.service.resolve + +import com.intellij.openapi.roots.ProjectFileIndex +import com.intellij.psi.PsiClass +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiElementFactory +import com.intellij.psi.PsiSubstitutor +import com.intellij.psi.PsiType +import icons.GradleIcons +import org.jetbrains.plugins.gradle.settings.GradleExtensionsSettings +import org.jetbrains.plugins.groovy.lang.resolve.api.GroovyPropertyBase +import javax.swing.Icon + +class GradleExtensionsContributorUtil { + companion object { + const val PROPERTIES_FILE_ORIGINAL_INFO : String = "by gradle.properties" + + fun getExtensionsFor(psiElement: PsiElement): GradleExtensionsSettings.GradleExtensionsData? { + val project = psiElement.project + val virtualFile = psiElement.containingFile?.originalFile?.virtualFile ?: return null + val module = ProjectFileIndex.getInstance(project).getModuleForFile(virtualFile) + return GradleExtensionsSettings.getInstance(project).getExtensionsFor(module) + } + + class StaticVersionCatalogProperty(place: PsiElement, name: String, val clazz: PsiClass) : GroovyPropertyBase(name, place) { + override fun getPropertyType(): PsiType { + return PsiElementFactory.getInstance(project).createType(clazz, PsiSubstitutor.EMPTY) + } + + override fun getIcon(flags: Int): Icon? { + return GradleIcons.Gradle + } + } + + } +} diff --git a/plugins/gradle/java/src/service/resolve/GradleProjectExtensionContributor.kt b/plugins/gradle/java/src/service/resolve/GradleProjectExtensionContributor.kt index bfa352418c22..89a4af6a905f 100644 --- a/plugins/gradle/java/src/service/resolve/GradleProjectExtensionContributor.kt +++ b/plugins/gradle/java/src/service/resolve/GradleProjectExtensionContributor.kt @@ -43,7 +43,7 @@ class GradleProjectExtensionContributor : NonCodeMembersContributor() { } val containingFile = place.containingFile - val extensionsData = GradleExtensionsContributor.getExtensionsFor(containingFile) ?: return + val extensionsData = GradleExtensionsContributorUtil.getExtensionsFor(containingFile) ?: return val name = processor.getName(state) val allExtensions = extensionsData.extensions diff --git a/plugins/gradle/java/src/service/resolve/GradleProjectMembersContributor.kt b/plugins/gradle/java/src/service/resolve/GradleProjectMembersContributor.kt index 3fd3dcfc42c5..ec94a6db2c77 100644 --- a/plugins/gradle/java/src/service/resolve/GradleProjectMembersContributor.kt +++ b/plugins/gradle/java/src/service/resolve/GradleProjectMembersContributor.kt @@ -26,7 +26,7 @@ class GradleProjectMembersContributor : NonCodeMembersContributor() { if (qualifierType !is GradleProjectAwareType) return val file = place.containingFile ?: return - val extensionsData = GradleExtensionsContributor.getExtensionsFor(file) ?: return + val extensionsData = GradleExtensionsContributorUtil.getExtensionsFor(file) ?: return for (convention in extensionsData.conventions) { if (!createType(convention.typeFqn, file).processReceiverType(processor, state, place)) { return diff --git a/plugins/gradle/java/src/service/resolve/GradleTaskContainerContributor.kt b/plugins/gradle/java/src/service/resolve/GradleTaskContainerContributor.kt index 44c5433eacff..f2b0deeb3251 100644 --- a/plugins/gradle/java/src/service/resolve/GradleTaskContainerContributor.kt +++ b/plugins/gradle/java/src/service/resolve/GradleTaskContainerContributor.kt @@ -40,7 +40,7 @@ class GradleTaskContainerContributor : NonCodeMembersContributor() { } val file = place.containingFile ?: return - val data = GradleExtensionsContributor.getExtensionsFor(file) ?: return + val data = GradleExtensionsContributorUtil.getExtensionsFor(file) ?: return val name = processor.getName(state) val gradleProjectType = JavaPsiFacade.getInstance(place.project).findClass(GradleCommonClassNames.GRADLE_API_PROJECT, diff --git a/plugins/gradle/java/src/service/resolve/util.kt b/plugins/gradle/java/src/service/resolve/util.kt index 6b385f1baf8c..2cf664dff5b0 100644 --- a/plugins/gradle/java/src/service/resolve/util.kt +++ b/plugins/gradle/java/src/service/resolve/util.kt @@ -2,6 +2,7 @@ package org.jetbrains.plugins.gradle.service.resolve import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil +import com.intellij.openapi.module.Module import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.openapi.util.Key import com.intellij.patterns.PatternCondition @@ -37,15 +38,11 @@ internal fun PsiClass?.isResolvedInGradleScript() = this is GroovyScriptClass && internal fun PsiFile?.isGradleScript() = this?.originalFile?.virtualFile?.extension == EXTENSION -private val PsiElement.module get() = containingFile?.originalFile?.virtualFile?.let { - ProjectFileIndex.getInstance(project).getModuleForFile(it) -} +@get:ApiStatus.Internal +val PsiElement.module: Module? + get() = containingFile?.originalFile?.virtualFile?.let { ProjectFileIndex.getInstance(project).getModuleForFile(it) } @ApiStatus.Internal fun PsiElement.getLinkedGradleProjectPath() : String? { return ExternalSystemApiUtil.getExternalProjectPath(module) -} - -internal fun PsiElement.getRootGradleProjectPath() : String? { - return ExternalSystemApiUtil.getExternalRootProjectPath(module) } \ No newline at end of file diff --git a/plugins/gradle/java/testSources/dsl/inspections/GradleRedundantKotlinStdLibInspectionTest.kt b/plugins/gradle/java/testSources/dsl/inspections/GradleRedundantKotlinStdLibInspectionTest.kt index a29d764064d5..72ebd08f7912 100644 --- a/plugins/gradle/java/testSources/dsl/inspections/GradleRedundantKotlinStdLibInspectionTest.kt +++ b/plugins/gradle/java/testSources/dsl/inspections/GradleRedundantKotlinStdLibInspectionTest.kt @@ -1,8 +1,8 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.plugins.gradle.dsl.inspections +import com.intellij.gradle.java.properties.codeInspection.GradleRedundantKotlinStdLibInspection import org.gradle.util.GradleVersion -import org.jetbrains.plugins.gradle.codeInspection.GradleRedundantKotlinStdLibInspection import org.jetbrains.plugins.gradle.testFramework.GradleCodeInsightTestCase import org.jetbrains.plugins.gradle.testFramework.GradleTestFixtureBuilder import org.jetbrains.plugins.gradle.testFramework.annotations.AllGradleVersionsSource diff --git a/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/BUILD.bazel b/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/BUILD.bazel index 759d4cfb5d56..1d244a87bcbd 100644 --- a/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/BUILD.bazel +++ b/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/BUILD.bazel @@ -169,6 +169,7 @@ jvm_library( "//plugins/gradle/completion", "//plugins/gradle/completion:completion_test_lib", "//plugins/gradle/java/toml", + "//plugins/gradle/java/properties", ] ) ### auto-generated section `build intellij.kotlin.gradle.scripting` end diff --git a/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/intellij.kotlin.gradle.scripting.iml b/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/intellij.kotlin.gradle.scripting.iml index 9d43140ec219..93b671f614c7 100644 --- a/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/intellij.kotlin.gradle.scripting.iml +++ b/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/intellij.kotlin.gradle.scripting.iml @@ -93,5 +93,6 @@ + \ No newline at end of file diff --git a/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/tests/org/jetbrains/kotlin/gradle/scripting/k2/inspections/RedundantKotlinStdLibInspectionTest.kt b/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/tests/org/jetbrains/kotlin/gradle/scripting/k2/inspections/RedundantKotlinStdLibInspectionTest.kt index e525643a2565..8b64160130e2 100644 --- a/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/tests/org/jetbrains/kotlin/gradle/scripting/k2/inspections/RedundantKotlinStdLibInspectionTest.kt +++ b/plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.k2/tests/org/jetbrains/kotlin/gradle/scripting/k2/inspections/RedundantKotlinStdLibInspectionTest.kt @@ -1,9 +1,9 @@ // Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.gradle.scripting.k2.inspections +import com.intellij.gradle.java.properties.codeInspection.GradleRedundantKotlinStdLibInspection import org.gradle.util.GradleVersion import org.jetbrains.kotlin.gradle.scripting.k2.K2GradleCodeInsightTestCase -import org.jetbrains.plugins.gradle.codeInspection.GradleRedundantKotlinStdLibInspection import org.jetbrains.plugins.gradle.frameworkSupport.GradleDsl import org.jetbrains.plugins.gradle.testFramework.GradleTestFixtureBuilder import org.jetbrains.plugins.gradle.testFramework.annotations.AllGradleVersionsSource