Gradle: resolve 'manifest' closure method of gradle Jar type

This commit is contained in:
Vladislav.Soroka
2017-04-24 14:47:57 +03:00
parent c148fcf98a
commit 7cdfaa4275
2 changed files with 11 additions and 6 deletions
@@ -56,6 +56,7 @@ public final class GradleCommonClassNames {
@NonNls public static final String GRADLE_API_TASK = "org.gradle.api.Task";
@NonNls public static final String GRADLE_API_DEFAULT_TASK = "org.gradle.api.DefaultTask";
@NonNls public static final String GRADLE_API_TASKS_DELETE = "org.gradle.api.tasks.Delete";
@NonNls public static final String GRADLE_JVM_TASKS_JAR = "org.gradle.jvm.tasks.Jar";
@NonNls public static final String GRADLE_API_TASKS_BUNDLING_JAR = "org.gradle.api.tasks.bundling.Jar";
@NonNls public static final String GRADLE_API_TASKS_BUNDLING_WAR = "org.gradle.api.tasks.bundling.War";
@NonNls public static final String GRADLE_API_TASKS_COMPILE_JAVA_COMPILE = "org.gradle.api.tasks.compile.JavaCompile";
@@ -25,7 +25,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlo
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil.createType
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder
import org.jetbrains.plugins.groovy.lang.psi.patterns.groovyClosure
import org.jetbrains.plugins.groovy.lang.psi.patterns.psiMethod
@@ -45,20 +45,24 @@ class GradleMiscContributor : GradleMethodContextContributor {
val testLoggingClosure = groovyClosure().inMethod(psiMethod(GRADLE_API_TASKS_TESTING_TEST, "testLogging"))
val downloadClosure = groovyClosure().inMethod(psiMethod(GRADLE_API_PROJECT, "download"))
val domainCollectionWithTypeClosure = groovyClosure().inMethod(psiMethod(GRADLE_API_DOMAIN_OBJECT_COLLECTION, "withType"))
// val publicationsClosure = groovyClosure().inMethod(psiMethod("org.gradle.api.publish.PublishingExtension", "publications"))
val manifestClosure = groovyClosure().inMethod(psiMethod(GRADLE_JVM_TASKS_JAR, "manifest"))
// val publicationsClosure = groovyClosure().inMethod(psiMethod("org.gradle.api.publish.PublishingExtension", "publications"))
val downloadSpecFqn = "de.undercouch.gradle.tasks.download.DownloadSpec"
val pluginDependenciesSpecFqn = "org.gradle.plugin.use.PluginDependenciesSpec"
}
override fun getDelegatesToInfo(closure: GrClosableBlock): DelegatesToInfo? {
if (useJUnitClosure.accepts(closure)) {
return DelegatesToInfo(TypesUtil.createType(GRADLE_API_JUNIT_OPTIONS, closure), Closure.DELEGATE_FIRST)
return DelegatesToInfo(createType(GRADLE_API_JUNIT_OPTIONS, closure), Closure.DELEGATE_FIRST)
}
if (testLoggingClosure.accepts(closure)) {
return DelegatesToInfo(TypesUtil.createType(GRADLE_API_TEST_LOGGING_CONTAINER, closure), Closure.DELEGATE_FIRST)
return DelegatesToInfo(createType(GRADLE_API_TEST_LOGGING_CONTAINER, closure), Closure.DELEGATE_FIRST)
}
if (downloadClosure.accepts(closure)) {
return DelegatesToInfo(TypesUtil.createType(downloadSpecFqn, closure), Closure.DELEGATE_FIRST)
return DelegatesToInfo(createType(downloadSpecFqn, closure), Closure.DELEGATE_FIRST)
}
if (manifestClosure.accepts(closure)) {
return DelegatesToInfo(createType(GRADLE_API_JAVA_ARCHIVES_MANIFEST, closure), Closure.DELEGATE_FIRST)
}
// if (publicationsClosure.accepts(closure)) {
// return DelegatesToInfo(TypesUtil.createType("org.gradle.api.publish.PublicationContainer", closure), Closure.DELEGATE_FIRST)
@@ -69,7 +73,7 @@ class GradleMiscContributor : GradleMethodContextContributor {
if (parent is GrMethodCallExpression) {
val psiElement = parent.argumentList.allArguments.singleOrNull()?.reference?.resolve()
if (psiElement is PsiClass) {
return DelegatesToInfo(TypesUtil.createType(psiElement.qualifiedName, closure), Closure.DELEGATE_FIRST)
return DelegatesToInfo(createType(psiElement.qualifiedName, closure), Closure.DELEGATE_FIRST)
}
}
}