[Parameter Name Hints] introduced getBlackListDependencyLanguage to parameter hints extension

This commit is contained in:
Yaroslav Lepenkin
2016-10-25 15:47:26 +03:00
parent dc819c7a8b
commit 90a8a599e2
3 changed files with 34 additions and 5 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.hints
import com.intellij.lang.Language
import com.intellij.lang.LanguageExtension
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.ApiStatus
@@ -27,19 +28,25 @@ interface InlayParameterHintsProvider {
/**
* Hints for params to be shown
*/
fun getParameterHints(element: PsiElement): List<InlayInfo> = emptyList()
fun getParameterHints(element: PsiElement): List<InlayInfo>
/**
* Provides fully qualified method name (e.g. "java.util.Map.put") and list of it's parameter names.
* Used when adding method to blacklist, when user invokes alt-enter on hint
* and selects "Do not show for this method".
*/
fun getMethodInfo(element: PsiElement): MethodInfo? = null
fun getMethodInfo(element: PsiElement): MethodInfo?
/**
* Default list of methods for which hints should not be shown
*/
val defaultBlackList: Set<String>
/**
* Returns language which blacklist will be appended to the resulting one
* E.g. to prevent possible Groovy and Kotlin extensions from showing hints for blacklisted java methods.
*/
fun getBlackListDependencyLanguage(): Language? = null
}
@@ -38,6 +38,7 @@ import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.SyntaxTraverser;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import gnu.trove.TIntObjectHashMap;
import org.jetbrains.annotations.NotNull;
@@ -77,8 +78,11 @@ public class ParameterHintsPassFactory extends AbstractProjectComponent implemen
InlayParameterHintsProvider provider = InlayParameterHintsExtension.INSTANCE.forLanguage(language);
if (provider == null) return;
Diff diff = ParameterNameHintsSettings.getInstance().getBlackListDiff(language);
Set<String> blackList = diff.applyOn(provider.getDefaultBlackList());
Set<String> blackList = getBlackList(language);
Language dependentLanguage = provider.getBlackListDependencyLanguage();
if (dependentLanguage != null) {
blackList.addAll(getBlackList(dependentLanguage));
}
List<Matcher> matchers = blackList
.stream()
@@ -88,6 +92,16 @@ public class ParameterHintsPassFactory extends AbstractProjectComponent implemen
SyntaxTraverser.psiTraverser(myFile).forEach(element -> process(element, provider, matchers));
}
private static Set<String> getBlackList(Language language) {
InlayParameterHintsProvider provider = InlayParameterHintsExtension.INSTANCE.forLanguage(language);
if (provider != null) {
ParameterNameHintsSettings settings = ParameterNameHintsSettings.getInstance();
Diff diff = settings.getBlackListDiff(language);
return diff.applyOn(provider.getDefaultBlackList());
}
return ContainerUtil.newHashOrEmptySet(ContainerUtil.emptyIterable());
}
private static boolean isEnabled() {
return EditorSettingsExternalizable.getInstance().isShowParameterNameHints();
}
@@ -15,12 +15,20 @@
*/
package com.intellij.codeInsight.hints.settings
import com.intellij.codeInsight.hints.InlayInfo
import com.intellij.codeInsight.hints.InlayParameterHintsProvider
import com.intellij.openapi.fileTypes.PlainTextLanguage
import com.intellij.psi.PsiElement
import junit.framework.TestCase
class MockInlayProvider(override val defaultBlackList: Set<String>): InlayParameterHintsProvider
class MockInlayProvider(override val defaultBlackList: Set<String>): InlayParameterHintsProvider {
override fun getParameterHints(element: PsiElement) = emptyList<InlayInfo>()
override fun getMethodInfo(element: PsiElement) = null
}
class ParameterNameSettingsTest : TestCase() {