diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java index 769d9a746be8..d3171d4cf5b9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java @@ -306,7 +306,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { @Nullable @TestOnly public static String getInfo(PsiElement element, PsiElement atPointer) { - return generateInfo(element, atPointer).text; + return generateInfo(element, atPointer, true).text; } @Nullable @@ -321,22 +321,17 @@ public class CtrlMouseHandler extends AbstractProjectComponent { } @NotNull - private static DocInfo generateInfo(PsiElement element, PsiElement atPointer) { + private static DocInfo generateInfo(PsiElement element, PsiElement atPointer, boolean fallbackToBasicInfo) { final DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(element, atPointer); - String result = doGenerateInfo(element, atPointer, documentationProvider); + String result = documentationProvider.getQuickNavigateInfo(element, atPointer); + if (result == null && fallbackToBasicInfo) { + result = doGenerateInfo(element); + } return result == null ? DocInfo.EMPTY : new DocInfo(result, documentationProvider, element); } @Nullable - private static String doGenerateInfo(@NotNull PsiElement element, - @NotNull PsiElement atPointer, - @NotNull DocumentationProvider documentationProvider) - { - String info = documentationProvider.getQuickNavigateInfo(element, atPointer); - if (info != null) { - return info; - } - + private static String doGenerateInfo(@NotNull PsiElement element) { if (element instanceof PsiFile) { final VirtualFile virtualFile = ((PsiFile)element).getVirtualFile(); if (virtualFile != null) { @@ -344,7 +339,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { } } - info = getQuickNavigateInfo(element); + String info = getQuickNavigateInfo(element); if (info != null) { return info; } @@ -454,7 +449,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { @Override public DocInfo compute() { try { - return generateInfo(myTargetElement, myElementAtPointer); + return generateInfo(myTargetElement, myElementAtPointer, isNavigatable()); } catch (IndexNotReadyException e) { showDumbModeNotification(myTargetElement.getProject()); @@ -893,7 +888,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { } } - if (!info.isValid(myEditor.getDocument())) { + if (!info.isValid(myEditor.getDocument()) || !info.isNavigatable() && docInfo.text == null) { return; } diff --git a/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFxRedundantPropertyValueInspectionTest.java b/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFxRedundantPropertyValueInspectionTest.java index 79f5c36a8ef6..0cf505859bad 100644 --- a/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFxRedundantPropertyValueInspectionTest.java +++ b/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFxRedundantPropertyValueInspectionTest.java @@ -61,6 +61,6 @@ public class JavaFxRedundantPropertyValueInspectionTest extends AbstractJavaFXQu if (getTestName(false).endsWith("Attribute")) { return "Remove attribute " + tagName; } - return "Remove tag '" + tagName + "'"; + return "Remove tag " + tagName; } } diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/codeInsight/inspections/JavaFxRedundantPropertyValueInspection.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/codeInsight/inspections/JavaFxRedundantPropertyValueInspection.java index b0d5713b083d..7f38409d6d8f 100644 --- a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/codeInsight/inspections/JavaFxRedundantPropertyValueInspection.java +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/codeInsight/inspections/JavaFxRedundantPropertyValueInspection.java @@ -1,6 +1,7 @@ package org.jetbrains.plugins.javaFX.fxml.codeInsight.inspections; import com.intellij.codeInsight.daemon.impl.analysis.RemoveAttributeIntentionFix; +import com.intellij.codeInsight.daemon.impl.analysis.RemoveTagIntentionFix; import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.XmlSuppressableInspectionTool; @@ -83,7 +84,7 @@ public class JavaFxRedundantPropertyValueInspection extends XmlSuppressableInspe return; } if (tag.getSubTags().length != 0) return; - final String tagText = tag.getValue().getText().trim(); + final String tagText = tag.getValue().getTrimmedText(); if (tagText.startsWith("$") || tagText.startsWith("#") || tagText.startsWith("%")) { @@ -97,7 +98,7 @@ public class JavaFxRedundantPropertyValueInspection extends XmlSuppressableInspe if (isEqualValue(tagClass, tagText, defaultValue, descriptor.getDeclaration())) { holder.registerProblem(tag, "Tag is redundant because it contains default value", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, - new RemoveTagFix(tag.getName())); + new RemoveTagIntentionFix(tag.getName(), tag)); } } }; diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/codeInsight/inspections/RemoveTagFix.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/codeInsight/inspections/RemoveTagFix.java deleted file mode 100644 index 0e97afd08bc7..000000000000 --- a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/codeInsight/inspections/RemoveTagFix.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.jetbrains.plugins.javaFX.fxml.codeInsight.inspections; - -import com.intellij.codeInsight.FileModificationService; -import com.intellij.codeInspection.LocalQuickFix; -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.xml.XmlTag; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.javaFX.fxml.JavaFxFileTypeFactory; - -/** - * @author Pavel.Dolgov - */ -public class RemoveTagFix implements LocalQuickFix { - private static final Logger LOG = Logger.getInstance("#" + RemoveTagFix.class.getName()); - - private final String myTagName; - - public RemoveTagFix(String name) { - myTagName = name; - } - - @Nls - @NotNull - @Override - public String getName() { - return "Remove tag '" + myTagName + "'"; - } - - @Nls - @NotNull - @Override - public String getFamilyName() { - return "Remove tag"; - } - - @Override - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { - final PsiElement element = descriptor.getPsiElement(); - if (element != null) { - final PsiFile containingFile = element.getContainingFile(); - LOG.assertTrue(containingFile != null && JavaFxFileTypeFactory.isFxml(containingFile), - containingFile == null ? "no containing file found" : "containing file: " + containingFile.getName()); - final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false); - if (xmlTag != null) { - final XmlTag parentTag = xmlTag.getParentTag(); - if (!FileModificationService.getInstance().preparePsiElementsForWrite(element)) return; - xmlTag.delete(); - if (parentTag != null) { - CodeStyleManager.getInstance(project).reformat(parentTag); - } - } - } - } -} diff --git a/plugins/javaFX/testData/inspections/redundantValue/immediateTag.fxml b/plugins/javaFX/testData/inspections/redundantValue/immediateTag.fxml index 05fce217fa21..ed969ce00022 100644 --- a/plugins/javaFX/testData/inspections/redundantValue/immediateTag.fxml +++ b/plugins/javaFX/testData/inspections/redundantValue/immediateTag.fxml @@ -5,8 +5,8 @@ minHeight="-Infinity" prefHeight="400.0" prefWidth="600.0"> - ent>TOP_LEFT - + ent>TOP_LEFT + \ No newline at end of file diff --git a/plugins/javaFX/testData/inspections/redundantValue/inheritedTag.fxml b/plugins/javaFX/testData/inspections/redundantValue/inheritedTag.fxml index 353c3a6adf33..e9365172b377 100644 --- a/plugins/javaFX/testData/inspections/redundantValue/inheritedTag.fxml +++ b/plugins/javaFX/testData/inspections/redundantValue/inheritedTag.fxml @@ -3,10 +3,10 @@ 1 0 - 100 + 100 - -1 + -1 500 ight>-1 diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/RemoveTagIntentionFix.java b/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/RemoveTagIntentionFix.java new file mode 100644 index 000000000000..d66d10c3d77d --- /dev/null +++ b/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/RemoveTagIntentionFix.java @@ -0,0 +1,77 @@ +/* + * Copyright 2000-2016 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 com.intellij.codeInsight.daemon.impl.analysis; + +import com.intellij.codeInsight.FileModificationService; +import com.intellij.codeInsight.daemon.XmlErrorMessages; +import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.xml.XmlTag; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Pavel.Dolgov + */ +public class RemoveTagIntentionFix extends LocalQuickFixAndIntentionActionOnPsiElement { + private final String myTagName; + + public RemoveTagIntentionFix(final String name, @NotNull final XmlTag tag) { + super(tag); + myTagName = name; + } + + @NotNull + @Override + public String getText() { + return XmlErrorMessages.message("remove.tag.quickfix.text", myTagName); + } + + @Nls + @NotNull + @Override + public String getFamilyName() { + return XmlErrorMessages.message("remove.tag.quickfix.family"); + } + + @Override + public void invoke(@NotNull Project project, + @NotNull PsiFile file, + @Nullable("is null when called from inspection") Editor editor, + @NotNull PsiElement startElement, + @NotNull PsiElement endElement) { + if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; + + final XmlTag next = editor != null ? PsiTreeUtil.getNextSiblingOfType(startElement, XmlTag.class) : null; + final XmlTag prev = editor != null ? PsiTreeUtil.getPrevSiblingOfType(startElement, XmlTag.class) : null; + + startElement.delete(); + + if (editor != null) { + if (next != null) { + editor.getCaretModel().moveToOffset(next.getTextRange().getStartOffset()); + } + else if (prev != null) { + editor.getCaretModel().moveToOffset(prev.getTextRange().getEndOffset()); + } + } + } +} diff --git a/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties b/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties index 11a15a04df1c..d148c5163dcb 100644 --- a/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties +++ b/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties @@ -28,6 +28,8 @@ insert.required.attribute.quickfix.text=Insert required attribute {0} insert.required.attribute.quickfix.family=Insert required attribute remove.attribute.quickfix.text=Remove attribute {0} remove.attribute.quickfix.family=Remove attribute +remove.tag.quickfix.text=Remove tag {0} +remove.tag.quickfix.family=Remove tag add.attribute.value.quickfix.text=Add attribute value remove.extra.closing.tag.quickfix=Remove extra closing tag create.namespace.declaration.quickfix=Create {0} declaration