diff options
author | Tor Norbye <tnorbye@google.com> | 2013-08-16 08:53:25 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-08-16 08:53:25 -0700 |
commit | 4db7dfd37df60de478b5d99be0554bc0e06dfdba (patch) | |
tree | 01e1b92d88bbb2b9cdf0941627054e7933c11ead /xml | |
parent | bb2fc4a79dd544c91510116bc692e0b8b09d2341 (diff) | |
download | idea-4db7dfd37df60de478b5d99be0554bc0e06dfdba.tar.gz |
Snapshot dc8d47d344cb8e7b04ed2af7a93fd95627f38ee0 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I7d6b4a705cb79fae78d9e845acad2d50fa3f4402
Diffstat (limited to 'xml')
10 files changed, 43 insertions, 96 deletions
diff --git a/xml/dom-openapi/src/com/intellij/util/xml/converters/DelimitedListConverter.java b/xml/dom-openapi/src/com/intellij/util/xml/converters/DelimitedListConverter.java index c15924c5f8cc..079495541c64 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/converters/DelimitedListConverter.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/converters/DelimitedListConverter.java @@ -25,6 +25,7 @@ package com.intellij.util.xml.converters; import com.intellij.codeInsight.daemon.EmptyResolveMessageProvider; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.text.DelimitedListProcessor; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; diff --git a/xml/dom-openapi/src/com/intellij/util/xml/converters/DelimitedListProcessor.java b/xml/dom-openapi/src/com/intellij/util/xml/converters/DelimitedListProcessor.java deleted file mode 100644 index ba05968c6a15..000000000000 --- a/xml/dom-openapi/src/com/intellij/util/xml/converters/DelimitedListProcessor.java +++ /dev/null @@ -1,66 +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.util.xml.converters; - -import org.jetbrains.annotations.NotNull; - -/** - * @author Dmitry Avdeev - */ -public abstract class DelimitedListProcessor { - - private final String myDelimiters; - - public DelimitedListProcessor(final String delimiters) { - myDelimiters = delimiters; - } - - public void processText(final @NotNull String text) { - int start; - int pos = 0; - - do { - start = pos; - pos = skipDelimiters(text, pos); - if (pos == text.length()) { - processToken(start, pos, true); - break; - } - start = pos; - while (++pos < text.length() && !isDelimiter(text.charAt(pos))) {} - processToken(start, pos, false); - pos++; - } while(pos < text.length()); - - } - - protected abstract void processToken(final int start, final int end, final boolean delimitersOnly); - - protected int skipDelimiters(String s, int pos) { - while (pos < s.length()) { - final char ch = s.charAt(pos); - if (!isDelimiter(ch)) { - break; - } - pos++; - } - return pos; - } - - protected boolean isDelimiter(char ch) { - return ch < ' ' || myDelimiters.indexOf(ch) != -1; - } -} diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DelimitedListProcessorTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DelimitedListProcessorTest.java index a206e43b5804..0dd231ec5ec4 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DelimitedListProcessorTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DelimitedListProcessorTest.java @@ -1,6 +1,6 @@ package com.intellij.util.xml; -import com.intellij.util.xml.converters.DelimitedListProcessor; +import com.intellij.openapi.util.text.DelimitedListProcessor; import junit.framework.TestCase; import java.util.ArrayList; diff --git a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java index 11677b3ed5b5..71cba6f09053 100644 --- a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java +++ b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlGtTypedHandler.java @@ -47,7 +47,12 @@ import org.jetbrains.annotations.NonNls; public class XmlGtTypedHandler extends TypedHandlerDelegate { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.editorActions.TypedHandler"); - public Result beforeCharTyped(final char c, final Project project, final Editor editor, final PsiFile editedFile, final FileType fileType) { + public Result beforeCharTyped(final char c, final Project project, Editor editor, PsiFile editedFile, final FileType fileType) { + final Editor injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, editedFile); + if (editor != injectedEditor) { + editor = injectedEditor; + editedFile = PsiDocumentManager.getInstance(project).getPsiFile(injectedEditor.getDocument()); + } final WebEditorOptions webEditorOptions = WebEditorOptions.getInstance(); if (c == '>' && webEditorOptions != null && webEditorOptions.isAutomaticallyInsertClosingTag() && fileContainsXmlLanguage(editedFile)) { PsiDocumentManager.getInstance(project).commitAllDocuments(); @@ -66,13 +71,6 @@ public class XmlGtTypedHandler extends TypedHandlerDelegate { // <xml_code><caret><outer_element> elementAtCaret = element = provider.findElementAt(offset - 1, XMLLanguage.class); } - if (element == null && offset > 0) { - // seems like an injection in a template file - final PsiElement injectedElement = InjectedLanguageUtil.findInjectedElementNoCommit(file, offset); - if (injectedElement != null && injectedElement.getContainingFile() instanceof XmlFile) { - elementAtCaret = element = injectedElement; - } - } if (!(element instanceof PsiWhiteSpace)) { boolean nonAcceptableDelimiter = true; diff --git a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/IdReferenceProvider.java b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/IdReferenceProvider.java index f7dd52aea37e..f8b14534f9cb 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/IdReferenceProvider.java +++ b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/IdReferenceProvider.java @@ -19,7 +19,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.PsiReferenceProvider; import com.intellij.psi.filters.ElementFilter; -import com.intellij.psi.impl.source.resolve.reference.PsiReferenceProviderBase; import com.intellij.psi.templateLanguages.OuterLanguageElement; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlAttributeValue; diff --git a/xml/impl/src/com/intellij/xml/util/XmlRefCountHolder.java b/xml/impl/src/com/intellij/xml/util/XmlRefCountHolder.java index 0a43ad190e36..023e3a97c441 100644 --- a/xml/impl/src/com/intellij/xml/util/XmlRefCountHolder.java +++ b/xml/impl/src/com/intellij/xml/util/XmlRefCountHolder.java @@ -226,28 +226,28 @@ public class XmlRefCountHolder { if (descriptor == null) return; final XmlAttributeDescriptor attributeDescriptor = descriptor.getAttributeDescriptor(attribute); - if (attributeDescriptor == null) return; - - if (attributeDescriptor.hasIdType()) { - updateMap(attribute, value, false); - } - else { - final PsiReference[] references = value.getReferences(); - for (PsiReference r : references) { - if (r instanceof IdReferenceProvider.GlobalAttributeValueSelfReference /*&& !r.isSoft()*/) { - updateMap(attribute, value, r.isSoft()); - } - else if (r instanceof SchemaPrefixReference) { - SchemaPrefix prefix = ((SchemaPrefixReference)r).resolve(); - if (prefix != null) { - myHolder.addUsedPrefix(prefix.getName()); + if (attributeDescriptor != null) { + if (attributeDescriptor.hasIdType()) { + updateMap(attribute, value, false); + } + else { + final PsiReference[] references = value.getReferences(); + for (PsiReference r : references) { + if (r instanceof IdReferenceProvider.GlobalAttributeValueSelfReference /*&& !r.isSoft()*/) { + updateMap(attribute, value, r.isSoft()); + } + else if (r instanceof SchemaPrefixReference) { + SchemaPrefix prefix = ((SchemaPrefixReference)r).resolve(); + if (prefix != null) { + myHolder.addUsedPrefix(prefix.getName()); + } } } } - } - if (attributeDescriptor.hasIdRefType() && PsiTreeUtil.getChildOfType(value, OuterLanguageElement.class) == null) { - myHolder.registerIdReference(value); + if (attributeDescriptor.hasIdRefType() && PsiTreeUtil.getChildOfType(value, OuterLanguageElement.class) == null) { + myHolder.registerIdReference(value); + } } String s = value.getValue(); diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/references/IdRefProvider.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/references/IdRefProvider.java index af803b4a62e7..d3857c7f728b 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/references/IdRefProvider.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/references/IdRefProvider.java @@ -23,7 +23,7 @@ import com.intellij.patterns.XmlAttributeValuePattern; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.PsiReferenceBase; -import com.intellij.psi.impl.source.resolve.reference.PsiReferenceProviderBase; +import com.intellij.psi.PsiReferenceProvider; import com.intellij.psi.impl.source.resolve.reference.impl.providers.AttributeValueSelfReference; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; @@ -40,7 +40,7 @@ import java.util.Set; import static com.intellij.patterns.XmlPatterns.xmlAttribute; import static com.intellij.patterns.XmlPatterns.xmlAttributeValue; -public class IdRefProvider extends PsiReferenceProviderBase { +public class IdRefProvider extends PsiReferenceProvider { public static final HasIdRefTypeCondition HAS_ID_REF_TYPE = new HasIdRefTypeCondition(); public static final HasIdTypeCondition HAS_ID_TYPE = new HasIdTypeCondition(); diff --git a/xml/tests/src/com/intellij/xml/XmlNamespacesTest.java b/xml/tests/src/com/intellij/xml/XmlNamespacesTest.java index e457bdc1cfb9..5e0932b2a579 100644 --- a/xml/tests/src/com/intellij/xml/XmlNamespacesTest.java +++ b/xml/tests/src/com/intellij/xml/XmlNamespacesTest.java @@ -216,6 +216,10 @@ public class XmlNamespacesTest extends CodeInsightFixtureTestCase { myFixture.checkResultByFile("spring_after.xml"); } + public void testXsiType() throws Exception { + myFixture.testHighlighting("import.xml", "import.xsd"); + } + private void doUnusedDeclarationTest(String text, String after, String name) throws Exception { doUnusedDeclarationTest(text, after, name, true); } diff --git a/xml/tests/testData/unusedNs/import.xml b/xml/tests/testData/unusedNs/import.xml new file mode 100644 index 000000000000..9468f0f982e2 --- /dev/null +++ b/xml/tests/testData/unusedNs/import.xml @@ -0,0 +1,5 @@ +<A xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="myNamespace" + xmlns:c="myNamespace" + xsi:type="c:CType"> +</A>
\ No newline at end of file diff --git a/xml/tests/testData/unusedNs/import.xsd b/xml/tests/testData/unusedNs/import.xsd new file mode 100644 index 000000000000..e40fae5ccb46 --- /dev/null +++ b/xml/tests/testData/unusedNs/import.xsd @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" + version="eeee" blockDefault="#all" finalDefault="" targetNamespace="myNamespace"> + + <xsd:simpleType name="CType"></xsd:simpleType> +</xsd:schema>
\ No newline at end of file |