summaryrefslogtreecommitdiff
path: root/xml/impl
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2013-04-01 14:41:51 -0700
committerJean-Baptiste Queru <jbq@google.com>2013-04-01 14:41:51 -0700
commit2bd2b7c2623d4266384e890271869efc044aabff (patch)
tree0b31f50e55975b6354ed458314e17b4441bb4e17 /xml/impl
parent1d526b16d476792ca7ce47616d55833115e8d6ab (diff)
downloadidea-2bd2b7c2623d4266384e890271869efc044aabff.tar.gz
Snapshot ee98b298267d0e09d2cd2f0731b6480a56dd48e7 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I4515f72af131fdea9fc6905a4dc0fe9532409a81
Diffstat (limited to 'xml/impl')
-rw-r--r--xml/impl/resources/inspectionDescriptions/XmlInvalidId.html6
-rw-r--r--xml/impl/resources/liveTemplates/zen_html.xml17
-rw-r--r--xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.form18
-rw-r--r--xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.java6
-rw-r--r--xml/impl/src/com/intellij/application/options/emmet/EmmetOptions.java9
-rw-r--r--xml/impl/src/com/intellij/codeInsight/actions/GenerateDTDAction.java42
-rw-r--r--xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java13
-rw-r--r--xml/impl/src/com/intellij/codeInsight/completion/XmlTagInsertHandler.java7
-rw-r--r--xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/AddSchemaPrefixIntention.java6
-rw-r--r--xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/ConvertSchemaPrefixToDefaultIntention.java3
-rw-r--r--xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java8
-rw-r--r--xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java35
-rw-r--r--xml/impl/src/com/intellij/codeInsight/editorActions/moveUpDown/XmlMover.java2
-rw-r--r--xml/impl/src/com/intellij/codeInsight/intentions/XmlChooseColorIntentionAction.java10
-rw-r--r--xml/impl/src/com/intellij/codeInsight/template/emmet/XmlEmmetParser.java4
-rw-r--r--xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java4
-rw-r--r--xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGeneratorImpl.java2
-rw-r--r--xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/GenerationNode.java26
-rw-r--r--xml/impl/src/com/intellij/codeInspection/htmlInspections/AddCustomTagOrAttributeIntentionAction.java15
-rw-r--r--xml/impl/src/com/intellij/codeInspection/htmlInspections/AddHtmlTagOrAttributeToCustomsIntention.java17
-rw-r--r--xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspection.java4
-rw-r--r--xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java5
-rw-r--r--xml/impl/src/com/intellij/codeInspection/htmlInspections/RequiredAttributesInspection.java7
-rw-r--r--xml/impl/src/com/intellij/codeInspection/htmlInspections/XmlInspectionToolProvider.java46
-rw-r--r--xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java4
-rw-r--r--xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java4
-rw-r--r--xml/impl/src/com/intellij/lang/html/structureView/Html5SectionsNodeProvider.java3
-rw-r--r--xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java29
-rw-r--r--xml/impl/src/com/intellij/psi/formatter/xml/XmlBlock.java46
-rw-r--r--xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URIReferenceProvider.java13
-rw-r--r--xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java8
-rw-r--r--xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java2
-rw-r--r--xml/impl/src/com/intellij/xml/DefaultXmlExtension.java115
-rw-r--r--xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java13
-rw-r--r--xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java18
-rw-r--r--xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java125
-rw-r--r--xml/impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java6
-rw-r--r--xml/impl/src/com/intellij/xml/util/HtmlUtil.java5
-rw-r--r--xml/impl/src/com/intellij/xml/util/XmlDuplicatedIdInspection.java77
-rw-r--r--xml/impl/src/com/intellij/xml/util/XmlInvalidIdInspection.java68
-rw-r--r--xml/impl/src/com/intellij/xml/util/XmlReferenceContributor.java6
-rw-r--r--xml/impl/src/com/intellij/xml/util/XmlUtil.java7
42 files changed, 421 insertions, 440 deletions
diff --git a/xml/impl/resources/inspectionDescriptions/XmlInvalidId.html b/xml/impl/resources/inspectionDescriptions/XmlInvalidId.html
new file mode 100644
index 000000000000..332e802540df
--- /dev/null
+++ b/xml/impl/resources/inspectionDescriptions/XmlInvalidId.html
@@ -0,0 +1,6 @@
+<html>
+<body>
+<font face="verdana" size="-1">This inspection checks for unresolved "id" attributes in XML.
+</font>
+</body>
+</html> \ No newline at end of file
diff --git a/xml/impl/resources/liveTemplates/zen_html.xml b/xml/impl/resources/liveTemplates/zen_html.xml
index 7f537b53fb32..c7aaa6094a1c 100644
--- a/xml/impl/resources/liveTemplates/zen_html.xml
+++ b/xml/impl/resources/liveTemplates/zen_html.xml
@@ -608,7 +608,7 @@
<option name="HTML_TEXT" value="true"/>
</context>
</template>
- <template description="&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;....css&quot; media=&quot;all&quot;&gt;" name="link:css" toReformat="true" toShortenFQNames="true" value="&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;$END$.css&quot; media=&quot;all&quot;/&gt;">
+ <template description="&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;....css&quot; /&gt;" name="link:css" toReformat="true" toShortenFQNames="true" value="&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;$END$.css&quot; /&gt;">
<context>
<option name="HTML_TEXT" value="true"/>
</context>
@@ -655,6 +655,21 @@
<option name="HTML_TEXT" value="true"/>
</context>
</template>
+ <template description="&lt;button type=&quot;button&quot;&gt;...&lt;/button&gt;" name="btn:b" toReformat="true" toShortenFQNames="true" value="&lt;button type=&quot;button&quot;&gt;$END$&lt;/button&gt;">
+ <context>
+ <option name="HTML_TEXT" value="true"/>
+ </context>
+ </template>
+ <template description="&lt;button type=&quot;reset&quot;&gt;...&lt;/button&gt;" name="btn:r" toReformat="true" toShortenFQNames="true" value="&lt;button type=&quot;reset&quot;&gt;$END$&lt;/button&gt;">
+ <context>
+ <option name="HTML_TEXT" value="true"/>
+ </context>
+ </template>
+ <template description="&lt;button type=&quot;submit&quot;&gt;...&lt;/button&gt;" name="btn:s" toReformat="true" toShortenFQNames="true" value="&lt;button type=&quot;submit&quot;&gt;$END$&lt;/button&gt;">
+ <context>
+ <option name="HTML_TEXT" value="true"/>
+ </context>
+ </template>
<template description="&lt;input type=&quot;url&quot; name=&quot;...&quot; id=&quot;...&quot;/&gt;" name="input:url" toReformat="true" toShortenFQNames="true" value="&lt;input type=&quot;url&quot; name=&quot;$VAR0$&quot; id=&quot;$VAR1$&quot;/&gt;">
<variable alwaysStopAt="true" defaultValue="&quot;&quot;" expression="" name="VAR0"/>
<variable alwaysStopAt="true" defaultValue="&quot;&quot;" expression="" name="VAR1"/>
diff --git a/xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.form b/xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.form
index 62127bcf42e3..e427db7d292c 100644
--- a/xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.form
+++ b/xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.form
@@ -21,8 +21,8 @@
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="1" use-parent-layout="false"/>
</constraints>
<properties>
- <labelFor value="ce319"/>
- <text value="Expand abbreviation with"/>
+ <labelFor value="59f5a"/>
+ <text resource-bundle="messages/XmlBundle" key="emmet.expand.abbreviation.with"/>
</properties>
</component>
<component id="59f5a" class="javax.swing.JComboBox" binding="myEmmetExpandShortcutCombo">
@@ -54,7 +54,7 @@
</component>
</children>
</grid>
- <grid id="bd64d" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <grid id="bd64d" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -67,7 +67,7 @@
<children>
<component id="65354" class="com.intellij.ui.components.JBCheckBox" binding="myAutoInsertCssVendorJBCheckBox" default-binding="true">
<constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/XmlBundle" key="emmet.auto.insert.vendor.prefixes"/>
@@ -76,12 +76,20 @@
<grid id="612b" binding="myPrefixesPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
+ <component id="b1849" class="com.intellij.ui.components.JBCheckBox" binding="myEnabledFuzzySearchJBCheckBox">
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text resource-bundle="messages/XmlBundle" key="emmet.fuzzy.search"/>
+ </properties>
+ </component>
</children>
</grid>
</children>
diff --git a/xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.java b/xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.java
index a8df5388e5c7..a702df6fde61 100644
--- a/xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.java
+++ b/xml/impl/src/com/intellij/application/options/emmet/EmmetConfigurable.java
@@ -40,6 +40,7 @@ public class EmmetConfigurable implements SearchableConfigurable, Disposable, Co
private JComboBox myEmmetExpandShortcutCombo;
private JBCheckBox myEnableBEMFilterJBCheckBox;
private JBCheckBox myAutoInsertCssVendorJBCheckBox;
+ private JBCheckBox myEnabledFuzzySearchJBCheckBox;
private JPanel myPanel;
private JPanel myPrefixesPanel;
@@ -59,6 +60,7 @@ public class EmmetConfigurable implements SearchableConfigurable, Disposable, Co
myAutoInsertCssVendorJBCheckBox.setEnabled(selected);
myCssEditPrefixesListPanel.setEnabled(selected && myAutoInsertCssVendorJBCheckBox.isSelected());
myEnableBEMFilterJBCheckBox.setEnabled(selected);
+ myEnabledFuzzySearchJBCheckBox.setEnabled(selected);
}
});
@@ -125,6 +127,7 @@ public class EmmetConfigurable implements SearchableConfigurable, Disposable, Co
return emmetOptions.isEmmetEnabled() != myEnableEmmetJBCheckBox.isSelected() ||
emmetOptions.isBemFilterEnabledByDefault() != myEnableBEMFilterJBCheckBox.isSelected() ||
emmetOptions.isAutoInsertCssPrefixedEnabled() != myAutoInsertCssVendorJBCheckBox.isSelected() ||
+ emmetOptions.isFuzzySearchEnabled() != myEnabledFuzzySearchJBCheckBox.isSelected() ||
!emmetOptions.getAllPrefixInfo().equals(myCssEditPrefixesListPanel.getState()) ||
emmetOptions.getEmmetExpandShortcut() != getSelectedEmmetExpandShortcut();
}
@@ -137,6 +140,7 @@ public class EmmetConfigurable implements SearchableConfigurable, Disposable, Co
emmetOptions.setEnableBemFilterByDefault(myEnableBEMFilterJBCheckBox.isSelected());
emmetOptions.setEmmetExpandShortcut(getSelectedEmmetExpandShortcut());
emmetOptions.setAutoInsertCssPrefixedEnabled(myAutoInsertCssVendorJBCheckBox.isSelected());
+ emmetOptions.setFuzzySearchEnabled(myEnabledFuzzySearchJBCheckBox.isSelected());
emmetOptions.setPrefixInfo(myCssEditPrefixesListPanel.getState());
}
@@ -149,6 +153,8 @@ public class EmmetConfigurable implements SearchableConfigurable, Disposable, Co
myEmmetExpandShortcutCombo.setEnabled(emmetOptions.isEmmetEnabled());
myAutoInsertCssVendorJBCheckBox.setEnabled(emmetOptions.isEmmetEnabled());
myAutoInsertCssVendorJBCheckBox.setSelected(emmetOptions.isAutoInsertCssPrefixedEnabled());
+ myEnabledFuzzySearchJBCheckBox.setEnabled(emmetOptions.isEmmetEnabled());
+ myEnabledFuzzySearchJBCheckBox.setSelected(emmetOptions.isFuzzySearchEnabled());
//myInsertFallbackGradientColorJBCheckBox.setEnabled(emmetOptions.isEmmetEnabled());
//myInsertFallbackGradientColorJBCheckBox.setSelected(emmetOptions.isInsertFallbackGradientColorEnabled());
diff --git a/xml/impl/src/com/intellij/application/options/emmet/EmmetOptions.java b/xml/impl/src/com/intellij/application/options/emmet/EmmetOptions.java
index 70ddaa453aae..dd005841293c 100644
--- a/xml/impl/src/com/intellij/application/options/emmet/EmmetOptions.java
+++ b/xml/impl/src/com/intellij/application/options/emmet/EmmetOptions.java
@@ -51,6 +51,7 @@ public class EmmetOptions implements PersistentStateComponent<EmmetOptions>, Exp
private boolean myEnableBemFilterByDefault = false;
private boolean myEmmetEnabled = WebEditorOptions.getInstance().isZenCodingEnabled();
private int myEmmetExpandShortcut = WebEditorOptions.getInstance().getZenCodingExpandShortcut();
+ private boolean myFuzzySearchEnabled = true;
private boolean myAutoInsertCssPrefixedEnabled = true;
@Nullable
private Map<String, Integer> prefixes = null;
@@ -106,6 +107,14 @@ public class EmmetOptions implements PersistentStateComponent<EmmetOptions>, Exp
myAutoInsertCssPrefixedEnabled = autoInsertCssPrefixedEnabled;
}
+ public void setFuzzySearchEnabled(boolean fuzzySearchEnabled) {
+ myFuzzySearchEnabled = fuzzySearchEnabled;
+ }
+
+ public boolean isFuzzySearchEnabled() {
+ return myFuzzySearchEnabled;
+ }
+
@NotNull
@Override
public File[] getExportFiles() {
diff --git a/xml/impl/src/com/intellij/codeInsight/actions/GenerateDTDAction.java b/xml/impl/src/com/intellij/codeInsight/actions/GenerateDTDAction.java
index 027bb15ac45b..0c9c6d70183d 100644
--- a/xml/impl/src/com/intellij/codeInsight/actions/GenerateDTDAction.java
+++ b/xml/impl/src/com/intellij/codeInsight/actions/GenerateDTDAction.java
@@ -16,12 +16,17 @@
package com.intellij.codeInsight.actions;
import com.intellij.codeInsight.CodeInsightActionHandler;
-import com.intellij.openapi.actionSystem.*;
+import com.intellij.lang.xml.XMLLanguage;
+import com.intellij.openapi.actionSystem.ActionPlaces;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.*;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiFileFactory;
+import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlDocument;
import com.intellij.psi.xml.XmlFile;
@@ -38,7 +43,6 @@ import org.jetbrains.annotations.Nullable;
* User: ik
* Date: 22.05.2003
* Time: 13:46:54
- * To change this template use Options | File Templates.
*/
public class GenerateDTDAction extends BaseCodeInsightAction{
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.actions.GenerateDTDAction");
@@ -82,12 +86,9 @@ public class GenerateDTDAction extends BaseCodeInsightAction{
@Nullable
private static XmlDocument findSuitableXmlDocument(@Nullable PsiFile psiFile) {
if (psiFile instanceof XmlFile) {
- final VirtualFile virtualFile = psiFile.getVirtualFile();
- if (virtualFile != null && virtualFile.isWritable()) {
- final XmlDocument document = ((XmlFile)psiFile).getDocument();
- if (document != null && document.getRootTag() != null) {
- return document;
- }
+ final XmlDocument document = ((XmlFile)psiFile).getDocument();
+ if (document != null && document.getRootTag() != null) {
+ return document;
}
}
return null;
@@ -95,28 +96,13 @@ public class GenerateDTDAction extends BaseCodeInsightAction{
public void update(AnActionEvent event) {
super.update(event);
-
- final DataContext dataContext = event.getDataContext();
- final Presentation presentation = event.getPresentation();
- Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
- Project project = PlatformDataKeys.PROJECT.getData(dataContext);
-
- final boolean enabled;
- if (editor != null && project != null) {
- PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
- enabled = findSuitableXmlDocument(file) != null;
- }
- else {
- enabled = false;
- }
-
- presentation.setEnabled(enabled);
if (ActionPlaces.isPopupPlace(event.getPlace())) {
- presentation.setVisible(enabled);
+ Presentation presentation = event.getPresentation();
+ presentation.setVisible(presentation.isEnabled());
}
}
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file){
- return file instanceof XmlFile;
+ return file.getLanguage() == XMLLanguage.INSTANCE && findSuitableXmlDocument(file) != null;
}
}
diff --git a/xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java b/xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java
index 001f33948182..108ba0951aef 100644
--- a/xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java
+++ b/xml/impl/src/com/intellij/codeInsight/completion/XmlSmartEnterProcessor.java
@@ -86,11 +86,12 @@ public class XmlSmartEnterProcessor extends SmartEnterProcessor {
final PsiElement element = psiFile.findElementAt(probableCommaOffset);
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
- final CharSequence text2insert = getClosingPart(xmlAttribute, tagAtCaret, false);
+ boolean shouldInsertClosingTag = shouldAfterWrapTextWithTag(caretAt, probableCommaOffset) || shouldInsertClosingTag(xmlAttribute, tagAtCaret);
+ final CharSequence text2insert = getClosingPart(xmlAttribute, tagAtCaret, !shouldInsertClosingTag);
if (tag != null && tag.getTextRange().getStartOffset() == probableCommaOffset) {
doc.insertString(caretAt, text2insert);
- if (shouldInsertClosingTag(xmlAttribute, tagAtCaret)) {
+ if (shouldInsertClosingTag) {
doc.insertString(tag.getTextRange().getEndOffset() + text2insert.length(), "</" + tagAtCaret.getName() + ">");
}
@@ -98,7 +99,7 @@ public class XmlSmartEnterProcessor extends SmartEnterProcessor {
}
else {
doc.insertString(caretAt, text2insert);
- if (shouldInsertClosingTag(xmlAttribute, tagAtCaret)) {
+ if (shouldInsertClosingTag) {
doc.insertString(probableCommaOffset + text2insert.length(), "</" + tagNameText + ">");
}
@@ -153,6 +154,10 @@ public class XmlSmartEnterProcessor extends SmartEnterProcessor {
return false;
}
+ protected boolean shouldAfterWrapTextWithTag(int caretAt, int probableCommaOffset) {
+ return probableCommaOffset > caretAt;
+ }
+
private void commitChanges(Project project, Editor editor, PsiFile psiFile, int caretOffset, @Nullable XmlTag tagToReformat) {
if (isUncommited(project)) {
commit(editor);
@@ -189,7 +194,7 @@ public class XmlSmartEnterProcessor extends SmartEnterProcessor {
}
protected boolean shouldInsertClosingTag(final XmlAttribute xmlAttribute, final XmlTag tagAtCaret) {
- return true;
+ return xmlAttribute == null || getClosingQuote(xmlAttribute).length() != 0;
}
protected String getClosingPart(final XmlAttribute xmlAttribute, final XmlTag tagAtCaret, final boolean emptyTag) {
diff --git a/xml/impl/src/com/intellij/codeInsight/completion/XmlTagInsertHandler.java b/xml/impl/src/com/intellij/codeInsight/completion/XmlTagInsertHandler.java
index a8ec5ee935ca..1f6b399f4b2f 100644
--- a/xml/impl/src/com/intellij/codeInsight/completion/XmlTagInsertHandler.java
+++ b/xml/impl/src/com/intellij/codeInsight/completion/XmlTagInsertHandler.java
@@ -27,12 +27,10 @@ import com.intellij.codeInsight.template.impl.MacroCallNode;
import com.intellij.codeInsight.template.macro.CompleteMacro;
import com.intellij.codeInsight.template.macro.CompleteSmartMacro;
import com.intellij.codeInspection.InspectionProfile;
-import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.command.undo.UndoManager;
-import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.ScrollType;
@@ -57,7 +55,6 @@ import java.util.*;
public class XmlTagInsertHandler implements InsertHandler<LookupElement> {
- private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.XmlTagInsertHandler");
public static final XmlTagInsertHandler INSTANCE = new XmlTagInsertHandler();
public void handleInsert(InsertionContext context, LookupElement item) {
@@ -201,10 +198,8 @@ public class XmlTagInsertHandler implements InsertHandler<LookupElement> {
if (tag instanceof HtmlTag) {
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile();
- LocalInspectionToolWrapper localInspectionToolWrapper = (LocalInspectionToolWrapper) profile.getInspectionTool(
+ RequiredAttributesInspection inspection = (RequiredAttributesInspection)profile.getUnwrappedTool(
RequiredAttributesInspection.SHORT_NAME, tag);
- RequiredAttributesInspection inspection = localInspectionToolWrapper != null ?
- (RequiredAttributesInspection) localInspectionToolWrapper.getTool(): null;
if (inspection != null) {
StringTokenizer tokenizer = new StringTokenizer(inspection.getAdditionalEntries(0));
diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/AddSchemaPrefixIntention.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/AddSchemaPrefixIntention.java
index e7d65657d0b4..723ba6e14fa6 100644
--- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/AddSchemaPrefixIntention.java
+++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/AddSchemaPrefixIntention.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2010 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -86,7 +86,7 @@ public class AddSchemaPrefixIntention extends PsiElementBaseIntentionAction {
tag.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlTag(XmlTag tag) {
- if (namespace.equals(tag.getNamespace()) && tag.getNamespacePrefix().length() == 0) {
+ if (tag.getNamespace().equals(namespace) && tag.getNamespacePrefix().length() == 0) {
tags.add(tag);
}
super.visitXmlTag(tag);
@@ -109,7 +109,7 @@ public class AddSchemaPrefixIntention extends PsiElementBaseIntentionAction {
if (xmlElement instanceof XmlElement) {
final XmlTag tag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class, false);
if (tag != null) {
- if (namespace.equals(tag.getNamespace())) {
+ if (tag.getNamespace().equals(namespace)) {
if (ref.getRangeInElement().getLength() == value.getValue().length()) { //no ns prefix
values.add(value);
}
diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/ConvertSchemaPrefixToDefaultIntention.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/ConvertSchemaPrefixToDefaultIntention.java
index 34c4809aa811..adfec6974ebc 100644
--- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/ConvertSchemaPrefixToDefaultIntention.java
+++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/ConvertSchemaPrefixToDefaultIntention.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2010 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -92,6 +92,7 @@ public class ConvertSchemaPrefixToDefaultIntention extends PsiElementBaseIntenti
}
}
for (XmlAttribute attr : attrs) {
+ //noinspection ConstantConditions
attr.setValue(attr.getValue().substring(index));
}
xmlns.setName("xmlns");
diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java
index cc56168ca95a..d4860becbf13 100644
--- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java
+++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java
@@ -26,7 +26,6 @@ import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
import com.intellij.codeInspection.InspectionProfile;
-import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection;
import com.intellij.codeInspection.htmlInspections.XmlEntitiesInspection;
import com.intellij.lang.ASTNode;
@@ -321,10 +320,9 @@ public class XmlHighlightVisitor extends XmlElementVisitor implements HighlightV
tag, attrName, null);
final String localizedMessage = XmlErrorMessages.message("element.doesnt.have.required.attribute", name, attrName);
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile();
- final LocalInspectionToolWrapper toolWrapper =
- (LocalInspectionToolWrapper)profile.getInspectionTool(RequiredAttributesInspection.SHORT_NAME, tag);
- if (toolWrapper != null) {
- RequiredAttributesInspection inspection = (RequiredAttributesInspection)toolWrapper.getTool();
+ RequiredAttributesInspection inspection =
+ (RequiredAttributesInspection)profile.getUnwrappedTool(RequiredAttributesInspection.SHORT_NAME, tag);
+ if (inspection != null) {
reportOneTagProblem(
tag,
attrName,
diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java
index 916f8f7eb730..c931ba5bff5f 100644
--- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java
+++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java
@@ -250,7 +250,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
resourceUrls.add(s);
}
- final List<String> newLinks = extractEmbeddedFileReferences(virtualFile, contextFile, psiManager);
+ final Set<String> newLinks = extractEmbeddedFileReferences(virtualFile, contextFile, psiManager);
for (String u : newLinks) {
baseUrls.put(u, resourceUrl);
if (!processedLinks.contains(u)) linksToProcess.add(u);
@@ -390,8 +390,8 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
return true;
}
- private static List<String> extractEmbeddedFileReferences(XmlFile file, XmlFile context) {
- final List<String> result = new LinkedList<String>();
+ private static Set<String> extractEmbeddedFileReferences(XmlFile file, XmlFile context) {
+ final Set<String> result = new LinkedHashSet<String>();
if (context != null) {
XmlEntityRefImpl.copyEntityCaches(file, context);
}
@@ -425,23 +425,13 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
String schemaLocation = tag.getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT);
if (schemaLocation != null) {
- final PsiReference[] references = tag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT, null).getValueElement().getReferences();
+ final PsiReference[] references = tag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT).getValueElement().getReferences();
if (references.length > 0) {
- final String namespace = tag.getAttributeValue("namespace");
-
- if (namespace != null && schemaLocation.indexOf('/') == -1) {
- result.add(namespace.substring(0, namespace.lastIndexOf('/') + 1) + schemaLocation);
- }
- else {
- result.add(schemaLocation);
- }
+ result.add(schemaLocation);
}
}
-
- final String prefix = tag.getPrefixByNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI);
- if (prefix != null) {
+ else {
schemaLocation = tag.getAttributeValue("schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI);
-
if (schemaLocation != null) {
final StringTokenizer tokenizer = new StringTokenizer(schemaLocation);
@@ -449,10 +439,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
tokenizer.nextToken();
if (!tokenizer.hasMoreTokens()) break;
String location = tokenizer.nextToken();
-
- if (!result.contains(location)) {
- result.add(location);
- }
+ result.add(location);
}
}
}
@@ -467,10 +454,10 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
return result;
}
- public static List<String> extractEmbeddedFileReferences(final VirtualFile vFile, @Nullable final VirtualFile contextVFile, final PsiManager psiManager) {
- return ApplicationManager.getApplication().runReadAction(new Computable<List<String>>() {
+ public static Set<String> extractEmbeddedFileReferences(final VirtualFile vFile, @Nullable final VirtualFile contextVFile, final PsiManager psiManager) {
+ return ApplicationManager.getApplication().runReadAction(new Computable<Set<String>>() {
@Override
- public List<String> compute() {
+ public Set<String> compute() {
PsiFile file = psiManager.findFile(vFile);
if (file instanceof XmlFile) {
@@ -478,7 +465,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
return extractEmbeddedFileReferences((XmlFile)file, contextFile instanceof XmlFile ? (XmlFile)contextFile : null);
}
- return Collections.emptyList();
+ return Collections.emptySet();
}
});
}
diff --git a/xml/impl/src/com/intellij/codeInsight/editorActions/moveUpDown/XmlMover.java b/xml/impl/src/com/intellij/codeInsight/editorActions/moveUpDown/XmlMover.java
index 3ef95edafd2f..09fb4a06bd14 100644
--- a/xml/impl/src/com/intellij/codeInsight/editorActions/moveUpDown/XmlMover.java
+++ b/xml/impl/src/com/intellij/codeInsight/editorActions/moveUpDown/XmlMover.java
@@ -108,7 +108,7 @@ class XmlMover extends LineMover {
final TextRange moveDestinationRange = new TextRange(
document.getLineStartOffset(info.toMove2.startLine),
- document.getLineStartOffset(info.toMove2.endLine) - 1
+ document.getLineEndOffset(info.toMove2.endLine - 1)
);
if (movedParent instanceof XmlAttribute) {
diff --git a/xml/impl/src/com/intellij/codeInsight/intentions/XmlChooseColorIntentionAction.java b/xml/impl/src/com/intellij/codeInsight/intentions/XmlChooseColorIntentionAction.java
index e92d59bdb5e9..1c0f5aa6986d 100644
--- a/xml/impl/src/com/intellij/codeInsight/intentions/XmlChooseColorIntentionAction.java
+++ b/xml/impl/src/com/intellij/codeInsight/intentions/XmlChooseColorIntentionAction.java
@@ -32,6 +32,7 @@ import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.ui.ColorChooser;
import com.intellij.ui.ColorUtil;
+import com.intellij.ui.JBColor;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -65,25 +66,26 @@ public class XmlChooseColorIntentionAction extends PsiElementBaseIntentionAction
final XmlAttributeValue literal = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class, false);
if (literal == null) return;
final String text = StringUtil.unquoteString(literal.getValue());
- final String hexPrefix = text.startsWith("#") ? "#" : "";
Color oldColor;
try {
oldColor = Color.decode(text);
}
catch (NumberFormatException e) {
- oldColor = Color.GRAY;
+ oldColor = JBColor.GRAY;
}
Color color = ColorChooser.chooseColor(editorComponent, caption, oldColor, true);
if (color == null) return;
if (!Comparing.equal(color, oldColor)) {
if (!CodeInsightUtilBase.preparePsiElementForWrite(element)) return;
- final String newText = hexPrefix + ColorUtil.toHex(color);
+ final String newText = "#" + ColorUtil.toHex(color);
final PsiManager manager = literal.getManager();
final XmlAttribute newAttribute = XmlElementFactory.getInstance(manager.getProject()).createXmlAttribute("name", newText);
final Runnable replaceRunnable = new Runnable() {
public void run() {
- literal.replace(newAttribute.getValueElement());
+ final XmlAttributeValue valueElement = newAttribute.getValueElement();
+ assert valueElement != null;
+ literal.replace(valueElement);
}
};
if (startInWriteAction) {
diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/XmlEmmetParser.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/XmlEmmetParser.java
index b8c5367e8fdf..803b955a41ed 100644
--- a/xml/impl/src/com/intellij/codeInsight/template/emmet/XmlEmmetParser.java
+++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/XmlEmmetParser.java
@@ -349,6 +349,10 @@ public class XmlEmmetParser extends EmmetParser {
final String name = ((IdentifierToken)token).getText();
+ if (name.isEmpty()) {
+ return null;
+ }
+
advance();
token = getToken();
if (token != ZenCodingTokens.EQ) {
diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java
index 3e2280e1de13..b945ca3fdd92 100644
--- a/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java
+++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java
@@ -197,6 +197,10 @@ public class ZenCodingTemplate implements CustomLiveTemplate {
GenerationNode genNode = genNodes.get(i);
TemplateImpl template = genNode.generate(callback, generator, filters, true);
int e = builder.insertTemplate(builder.length(), template, null);
+ if (i < genNodesSize - 1 && genNode.isInsertNewLineBetweenNodes()) {
+ builder.insertText(e, "\n", false);
+ e++;
+ }
if (end == -1 && end < builder.length()) {
end = e;
}
diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGeneratorImpl.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGeneratorImpl.java
index 2fbfc13be583..d595af8403f6 100644
--- a/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGeneratorImpl.java
+++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/generators/XmlZenCodingGeneratorImpl.java
@@ -107,7 +107,7 @@ public class XmlZenCodingGeneratorImpl extends XmlZenCodingGenerator {
@Override
public void visitXmlTag(final XmlTag tag) {
if (!isTagClosed(tag)) {
- tagToClose.add(pointerManager.createLazyPointer(tag));
+ tagToClose.add(pointerManager.createSmartPsiElementPointer(tag));
}
}
});
diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/GenerationNode.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/GenerationNode.java
index 031ed23394ae..e31b36ccb00b 100644
--- a/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/GenerationNode.java
+++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/nodes/GenerationNode.java
@@ -32,6 +32,7 @@ import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.UserDataHolderBase;
+import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
@@ -61,24 +62,39 @@ public class GenerationNode extends UserDataHolderBase {
private final int myTotalIterations;
private String mySurroundedText;
private final boolean myInsertSurroundedTextAtTheEnd;
- private GenerationNode myParent;
+ private final boolean myInsertNewLineBetweenNodes;
+
+ private GenerationNode myParent;
private boolean myContainsSurroundedTextMarker = false;
public GenerationNode(TemplateToken templateToken,
int numberInIteration,
int totalIterations, String surroundedText,
boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
+ this(templateToken, numberInIteration, totalIterations, surroundedText, insertSurroundedTextAtTheEnd, parent, false);
+ }
+
+
+ public GenerationNode(TemplateToken templateToken,
+ int numberInIteration,
+ int totalIterations, String surroundedText,
+ boolean insertSurroundedTextAtTheEnd, GenerationNode parent, boolean insertNewLineBetweenNodes) {
myTemplateToken = templateToken;
myNumberInIteration = numberInIteration;
myTotalIterations = totalIterations;
mySurroundedText = surroundedText;
myInsertSurroundedTextAtTheEnd = insertSurroundedTextAtTheEnd;
+ myInsertNewLineBetweenNodes = insertNewLineBetweenNodes;
if(parent != null) {
parent.addChild(this);
}
}
+ public boolean isInsertNewLineBetweenNodes() {
+ return myInsertNewLineBetweenNodes;
+ }
+
public List<GenerationNode> getChildren() {
return myChildren;
}
@@ -181,12 +197,8 @@ public class GenerationNode extends UserDataHolderBase {
indentStr = "\t";
}
else {
- StringBuilder tab = new StringBuilder();
int tabSize = settings.getTabSize(callback.getFileType());
- while (tabSize-- > 0) {
- tab.append(' ');
- }
- indentStr = tab.toString();
+ indentStr = StringUtil.repeatSymbol(' ', tabSize);
}
for (int i = 0, myChildrenSize = myChildren.size(); i < myChildrenSize; i++) {
@@ -203,7 +215,7 @@ public class GenerationNode extends UserDataHolderBase {
int e = builder.insertTemplate(offset, childTemplate, null);
offset = marker != null ? marker.getEndOffset() : builder.length();
- if (!singleLineFilterEnabled && blockTag && !isNewLineAfter(builder.getText(), offset)) {
+ if (!singleLineFilterEnabled && ((blockTag && !isNewLineAfter(builder.getText(), offset)) || myInsertNewLineBetweenNodes)) {
builder.insertText(offset, "\n" + indentStr, false);
offset += indentStr.length() + 1;
}
diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/AddCustomTagOrAttributeIntentionAction.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/AddCustomTagOrAttributeIntentionAction.java
index ce0d01ef3cc2..ba84b96d3f62 100644
--- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/AddCustomTagOrAttributeIntentionAction.java
+++ b/xml/impl/src/com/intellij/codeInspection/htmlInspections/AddCustomTagOrAttributeIntentionAction.java
@@ -16,10 +16,11 @@
package com.intellij.codeInspection.htmlInspections;
+import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.LocalQuickFix;
-import com.intellij.codeInspection.ModifiableModel;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Key;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.PsiElement;
import com.intellij.util.Consumer;
@@ -32,10 +33,10 @@ import org.jetbrains.annotations.NotNull;
public class AddCustomTagOrAttributeIntentionAction implements LocalQuickFix {
private final String myName;
private final int myType;
- private final String myInspectionName;
+ @NotNull private final Key<HtmlUnknownTagInspection> myInspectionKey;
- public AddCustomTagOrAttributeIntentionAction(@NotNull String shortName, String name, int type) {
- myInspectionName = shortName;
+ public AddCustomTagOrAttributeIntentionAction(@NotNull Key<HtmlUnknownTagInspection> inspectionKey, String name, int type) {
+ myInspectionKey = inspectionKey;
myName = name;
myType = type;
}
@@ -65,10 +66,10 @@ public class AddCustomTagOrAttributeIntentionAction implements LocalQuickFix {
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
- InspectionProjectProfileManager.getInstance(project).getInspectionProfile().modifyProfile(new Consumer<ModifiableModel>() {
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
+ profile.modifyToolSettings(myInspectionKey, element, new Consumer<HtmlUnknownTagInspection>() {
@Override
- public void consume(ModifiableModel model) {
- HtmlUnknownTagInspection tool = (HtmlUnknownTagInspection)model.getUnwrappedTool(myInspectionName, element);
+ public void consume(HtmlUnknownTagInspection tool) {
tool.addCustomPropertyName(myName);
}
});
diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/AddHtmlTagOrAttributeToCustomsIntention.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/AddHtmlTagOrAttributeToCustomsIntention.java
index 63be9c5ab72d..78366a2c0ab1 100644
--- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/AddHtmlTagOrAttributeToCustomsIntention.java
+++ b/xml/impl/src/com/intellij/codeInspection/htmlInspections/AddHtmlTagOrAttributeToCustomsIntention.java
@@ -17,9 +17,11 @@
package com.intellij.codeInspection.htmlInspections;
import com.intellij.codeInsight.intention.IntentionAction;
-import com.intellij.codeInspection.ModifiableModel;
+import com.intellij.codeInspection.InspectionProfile;
+import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Key;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.PsiFile;
import com.intellij.util.Consumer;
@@ -33,10 +35,10 @@ import org.jetbrains.annotations.NotNull;
public class AddHtmlTagOrAttributeToCustomsIntention implements IntentionAction {
private final String myName;
private final int myType;
- private final String myInspectionName;
+ private final Key<InspectionProfileEntry> myInspectionKey;
- public AddHtmlTagOrAttributeToCustomsIntention(String shortName, String name, int type) {
- myInspectionName = shortName;
+ public AddHtmlTagOrAttributeToCustomsIntention(Key<InspectionProfileEntry> inspectionKey, String name, int type) {
+ myInspectionKey = inspectionKey;
myName = name;
myType = type;
}
@@ -68,10 +70,11 @@ public class AddHtmlTagOrAttributeToCustomsIntention implements IntentionAction
}
public void invoke(@NotNull Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
- InspectionProjectProfileManager.getInstance(project).getInspectionProfile().modifyProfile(new Consumer<ModifiableModel>() {
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
+ profile.modifyToolSettings(myInspectionKey, file, new Consumer<InspectionProfileEntry>() {
@Override
- public void consume(ModifiableModel model) {
- XmlEntitiesInspection xmlEntitiesInspection = (XmlEntitiesInspection)model.getUnwrappedTool(myInspectionName, file);
+ public void consume(InspectionProfileEntry entry) {
+ XmlEntitiesInspection xmlEntitiesInspection = (XmlEntitiesInspection) entry;
xmlEntitiesInspection.setAdditionalEntries(myType, appendName(xmlEntitiesInspection.getAdditionalEntries(myType)));
}
});
diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspection.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspection.java
index 9dac096fc6db..58617e8d1b29 100644
--- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspection.java
+++ b/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspection.java
@@ -22,6 +22,7 @@ import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiElement;
import com.intellij.psi.html.HtmlTag;
import com.intellij.psi.xml.XmlAttribute;
@@ -44,6 +45,7 @@ public class HtmlUnknownAttributeInspection extends HtmlUnknownTagInspection {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.htmlInspections.HtmlUnknownAttributeInspection");
@NonNls public static final String ATTRIBUTE_SHORT_NAME = "HtmlUnknownAttribute";
+ public static final Key<HtmlUnknownTagInspection> ATTRIBUTE_KEY = Key.create(ATTRIBUTE_SHORT_NAME);
public HtmlUnknownAttributeInspection() {
super("");
@@ -100,7 +102,7 @@ public class HtmlUnknownAttributeInspection extends HtmlUnknownTagInspection {
boolean maySwitchToHtml5 = HtmlUtil.isCustomHtml5Attribute(name) && !HtmlUtil.hasNonHtml5Doctype(tag);
LocalQuickFix[] quickfixes = new LocalQuickFix[maySwitchToHtml5 ? 3 : 2];
- quickfixes[0] = new AddCustomTagOrAttributeIntentionAction(getShortName(), name, XmlEntitiesInspection.UNKNOWN_ATTRIBUTE);
+ quickfixes[0] = new AddCustomTagOrAttributeIntentionAction(ATTRIBUTE_KEY, name, XmlEntitiesInspection.UNKNOWN_ATTRIBUTE);
quickfixes[1] = new RemoveAttributeIntentionAction(name);
if (maySwitchToHtml5) {
quickfixes[2] = new SwitchToHtml5WithHighPriorityAction();
diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java
index 08ab3339463f..38a54cd7d944 100644
--- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java
+++ b/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java
@@ -24,6 +24,7 @@ import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMExternalizableStringList;
+import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiElement;
import com.intellij.psi.html.HtmlTag;
import com.intellij.psi.impl.source.html.dtd.HtmlElementDescriptorImpl;
@@ -43,7 +44,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
-import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
@@ -63,6 +63,7 @@ public class HtmlUnknownTagInspection extends HtmlLocalInspectionTool {
public JDOMExternalizableStringList myValues;
public boolean myCustomValuesEnabled = true;
@NonNls public static final String TAG_SHORT_NAME = "HtmlUnknownTag";
+ public static final Key<HtmlUnknownTagInspection> TAG_KEY = Key.create(TAG_SHORT_NAME);
public HtmlUnknownTagInspection() {
this("nobr,noembed,comment,noscript,embed,script");
@@ -229,7 +230,7 @@ public class HtmlUnknownTagInspection extends HtmlLocalInspectionTool {
if (!isCustomValuesEnabled() || !isCustomValue(name)) {
final AddCustomTagOrAttributeIntentionAction action =
- new AddCustomTagOrAttributeIntentionAction(getShortName(), name, XmlEntitiesInspection.UNKNOWN_TAG);
+ new AddCustomTagOrAttributeIntentionAction(TAG_KEY, name, XmlEntitiesInspection.UNKNOWN_TAG);
// todo: support "element is not allowed" message for html5
// some tags in html5 cannot be found in xhtml5.xsd if they are located in incorrect context, so they get any-element descriptor (ex. "canvas: tag)
diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/RequiredAttributesInspection.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/RequiredAttributesInspection.java
index d4cdffe1d274..bde145d007a8 100644
--- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/RequiredAttributesInspection.java
+++ b/xml/impl/src/com/intellij/codeInspection/htmlInspections/RequiredAttributesInspection.java
@@ -16,11 +16,13 @@
package com.intellij.codeInspection.htmlInspections;
import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsBundle;
-import com.intellij.codeInspection.XmlSuppressableInspectionTool;
import com.intellij.codeInspection.XmlInspectionGroupNames;
+import com.intellij.codeInspection.XmlSuppressableInspectionTool;
import com.intellij.codeInspection.ex.UnfairLocalInspectionTool;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.util.Key;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.FieldPanel;
import org.jetbrains.annotations.NonNls;
@@ -43,6 +45,7 @@ public class RequiredAttributesInspection extends XmlSuppressableInspectionTool
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection");
@NonNls public static final String SHORT_NAME = "RequiredAttributes";
+ @NonNls public static final Key<InspectionProfileEntry> SHORT_NAME_KEY = Key.create(SHORT_NAME);
@NotNull
public String getGroupDisplayName() {
@@ -87,7 +90,7 @@ public class RequiredAttributesInspection extends XmlSuppressableInspectionTool
}
public IntentionAction getIntentionAction(String name, int type) {
- return new AddHtmlTagOrAttributeToCustomsIntention(getShortName(), name, type);
+ return new AddHtmlTagOrAttributeToCustomsIntention(SHORT_NAME_KEY, name, type);
}
public String getAdditionalEntries(int type) {
diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/XmlInspectionToolProvider.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/XmlInspectionToolProvider.java
deleted file mode 100644
index 287591f79901..000000000000
--- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/XmlInspectionToolProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2000-2009 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.codeInspection.htmlInspections;
-
-import com.intellij.codeInsight.daemon.impl.analysis.*;
-import com.intellij.codeInspection.InspectionToolProvider;
-import com.intellij.xml.util.*;
-
-/**
- * @author yole
- */
-public class XmlInspectionToolProvider implements InspectionToolProvider {
- public Class[] getInspectionClasses() {
- return new Class[] {
- CheckTagEmptyBodyInspection.class,
- CheckDtdReferencesInspection.class,
- CheckEmptyTagInspection.class,
- CheckValidXmlInScriptBodyInspection.class,
- CheckXmlFileWithXercesValidatorInspection.class,
- XmlDuplicatedIdInspection.class,
- RequiredAttributesInspection.class,
- HtmlExtraClosingTagInspection.class,
- XmlWrongRootElementInspection.class,
- HtmlUnknownTagInspection.class,
- HtmlUnknownAttributeInspection.class,
- XmlUnboundNsPrefixInspection.class,
- XmlUnusedNamespaceInspection.class,
- XmlHighlightVisitorBasedInspection.class,
- XmlPathReferenceInspection.class,
- HtmlUnknownTargetInspection.class
- };
- }
-}
diff --git a/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java b/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java
index de54dc37e24c..fb7e632de572 100644
--- a/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java
+++ b/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java
@@ -94,7 +94,7 @@ public class ExternalResourceManagerImpl extends ExternalResourceManagerEx imple
return registrar.getResources();
}
- private final List<ExternalResourceListener> myListeners = new ArrayList<ExternalResourceListener>();
+ private final List<ExternalResourceListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
private long myModificationCount = 0;
private final PathMacrosImpl myPathMacros;
@NonNls private static final String RESOURCE_ELEMENT = "resource";
@@ -437,7 +437,7 @@ public class ExternalResourceManagerImpl extends ExternalResourceManagerEx imple
}
private void fireExternalResourceChanged() {
- for (ExternalResourceListener listener : myListeners.toArray(new ExternalResourceListener[myListeners.size()])) {
+ for (ExternalResourceListener listener : myListeners) {
listener.externalResourceChanged();
}
}
diff --git a/xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java b/xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java
index 5f319306c598..ac828cbf5b88 100644
--- a/xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java
+++ b/xml/impl/src/com/intellij/javaee/HtmlLanguageLevelForm.java
@@ -19,6 +19,7 @@ import com.intellij.openapi.editor.event.DocumentAdapter;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.project.Project;
import com.intellij.ui.TextFieldWithAutoCompletion;
+import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.xml.Html5SchemaProvider;
import com.intellij.xml.util.XmlUtil;
@@ -27,7 +28,6 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -41,7 +41,7 @@ public class HtmlLanguageLevelForm {
private JPanel myContentPanel;
private JPanel myOtherDoctypeWrapper;
private final TextFieldWithAutoCompletion myDoctypeTextField;
- private final List<MyListener> myListeners = new ArrayList<MyListener>();
+ private final List<MyListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
public HtmlLanguageLevelForm(Project project) {
final String[] urls = ExternalResourceManager.getInstance().getResourceUrls(null, true);
diff --git a/xml/impl/src/com/intellij/lang/html/structureView/Html5SectionsNodeProvider.java b/xml/impl/src/com/intellij/lang/html/structureView/Html5SectionsNodeProvider.java
index 49ad3fbba26e..a1cbc3555a89 100644
--- a/xml/impl/src/com/intellij/lang/html/structureView/Html5SectionsNodeProvider.java
+++ b/xml/impl/src/com/intellij/lang/html/structureView/Html5SectionsNodeProvider.java
@@ -15,6 +15,7 @@
*/
package com.intellij.lang.html.structureView;
+import com.intellij.icons.AllIcons;
import com.intellij.ide.util.FileStructureNodeProvider;
import com.intellij.ide.util.treeView.smartTree.ActionPresentation;
import com.intellij.ide.util.treeView.smartTree.ActionPresentationData;
@@ -47,7 +48,7 @@ public class Html5SectionsNodeProvider implements FileStructureNodeProvider<Html
@NotNull
public ActionPresentation getPresentation() {
- return new ActionPresentationData(XmlBundle.message("html5.outline.mode"), null, null);
+ return new ActionPresentationData(XmlBundle.message("html5.outline.mode"), null, AllIcons.Xml.Html5);
}
public String getCheckBoxText() {
diff --git a/xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java b/xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java
index 4609f73e79fc..8b602e1b51a7 100644
--- a/xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java
+++ b/xml/impl/src/com/intellij/psi/formatter/xml/AbstractXmlBlock.java
@@ -22,6 +22,7 @@ import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
+import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.formatter.WhiteSpaceFormattingStrategy;
import com.intellij.psi.formatter.WhiteSpaceFormattingStrategyFactory;
import com.intellij.psi.formatter.common.AbstractBlock;
@@ -61,9 +62,6 @@ public abstract class AbstractXmlBlock extends AbstractBlock {
final boolean preserveSpace) {
super(node, wrap, alignment);
myXmlFormattingPolicy = policy;
- if (node == null) {
- LOG.assertTrue(false);
- }
if (node.getTreeParent() == null) {
myXmlFormattingPolicy.setRootBlock(node, this);
}
@@ -105,9 +103,9 @@ public abstract class AbstractXmlBlock extends AbstractBlock {
public static WrapType getWrapType(final int type) {
- if (type == CodeStyleSettings.DO_NOT_WRAP) return WrapType.NONE;
- if (type == CodeStyleSettings.WRAP_ALWAYS) return WrapType.ALWAYS;
- if (type == CodeStyleSettings.WRAP_AS_NEEDED) return WrapType.NORMAL;
+ if (type == CommonCodeStyleSettings.DO_NOT_WRAP) return WrapType.NONE;
+ if (type == CommonCodeStyleSettings.WRAP_ALWAYS) return WrapType.ALWAYS;
+ if (type == CommonCodeStyleSettings.WRAP_AS_NEEDED) return WrapType.NORMAL;
return WrapType.CHOP_DOWN_IF_LONG;
}
@@ -127,8 +125,8 @@ public abstract class AbstractXmlBlock extends AbstractBlock {
if (myNode.getElementType() == XmlElementType.XML_TEXT) return textWrap;
final IElementType elementType = child.getElementType();
if (elementType == XmlElementType.XML_ATTRIBUTE) return attrWrap;
- if (elementType == XmlElementType.XML_START_TAG_START) return tagBeginWrap;
- if (elementType == XmlElementType.XML_END_TAG_START) {
+ if (elementType == XmlTokenType.XML_START_TAG_START) return tagBeginWrap;
+ if (elementType == XmlTokenType.XML_END_TAG_START) {
final PsiElement parent = SourceTreeToPsiMap.treeElementToPsi(child.getTreeParent());
if (parent instanceof XmlTag) {
final XmlTag tag = (XmlTag)parent;
@@ -138,7 +136,7 @@ public abstract class AbstractXmlBlock extends AbstractBlock {
}
return null;
}
- if (elementType == XmlElementType.XML_TEXT || elementType == XmlElementType.XML_DATA_CHARACTERS) return textWrap;
+ if (elementType == XmlElementType.XML_TEXT || elementType == XmlTokenType.XML_DATA_CHARACTERS) return textWrap;
return null;
}
@@ -273,7 +271,7 @@ public abstract class AbstractXmlBlock extends AbstractBlock {
final Indent indent) {
ASTNode resultNode = child;
ASTNode currentChild = child.getTreeNext();
- while (currentChild != null && currentChild.getElementType() != XmlElementType.XML_END_TAG_START) {
+ while (currentChild != null && currentChild.getElementType() != XmlTokenType.XML_END_TAG_START) {
if (!containsWhiteSpacesOnly(currentChild)) {
currentChild = processChild(result, currentChild, wrap, alignment, indent);
resultNode = currentChild;
@@ -297,7 +295,8 @@ public abstract class AbstractXmlBlock extends AbstractBlock {
new XmlBlock(child, wrap, alignment, myXmlFormattingPolicy, indent, null, isPreserveSpace()) {
protected Wrap getDefaultWrap(final ASTNode node) {
final IElementType type = node.getElementType();
- return type == XmlElementType.XML_ATTRIBUTE_VALUE_TOKEN ? Wrap.createWrap(getWrapType(myXmlFormattingPolicy.getAttributesWrap()), false) : null;
+ return type == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN
+ ? Wrap.createWrap(getWrapType(myXmlFormattingPolicy.getAttributesWrap()), false) : null;
}
}
);
@@ -415,8 +414,8 @@ public abstract class AbstractXmlBlock extends AbstractBlock {
public boolean isLeaf() {
return (isComment(myNode)) ||
myNode.getElementType() == TokenType.WHITE_SPACE ||
- myNode.getElementType() == XmlElementType.XML_DATA_CHARACTERS ||
- myNode.getElementType() == XmlElementType.XML_ATTRIBUTE_VALUE_TOKEN;
+ myNode.getElementType() == XmlTokenType.XML_DATA_CHARACTERS ||
+ myNode.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN;
}
private static boolean isComment(final ASTNode node) {
@@ -460,11 +459,11 @@ public abstract class AbstractXmlBlock extends AbstractBlock {
}
public boolean isCDATAStart() {
- return myNode.getElementType() == XmlElementType.XML_CDATA_START;
+ return myNode.getElementType() == XmlTokenType.XML_CDATA_START;
}
public boolean isCDATAEnd() {
- return myNode.getElementType() == XmlElementType.XML_CDATA_END;
+ return myNode.getElementType() == XmlTokenType.XML_CDATA_END;
}
public static boolean containsWhiteSpacesOnly(ASTNode node) {
diff --git a/xml/impl/src/com/intellij/psi/formatter/xml/XmlBlock.java b/xml/impl/src/com/intellij/psi/formatter/xml/XmlBlock.java
index f4a6dc528b95..89be0169aeeb 100644
--- a/xml/impl/src/com/intellij/psi/formatter/xml/XmlBlock.java
+++ b/xml/impl/src/com/intellij/psi/formatter/xml/XmlBlock.java
@@ -91,28 +91,22 @@ public class XmlBlock extends AbstractXmlBlock {
return result;
}
return splitComment();
- }
-
- if (myNode.getElementType() == XmlElementType.XML_TEXT) {
- if (myXmlFormattingPolicy.getShouldKeepWhiteSpaces()) {
- return EMPTY;
- }
-
- final ASTNode treeParent = myNode.getTreeParent();
- final XmlTag tag = getTag(treeParent);
- if (tag != null) {
- if (myXmlFormattingPolicy.keepWhiteSpacesInsideTag(tag)) {
- return EMPTY;
- }
- }
- }
+ }
if (myNode.getFirstChildNode() != null) {
+ boolean keepWhitespaces = shouldKeepWhitespaces();
final ArrayList<Block> result = new ArrayList<Block>(5);
ASTNode child = myNode.getFirstChildNode();
while (child != null) {
- if (!containsWhiteSpacesOnly(child) && child.getTextLength() > 0) {
- child = processChild(result, child, getDefaultWrap(child), null, getChildDefaultIndent());
+ if (child.getTextLength() > 0) {
+ if (containsWhiteSpacesOnly(child)) {
+ if (keepWhitespaces) {
+ result.add(new ReadOnlyBlock(child));
+ }
+ }
+ else {
+ child = processChild(result, child, getDefaultWrap(child), null, getChildDefaultIndent());
+ }
}
if (child != null) {
LOG.assertTrue(child.getTreeParent() == myNode);
@@ -126,6 +120,24 @@ public class XmlBlock extends AbstractXmlBlock {
}
}
+ private boolean shouldKeepWhitespaces() {
+ if (myNode.getElementType() == XmlElementType.XML_TEXT) {
+ if (myXmlFormattingPolicy.getShouldKeepWhiteSpaces()) {
+ return true;
+ }
+ else {
+ final ASTNode treeParent = myNode.getTreeParent();
+ final XmlTag tag = getTag(treeParent);
+ if (tag != null) {
+ if (myXmlFormattingPolicy.keepWhiteSpacesInsideTag(tag)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
private List<Block> splitAttribute(ASTNode node, XmlFormattingPolicy formattingPolicy) {
final ArrayList<Block> result = new ArrayList<Block>(3);
diff --git a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URIReferenceProvider.java b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URIReferenceProvider.java
index 5c8eb583f01e..23ab5613fe7b 100644
--- a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URIReferenceProvider.java
+++ b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URIReferenceProvider.java
@@ -78,14 +78,9 @@ public class URIReferenceProvider extends PsiReferenceProvider {
}
@Nullable
- public PsiFile resolveResource() {
- final String canonicalText = getCanonicalText();
- return ExternalResourceManager.getInstance().getResourceLocation(canonicalText, myElement.getContainingFile(), null);
- }
-
- @Nullable
public PsiElement resolve() {
- final PsiFile file = resolveResource();
+ final String canonicalText = getCanonicalText();
+ final PsiFile file = ExternalResourceManager.getInstance().getResourceLocation(canonicalText, myElement.getContainingFile(), null);
if (file != null) return file;
return myReference.resolve();
}
@@ -112,7 +107,9 @@ public class URIReferenceProvider extends PsiReferenceProvider {
String s = StringUtil.stripQuotesAroundValue(text);
final PsiElement parent = element.getParent();
- if (parent instanceof XmlAttribute && "xsi:schemaLocation".equals(((XmlAttribute)parent).getName())) {
+ if (parent instanceof XmlAttribute &&
+ XmlUtil.SCHEMA_LOCATION_ATT.equals(((XmlAttribute)parent).getLocalName()) &&
+ XmlUtil.XML_SCHEMA_INSTANCE_URI.equals(((XmlAttribute)parent).getNamespace())) {
final List<PsiReference> refs = new ArrayList<PsiReference>(2);
final StringTokenizer tokenizer = new StringTokenizer(s);
diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java b/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java
index be38440de4d6..de520f9add66 100644
--- a/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java
+++ b/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.codeInsight.lookup.TailTypeDecorator;
+import com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.TextRange;
@@ -288,7 +289,10 @@ public class TagNameReference implements PsiReference {
context instanceof XmlTag ? (XmlTag)context : element, extension);
if (nsInfo != null) {
for (int i = initialSize; i < variants.size(); i++) {
- nsInfo.add(namespace);
+ XmlElementDescriptor descriptor = variants.get(i);
+ nsInfo.add(descriptor instanceof XmlElementDescriptorImpl && !(descriptor instanceof RelaxedHtmlFromSchemaElementDescriptor)
+ ? ((XmlElementDescriptorImpl)descriptor).getNamespaceByContext(element)
+ : namespace);
}
}
}
@@ -299,7 +303,7 @@ public class TagNameReference implements PsiReference {
if (descriptor instanceof AnyXmlElementDescriptor) {
return null;
}
- else if (hasPrefix && descriptor instanceof XmlElementDescriptorImpl &&
+ else if (hasPrefix && descriptor instanceof XmlElementDescriptorImpl &&
!namespaces.contains(((XmlElementDescriptorImpl)descriptor).getNamespace())) {
return null;
}
diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java b/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java
index e9773014b980..45e41d36fc73 100644
--- a/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java
+++ b/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java
@@ -295,7 +295,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag {
while (tokenizer.hasMoreTokens()) {
final String uri = tokenizer.nextToken();
if (tokenizer.hasMoreTokens()) {
- map = initializeSchema(uri, null, tokenizer.nextToken(), map);
+ map = initializeSchema(uri, getNSVersion(uri, this), tokenizer.nextToken(), map);
}
}
}
diff --git a/xml/impl/src/com/intellij/xml/DefaultXmlExtension.java b/xml/impl/src/com/intellij/xml/DefaultXmlExtension.java
index f024e874b2e7..1d1e28f12d7a 100644
--- a/xml/impl/src/com/intellij/xml/DefaultXmlExtension.java
+++ b/xml/impl/src/com/intellij/xml/DefaultXmlExtension.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -173,35 +173,23 @@ public class DefaultXmlExtension extends XmlExtension {
final String namespace = possibleNamespaces.iterator().next();
final Project project = file.getProject();
- final XmlDocument document = file.getDocument();
- assert document != null;
- final XmlTag rootTag = document.getRootTag();
+ final XmlTag rootTag = file.getRootTag();
assert rootTag != null;
- final XmlAttribute[] attributes = rootTag.getAttributes();
- XmlAttribute anchor = null;
- for (XmlAttribute attribute : attributes) {
- final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
- if (attribute.isNamespaceDeclaration() || (descriptor != null && descriptor.isRequired())) {
- anchor = attribute;
- } else {
- break;
- }
- }
+ XmlAttribute anchor = getAnchor(rootTag);
final List<XmlSchemaProvider> providers = XmlSchemaProvider.getAvailableProviders(file);
- String prefix = nsPrefix;
- if (prefix == null) {
- for (XmlSchemaProvider provider : providers) {
- prefix = provider.getDefaultPrefix(namespace, file);
- if (prefix != null) {
- break;
- }
+ String prefix = getPrefix(file, nsPrefix, namespace, providers);
+
+ final XmlElementFactory elementFactory = XmlElementFactory.getInstance(project);
+ String location = getLocation(file, namespace, providers);
+ String xsiPrefix = null;
+ if (location != null) {
+ xsiPrefix = rootTag.getPrefixByNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI);
+ if (xsiPrefix == null) {
+ xsiPrefix = "xsi";
+ rootTag.add(elementFactory.createXmlAttribute("xmlns:xsi", XmlUtil.XML_SCHEMA_INSTANCE_URI));
}
}
- if (prefix == null) {
- prefix = "";
- }
- final XmlElementFactory elementFactory = XmlElementFactory.getInstance(project);
@NonNls final String qname = "xmlns" + (prefix.length() > 0 ? ":"+ prefix :"");
final XmlAttribute attribute = elementFactory.createXmlAttribute(qname, namespace);
@@ -211,29 +199,21 @@ public class DefaultXmlExtension extends XmlExtension {
rootTag.addAfter(attribute, anchor);
}
- String location = null;
- if (namespace.length() > 0) {
- for (XmlSchemaProvider provider : providers) {
- Set<String> locations = provider.getLocations(namespace, file);
- if (locations != null && !locations.isEmpty()) {
- location = locations.iterator().next();
- }
- }
- }
-
if (location != null) {
- XmlAttribute xmlAttribute = rootTag.getAttribute("xsi:schemaLocation");
+ XmlAttribute locationAttribute = rootTag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT, XmlUtil.XML_SCHEMA_INSTANCE_URI);
final String pair = namespace + " " + location;
- if (xmlAttribute == null) {
- xmlAttribute = elementFactory.createXmlAttribute("xsi:schemaLocation", pair);
- rootTag.add(xmlAttribute);
- } else {
- final String value = xmlAttribute.getValue();
- if (!value.contains(namespace)) {
- if (StringUtil.isEmptyOrSpaces(value)) {
- xmlAttribute.setValue(pair);
- } else {
- xmlAttribute.setValue(value.trim() + " " + pair);
+ if (locationAttribute == null) {
+ locationAttribute = elementFactory.createXmlAttribute(xsiPrefix + ":" + XmlUtil.SCHEMA_LOCATION_ATT, pair);
+ rootTag.add(locationAttribute);
+ }
+ else {
+ final String value = locationAttribute.getValue();
+ if (!StringUtil.notNullize(value).contains(namespace)) {
+ if (value == null || StringUtil.isEmptyOrSpaces(value)) {
+ locationAttribute.setValue(pair);
+ }
+ else {
+ locationAttribute.setValue(value.trim() + " " + pair);
}
}
}
@@ -255,6 +235,49 @@ public class DefaultXmlExtension extends XmlExtension {
}
}
+ private static String getPrefix(XmlFile file, String nsPrefix, String namespace, List<XmlSchemaProvider> providers) {
+ String prefix = nsPrefix;
+ if (prefix == null) {
+ for (XmlSchemaProvider provider : providers) {
+ prefix = provider.getDefaultPrefix(namespace, file);
+ if (prefix != null) {
+ break;
+ }
+ }
+ }
+ if (prefix == null) {
+ prefix = "";
+ }
+ return prefix;
+ }
+
+ private static XmlAttribute getAnchor(XmlTag rootTag) {
+ final XmlAttribute[] attributes = rootTag.getAttributes();
+ XmlAttribute anchor = null;
+ for (XmlAttribute attribute : attributes) {
+ final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
+ if (attribute.isNamespaceDeclaration() || (descriptor != null && descriptor.isRequired())) {
+ anchor = attribute;
+ } else {
+ break;
+ }
+ }
+ return anchor;
+ }
+
+ private static String getLocation(XmlFile file, String namespace, List<XmlSchemaProvider> providers) {
+ String location = null;
+ if (namespace.length() > 0) {
+ for (XmlSchemaProvider provider : providers) {
+ Set<String> locations = provider.getLocations(namespace, file);
+ if (locations != null && !locations.isEmpty()) {
+ location = locations.iterator().next();
+ }
+ }
+ }
+ return location;
+ }
+
public SchemaPrefix getPrefixDeclaration(final XmlTag context, String namespacePrefix) {
@NonNls String nsDeclarationAttrName = null;
for(XmlTag t = context; t != null; t = t.getParentTag()) {
diff --git a/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java b/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java
index e455843ed7db..907ca9151988 100644
--- a/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java
+++ b/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java
@@ -4,7 +4,7 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.XmlElementVisitor;
import com.intellij.psi.codeStyle.arrangement.DefaultArrangementEntry;
-import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
+import com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
@@ -14,6 +14,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection;
+import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.EntryType.XML_ATTRIBUTE;
+import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.EntryType.XML_TAG;
+
/**
* @author Eugene.Kudelevsky
*/
@@ -41,7 +44,7 @@ public class XmlArrangementVisitor extends XmlElementVisitor {
@Override
public void visitXmlTag(XmlTag tag) {
final XmlElementArrangementEntry entry = createNewEntry(
- tag.getTextRange(), ArrangementEntryType.XML_TAG, null, true);
+ tag.getTextRange(), XML_TAG, null, true);
processEntry(entry, tag);
}
@@ -49,7 +52,7 @@ public class XmlArrangementVisitor extends XmlElementVisitor {
public void visitXmlAttribute(XmlAttribute attribute) {
final String name = attribute.isNamespaceDeclaration() ? "" : attribute.getName();
final XmlElementArrangementEntry entry = createNewEntry(
- attribute.getTextRange(), ArrangementEntryType.XML_ATTRIBUTE, name, true);
+ attribute.getTextRange(), XML_ATTRIBUTE, name, true);
processEntry(entry, null);
}
@@ -68,7 +71,7 @@ public class XmlArrangementVisitor extends XmlElementVisitor {
@Nullable
private XmlElementArrangementEntry createNewEntry(@NotNull TextRange range,
- @NotNull ArrangementEntryType type,
+ @NotNull ArrangementSettingsToken type,
@Nullable String name,
boolean canBeMatched) {
if (!isWithinBounds(range)) {
@@ -100,4 +103,6 @@ public class XmlArrangementVisitor extends XmlElementVisitor {
}
return false;
}
+
+
}
diff --git a/xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java b/xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java
index e315a79fbd8a..164465d4b0ae 100644
--- a/xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java
+++ b/xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java
@@ -5,7 +5,7 @@ import com.intellij.psi.codeStyle.arrangement.ArrangementEntry;
import com.intellij.psi.codeStyle.arrangement.DefaultArrangementEntry;
import com.intellij.psi.codeStyle.arrangement.NameAwareArrangementEntry;
import com.intellij.psi.codeStyle.arrangement.TypeAwareArrangementEntry;
-import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
+import com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -18,14 +18,15 @@ import java.util.Set;
public class XmlElementArrangementEntry extends DefaultArrangementEntry
implements TypeAwareArrangementEntry, NameAwareArrangementEntry {
- private final ArrangementEntryType myType;
- private final String myName;
+ private final ArrangementSettingsToken myType;
+ private final String myName;
public XmlElementArrangementEntry(@Nullable ArrangementEntry parent,
@NotNull TextRange range,
- @NotNull ArrangementEntryType type,
+ @NotNull ArrangementSettingsToken type,
@Nullable String name,
- boolean canBeMatched) {
+ boolean canBeMatched)
+ {
super(parent, range.getStartOffset(), range.getEndOffset(), canBeMatched);
myName = name;
myType = type;
@@ -39,12 +40,7 @@ public class XmlElementArrangementEntry extends DefaultArrangementEntry
@NotNull
@Override
- public Set<ArrangementEntryType> getTypes() {
+ public Set<ArrangementSettingsToken> getTypes() {
return Collections.singleton(myType);
}
-
- @NotNull
- public ArrangementEntryType getType() {
- return myType;
- }
}
diff --git a/xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java b/xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java
index a13db532b501..c167236ae7d8 100644
--- a/xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java
+++ b/xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java
@@ -7,69 +7,36 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.arrangement.ArrangementSettings;
import com.intellij.psi.codeStyle.arrangement.Rearranger;
-import com.intellij.psi.codeStyle.arrangement.StdArrangementSettings;
import com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule;
-import com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingType;
-import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
-import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
+import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
-import com.intellij.psi.codeStyle.arrangement.order.ArrangementEntryOrderType;
-import com.intellij.psi.codeStyle.arrangement.settings.ArrangementStandardSettingsAware;
-import com.intellij.psi.codeStyle.arrangement.settings.ArrangementStandardSettingsRepresentationAware;
-import com.intellij.psi.codeStyle.arrangement.settings.DefaultArrangementSettingsRepresentationManager;
-import gnu.trove.TObjectIntHashMap;
+import com.intellij.psi.codeStyle.arrangement.std.*;
+import com.intellij.util.containers.ContainerUtilRt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
+import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.EntryType.XML_ATTRIBUTE;
+import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.EntryType.XML_TAG;
+import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.General.*;
+import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.Order.BY_NAME;
+import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.Order.KEEP;
+
/**
* @author Eugene.Kudelevsky
*/
public class XmlRearranger
implements Rearranger<XmlElementArrangementEntry>,
- ArrangementStandardSettingsAware,
- ArrangementStandardSettingsRepresentationAware {
-
- private static final Set<ArrangementEntryType> SUPPORTED_TYPES = EnumSet.of(
- ArrangementEntryType.XML_ATTRIBUTE, ArrangementEntryType.XML_TAG);
+ ArrangementStandardSettingsAware {
+ private static final Set<ArrangementSettingsToken> SUPPORTED_TYPES = ContainerUtilRt.newLinkedHashSet(XML_TAG, XML_ATTRIBUTE);
private static final List<StdArrangementMatchRule> DEFAULT_MATCH_RULES = new ArrayList<StdArrangementMatchRule>();
private static final StdArrangementSettings DEFAULT_SETTINGS = new StdArrangementSettings(
Collections.<ArrangementGroupingRule>emptyList(), DEFAULT_MATCH_RULES);
- @NotNull private static final TObjectIntHashMap<Object> WEIGHTS = new TObjectIntHashMap<Object>();
-
- @NotNull
- private static final Comparator<Object> COMPARATOR = new Comparator<Object>() {
- @Override
- public int compare(Object o1, Object o2) {
- if (WEIGHTS.containsKey(o1) && WEIGHTS.containsKey(o2)) {
- return WEIGHTS.get(o1) - WEIGHTS.get(o2);
- }
- else if (WEIGHTS.containsKey(o1) && !WEIGHTS.containsKey(o2)) {
- return -1;
- }
- else if (!WEIGHTS.containsKey(o1) && WEIGHTS.containsKey(o2)) {
- return 1;
- }
- else {
- return o1.hashCode() - o2.hashCode();
- }
- }
- };
-
- static {
- final Object[] ids = {
- ArrangementEntryType.XML_TAG, ArrangementEntryType.XML_ATTRIBUTE
- };
- for (int i = 0; i < ids.length; i++) {
- WEIGHTS.put(ids[i], i);
- }
- }
-
@Nullable
@Override
public StdArrangementSettings getDefaultSettings() {
@@ -77,29 +44,15 @@ public class XmlRearranger
}
@Override
- public boolean isNameFilterSupported() {
- return true;
- }
-
- @Override
- public boolean isEnabled(@NotNull ArrangementEntryType type, @Nullable ArrangementMatchCondition current) {
- return SUPPORTED_TYPES.contains(type);
- }
-
- @Override
- public boolean isEnabled(@NotNull ArrangementModifier modifier, @Nullable ArrangementMatchCondition current) {
- return false;
- }
-
- @Override
- public boolean isEnabled(@NotNull ArrangementGroupingType groupingType, @Nullable ArrangementEntryOrderType orderType) {
- return false;
+ public boolean isEnabled(@NotNull ArrangementSettingsToken token, @Nullable ArrangementMatchCondition current) {
+ return SUPPORTED_TYPES.contains(token) || StdArrangementTokens.Regexp.NAME.equals(token) || StdArrangementTokens.Regexp.XML_NAMESPACE.equals(token) || KEEP.equals(token)
+ || BY_NAME.equals(token) || SUPPORTED_TYPES.contains(token);
}
@NotNull
@Override
- public Collection<Set<?>> getMutexes() {
- return Collections.<Set<?>>singleton(SUPPORTED_TYPES);
+ public Collection<Set<ArrangementSettingsToken>> getMutexes() {
+ return Collections.singleton(SUPPORTED_TYPES);
}
@Nullable
@@ -108,7 +61,8 @@ public class XmlRearranger
@Nullable Document document,
@NotNull Collection<TextRange> ranges,
@NotNull PsiElement element,
- @Nullable ArrangementSettings settings) {
+ @Nullable ArrangementSettings settings)
+ {
final XmlArrangementParseInfo newEntryInfo = new XmlArrangementParseInfo();
element.accept(new XmlArrangementVisitor(newEntryInfo, Collections.singleton(element.getTextRange())));
@@ -140,43 +94,26 @@ public class XmlRearranger
return -1;
}
- @NotNull
- @Override
- public String getDisplayValue(@NotNull ArrangementEntryType type) {
- switch (type) {
- case XML_TAG:
- return "tag";
- case XML_ATTRIBUTE:
- return "attribute";
- default:
- return DefaultArrangementSettingsRepresentationManager.
- INSTANCE.getDisplayValue(type);
- }
- }
-
- @NotNull
- @Override
- public String getDisplayValue(@NotNull ArrangementModifier modifier) {
- return DefaultArrangementSettingsRepresentationManager.INSTANCE.getDisplayValue(modifier);
- }
-
- @NotNull
+ @Nullable
@Override
- public String getDisplayValue(@NotNull ArrangementGroupingType groupingType) {
- return DefaultArrangementSettingsRepresentationManager.INSTANCE.getDisplayValue(groupingType);
+ public List<CompositeArrangementSettingsToken> getSupportedGroupingTokens() {
+ return null;
}
- @NotNull
+ @Nullable
@Override
- public String getDisplayValue(@NotNull ArrangementEntryOrderType orderType) {
- return DefaultArrangementSettingsRepresentationManager.INSTANCE.getDisplayValue(orderType);
+ public List<CompositeArrangementSettingsToken> getSupportedMatchingTokens() {
+ return ContainerUtilRt.newArrayList(
+ new CompositeArrangementSettingsToken(TYPE, SUPPORTED_TYPES),
+ new CompositeArrangementSettingsToken(StdArrangementTokens.Regexp.NAME),
+ new CompositeArrangementSettingsToken(StdArrangementTokens.Regexp.XML_NAMESPACE),
+ new CompositeArrangementSettingsToken(ORDER, KEEP, BY_NAME)
+ );
}
@NotNull
@Override
- public <T> List<T> sort(@NotNull Collection<T> ids) {
- final List<T> result = new ArrayList<T>(ids);
- Collections.sort(result, COMPARATOR);
- return result;
+ public ArrangementEntryMatcher buildMatcher(@NotNull ArrangementMatchCondition condition) throws IllegalArgumentException {
+ throw new IllegalArgumentException("Can't build a matcher for condition " + condition);
}
}
diff --git a/xml/impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java b/xml/impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java
index 643470597dba..ac00589000d2 100644
--- a/xml/impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java
+++ b/xml/impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java
@@ -109,10 +109,10 @@ public class XmlElementDescriptorImpl implements XmlElementDescriptor, PsiWritab
public String getNamespace(){
String name = getName();
if (name == null) return XmlUtil.EMPTY_URI;
- final String namespacePrefix = XmlUtil.findPrefixByQualifiedName(name);
final XmlNSDescriptorImpl xmlNSDescriptor = (XmlNSDescriptorImpl)getNSDescriptor();
- if(xmlNSDescriptor == null || myDescriptorTag == null) return XmlUtil.EMPTY_URI;
- return "".equals(namespacePrefix) ?
+ if (xmlNSDescriptor == null || myDescriptorTag == null) return XmlUtil.EMPTY_URI;
+ final String namespacePrefix = XmlUtil.findPrefixByQualifiedName(name);
+ return namespacePrefix.isEmpty() ?
xmlNSDescriptor.getDefaultNamespace() :
myDescriptorTag.getNamespaceByPrefix(namespacePrefix);
}
diff --git a/xml/impl/src/com/intellij/xml/util/HtmlUtil.java b/xml/impl/src/com/intellij/xml/util/HtmlUtil.java
index 91cb2bccdd03..86252c1d22f1 100644
--- a/xml/impl/src/com/intellij/xml/util/HtmlUtil.java
+++ b/xml/impl/src/com/intellij/xml/util/HtmlUtil.java
@@ -308,9 +308,8 @@ public class HtmlUtil {
switch (type) {
case XmlEntitiesInspection.UNKNOWN_TAG:
- LocalInspectionToolWrapper wrapper = (LocalInspectionToolWrapper)profile.getInspectionTool(HtmlUnknownTagInspection.TAG_SHORT_NAME,
- containingFile);
- HtmlUnknownTagInspection unknownTagInspection = wrapper != null ? (HtmlUnknownTagInspection)wrapper.getTool() : null;
+ HtmlUnknownTagInspection unknownTagInspection = (HtmlUnknownTagInspection)profile.getUnwrappedTool(HtmlUnknownTagInspection.TAG_SHORT_NAME,
+ containingFile);
if (unknownTagInspection != null) {
return unknownTagInspection.getAdditionalEntries();
}
diff --git a/xml/impl/src/com/intellij/xml/util/XmlDuplicatedIdInspection.java b/xml/impl/src/com/intellij/xml/util/XmlDuplicatedIdInspection.java
index 19b2012fdd1e..ddee1092680d 100644
--- a/xml/impl/src/com/intellij/xml/util/XmlDuplicatedIdInspection.java
+++ b/xml/impl/src/com/intellij/xml/util/XmlDuplicatedIdInspection.java
@@ -15,28 +15,22 @@
*/
package com.intellij.xml.util;
-import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.XmlErrorMessages;
-import com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor;
-import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
-import com.intellij.openapi.extensions.Extensions;
+import com.intellij.codeInspection.XmlSuppressableInspectionTool;
import com.intellij.psi.*;
-import com.intellij.psi.html.HtmlTag;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
-import com.intellij.xml.XmlBundle;
-import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* @author Dmitry Avdeev
*/
-public class XmlDuplicatedIdInspection extends LocalInspectionTool {
+public class XmlDuplicatedIdInspection extends XmlSuppressableInspectionTool {
@NotNull
@Override
@@ -64,70 +58,15 @@ public class XmlDuplicatedIdInspection extends LocalInspectionTool {
final XmlTag tag = (XmlTag)parent.getParent();
if (tag == null) return;
- if (refHolder.isValidatable(tag.getParent()) && refHolder.isDuplicateIdAttributeValue(value)) {
- holder.registerProblem(value, XmlErrorMessages.message("duplicate.id.reference"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
- }
-
- String idRef = XmlHighlightVisitor.getUnquotedValue(value, tag);
-
- if (tag instanceof HtmlTag) {
- idRef = idRef.toLowerCase();
- }
-
- if (XmlUtil.isSimpleXmlAttributeValue(idRef, value) && refHolder.isIdReferenceValue(value)) {
- boolean hasIdDeclaration = refHolder.hasIdDeclaration(idRef);
- if (!hasIdDeclaration && tag instanceof HtmlTag) {
- hasIdDeclaration = refHolder.hasIdDeclaration(value.getValue());
- }
-
- if (!hasIdDeclaration) {
- for(XmlIdContributor contributor: Extensions.getExtensions(XmlIdContributor.EP_NAME)) {
- if (contributor.suppressExistingIdValidation((XmlFile)file)) {
- return;
- }
- }
-
- final FileViewProvider viewProvider = tag.getContainingFile().getViewProvider();
- if (viewProvider instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
- holder.registerProblem(value, XmlErrorMessages.message("invalid.id.reference"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL,
- new XmlDeclareIdInCommentAction(idRef));
-
- }
- else {
- holder.registerProblem(value, XmlErrorMessages.message("invalid.id.reference"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
- }
- }
- }
+ checkValue(value, (XmlFile)file, refHolder, tag, holder);
}
};
}
- public boolean runForWholeFile() {
- return false;
- }
-
- @NotNull
- public HighlightDisplayLevel getDefaultLevel() {
- return HighlightDisplayLevel.ERROR;
- }
-
- public boolean isEnabledByDefault() {
- return true;
- }
-
- @NotNull
- public String getGroupDisplayName() {
- return XmlBundle.message("xml.inspections.group.name");
- }
-
- @NotNull
- public String getDisplayName() {
- return XmlBundle.message("xml.inspections.duplicate.id");
- }
-
- @NotNull
- @NonNls
- public String getShortName() {
- return "XmlDuplicatedId";
+ protected void checkValue(XmlAttributeValue value, XmlFile file, XmlRefCountHolder refHolder, XmlTag tag, ProblemsHolder holder) {
+ if (refHolder.isValidatable(tag.getParent()) && refHolder.isDuplicateIdAttributeValue(value)) {
+ holder.registerProblem(value, XmlErrorMessages.message("duplicate.id.reference"), ProblemHighlightType.GENERIC_ERROR,
+ ElementManipulators.getValueTextRange(value));
+ }
}
}
diff --git a/xml/impl/src/com/intellij/xml/util/XmlInvalidIdInspection.java b/xml/impl/src/com/intellij/xml/util/XmlInvalidIdInspection.java
new file mode 100644
index 000000000000..afe28eda4b4d
--- /dev/null
+++ b/xml/impl/src/com/intellij/xml/util/XmlInvalidIdInspection.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2000-2013 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.xml.util;
+
+import com.intellij.codeInsight.daemon.XmlErrorMessages;
+import com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor;
+import com.intellij.codeInspection.ProblemHighlightType;
+import com.intellij.codeInspection.ProblemsHolder;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.psi.FileViewProvider;
+import com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider;
+import com.intellij.psi.html.HtmlTag;
+import com.intellij.psi.xml.XmlAttributeValue;
+import com.intellij.psi.xml.XmlFile;
+import com.intellij.psi.xml.XmlTag;
+
+/**
+ * @author Dmitry Avdeev
+ */
+public class XmlInvalidIdInspection extends XmlDuplicatedIdInspection {
+
+ protected void checkValue(XmlAttributeValue value, XmlFile file, XmlRefCountHolder refHolder, XmlTag tag, ProblemsHolder holder) {
+
+ String idRef = XmlHighlightVisitor.getUnquotedValue(value, tag);
+
+ if (tag instanceof HtmlTag) {
+ idRef = idRef.toLowerCase();
+ }
+
+ if (XmlUtil.isSimpleXmlAttributeValue(idRef, value) && refHolder.isIdReferenceValue(value)) {
+ boolean hasIdDeclaration = refHolder.hasIdDeclaration(idRef);
+ if (!hasIdDeclaration && tag instanceof HtmlTag) {
+ hasIdDeclaration = refHolder.hasIdDeclaration(value.getValue());
+ }
+
+ if (!hasIdDeclaration) {
+ for(XmlIdContributor contributor: Extensions.getExtensions(XmlIdContributor.EP_NAME)) {
+ if (contributor.suppressExistingIdValidation(file)) {
+ return;
+ }
+ }
+
+ final FileViewProvider viewProvider = tag.getContainingFile().getViewProvider();
+ if (viewProvider instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
+ holder.registerProblem(value, XmlErrorMessages.message("invalid.id.reference"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL,
+ new XmlDeclareIdInCommentAction(idRef));
+
+ }
+ else {
+ holder.registerProblem(value, XmlErrorMessages.message("invalid.id.reference"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
+ }
+ }
+ }
+ }
+}
diff --git a/xml/impl/src/com/intellij/xml/util/XmlReferenceContributor.java b/xml/impl/src/com/intellij/xml/util/XmlReferenceContributor.java
index 6b68974f4ecc..21d6abcca803 100644
--- a/xml/impl/src/com/intellij/xml/util/XmlReferenceContributor.java
+++ b/xml/impl/src/com/intellij/xml/util/XmlReferenceContributor.java
@@ -4,7 +4,6 @@ import com.intellij.codeInsight.daemon.impl.analysis.encoding.XmlEncodingReferen
import com.intellij.html.impl.providers.MicrodataReferenceProvider;
import com.intellij.html.impl.util.MicrodataUtil;
import com.intellij.patterns.PlatformPatterns;
-import com.intellij.patterns.XmlPatterns;
import com.intellij.psi.PsiReferenceContributor;
import com.intellij.psi.PsiReferenceRegistrar;
import com.intellij.psi.filters.*;
@@ -16,7 +15,6 @@ import com.intellij.psi.impl.source.resolve.reference.impl.providers.SchemaRefer
import com.intellij.psi.impl.source.resolve.reference.impl.providers.URIReferenceProvider;
import com.intellij.psi.xml.*;
-import static com.intellij.patterns.StandardPatterns.string;
import static com.intellij.patterns.XmlPatterns.*;
/**
@@ -82,7 +80,7 @@ public class XmlReferenceContributor extends PsiReferenceContributor {
registrar.registerReferenceProvider(
xmlAttributeValue().withLocalName("schemaLocation","namespace").
withSuperParent(2,
- xmlTag().withNamespace(XmlUtil.SCHEMA_URIS).withLocalName(string().oneOf("import", "include","redefine"))),
+ xmlTag().withNamespace(XmlUtil.SCHEMA_URIS).withLocalName("import", "include","redefine")),
uriProvider);
XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, URIReferenceProvider.ELEMENT_FILTER, true, uriProvider);
@@ -90,6 +88,6 @@ public class XmlReferenceContributor extends PsiReferenceContributor {
XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[] {"encoding"}, new ScopeFilter(new ParentElementFilter(new ClassFilter(XmlProcessingInstruction.class))), true,
new XmlEncodingReferenceProvider());
- registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue(), new XmlPrefixReferenceProvider());
+ registrar.registerReferenceProvider(xmlAttributeValue(), new XmlPrefixReferenceProvider());
}
}
diff --git a/xml/impl/src/com/intellij/xml/util/XmlUtil.java b/xml/impl/src/com/intellij/xml/util/XmlUtil.java
index e9c8abd6c2ba..f18bf30f993b 100644
--- a/xml/impl/src/com/intellij/xml/util/XmlUtil.java
+++ b/xml/impl/src/com/intellij/xml/util/XmlUtil.java
@@ -197,15 +197,15 @@ public class XmlUtil {
}
@Nullable
- public static String findNamespacePrefixByURI(XmlFile file, @NonNls String uri) {
+ public static String findNamespacePrefixByURI(XmlFile file, @NotNull @NonNls String uri) {
final XmlTag tag = file.getRootTag();
if (tag == null) return null;
for (XmlAttribute attribute : tag.getAttributes()) {
- if (attribute.getName().startsWith("xmlns:") && attribute.getValue().equals(uri)) {
+ if (attribute.getName().startsWith("xmlns:") && uri.equals(attribute.getValue())) {
return attribute.getName().substring("xmlns:".length());
}
- if ("xmlns".equals(attribute.getName()) && attribute.getValue().equals(uri)) return "";
+ if ("xmlns".equals(attribute.getName()) && uri.equals(attribute.getValue())) return "";
}
return null;
@@ -1398,6 +1398,7 @@ public class XmlUtil {
return contextTag.getNamespaceByPrefix(prefix);
}
+ @NotNull
public static String findPrefixByQualifiedName(@NotNull String name) {
final int prefixEnd = name.indexOf(':');
if (prefixEnd > 0) {