<commit_before>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.service.resolve

import com.intellij.psi.*
import com.intellij.psi.scope.PsiScopeProcessor
import icons.GradleIcons.Gradle
import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames.GRADLE_API_ARTIFACT_HANDLER
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil.getJavaLangObject
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder
import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor
import org.jetbrains.plugins.groovy.lang.resolve.getName
import org.jetbrains.plugins.groovy.lang.resolve.shouldProcessMethods

class GradleArtifactHandlerContributor : NonCodeMembersContributor() {

  companion object {
    const val ourMethodKind: String = "gradle:artifactsConfigurationMethod"
  }

  override fun getParentClassName(): String? = GRADLE_API_ARTIFACT_HANDLER

  override fun processDynamicElements(qualifierType: PsiType,
                                      clazz: PsiClass?,
                                      processor: PsiScopeProcessor,
                                      place: PsiElement,
                                      state: ResolveState) {
    if (qualifierType !is GradleProjectAwareType) return
    if (clazz == null) return
    if (!processor.shouldProcessMethods()) return

    val data = GradleExtensionsContributor.getExtensionsFor(place) ?: return
    val methodName = processor.getName(state)
    val manager = place.manager
    val objectVarargType = PsiEllipsisType(getJavaLangObject(place))

    val configuration = data.configurations[methodName] ?: return
    val configurationName = configuration.name ?: return

    val method = GrLightMethodBuilder(manager, configurationName).apply {
      methodKind = ourMethodKind
      containingClass = clazz
      returnType = null
      addParameter("artifactNotation", objectVarargType)
      setBaseIcon(Gradle)
    }
    if (!processor.execute(method, state)) return
  }
}<commit_msg>IDEA-CR-45602: all available declarations should be fed into the processor for "completion", i.e. when method is null<commit_after>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.service.resolve

import com.intellij.psi.*
import com.intellij.psi.scope.PsiScopeProcessor
import icons.GradleIcons.Gradle
import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames.GRADLE_API_ARTIFACT_HANDLER
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil.getJavaLangObject
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder
import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor
import org.jetbrains.plugins.groovy.lang.resolve.getName
import org.jetbrains.plugins.groovy.lang.resolve.shouldProcessMethods

class GradleArtifactHandlerContributor : NonCodeMembersContributor() {

  companion object {
    const val ourMethodKind: String = "gradle:artifactsConfigurationMethod"
  }

  override fun getParentClassName(): String? = GRADLE_API_ARTIFACT_HANDLER

  override fun processDynamicElements(qualifierType: PsiType,
                                      clazz: PsiClass?,
                                      processor: PsiScopeProcessor,
                                      place: PsiElement,
                                      state: ResolveState) {
    if (qualifierType !is GradleProjectAwareType) return
    if (clazz == null) return
    if (!processor.shouldProcessMethods()) return

    val data = GradleExtensionsContributor.getExtensionsFor(place) ?: return
    val methodName = processor.getName(state)
    val manager = place.manager
    val objectVarargType = PsiEllipsisType(getJavaLangObject(place))

    // The null method name means we are in completion, and in this case all available declarations should be fed into the processor.
    val configurations = if (methodName == null) data.configurations.values else listOf(data.configurations[methodName] ?: return)
    for (configuration in configurations) {
      val configurationName = configuration.name ?: continue
      val method = GrLightMethodBuilder(manager, configurationName).apply {
        methodKind = ourMethodKind
        containingClass = clazz
        returnType = null
        addParameter("artifactNotation", objectVarargType)
        setBaseIcon(Gradle)
      }
      if (!processor.execute(method, state)) return
    }
  }
}
{'fraction_non_alphanumeric': 0.07495741056218058, 'fraction_numerical': 0.005323679727427598, 'mean_word_length': 3.5513565891472867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5398340', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1236, 'n_words': 291}