IDEA-92100 NPE at QuickEditHandler.commitToOriginal(): ensure host manipulator is available

This commit is contained in:
Gregory.Shrago
2012-09-26 20:31:16 +04:00
parent 76237ac3b6
commit 73e52e462d
4 changed files with 2 additions and 53 deletions
@@ -1,7 +1,6 @@
<idea-plugin>
<extensionPoints>
<extensionPoint name="regExpLanguageHost" beanClass="com.intellij.openapi.util.ClassExtensionPoint"/>
<extensionPoint qualifiedName="com.intellij.regExpRangeProvider" interface="org.intellij.lang.regexp.RegExpRangeProvider"/>
</extensionPoints>
<extensions defaultExtensionNs="com.intellij">
<lang.documentationProvider language="RegExp" implementationClass="org.intellij.lang.regexp.RegExpDocumentationProvider"/>
@@ -1,30 +0,0 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.intellij.lang.regexp;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
/**
* @author Anna Bulenkova
*/
public interface RegExpRangeProvider {
ExtensionPointName<RegExpRangeProvider> EP_NAME = new ExtensionPointName<RegExpRangeProvider>("com.intellij.regExpRangeProvider");
Pair<PsiElement, TextRange> getRangePair(PsiElement element);
}
@@ -28,9 +28,7 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiUtilBase;
import org.intellij.lang.regexp.RegExpLanguage;
import org.intellij.lang.regexp.RegExpRangeProvider;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -41,21 +39,6 @@ import javax.swing.*;
*/
public class CheckRegExpIntentionAction extends QuickEditAction implements Iconable {
@Override
protected Pair<PsiElement, TextRange> getRangePair(PsiFile file, Editor editor) {
Pair<PsiElement, TextRange> pair = super.getRangePair(file, editor);
if (pair == null) {
RegExpRangeProvider[] rangeProviders = RegExpRangeProvider.EP_NAME.getExtensions();
PsiElement element = PsiUtilBase.getElementAtCaret(editor);
for (RegExpRangeProvider provider : rangeProviders) {
pair = provider.getRangePair(element);
if (pair != null) break;
}
}
return pair;
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
final Pair<PsiElement, TextRange> pair = getRangePair(file, editor);
@@ -25,10 +25,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
@@ -62,7 +59,7 @@ public class QuickEditAction implements IntentionAction, LowPriorityAction {
final int offset = editor.getCaretModel().getOffset();
final PsiLanguageInjectionHost host =
PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiLanguageInjectionHost.class, false);
if (host == null) return null;
if (host == null || ElementManipulators.getManipulator(host) == null) return null;
final List<Pair<PsiElement, TextRange>> injections = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host);
if (injections == null || injections.isEmpty()) return null;
final int offsetInElement = offset - host.getTextRange().getStartOffset();