Search in sources :

Example 1 with SpellCheckerManager

use of com.intellij.spellchecker.SpellCheckerManager in project intellij-community by JetBrains.

the class FormSpellCheckingInspection method checkStringDescriptor.

@Override
protected void checkStringDescriptor(Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
    final String value = descriptor.getResolvedValue();
    if (value == null) {
        return;
    }
    final SpellCheckerManager manager = SpellCheckerManager.getInstance(module.getProject());
    PlainTextSplitter.getInstance().split(value, TextRange.allOf(value), textRange -> {
        final String word = textRange.substring(value);
        if (manager.hasProblem(word)) {
            final List<String> suggestions = manager.getSuggestions(word);
            if (!suggestions.isEmpty() && prop instanceof IntroStringProperty) {
                EditorQuickFixProvider changeToProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, final RadComponent component1) {
                        return new PopupQuickFix<String>(editor, "Change to...", component1) {

                            @Override
                            public void run() {
                                ListPopup popup = JBPopupFactory.getInstance().createListPopup(getPopupStep());
                                popup.showUnderneathOf(component1.getDelegee());
                            }

                            @Override
                            public ListPopupStep<String> getPopupStep() {
                                return new BaseListPopupStep<String>("Select Replacement", suggestions) {

                                    @Override
                                    public PopupStep onChosen(String selectedValue, boolean finalChoice) {
                                        FormInspectionUtil.updateStringPropertyValue(editor, component1, (IntroStringProperty) prop, descriptor, selectedValue);
                                        return FINAL_CHOICE;
                                    }
                                };
                            }
                        };
                    }
                };
                EditorQuickFixProvider acceptProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, RadComponent component1) {
                        return new QuickFix(editor, "Save '" + word + "' to dictionary", component1) {

                            @Override
                            public void run() {
                                manager.acceptWordAsCorrect(word, editor.getProject());
                            }
                        };
                    }
                };
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'", changeToProvider, acceptProvider);
            } else {
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'");
            }
        }
    });
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor)

Example 2 with SpellCheckerManager

use of com.intellij.spellchecker.SpellCheckerManager in project intellij-community by JetBrains.

the class SpellCheckingInspection method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    final SpellCheckerManager manager = SpellCheckerManager.getInstance(holder.getProject());
    return new PsiElementVisitor() {

        @Override
        public void visitElement(final PsiElement element) {
            final ASTNode node = element.getNode();
            if (node == null) {
                return;
            }
            // Extract parser definition from element
            final Language language = element.getLanguage();
            final IElementType elementType = node.getElementType();
            final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
            // Handle selected options
            if (parserDefinition != null) {
                if (parserDefinition.getStringLiteralElements().contains(elementType)) {
                    if (!processLiterals) {
                        return;
                    }
                } else if (parserDefinition.getCommentTokens().contains(elementType)) {
                    if (!processComments) {
                        return;
                    }
                } else if (!processCode) {
                    return;
                }
            }
            tokenize(element, language, new MyTokenConsumer(manager, holder, LanguageNamesValidation.INSTANCE.forLanguage(language)));
        }
    };
}
Also used : IElementType(com.intellij.psi.tree.IElementType) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SpellCheckerManager

use of com.intellij.spellchecker.SpellCheckerManager in project intellij-community by JetBrains.

the class DictionarySuggestionProvider method getSuggestedNames.

@Override
public SuggestedNameInfo getSuggestedNames(PsiElement element, PsiElement nameSuggestionContext, Set<String> result) {
    assert result != null;
    if (!active || nameSuggestionContext == null) {
        return null;
    }
    String text = nameSuggestionContext.getText();
    if (nameSuggestionContext instanceof PsiNamedElement) {
        //noinspection ConstantConditions
        text = ((PsiNamedElement) element).getName();
    }
    if (text == null) {
        return null;
    }
    Project project = element.getProject();
    SpellCheckerManager manager = SpellCheckerManager.getInstance(project);
    manager.getSuggestions(text).stream().filter(newName -> RenameUtil.isValidName(project, element, newName)).forEach(result::add);
    return SuggestedNameInfo.NULL_INFO;
}
Also used : SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) RenameUtil(com.intellij.refactoring.rename.RenameUtil) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Set(java.util.Set) PsiNamedElement(com.intellij.psi.PsiNamedElement) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) PreferrableNameSuggestionProvider(com.intellij.refactoring.rename.PreferrableNameSuggestionProvider) Project(com.intellij.openapi.project.Project) PsiNamedElement(com.intellij.psi.PsiNamedElement) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager)

Aggregations

SpellCheckerManager (com.intellij.spellchecker.SpellCheckerManager)3 PsiElement (com.intellij.psi.PsiElement)2 Project (com.intellij.openapi.project.Project)1 ListPopup (com.intellij.openapi.ui.popup.ListPopup)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1 PsiNamedElement (com.intellij.psi.PsiNamedElement)1 SuggestedNameInfo (com.intellij.psi.codeStyle.SuggestedNameInfo)1 IElementType (com.intellij.psi.tree.IElementType)1 PreferrableNameSuggestionProvider (com.intellij.refactoring.rename.PreferrableNameSuggestionProvider)1 RenameUtil (com.intellij.refactoring.rename.RenameUtil)1 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)1 IntroStringProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty)1 PopupQuickFix (com.intellij.uiDesigner.quickFixes.PopupQuickFix)1 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)1 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)1 Set (java.util.Set)1 NotNull (org.jetbrains.annotations.NotNull)1