diff options
author | Tor Norbye <tnorbye@google.com> | 2013-06-21 16:58:30 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-06-21 16:58:30 -0700 |
commit | c6218e46d5d2017e987ecdbd99b318a95c42abc0 (patch) | |
tree | 85106b3c757a794fb274159cebe07c8d979740a5 /xml/impl | |
parent | 0e154c74931b6ff5ad6e0ec512b32e30df3cb068 (diff) | |
download | idea-c6218e46d5d2017e987ecdbd99b318a95c42abc0.tar.gz |
Snapshot d8891a7de15cebb78b6ce5711e50e531b42c0baf from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: Ida9d1b0a2341112b9ebcf67bf560c8f62f0afdc6
Diffstat (limited to 'xml/impl')
14 files changed, 868 insertions, 169 deletions
diff --git a/xml/impl/resources/com/intellij/codeInsight/completion/TagNameReferenceCompletionProvider.java b/xml/impl/resources/com/intellij/codeInsight/completion/TagNameReferenceCompletionProvider.java index 45220b08a552..fa2f1609c3b9 100644 --- a/xml/impl/resources/com/intellij/codeInsight/completion/TagNameReferenceCompletionProvider.java +++ b/xml/impl/resources/com/intellij/codeInsight/completion/TagNameReferenceCompletionProvider.java @@ -23,11 +23,9 @@ import com.intellij.codeInsight.lookup.TailTypeDecorator; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; -import com.intellij.psi.impl.source.xml.SchemaPrefixReference; import com.intellij.psi.impl.source.xml.TagNameReference; import com.intellij.psi.xml.XmlTag; import com.intellij.util.Consumer; -import com.intellij.util.PairConsumer; import com.intellij.util.ProcessingContext; import com.intellij.xml.XmlTagNameProvider; import org.jetbrains.annotations.NotNull; @@ -50,21 +48,12 @@ public class TagNameReferenceCompletionProvider extends CompletionProvider<Compl @Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, - @NotNull final CompletionResultSet result) { - LegacyCompletionContributor.processReferences(parameters, result, new PairConsumer<PsiReference, CompletionResultSet>() { - @Override - public void consume(PsiReference reference, CompletionResultSet set) { - if (reference instanceof TagNameReference) { - collectCompletionVariants((TagNameReference)reference, set); - } - else if (reference instanceof SchemaPrefixReference) { - TagNameReference tagNameReference = ((SchemaPrefixReference)reference).getTagNameReference(); - if (tagNameReference != null && !tagNameReference.isStartTagFlag()) { - set.consume(createClosingTagLookupElement((XmlTag)tagNameReference.getElement(), true, tagNameReference.getNameElement())); - } - } - } - }); + @NotNull CompletionResultSet result) { + PsiReference reference = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset()); + if (reference instanceof TagNameReference) { + TagNameReference tagNameReference = (TagNameReference)reference; + collectCompletionVariants(tagNameReference, result); + } } public static void collectCompletionVariants(TagNameReference tagNameReference, diff --git a/xml/impl/src/com/intellij/ide/browsers/OpenFileInBrowserAction.java b/xml/impl/src/com/intellij/ide/browsers/OpenFileInBrowserAction.java index 969e7f8b3793..130fd1fc17f9 100644 --- a/xml/impl/src/com/intellij/ide/browsers/OpenFileInBrowserAction.java +++ b/xml/impl/src/com/intellij/ide/browsers/OpenFileInBrowserAction.java @@ -25,7 +25,6 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiFile; -import com.intellij.testFramework.LightVirtualFile; import com.intellij.xml.XmlBundle; import com.intellij.xml.util.HtmlUtil; @@ -40,59 +39,48 @@ public class OpenFileInBrowserAction extends DumbAwareAction { final PsiFile file = LangDataKeys.PSI_FILE.getData(dataContext); final Presentation presentation = e.getPresentation(); - if (file == null || file.getVirtualFile() == null) { - presentation.setVisible(false); - presentation.setEnabled(false); - return; - } + if (file != null && file.getVirtualFile() != null) { + presentation.setVisible(true); - Pair<WebBrowserUrlProvider, Url> browserUrlProvider = WebBrowserServiceImpl.getProvider(file); - final boolean isHtmlFile = HtmlUtil.isHtmlFile(file); - if (browserUrlProvider == null) { - if (file.getVirtualFile() instanceof LightVirtualFile) { - presentation.setVisible(false); - presentation.setEnabled(false); - return; - } - else { - presentation.setEnabled(isHtmlFile); - } - } - else { - presentation.setEnabled(true); - } - presentation.setVisible(true); + Pair<WebBrowserUrlProvider, Url> browserUrlProvider = WebBrowserServiceImpl.getProvider(file); + final boolean isHtmlFile = HtmlUtil.isHtmlFile(file); + presentation.setEnabled(browserUrlProvider != null || isHtmlFile); - String text = getTemplatePresentation().getText(); - String description = getTemplatePresentation().getDescription(); + String text = getTemplatePresentation().getText(); + String description = getTemplatePresentation().getDescription(); - if (browserUrlProvider != null) { - final String customText = browserUrlProvider.first.getOpenInBrowserActionText(file); - if (customText != null) { - text = customText; - } - final String customDescription = browserUrlProvider.first.getOpenInBrowserActionDescription(file); - if (customDescription != null) { - description = customDescription; + if (browserUrlProvider != null) { + final String customText = browserUrlProvider.first.getOpenInBrowserActionText(file); + if (customText != null) { + text = customText; + } + final String customDescription = browserUrlProvider.first.getOpenInBrowserActionDescription(file); + if (customDescription != null) { + description = customDescription; + } + if (isHtmlFile) { + description += " (hold Shift to open URL of local file)"; + } } - if (isHtmlFile) { - description += " (hold Shift to open URL of local file)"; - } - } - presentation.setText(text); - presentation.setDescription(description); + presentation.setText(text); + presentation.setDescription(description); - GeneralSettings settings = GeneralSettings.getInstance(); - if (!settings.isUseDefaultBrowser()) { - BrowsersConfiguration.BrowserFamily family = BrowsersConfiguration.getInstance().findFamilyByPath(settings.getBrowserPath()); - if (family != null) { - presentation.setIcon(family.getIcon()); + GeneralSettings settings = GeneralSettings.getInstance(); + if (!settings.isUseDefaultBrowser()) { + BrowsersConfiguration.BrowserFamily family = BrowsersConfiguration.getInstance().findFamilyByPath(settings.getBrowserPath()); + if (family != null) { + presentation.setIcon(family.getIcon()); + } } - } - if (ActionPlaces.isPopupPlace(e.getPlace())) { - presentation.setVisible(presentation.isEnabled()); + if (ActionPlaces.isPopupPlace(e.getPlace())) { + presentation.setVisible(presentation.isEnabled()); + } + } + else { + presentation.setVisible(false); + presentation.setEnabled(false); } } diff --git a/xml/impl/src/com/intellij/ide/browsers/UrlImpl.java b/xml/impl/src/com/intellij/ide/browsers/UrlImpl.java index 05fa403faf67..c89c6c5bb7dd 100644 --- a/xml/impl/src/com/intellij/ide/browsers/UrlImpl.java +++ b/xml/impl/src/com/intellij/ide/browsers/UrlImpl.java @@ -13,7 +13,6 @@ import java.net.URISyntaxException; public final class UrlImpl implements Url { private String raw; - private final String scheme; private final String authority; @@ -22,8 +21,6 @@ public final class UrlImpl implements Url { private final String parameters; - private String externalFormWithoutParameters; - public UrlImpl(@Nullable String raw, @NotNull String scheme, @Nullable String authority, @Nullable String path, @Nullable String parameters) { this.raw = raw; this.scheme = scheme; @@ -88,41 +85,28 @@ public final class UrlImpl implements Url { @Override @NotNull public String toExternalForm(boolean skipQueryAndFragment) { - if (parameters == null || !skipQueryAndFragment) { - if (raw != null) { - return raw; - } - } - else if (externalFormWithoutParameters != null) { - return externalFormWithoutParameters; + if (raw != null && (parameters == null || !skipQueryAndFragment)) { + return raw; } - String result; try { String externalPath = path; boolean inLocalFileSystem = isInLocalFileSystem(); if (inLocalFileSystem && SystemInfo.isWindows && externalPath.charAt(0) != '/') { externalPath = '/' + externalPath; } - result = new URI(scheme, inLocalFileSystem ? "" : authority, externalPath, null, null).toASCIIString(); + String result = new URI(scheme, inLocalFileSystem ? "" : authority, externalPath, null, null).toASCIIString(); + if (!skipQueryAndFragment) { + if (parameters != null) { + result += parameters; + } + raw = result; + } + return result; } catch (URISyntaxException e) { throw new RuntimeException(e); } - - if (skipQueryAndFragment) { - externalFormWithoutParameters = result; - if (parameters == null) { - raw = externalFormWithoutParameters; - } - } - else { - if (parameters != null) { - result += parameters; - } - raw = result; - } - return result; } @NotNull diff --git a/xml/impl/src/com/intellij/ide/browsers/Urls.java b/xml/impl/src/com/intellij/ide/browsers/Urls.java index 797d95422615..f6aa46e10067 100644 --- a/xml/impl/src/com/intellij/ide/browsers/Urls.java +++ b/xml/impl/src/com/intellij/ide/browsers/Urls.java @@ -2,7 +2,6 @@ package com.intellij.ide.browsers; import com.google.common.base.CharMatcher; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VfsUtil; @@ -49,12 +48,7 @@ public final class Urls { } String scheme = matcher.group(1); String authority = StringUtil.nullize(matcher.group(2)); - String path = StringUtil.nullize(matcher.group(3)); - if (path != null) { - path = FileUtil.toCanonicalUriPath(path); - } - String parameters = matcher.group(4); if (authority != null && StandardFileSystems.FILE_PROTOCOL.equals(scheme)) { path = path == null ? authority : (authority + path); diff --git a/xml/impl/src/com/intellij/ide/browsers/impl/WebBrowserServiceImpl.java b/xml/impl/src/com/intellij/ide/browsers/impl/WebBrowserServiceImpl.java index bee53af627be..bb477c2e5c19 100644 --- a/xml/impl/src/com/intellij/ide/browsers/impl/WebBrowserServiceImpl.java +++ b/xml/impl/src/com/intellij/ide/browsers/impl/WebBrowserServiceImpl.java @@ -26,7 +26,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.testFramework.LightVirtualFile; import com.intellij.xml.util.HtmlUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,10 +36,9 @@ import java.util.List; public class WebBrowserServiceImpl extends WebBrowserService { @Override public boolean canOpenInBrowser(@NotNull PsiElement psiElement) { - PsiFile psiFile = psiElement instanceof PsiFile ? (PsiFile)psiElement : psiElement.getContainingFile(); - VirtualFile virtualFile = psiFile == null ? null : psiFile.getVirtualFile(); - return virtualFile != null && - ((HtmlUtil.isHtmlFile(psiFile) && !(virtualFile instanceof LightVirtualFile)) || getProvider(psiElement, psiFile) != null); + final PsiFile psiFile = psiElement instanceof PsiFile ? (PsiFile)psiElement : psiElement.getContainingFile(); + return psiFile != null && psiFile.getVirtualFile() != null && + (HtmlUtil.isHtmlFile(psiFile) || getProvider(psiElement) != null); } @Override @@ -78,7 +76,7 @@ public class WebBrowserServiceImpl extends WebBrowserService { } } } - return virtualFile instanceof LightVirtualFile ? null : Urls.newFromVirtualFile(virtualFile); + return Urls.newFromVirtualFile(virtualFile); } @Override @@ -95,10 +93,10 @@ public class WebBrowserServiceImpl extends WebBrowserService { @Nullable public static Pair<WebBrowserUrlProvider, Url> getProvider(@Nullable PsiElement element) { PsiFile psiFile = element == null ? null : element.getContainingFile(); - return psiFile == null ? null : getProvider(element, psiFile); - } + if (psiFile == null) { + return null; + } - private static Pair<WebBrowserUrlProvider, Url> getProvider(PsiElement element, PsiFile psiFile) { Ref<Url> result = Ref.create(); List<WebBrowserUrlProvider> allProviders = Arrays.asList(WebBrowserUrlProvider.EP_NAME.getExtensions()); for (WebBrowserUrlProvider urlProvider : DumbService.getInstance(element.getProject()).filterByDumbAwareness(allProviders)) { diff --git a/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java b/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java index 8606e11e899c..cd97d262957b 100644 --- a/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java +++ b/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java @@ -16,28 +16,570 @@ package com.intellij.javaee; import com.intellij.application.options.PathMacrosImpl; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.components.State; -import com.intellij.openapi.components.Storage; -import com.intellij.openapi.components.StoragePathMacros; +import com.intellij.application.options.ReplacePathToMacroMap; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.components.*; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.JDOMExternalizable; -import com.intellij.openapi.util.NotNullLazyKey; +import com.intellij.openapi.util.*; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiFile; +import com.intellij.psi.xml.XmlFile; +import com.intellij.util.ArrayUtil; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.HashMap; +import com.intellij.xml.Html5SchemaProvider; +import com.intellij.xml.XmlSchemaProvider; +import com.intellij.xml.util.XmlUtil; +import org.jdom.Element; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; + +import java.io.File; +import java.net.URL; +import java.util.*; /** * @author mike */ @State(name = "ExternalResourceManagerImpl", storages = {@Storage( file = StoragePathMacros.APP_CONFIG + "/other.xml")}) -public class ExternalResourceManagerImpl extends ExternalResourceManagerExImpl implements JDOMExternalizable { +public class ExternalResourceManagerImpl extends ExternalResourceManagerEx implements JDOMExternalizable { + static final Logger LOG = Logger.getInstance("#com.intellij.j2ee.openapi.impl.ExternalResourceManagerImpl"); + + @NonNls public static final String J2EE_1_3 = "http://java.sun.com/dtd/"; + @NonNls public static final String J2EE_1_2 = "http://java.sun.com/j2ee/dtds/"; + @NonNls public static final String J2EE_NS = "http://java.sun.com/xml/ns/j2ee/"; + @NonNls public static final String JAVAEE_NS = "http://java.sun.com/xml/ns/javaee/"; + private static final String CATALOG_PROPERTIES_ELEMENT = "CATALOG_PROPERTIES"; + + + private final Map<String, Map<String, String>> myResources = new HashMap<String, Map<String, String>>(); + private final Set<String> myResourceLocations = new HashSet<String>(); + + private final Set<String> myIgnoredResources = new HashSet<String>(); + + private final AtomicNotNullLazyValue<Map<String, Map<String, Resource>>> myStdResources = new AtomicNotNullLazyValue<Map<String, Map<String, Resource>>>() { + + @NotNull + @Override + protected Map<String, Map<String, Resource>> compute() { + return computeStdResources(); + } + }; + + private String myDefaultHtmlDoctype = HTML5_DOCTYPE_ELEMENT; + + private String myCatalogPropertiesFile; + private XMLCatalogManager myCatalogManager; + private static final String HTML5_DOCTYPE_ELEMENT = "HTML5"; + + protected Map<String, Map<String, Resource>> computeStdResources() { + ResourceRegistrarImpl registrar = new ResourceRegistrarImpl(); + for (StandardResourceProvider provider : Extensions.getExtensions(StandardResourceProvider.EP_NAME)) { + provider.registerResources(registrar); + } + StandardResourceEP[] extensions = Extensions.getExtensions(StandardResourceEP.EP_NAME); + for (StandardResourceEP extension : extensions) { + registrar.addStdResource(extension.url, extension.version, extension.resourcePath, null, extension.getLoaderForClass()); + } + + myIgnoredResources.addAll(registrar.getIgnored()); + return registrar.getResources(); + } + + private final List<ExternalResourceListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); + private long myModificationCount = 0; + private final PathMacrosImpl myPathMacros; + @NonNls private static final String RESOURCE_ELEMENT = "resource"; + @NonNls private static final String URL_ATTR = "url"; + @NonNls private static final String LOCATION_ATTR = "location"; + @NonNls private static final String IGNORED_RESOURCE_ELEMENT = "ignored-resource"; + @NonNls private static final String HTML_DEFAULT_DOCTYPE_ELEMENT = "default-html-doctype"; + private static final String DEFAULT_VERSION = null; + public ExternalResourceManagerImpl(PathMacrosImpl pathMacros) { - super(pathMacros); + myPathMacros = pathMacros; } - private static final NotNullLazyKey<ProjectResources, Project> INSTANCE_CACHE = ServiceManager.createLazyKey(ProjectResources.class); + public boolean isStandardResource(VirtualFile file) { + VirtualFile parent = file.getParent(); + return parent != null && parent.getName().equals("standardSchemas"); + } @Override - protected ExternalResourceManagerExImpl getProjectResources(Project project) { + public boolean isUserResource(VirtualFile file) { + return myResourceLocations.contains(file.getUrl()); + } + + @Nullable + static <T> Map<String, T> getMap(@NotNull final Map<String, Map<String, T>> resources, + @Nullable final String version, + final boolean create) { + Map<String, T> map = resources.get(version); + if (map == null) { + if (create) { + map = ContainerUtil.newHashMap(); + resources.put(version, map); + } + else if (version == null || !version.equals(DEFAULT_VERSION)) { + map = resources.get(DEFAULT_VERSION); + } + } + + return map; + } + + public String getResourceLocation(String url) { + return getResourceLocation(url, DEFAULT_VERSION); + } + + public String getResourceLocation(@NonNls String url, String version) { + String result = getUserResource(url, version); + if (result == null) { + XMLCatalogManager manager = getCatalogManager(); + if (manager != null) { + result = manager.resolve(url); + } + } + if (result == null) { + result = getStdResource(url, version); + } + if (result == null) { + result = url; + } + return result; + } + + @Override + @Nullable + public String getUserResource(Project project, String url, String version) { + String resource = getProjectResources(project).getUserResource(url, version); + return resource == null ? getUserResource(url, version) : resource; + } + + @Override + @Nullable + public String getStdResource(String url, String version) { + Map<String, Resource> map = getMap(myStdResources.getValue(), version, false); + if (map != null) { + Resource resource = map.get(url); + return resource == null ? null : resource.getResourceUrl(); + } + else { + return null; + } + } + + @Nullable + private String getUserResource(String url, String version) { + Map<String, String> map = getMap(myResources, version, false); + return map != null ? map.get(url) : null; + } + + public String getResourceLocation(@NonNls String url, @NotNull Project project) { + String location = getProjectResources(project).getResourceLocation(url); + return location == null || location.equals(url) ? getResourceLocation(url) : location; + } + + public String getResourceLocation(@NonNls String url, String version, @NotNull Project project) { + String location = getProjectResources(project).getResourceLocation(url, version); + return location == null || location.equals(url) ? getResourceLocation(url, version) : location; + } + + @Nullable + public PsiFile getResourceLocation(@NotNull @NonNls final String url, @NotNull final PsiFile baseFile, final String version) { + final XmlFile schema = XmlSchemaProvider.findSchema(url, baseFile); + if (schema != null) { + return schema; + } + final String location = getResourceLocation(url, version, baseFile.getProject()); + return XmlUtil.findXmlFile(baseFile, location); + } + + public String[] getResourceUrls(FileType fileType, final boolean includeStandard) { + return getResourceUrls(fileType, DEFAULT_VERSION, includeStandard); + } + + public String[] getResourceUrls(@Nullable final FileType fileType, @NonNls final String version, final boolean includeStandard) { + final List<String> result = new LinkedList<String>(); + addResourcesFromMap(result, version, myResources); + + if (includeStandard) { + addResourcesFromMap(result, version, myStdResources.getValue()); + } + + return ArrayUtil.toStringArray(result); + } + + private static <T> void addResourcesFromMap(final List<String> result, + String version, + Map<String, Map<String, T>> resourcesMap) { + Map<String, T> resources = getMap(resourcesMap, version, false); + if (resources == null) return; + result.addAll(resources.keySet()); + } + + @TestOnly + public static void addTestResource(final String url, final String location, Disposable parentDisposable) { + final ExternalResourceManagerImpl instance = (ExternalResourceManagerImpl)getInstance(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + instance.addResource(url, location); + } + }); + Disposer.register(parentDisposable, new Disposable() { + @Override + public void dispose() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + instance.removeResource(url); + } + }); + } + }); + } + public void addResource(String url, String location) { + addResource(url, DEFAULT_VERSION, location); + } + + public void addResource(@NonNls String url, @NonNls String version, @NonNls String location) { + ApplicationManager.getApplication().assertWriteAccessAllowed(); + addSilently(url, version, location); + fireExternalResourceChanged(); + } + + private void addSilently(String url, String version, String location) { + final Map<String, String> map = getMap(myResources, version, true); + assert map != null; + map.put(url, location); + myResourceLocations.add(location); + myModificationCount++; + } + + public void removeResource(String url) { + removeResource(url, DEFAULT_VERSION); + } + + public void removeResource(String url, String version) { + ApplicationManager.getApplication().assertWriteAccessAllowed(); + Map<String, String> map = getMap(myResources, version, false); + if (map != null) { + String location = map.remove(url); + if (location != null) { + myResourceLocations.remove(location); + } + myModificationCount++; + fireExternalResourceChanged(); + } + } + + @Override + public void removeResource(String url, @NotNull Project project) { + getProjectResources(project).removeResource(url); + } + + @Override + public void addResource(@NonNls String url, @NonNls String location, @NotNull Project project) { + getProjectResources(project).addResource(url, location); + } + + public String[] getAvailableUrls() { + Set<String> urls = new HashSet<String>(); + for (Map<String, String> map : myResources.values()) { + urls.addAll(map.keySet()); + } + return ArrayUtil.toStringArray(urls); + } + + @Override + public String[] getAvailableUrls(Project project) { + return getProjectResources(project).getAvailableUrls(); + } + + public void clearAllResources() { + myResources.clear(); + myIgnoredResources.clear(); + } + + public void clearAllResources(Project project) { + ApplicationManager.getApplication().assertWriteAccessAllowed(); + clearAllResources(); + getProjectResources(project).clearAllResources(); + myModificationCount++; + fireExternalResourceChanged(); + } + + public void addIgnoredResource(String url) { + ApplicationManager.getApplication().assertWriteAccessAllowed(); + addIgnoredSilently(url); + fireExternalResourceChanged(); + } + + private void addIgnoredSilently(String url) { + myIgnoredResources.add(url); + myModificationCount++; + } + + public void removeIgnoredResource(String url) { + ApplicationManager.getApplication().assertWriteAccessAllowed(); + if (myIgnoredResources.remove(url)) { + myModificationCount++; + fireExternalResourceChanged(); + } + } + + public boolean isIgnoredResource(String url) { + myStdResources.getValue(); // ensure ignored resources are loaded + return myIgnoredResources.contains(url) || isImplicitNamespaceDescriptor(url); + } + + private static boolean isImplicitNamespaceDescriptor(String url) { + for (ImplicitNamespaceDescriptorProvider namespaceDescriptorProvider : Extensions + .getExtensions(ImplicitNamespaceDescriptorProvider.EP_NAME)) { + if (namespaceDescriptorProvider.getNamespaceDescriptor(null, url, null) != null) return true; + } + return false; + } + + public String[] getIgnoredResources() { + myStdResources.getValue(); // ensure ignored resources are loaded + return ArrayUtil.toStringArray(myIgnoredResources); + } + + public long getModificationCount() { + return myModificationCount; + } + + @Override + public long getModificationCount(@NotNull Project project) { + return getProjectResources(project).getModificationCount(); + } + + public void readExternal(Element element) throws InvalidDataException { + final ExpandMacroToPathMap macroExpands = new ExpandMacroToPathMap(); + myPathMacros.addMacroExpands(macroExpands); + macroExpands.substitute(element, SystemInfo.isFileSystemCaseSensitive); + + myModificationCount++; + for (final Object o1 : element.getChildren(RESOURCE_ELEMENT)) { + Element e = (Element)o1; + addSilently(e.getAttributeValue(URL_ATTR), DEFAULT_VERSION, e.getAttributeValue(LOCATION_ATTR).replace('/', File.separatorChar)); + } + + for (final Object o : element.getChildren(IGNORED_RESOURCE_ELEMENT)) { + Element e = (Element)o; + addIgnoredSilently(e.getAttributeValue(URL_ATTR)); + } + + Element child = element.getChild(HTML_DEFAULT_DOCTYPE_ELEMENT); + if (child != null) { + String text = child.getText(); + if (FileUtil.toSystemIndependentName(text).endsWith(".jar!/resources/html5-schema/html5.rnc")) { + text = HTML5_DOCTYPE_ELEMENT; + } + myDefaultHtmlDoctype = text; + } + Element catalogElement = element.getChild(CATALOG_PROPERTIES_ELEMENT); + if (catalogElement != null) { + myCatalogPropertiesFile = catalogElement.getTextTrim(); + } + } + + public void writeExternal(Element element) throws WriteExternalException { + final String[] urls = getAvailableUrls(); + for (String url : urls) { + if (url == null) continue; + String location = getResourceLocation(url); + if (location == null) continue; + final Element e = new Element(RESOURCE_ELEMENT); + + e.setAttribute(URL_ATTR, url); + e.setAttribute(LOCATION_ATTR, location.replace(File.separatorChar, '/')); + element.addContent(e); + } + + final String[] ignoredResources = getIgnoredResources(); + for (String ignoredResource : ignoredResources) { + final Element e = new Element(IGNORED_RESOURCE_ELEMENT); + + e.setAttribute(URL_ATTR, ignoredResource); + element.addContent(e); + } + + if (myDefaultHtmlDoctype != null && !HTML5_DOCTYPE_ELEMENT.equals(myDefaultHtmlDoctype)) { + final Element e = new Element(HTML_DEFAULT_DOCTYPE_ELEMENT); + e.setText(myDefaultHtmlDoctype); + element.addContent(e); + } + if (myCatalogPropertiesFile != null) { + Element properties = new Element(CATALOG_PROPERTIES_ELEMENT); + properties.setText(myCatalogPropertiesFile); + element.addContent(properties); + } + final ReplacePathToMacroMap macroReplacements = new ReplacePathToMacroMap(); + PathMacrosImpl.getInstanceEx().addMacroReplacements(macroReplacements); + macroReplacements.substitute(element, SystemInfo.isFileSystemCaseSensitive); + } + + public void addExternalResourceListener(ExternalResourceListener listener) { + myListeners.add(listener); + } + + public void removeExternalResourceListener(ExternalResourceListener listener) { + myListeners.remove(listener); + } + + private void fireExternalResourceChanged() { + for (ExternalResourceListener listener : myListeners) { + listener.externalResourceChanged(); + } + } + + Collection<Map<String, Resource>> getStandardResources() { + return myStdResources.getValue().values(); + } + + + private static final NotNullLazyKey<ProjectResources, Project> INSTANCE_CACHE = ServiceManager.createLazyKey(ProjectResources.class); + + private static ExternalResourceManagerImpl getProjectResources(Project project) { return INSTANCE_CACHE.getValue(project); } + + @Override + @NotNull + public String getDefaultHtmlDoctype(@NotNull Project project) { + final String doctype = getProjectResources(project).myDefaultHtmlDoctype; + if (XmlUtil.XHTML_URI.equals(doctype)) { + return XmlUtil.XHTML4_SCHEMA_LOCATION; + } + else if (HTML5_DOCTYPE_ELEMENT.equals(doctype)) { + return Html5SchemaProvider.getHtml5SchemaLocation(); + } + else { + return doctype; + } + } + + @Override + public void setDefaultHtmlDoctype(@NotNull String defaultHtmlDoctype, @NotNull Project project) { + getProjectResources(project).setDefaultHtmlDoctype(defaultHtmlDoctype); + } + + @Override + public String getCatalogPropertiesFile() { + return myCatalogPropertiesFile; + } + + @Override + public void setCatalogPropertiesFile(String filePath) { + myCatalogManager = null; + myCatalogPropertiesFile = filePath; + myModificationCount++; + } + + @Nullable + private XMLCatalogManager getCatalogManager() { + if (myCatalogManager == null && myCatalogPropertiesFile != null) { + myCatalogManager = new XMLCatalogManager(myCatalogPropertiesFile); + } + return myCatalogManager; + } + + private void setDefaultHtmlDoctype(String defaultHtmlDoctype) { + myModificationCount++; + + if (Html5SchemaProvider.getHtml5SchemaLocation().equals(defaultHtmlDoctype)) { + myDefaultHtmlDoctype = HTML5_DOCTYPE_ELEMENT; + } + else { + myDefaultHtmlDoctype = defaultHtmlDoctype; + } + fireExternalResourceChanged(); + } + + @TestOnly + public static void registerResourceTemporarily(final String url, final String location, Disposable disposable) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + getInstance().addResource(url, location); + } + }); + + Disposer.register(disposable, new Disposable() { + @Override + public void dispose() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + getInstance().removeResource(url); + } + }); + } + }); + } + + static class Resource { + String file; + ClassLoader classLoader; + Class clazz; + + @Nullable + String getResourceUrl() { + + if (classLoader == null && clazz == null) return file; + + final URL resource = clazz == null ? classLoader.getResource(file) : clazz.getResource(file); + classLoader = null; + clazz = null; + if (resource == null) { + String message = "Cannot find standard resource. filename:" + file + " class=" + classLoader; + if (ApplicationManager.getApplication().isUnitTestMode()) { + LOG.error(message); + } + else { + LOG.warn(message); + } + + return null; + } + + String path = FileUtil.unquote(resource.toString()); + // this is done by FileUtil for windows + path = path.replace('\\','/'); + file = path; + return path; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Resource resource = (Resource)o; + + if (classLoader != resource.classLoader) return false; + if (clazz != resource.clazz) return false; + if (file != null ? !file.equals(resource.file) : resource.file != null) return false; + + return true; + } + + @Override + public int hashCode() { + return file.hashCode(); + } + + @Override + public String toString() { + return file + " for " + classLoader; + } + } } diff --git a/xml/impl/src/com/intellij/javaee/InternalResourceProvider.java b/xml/impl/src/com/intellij/javaee/InternalResourceProvider.java new file mode 100644 index 000000000000..d9755ad98847 --- /dev/null +++ b/xml/impl/src/com/intellij/javaee/InternalResourceProvider.java @@ -0,0 +1,66 @@ +/* + * 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.javaee; + +import com.intellij.xml.util.HtmlUtil; +import com.intellij.xml.util.XmlUtil; + +/** + * @author Dmitry Avdeev + */ +public class InternalResourceProvider implements StandardResourceProvider{ + + public void registerResources(ResourceRegistrar registrar) { + ResourceRegistrarImpl impl = (ResourceRegistrarImpl)registrar; + + impl.addInternalResource(XmlUtil.XSLT_URI,"xslt-1_0.xsd"); + impl.addInternalResource(XmlUtil.XSLT_URI,"2.0", "xslt-2_0.xsd"); + impl.addInternalResource(XmlUtil.XINCLUDE_URI,"xinclude.xsd"); + impl.addInternalResource(XmlUtil.XML_SCHEMA_URI, "XMLSchema.xsd"); + impl.addInternalResource(XmlUtil.XML_SCHEMA_URI + ".xsd", "XMLSchema.xsd"); + impl.addInternalResource("http://www.w3.org/2001/XMLSchema.dtd", "XMLSchema.dtd"); + impl.addInternalResource(XmlUtil.XML_SCHEMA_INSTANCE_URI, "XMLSchema-instance.xsd"); + impl.addInternalResource("http://www.w3.org/2001/xml.xsd","xml.xsd"); + impl.addInternalResource(XmlUtil.XML_NAMESPACE_URI,"xml.xsd"); + impl.addInternalResource(XmlUtil.XHTML_URI,"xhtml1-transitional.xsd"); + impl.addInternalResource("http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd","xhtml1-strict.xsd"); + + impl.addInternalResource("http://www.w3.org/TR/html4/strict.dtd","xhtml1-strict.dtd"); + impl.addInternalResource(XmlUtil.HTML4_LOOSE_URI,"xhtml1-transitional.dtd"); + impl.addInternalResource("http://www.w3.org/TR/html4/frameset.dtd","xhtml1-frameset.dtd"); + impl.addInternalResource("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd","xhtml1-strict.dtd"); + impl.addInternalResource("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd","xhtml1-transitional.dtd"); + impl.addInternalResource("http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd","xhtml1-frameset.dtd"); + impl.addInternalResource("http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd","xhtml11/xhtml11.dtd"); + + impl.addInternalResource("urn:oasis:names:tc:entity:xmlns:xml:catalog", "catalog.xsd"); + + // Plugins DTDs // stathik + impl.addInternalResource("http://plugins.intellij.net/plugin.dtd", "plugin.dtd"); + impl.addInternalResource("http://plugins.intellij.net/plugin-repository.dtd", "plugin-repository.dtd"); + + // mobile + impl.addInternalResource("http://www.wapforum.org/DTD/xhtml-mobile10.dtd", "xhtml-mobile/xhtml-mobile10.dtd"); + impl.addInternalResource("http://www.wapforum.org/DTD/xhtml-mobile10-flat.dtd", "xhtml-mobile/xhtml-mobile10-flat.dtd"); + impl.addInternalResource("http://www.wapforum.org/DTD/xhtml-mobile12.dtd", "xhtml-mobile/xhtml-mobile12.dtd"); + + impl.addInternalResource("http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd", "xhtml-mobile/xhtml-mobile12.dtd"); + + // svg and mathML + impl.addIgnoredResource(HtmlUtil.MATH_ML_NAMESPACE); + impl.addIgnoredResource(HtmlUtil.SVG_NAMESPACE); + } +} diff --git a/xml/impl/src/com/intellij/javaee/ResourceRegistrarImpl.java b/xml/impl/src/com/intellij/javaee/ResourceRegistrarImpl.java new file mode 100644 index 000000000000..10bb8528135f --- /dev/null +++ b/xml/impl/src/com/intellij/javaee/ResourceRegistrarImpl.java @@ -0,0 +1,84 @@ +/* + * 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.javaee; + +import com.intellij.util.containers.HashMap; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author Dmitry Avdeev + */ +public class ResourceRegistrarImpl implements ResourceRegistrar { + + private final Map<String, Map<String, ExternalResourceManagerImpl.Resource>> myResources = new HashMap<String, Map<String, ExternalResourceManagerImpl.Resource>>(); + private final List<String> myIgnored = new ArrayList<String>(); + + public void addStdResource(@NonNls String resource, @NonNls String fileName) { + addStdResource(resource, null, fileName, getClass()); + } + + public void addStdResource(@NonNls String resource, @NonNls String fileName, Class klass) { + addStdResource(resource, null, fileName, klass); + } + + public void addStdResource(@NonNls String resource, @NonNls String version, @NonNls String fileName, @Nullable Class klass, @Nullable ClassLoader classLoader) { + final Map<String, ExternalResourceManagerImpl.Resource> map = ExternalResourceManagerImpl.getMap(myResources, version, true); + assert map != null; + ExternalResourceManagerImpl.Resource res = new ExternalResourceManagerImpl.Resource(); + res.file = fileName; + res.classLoader = classLoader; + res.clazz = klass; + map.put(resource, res); + } + + public void addStdResource(@NonNls String resource, @Nullable @NonNls String version, @NonNls String fileName, Class klass) { + addStdResource(resource, version, fileName, klass, null); + } + + public void addIgnoredResource(@NonNls String url) { + myIgnored.add(url); + } + + public void addInternalResource(@NonNls String resource, @NonNls String fileName) { + addInternalResource(resource, null, fileName, getClass()); + } + + public void addInternalResource(@NonNls String resource, @NonNls String fileName, Class clazz) { + addInternalResource(resource, null, fileName, clazz); + } + + public void addInternalResource(@NonNls String resource, @NonNls String version, @NonNls String fileName) { + addInternalResource(resource, version, fileName, getClass()); + } + + public void addInternalResource(@NonNls String resource, @Nullable @NonNls String version, @NonNls String fileName, @Nullable Class clazz) { + addStdResource(resource, version, ExternalResourceManagerEx.STANDARD_SCHEMAS + fileName, clazz); + } + + public Map<String, Map<String, ExternalResourceManagerImpl.Resource>> getResources() { + return myResources; + } + + public List<String> getIgnored() { + return myIgnored; + } +} diff --git a/xml/impl/src/com/intellij/javaee/XMLCatalogManager.java b/xml/impl/src/com/intellij/javaee/XMLCatalogManager.java new file mode 100644 index 000000000000..c9eacea92662 --- /dev/null +++ b/xml/impl/src/com/intellij/javaee/XMLCatalogManager.java @@ -0,0 +1,92 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.javaee; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.io.FileUtil; +import org.apache.xml.resolver.Catalog; +import org.apache.xml.resolver.CatalogManager; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; + +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.lang.reflect.Field; +import java.util.PropertyResourceBundle; + +/** + * @author Dmitry Avdeev + * Date: 7/20/12 + */ +public class XMLCatalogManager { + + private final static Logger LOG = Logger.getInstance(XMLCatalogManager.class); + + private static Field ourResources; + private static Field ourPropertyFileUri; + + static { + try { + ourResources = CatalogManager.class.getDeclaredField("resources"); + ourResources.setAccessible(true); + ourPropertyFileUri = CatalogManager.class.getDeclaredField("propertyFileURI"); + ourPropertyFileUri.setAccessible(true); + } + catch (NoSuchFieldException e) { + LOG.error(e); + } + } + + private final CatalogManager myManager = new CatalogManager(); + + public XMLCatalogManager(@NotNull String propertiesFilePath) { + + File file = new File(propertiesFilePath); + try { + String s = FileUtil.loadFile(file); + PropertyResourceBundle bundle = new PropertyResourceBundle(new StringReader(s)); + ourResources.set(myManager, bundle); + ourPropertyFileUri.set(myManager, file.toURI().toURL()); + } + catch (IllegalAccessException e) { + LOG.error(e); + } + catch (IOException e) { + LOG.warn(e); + } + } + + @Nullable + public String resolve(String uri) { + try { + Catalog catalog = myManager.getCatalog(); + if (catalog == null) return null; + String resolved = catalog.resolveSystem(uri); + return resolved == null ? catalog.resolvePublic(uri, null) : resolved; + } + catch (IOException e) { + LOG.warn(e); + return null; + } + } + + @TestOnly + public CatalogManager getManager() { + return myManager; + } +} diff --git a/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java b/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java index 7f118e889588..907ca9151988 100644 --- a/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java +++ b/xml/impl/src/com/intellij/xml/arrangement/XmlArrangementVisitor.java @@ -44,14 +44,15 @@ public class XmlArrangementVisitor extends XmlElementVisitor { @Override public void visitXmlTag(XmlTag tag) { final XmlElementArrangementEntry entry = createNewEntry( - tag.getTextRange(), XML_TAG, null, null, true); + tag.getTextRange(), XML_TAG, null, true); processEntry(entry, tag); } @Override public void visitXmlAttribute(XmlAttribute attribute) { + final String name = attribute.isNamespaceDeclaration() ? "" : attribute.getName(); final XmlElementArrangementEntry entry = createNewEntry( - attribute.getTextRange(), XML_ATTRIBUTE, attribute.getName(), attribute.getNamespace(), true); + attribute.getTextRange(), XML_ATTRIBUTE, name, true); processEntry(entry, null); } @@ -72,14 +73,13 @@ public class XmlArrangementVisitor extends XmlElementVisitor { private XmlElementArrangementEntry createNewEntry(@NotNull TextRange range, @NotNull ArrangementSettingsToken type, @Nullable String name, - @Nullable String namespace, boolean canBeMatched) { if (!isWithinBounds(range)) { return null; } final DefaultArrangementEntry current = getCurrent(); final XmlElementArrangementEntry entry = new XmlElementArrangementEntry( - current, range, type, name, namespace, canBeMatched); + current, range, type, name, canBeMatched); if (current == null) { myInfo.addEntry(entry); diff --git a/xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java b/xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java index c6099fb96d61..164465d4b0ae 100644 --- a/xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java +++ b/xml/impl/src/com/intellij/xml/arrangement/XmlElementArrangementEntry.java @@ -1,7 +1,10 @@ package com.intellij.xml.arrangement; import com.intellij.openapi.util.TextRange; -import com.intellij.psi.codeStyle.arrangement.*; +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.std.ArrangementSettingsToken; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,22 +16,19 @@ import java.util.Set; * @author Eugene.Kudelevsky */ public class XmlElementArrangementEntry extends DefaultArrangementEntry - implements TypeAwareArrangementEntry, NameAwareArrangementEntry, NamespaceAwareArrangementEntry { + implements TypeAwareArrangementEntry, NameAwareArrangementEntry { private final ArrangementSettingsToken myType; private final String myName; - private final String myNamespace; public XmlElementArrangementEntry(@Nullable ArrangementEntry parent, @NotNull TextRange range, @NotNull ArrangementSettingsToken type, @Nullable String name, - @Nullable String namespace, boolean canBeMatched) { super(parent, range.getStartOffset(), range.getEndOffset(), canBeMatched); myName = name; - myNamespace = namespace; myType = type; } @@ -38,12 +38,6 @@ public class XmlElementArrangementEntry extends DefaultArrangementEntry return myName; } - @Nullable - @Override - public String getNamespace() { - return myNamespace; - } - @NotNull @Override public Set<ArrangementSettingsToken> getTypes() { diff --git a/xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java b/xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java index 9e20743b76c9..add2e0d87a5d 100644 --- a/xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java +++ b/xml/impl/src/com/intellij/xml/arrangement/XmlRearranger.java @@ -6,13 +6,10 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.arrangement.ArrangementSettings; -import com.intellij.psi.codeStyle.arrangement.ArrangementUtil; import com.intellij.psi.codeStyle.arrangement.Rearranger; import com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule; import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher; -import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher; import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule; -import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition; import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition; import com.intellij.psi.codeStyle.arrangement.std.*; import com.intellij.util.containers.ContainerUtilRt; @@ -37,24 +34,8 @@ public class XmlRearranger 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; - - static { - DEFAULT_MATCH_RULES.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher( - new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, "xmlns:.*")))); - DEFAULT_SETTINGS = new StdRulePriorityAwareSettings( - Collections.<ArrangementGroupingRule>emptyList(), DEFAULT_MATCH_RULES); - } - - @NotNull - public static StdArrangementMatchRule attrArrangementRule(@NotNull String nameFilter, - @NotNull String namespaceFilter, - @NotNull ArrangementSettingsToken orderType) { - return new StdArrangementMatchRule(new StdArrangementEntryMatcher(ArrangementUtil.combine( - new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, nameFilter), - new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.XML_NAMESPACE, namespaceFilter) - )), orderType); - } + private static final StdArrangementSettings DEFAULT_SETTINGS = new StdRulePriorityAwareSettings( + Collections.<ArrangementGroupingRule>emptyList(), DEFAULT_MATCH_RULES); @Nullable @Override diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java index cd62adf16f1d..56b9b063d118 100644 --- a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java @@ -16,8 +16,6 @@ package com.intellij.xml.breadcrumbs; import com.intellij.application.options.editor.WebEditorOptions; -import com.intellij.ide.ui.UISettings; -import com.intellij.ide.ui.UISettingsListener; import com.intellij.lang.Language; import com.intellij.lang.xml.XMLLanguage; import com.intellij.openapi.Disposable; @@ -86,20 +84,17 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb final FileStatusManager manager = FileStatusManager.getInstance(project); manager.addFileStatusListener(new FileStatusListener() { public void fileStatusesChanged() { - updateCrumbs(); + if (myComponent != null && myEditor != null) { + final Font editorFont = myEditor.getColorsScheme().getFont(EditorFontType.PLAIN); + myComponent.setFont(editorFont.deriveFont(Font.PLAIN, editorFont.getSize2D())); + updateCrumbs(myEditor.getCaretModel().getLogicalPosition()); + } } public void fileStatusChanged(@NotNull final VirtualFile virtualFile) { } }, this); - UISettings.getInstance().addUISettingsListener(new UISettingsListener() { - @Override - public void uiSettingsChanged(UISettings source) { - updateCrumbs(); - } - }, this); - myInfoProvider = findInfoProvider(findViewProvider(myFile, myProject)); @@ -188,14 +183,6 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb myWrapperPanel.add(myComponent, BorderLayout.CENTER); } - private void updateCrumbs() { - if (myComponent != null && myEditor != null) { - final Font editorFont = myEditor.getColorsScheme().getFont(EditorFontType.PLAIN); - myComponent.setFont(editorFont.deriveFont(Font.PLAIN, editorFont.getSize2D())); - updateCrumbs(myEditor.getCaretModel().getLogicalPosition()); - } - } - public void queueUpdate(Editor editor) { myQueue.cancelAllUpdates(); myQueue.queue(new MyUpdate(this, editor)); diff --git a/xml/impl/src/com/intellij/xml/util/XmlPrefixReferenceProvider.java b/xml/impl/src/com/intellij/xml/util/XmlPrefixReferenceProvider.java index f1b829475a3b..38fbf27d53ce 100644 --- a/xml/impl/src/com/intellij/xml/util/XmlPrefixReferenceProvider.java +++ b/xml/impl/src/com/intellij/xml/util/XmlPrefixReferenceProvider.java @@ -37,7 +37,7 @@ public class XmlPrefixReferenceProvider extends PsiReferenceProvider { int i = value.indexOf(':'); if (i > 0) { return new PsiReference[] { - new SchemaPrefixReference(attributeValue, TextRange.from(1, i), value.substring(0, i), null) + new SchemaPrefixReference(attributeValue, TextRange.from(1, i), value.substring(0, i)) }; } } |