Search in sources :

Example 1 with ProblemDescriptorBase

use of com.intellij.codeInspection.ProblemDescriptorBase in project intellij-community by JetBrains.

the class ChangeTo method applyFix.

public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement element = descriptor.getPsiElement();
    if (element == null)
        return;
    Editor editor = PsiUtilBase.findEditor(element);
    if (editor == null) {
        return;
    }
    TextRange textRange = ((ProblemDescriptorBase) descriptor).getTextRange();
    editor.getSelectionModel().setSelection(textRange.getStartOffset(), textRange.getEndOffset());
    String word = editor.getSelectionModel().getSelectedText();
    if (word == null || StringUtil.isEmpty(word)) {
        return;
    }
    List<LookupElement> lookupItems = new ArrayList<>();
    for (String variant : getSuggestions(project)) {
        lookupItems.add(LookupElementBuilder.create(variant));
    }
    LookupElement[] items = new LookupElement[lookupItems.size()];
    items = lookupItems.toArray(items);
    LookupManager lookupManager = LookupManager.getInstance(project);
    lookupManager.showLookup(editor, items);
}
Also used : ProblemDescriptorBase(com.intellij.codeInspection.ProblemDescriptorBase) LookupManager(com.intellij.codeInsight.lookup.LookupManager) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 ProblemDescriptorBase (com.intellij.codeInspection.ProblemDescriptorBase)1 Editor (com.intellij.openapi.editor.Editor)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 ArrayList (java.util.ArrayList)1