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 | |
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')
29 files changed, 653 insertions, 933 deletions
diff --git a/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementAnnotationsManagerImpl.java b/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementAnnotationsManagerImpl.java index de884cf3ca98..fc673eca562c 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementAnnotationsManagerImpl.java +++ b/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementAnnotationsManagerImpl.java @@ -21,7 +21,6 @@ import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.Disposable; @@ -63,25 +62,21 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag private final EventDispatcher<DomHighlightingListener> myDispatcher = EventDispatcher.create(DomHighlightingListener.class); private static final DomElementsProblemsHolder EMPTY_PROBLEMS_HOLDER = new DomElementsProblemsHolder() { - @Override @NotNull public List<DomElementProblemDescriptor> getProblems(DomElement domElement) { return Collections.emptyList(); } - @Override public List<DomElementProblemDescriptor> getProblems(final DomElement domElement, boolean includeXmlProblems) { return Collections.emptyList(); } - @Override public List<DomElementProblemDescriptor> getProblems(final DomElement domElement, final boolean includeXmlProblems, final boolean withChildren) { return Collections.emptyList(); } - @Override public List<DomElementProblemDescriptor> getProblems(DomElement domElement, final boolean includeXmlProblems, final boolean withChildren, @@ -89,22 +84,18 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag return Collections.emptyList(); } - @Override public List<DomElementProblemDescriptor> getProblems(DomElement domElement, final boolean withChildren, HighlightSeverity minSeverity) { return Collections.emptyList(); } - @Override public List<DomElementProblemDescriptor> getAllProblems() { return Collections.emptyList(); } - @Override public List<DomElementProblemDescriptor> getAllProblems(@NotNull DomElementsInspection inspection) { return Collections.emptyList(); } - @Override public boolean isInspectionCompleted(@NotNull final DomElementsInspection inspectionClass) { return false; } @@ -117,18 +108,15 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag public DomElementAnnotationsManagerImpl(Project project) { myProject = project; myModificationTracker = new ModificationTracker() { - @Override public long getModificationCount() { return myModificationCount; } }; final ProfileChangeAdapter profileChangeAdapter = new ProfileChangeAdapter() { - @Override public void profileActivated(@NotNull Profile oldProfile, Profile profile) { dropAnnotationsCache(); } - @Override public void profileChanged(Profile profile) { dropAnnotationsCache(); } @@ -137,14 +125,12 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag final InspectionProfileManager inspectionProfileManager = InspectionProfileManager.getInstance(); inspectionProfileManager.addProfileChangeListener(profileChangeAdapter, project); Disposer.register(project, new Disposable() { - @Override public void dispose() { inspectionProfileManager.removeProfileChangeListener(profileChangeAdapter); } }); } - @Override public void dropAnnotationsCache() { myModificationCount++; } @@ -170,7 +156,6 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag holder = new DomElementsProblemsHolderImpl(element); rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder); final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Boolean>() { - @Override public Result<Boolean> compute() { return new Result<Boolean>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myModificationTracker, ProjectRootManager.getInstance(myProject)); } @@ -198,7 +183,6 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag return cachedValue == null || !cachedValue.hasUpToDateValue(); } - @Override @NotNull public DomElementsProblemsHolder getProblemHolder(DomElement element) { if (element == null || !element.isValid()) return EMPTY_PROBLEMS_HOLDER; @@ -216,7 +200,6 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag } } - @Override @NotNull public DomElementsProblemsHolder getCachedProblemHolder(DomElement element) { return getProblemHolder(element); @@ -229,12 +212,10 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag } } - @Override public List<ProblemDescriptor> createProblemDescriptors(final InspectionManager manager, DomElementProblemDescriptor problemDescriptor) { return ContainerUtil.createMaybeSingletonList(DomElementsHighlightingUtil.createProblemDescriptors(manager, problemDescriptor)); } - @Override public boolean isHighlightingFinished(final DomElement[] domElements) { for (final DomElement domElement : domElements) { if (getHighlightStatus(domElement) != DomHighlightStatus.INSPECTIONS_FINISHED) { @@ -244,17 +225,14 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag return true; } - @Override public void addHighlightingListener(DomHighlightingListener listener, Disposable parentDisposable) { myDispatcher.addListener(listener, parentDisposable); } - @Override public DomHighlightingHelper getHighlightingHelper() { return DomHighlightingHelperImpl.INSTANCE; } - @Override @NotNull public <T extends DomElement> List<DomElementProblemDescriptor> checkFileElement(@NotNull final DomFileElement<T> domFileElement, @NotNull final DomElementsInspection<T> inspection, @@ -273,9 +251,9 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag Class rootType = fileElement.getRootElementClass(); final InspectionProfile profile = getInspectionProfile(fileElement); final List<DomElementsInspection> inspections = new SmartList<DomElementsInspection>(); - for (final InspectionToolWrapper toolWrapper : (InspectionToolWrapper[])profile.getInspectionTools(fileElement.getFile())) { - if (!enabledOnly || profile.isToolEnabled(HighlightDisplayKey.find(toolWrapper.getShortName()), fileElement.getFile())) { - ContainerUtil.addIfNotNull(getSuitableInspection(toolWrapper, rootType), inspections); + for (final InspectionProfileEntry profileEntry : profile.getInspectionTools(fileElement.getFile())) { + if (!enabledOnly || profile.isToolEnabled(HighlightDisplayKey.find(profileEntry.getShortName()), fileElement.getFile())) { + ContainerUtil.addIfNotNull(getSuitableInspection(profileEntry, rootType), inspections); } } return inspections; diff --git a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java index 10d4ab83caca..623b11616f59 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/DomHighlightingLiteTest.java @@ -21,7 +21,6 @@ import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.InspectionToolProvider; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ex.InspectionToolRegistrar; -import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.ide.ui.search.SearchableOptionsRegistrar; import com.intellij.lang.annotation.Annotation; import com.intellij.mock.MockInspectionProfile; @@ -178,7 +177,7 @@ public class DomHighlightingLiteTest extends DomTestCase { public void testNoMockInspection() throws Throwable { myElement.setFileDescription(new MyNonHighlightingDomFileDescription()); - myInspectionProfile.setInspectionTools(new LocalInspectionToolWrapper(new MyDomElementsInspection())); + myInspectionProfile.setInspectionTools(new MyDomElementsInspection()); assertNull(myAnnotationsManager.getMockInspection(myElement)); } @@ -239,7 +238,7 @@ public class DomHighlightingLiteTest extends DomTestCase { } }; HighlightDisplayKey.register(inspection.getShortName()); - myInspectionProfile.setInspectionTools(new LocalInspectionToolWrapper(inspection)); + myInspectionProfile.setInspectionTools(inspection); myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class); assertEquals(DomHighlightStatus.ANNOTATORS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement)); @@ -264,9 +263,8 @@ public class DomHighlightingLiteTest extends DomTestCase { } }; HighlightDisplayKey.register(inspection.getShortName()); - LocalInspectionToolWrapper toolWrapper = new LocalInspectionToolWrapper(inspection); - myInspectionProfile.setInspectionTools(toolWrapper); - myInspectionProfile.setEnabled(toolWrapper, false); + myInspectionProfile.setInspectionTools(inspection); + myInspectionProfile.setEnabled(inspection, false); myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class); assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement)); 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/xml-psi-impl/src/com/intellij/javaee/InternalResourceProvider.java b/xml/impl/src/com/intellij/javaee/InternalResourceProvider.java index d9755ad98847..d9755ad98847 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/InternalResourceProvider.java +++ b/xml/impl/src/com/intellij/javaee/InternalResourceProvider.java diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/ResourceRegistrarImpl.java b/xml/impl/src/com/intellij/javaee/ResourceRegistrarImpl.java index b3dcdcf7f8cd..10bb8528135f 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/ResourceRegistrarImpl.java +++ b/xml/impl/src/com/intellij/javaee/ResourceRegistrarImpl.java @@ -29,7 +29,7 @@ import java.util.Map; */ public class ResourceRegistrarImpl implements ResourceRegistrar { - private final Map<String, Map<String, ExternalResourceManagerExImpl.Resource>> myResources = new HashMap<String, Map<String, ExternalResourceManagerExImpl.Resource>>(); + 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) { @@ -41,9 +41,9 @@ public class ResourceRegistrarImpl implements ResourceRegistrar { } public void addStdResource(@NonNls String resource, @NonNls String version, @NonNls String fileName, @Nullable Class klass, @Nullable ClassLoader classLoader) { - final Map<String, ExternalResourceManagerExImpl.Resource> map = ExternalResourceManagerExImpl.getMap(myResources, version, true); + final Map<String, ExternalResourceManagerImpl.Resource> map = ExternalResourceManagerImpl.getMap(myResources, version, true); assert map != null; - ExternalResourceManagerExImpl.Resource res = new ExternalResourceManagerExImpl.Resource(); + ExternalResourceManagerImpl.Resource res = new ExternalResourceManagerImpl.Resource(); res.file = fileName; res.classLoader = classLoader; res.clazz = klass; @@ -74,7 +74,7 @@ public class ResourceRegistrarImpl implements ResourceRegistrar { addStdResource(resource, version, ExternalResourceManagerEx.STANDARD_SCHEMAS + fileName, clazz); } - public Map<String, Map<String, ExternalResourceManagerExImpl.Resource>> getResources() { + public Map<String, Map<String, ExternalResourceManagerImpl.Resource>> getResources() { return myResources; } diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/XMLCatalogManager.java b/xml/impl/src/com/intellij/javaee/XMLCatalogManager.java index c9eacea92662..c9eacea92662 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/XMLCatalogManager.java +++ b/xml/impl/src/com/intellij/javaee/XMLCatalogManager.java 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)) }; } } diff --git a/xml/xml-psi-api/src/com/intellij/javaee/ResourceRegistrar.java b/xml/openapi/src/com/intellij/javaee/ResourceRegistrar.java index 35c0be48466d..35c0be48466d 100644 --- a/xml/xml-psi-api/src/com/intellij/javaee/ResourceRegistrar.java +++ b/xml/openapi/src/com/intellij/javaee/ResourceRegistrar.java diff --git a/xml/xml-psi-api/src/com/intellij/javaee/StandardResourceEP.java b/xml/openapi/src/com/intellij/javaee/StandardResourceEP.java index bf91c4eb3a13..bf91c4eb3a13 100644 --- a/xml/xml-psi-api/src/com/intellij/javaee/StandardResourceEP.java +++ b/xml/openapi/src/com/intellij/javaee/StandardResourceEP.java diff --git a/xml/xml-psi-api/src/com/intellij/javaee/StandardResourceProvider.java b/xml/openapi/src/com/intellij/javaee/StandardResourceProvider.java index 8b3313201b3a..8b3313201b3a 100644 --- a/xml/xml-psi-api/src/com/intellij/javaee/StandardResourceProvider.java +++ b/xml/openapi/src/com/intellij/javaee/StandardResourceProvider.java diff --git a/xml/tests/src/com/intellij/xml/arrangement/XmlRearrangerTest.groovy b/xml/tests/src/com/intellij/xml/arrangement/XmlRearrangerTest.groovy index a9c9d33b7b0c..15c3649478c0 100644 --- a/xml/tests/src/com/intellij/xml/arrangement/XmlRearrangerTest.groovy +++ b/xml/tests/src/com/intellij/xml/arrangement/XmlRearrangerTest.groovy @@ -2,13 +2,9 @@ package com.intellij.xml.arrangement import com.intellij.ide.highlighter.XmlFileType import com.intellij.lang.xml.XMLLanguage import com.intellij.psi.codeStyle.arrangement.AbstractRearrangerTest -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.std.StdArrangementTokens -import org.jetbrains.annotations.NotNull import static com.intellij.psi.codeStyle.arrangement.std.StdArrangementTokens.Order.BY_NAME + /** * @author Eugene.Kudelevsky */ @@ -21,7 +17,7 @@ class XmlRearrangerTest extends AbstractRearrangerTest { void testAttributeSorting1() { doTest( initial: '''<root xmlns:ns="http://ns.com" attr2="value2" attr1="value1" attr3="value3"/>''', - expected: '''<root attr1="value1" attr2="value2" attr3="value3" xmlns:ns="http://ns.com"/>''', + expected: '''<root xmlns:ns="http://ns.com" attr1="value1" attr2="value2" attr3="value3"/>''', rules: [ruleWithOrder(BY_NAME, nameRule(".*"))] ) } @@ -29,7 +25,7 @@ class XmlRearrangerTest extends AbstractRearrangerTest { void testAttributeSorting2() { doTest( initial: '''<root attr3="value3" attr2="value2" attr1="value1" xmlns:ns="http://ns.com"/>''', - expected: '''<root attr1="value1" attr2="value2" attr3="value3" xmlns:ns="http://ns.com"/>''', + expected: '''<root xmlns:ns="http://ns.com" attr1="value1" attr2="value2" attr3="value3"/>''', rules: [ruleWithOrder(BY_NAME, nameRule(".*"))] ) } @@ -52,139 +48,7 @@ class XmlRearrangerTest extends AbstractRearrangerTest { </tag1> </root> ''', - rules: [ruleWithOrder(BY_NAME, nameRule("xmlns:.*")), ruleWithOrder(BY_NAME, nameRule(".*"))] - ) - } - - public void testAttributeSorting4() throws Exception { - doTest( - initial: '''<root attr3="value3" attr2="value2" attr1="value1" xmlns:ns="http://ns.com"/>''', - expected: '''<root xmlns:ns="http://ns.com" attr1="value1" attr2="value2" attr3="value3"/>''', - rules: [ruleWithOrder(BY_NAME, nameRule("xmlns:.*")), ruleWithOrder(BY_NAME, nameRule(".*"))] - ) - } - - public void testAttributeSortingByNamespace1() throws Exception { - doTest( - initial: '''\ -<root attr1="value1" ns1:attr2="value2" xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1"> - <tag1 ns2:attr2="value2" attr2="value2" attr1="value1" ns2:attr1="value1" ns1:attr2="value2" ns1:attr1="value1"> - </tag1> -</root> -''', - expected: '''\ -<root xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" attr1="value1" ns1:attr1="value1" ns1:attr2="value2"> - <tag1 attr1="value1" attr2="value2" ns1:attr1="value1" ns1:attr2="value2" ns2:attr1="value1" ns2:attr2="value2"> - </tag1> -</root> -''', - rules: [ruleWithOrder(BY_NAME, nameRule("xmlns:.*")), ruleWithOrder(BY_NAME, namespaceRule(".*"))] - ) - } - - public void testAttributeSortingByNamespace2() throws Exception { - doTest( - initial: '''\ -<root attr1="value1" ns1:attr2="value2" xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1"> - <tag1 ns2:attr2="value2" attr2="value2" attr1="value1" ns2:attr1="value1" ns1:attr2="value2" ns1:attr1="value1"> - </tag1> -</root> -''', - expected: '''\ -<root xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1" ns1:attr2="value2" attr1="value1"> - <tag1 ns1:attr1="value1" ns1:attr2="value2" ns2:attr1="value1" ns2:attr2="value2" attr2="value2" attr1="value1"> - </tag1> -</root> -''', - rules: [ruleWithOrder(BY_NAME, nameRule("xmlns:.*")), ruleWithOrder(BY_NAME, namespaceRule("http://ns.*"))] - ) - } - - public void testAttributeSortingByNamespace3() throws Exception { - doTest( - initial: '''\ -<root attr1="value1" ns1:attr2="value2" xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1"> - <tag1 ns2:attr2="value2" attr2="value2" attr1="value1" ns2:attr1="value1" ns1:attr2="value2" ns1:attr1="value1"> - </tag1> -</root> -''', - expected: '''\ -<root xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1" ns1:attr2="value2" attr1="value1"> - <tag1 ns1:attr1="value1" ns1:attr2="value2" ns2:attr1="value1" ns2:attr2="value2" attr1="value1" attr2="value2"> - </tag1> -</root> -''', - rules: [ruleWithOrder(BY_NAME, nameRule("xmlns:.*")), ruleWithOrder(BY_NAME, namespaceRule("http://ns.*")), - ruleWithOrder(BY_NAME, nameRule(".*"))] - ) - } - - public void testAttributeSortingByNamespace4() throws Exception { - doTest( - initial: '''\ -<root attr1="value1" ns1:attr2="value2" xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1"> - <tag1 ns2:attr2="value2" attr2="value2" attr1="value1" ns2:attr1="value1" ns1:attr2="value2" ns1:attr1="value1"> - </tag1> -</root> -''', - expected: '''\ -<root xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" attr1="value1" ns1:attr1="value1" ns1:attr2="value2"> - <tag1 ns2:attr1="value1" ns2:attr2="value2" attr1="value1" attr2="value2" ns1:attr1="value1" ns1:attr2="value2"> - </tag1> -</root> -''', - rules: [ruleWithOrder(BY_NAME, nameRule("xmlns:.*")), ruleWithOrder(BY_NAME, namespaceRule("http://ns2.com")), - ruleWithOrder(BY_NAME, nameRule(".*"))] - ) - } - - public void testAttributeSortingByNamespace5() throws Exception { - doTest( - initial: '''\ -<root attr1="value1" ns1:attr2="value2" xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1"> - <tag1 ns2:attr2="value2" attr2="value2" attr1="value1" ns2:attr1="value1" ns1:attr2="value2" ns1:attr1="value1"> - </tag1> -</root> -''', - expected: '''\ -<root xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1" ns1:attr2="value2" attr1="value1"> - <tag1 ns2:attr1="value1" ns2:attr2="value2" ns1:attr1="value1" ns1:attr2="value2" attr2="value2" attr1="value1"> - </tag1> -</root> -''', - rules: [ruleWithOrder(BY_NAME, nameRule("xmlns:.*")), ruleWithOrder(BY_NAME, namespaceRule("http://ns2.com")), - ruleWithOrder(BY_NAME, namespaceRule("http://ns1.com"))] - ) - } - - public void testAttributeSortingByNamespace6() throws Exception { - doTest( - initial: '''\ -<root attr1="value1" ns1:attr2="value2" xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr1="value1"> - <tag1 ns2:attr2="value2" attr2="value2" attr1="value1" ns2:attr1="value1" ns1:attr2="value2" ns1:attr1="value1"> - </tag1> -</root> -''', - expected: '''\ -<root xmlns:ns1="http://ns1.com" xmlns:ns2="http://ns2.com" ns1:attr2="value2" attr1="value1" ns1:attr1="value1"> - <tag1 ns1:attr2="value2" ns2:attr2="value2" attr1="value1" attr2="value2" ns1:attr1="value1" ns2:attr1="value1"> - </tag1> -</root> -''', - rules: [ruleWithOrder(BY_NAME, nameRule("xmlns:.*")), ruleWithOrder(BY_NAME, compositeRule(".*:attr2", "http://ns.*")), - ruleWithOrder(BY_NAME, nameRule(".*"))] + rules: [ruleWithOrder(BY_NAME, nameRule(".*"))] ) } - - @NotNull - private static StdArrangementMatchRule namespaceRule(@NotNull String filter) { - return new StdArrangementMatchRule(new StdArrangementEntryMatcher( - new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.XML_NAMESPACE, filter))) - } - - @NotNull - protected static StdArrangementMatchRule compositeRule(@NotNull String nameFilter, @NotNull String namespaceFilter) { - return rule(new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, nameFilter), - new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.XML_NAMESPACE, namespaceFilter)); - } } diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java deleted file mode 100644 index 4d58a5524bfe..000000000000 --- a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java +++ /dev/null @@ -1,563 +0,0 @@ -package com.intellij.javaee; - -import com.intellij.application.options.PathMacrosImpl; -import com.intellij.application.options.ReplacePathToMacroMap; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ExpandMacroToPathMap; -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.*; -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.*; - -public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx { - 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 ExternalResourceManagerExImpl(PathMacrosImpl pathMacros) { - myPathMacros = pathMacros; - } - - public boolean isStandardResource(VirtualFile file) { - VirtualFile parent = file.getParent(); - return parent != null && parent.getName().equals("standardSchemas"); - } - - @Override - 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 ExternalResourceManagerExImpl instance = (ExternalResourceManagerExImpl)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(); - } - - - protected ExternalResourceManagerExImpl getProjectResources(Project project) { - return this; - } - - @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/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java index 8862ac892f0e..8578453b1476 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java @@ -568,7 +568,7 @@ public class SchemaReferencesProvider extends PsiReferenceProvider { final XmlAttributeValue attributeValue = (XmlAttributeValue)element; final String prefix = XmlUtil.findPrefixByQualifiedName(attributeValue.getValue()); if (prefix.length() > 0) { - return new SchemaPrefixReference(attributeValue, TextRange.from(1, prefix.length()), prefix, null); + return new SchemaPrefixReference(attributeValue, TextRange.from(1, prefix.length()), prefix); } } return null; diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java index 2c963a95bd80..f8a4833f84d6 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java @@ -37,20 +37,16 @@ public class SchemaPrefixReference extends PsiReferenceBase<XmlElement> implemen private final SchemaPrefix myPrefix; private final String myName; - @Nullable - private final TagNameReference myTagNameReference; /** * * @param element XmlAttribute || XmlAttributeValue * @param range * @param name - * @param reference */ - public SchemaPrefixReference(XmlElement element, TextRange range, String name, TagNameReference reference) { + public SchemaPrefixReference(XmlElement element, TextRange range, String name) { super(element, range); myName = name; - myTagNameReference = reference; if (myElement instanceof XmlAttribute && (((XmlAttribute)myElement).isNamespaceDeclaration())) { myPrefix = new SchemaPrefix((XmlAttribute)myElement, getRangeInElement(), myName); } @@ -112,9 +108,4 @@ public class SchemaPrefixReference extends PsiReferenceBase<XmlElement> implemen public boolean isPrefixReference() { return true; } - - @Nullable - public TagNameReference getTagNameReference() { - return myTagNameReference; - } } diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java index 89237674fa37..a7aff7848548 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java @@ -325,13 +325,13 @@ public class XmlAttributeImpl extends XmlElementImpl implements XmlAttribute { final String prefix = XmlUtil.findPrefixByQualifiedName(getName()); final TextRange range = prefix.length() == 0 ? TextRange.from(getName().length(), 0) : TextRange.from(prefix.length() + 1, localName.length()); - refs[0] = new SchemaPrefixReference(this, range, localName, null); + refs[0] = new SchemaPrefixReference(this, range, localName); } else { final String prefix = getNamespacePrefix(); if (prefix.length() > 0 && getLocalName().length() > 0) { refs = new PsiReference[referencesFromProviders.length + 2]; - refs[0] = new SchemaPrefixReference(this, TextRange.from(0, prefix.length()), prefix, null); + refs[0] = new SchemaPrefixReference(this, TextRange.from(0, prefix.length()), prefix); refs[1] = new XmlAttributeReference(this); } else { diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java index 81645bd453f3..30496bcd9eec 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java @@ -180,8 +180,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag { } private SchemaPrefixReference createPrefixReference(ASTNode startTagName, String prefix, TagNameReference tagRef) { - return new SchemaPrefixReference(this, TextRange.from(startTagName.getStartOffset() - getStartOffset(), prefix.length()), prefix, - tagRef); + return new SchemaPrefixReference(this, TextRange.from(startTagName.getStartOffset() - getStartOffset(), prefix.length()), prefix); } @Override diff --git a/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java b/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java index cdf33c39eed7..d844267fc124 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/XmlCoreEnvironment.java @@ -7,7 +7,10 @@ import com.intellij.ide.highlighter.DTDFileType; import com.intellij.ide.highlighter.HtmlFileType; import com.intellij.ide.highlighter.XHtmlFileType; import com.intellij.ide.highlighter.XmlFileType; -import com.intellij.javaee.*; +import com.intellij.javaee.CoreExternalResourceManager; +import com.intellij.javaee.ExternalResourceManager; +import com.intellij.javaee.ExternalResourceManagerEx; +import com.intellij.javaee.ImplicitNamespaceDescriptorProvider; import com.intellij.lang.LanguageASTFactory; import com.intellij.lang.LanguageParserDefinitions; import com.intellij.lang.dtd.DTDLanguage; @@ -67,12 +70,9 @@ public class XmlCoreEnvironment { CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlAttributeDescriptorsProvider.EP_NAME, XmlAttributeDescriptorsProvider.class); CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), XmlExtension.EP_NAME, XmlExtension.class); CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), HtmlEmbeddedTokenTypesProvider.EXTENSION_POINT_NAME, HtmlEmbeddedTokenTypesProvider.class); - CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), StandardResourceProvider.EP_NAME, StandardResourceProvider.class); - CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), StandardResourceEP.EP_NAME, StandardResourceEP.class); appEnvironment.addExtension(MetaDataContributor.EP_NAME, new XmlApplicationComponent()); appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlNamespaceIndex()); - appEnvironment.addExtension(StandardResourceProvider.EP_NAME, new InternalResourceProvider()); appEnvironment.registerApplicationService(ExternalResourceManager.class, createExternalResourceManager()); } diff --git a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlNSDescriptorImpl.java b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlNSDescriptorImpl.java index 157536762a5a..1c704a01c3b3 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlNSDescriptorImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlNSDescriptorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -396,7 +396,7 @@ public class XmlNSDescriptorImpl implements XmlNSDescriptorEx,Validator<XmlDocum if (namespace.length() > 0) { return checkSchemaNamespace(namespace); } - return StringUtil.startsWithConcatenation(context.getName(), XSD_PREFIX, ":"); + return StringUtil.startsWithConcatenationOf(context.getName(), XSD_PREFIX, ":"); } static @NotNull XmlNSDescriptorImpl getNSDescriptorToSearchIn(XmlTag rootTag, final String name, XmlNSDescriptorImpl defaultNSDescriptor) { diff --git a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlSchemaTagsProcessor.java b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlSchemaTagsProcessor.java index b884ced15bf6..3a703c179e59 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlSchemaTagsProcessor.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlSchemaTagsProcessor.java @@ -16,7 +16,6 @@ package com.intellij.xml.impl.schema; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiReference; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlAttributeValue; import com.intellij.psi.xml.XmlTag; @@ -125,9 +124,7 @@ public abstract class XmlSchemaTagsProcessor { if (ref != null) { XmlAttributeValue value = ref.getValueElement(); if (value != null) { - PsiReference[] references = value.getReferences(); - if (references.length > 0) - return references[0].resolve(); + return value.getReferences()[0].resolve(); } } return null; diff --git a/xml/xml-psi-impl/xml-psi-impl.iml b/xml/xml-psi-impl/xml-psi-impl.iml index ea9932aed511..b12b84d69dcf 100644 --- a/xml/xml-psi-impl/xml-psi-impl.iml +++ b/xml/xml-psi-impl/xml-psi-impl.iml @@ -15,7 +15,6 @@ <orderEntry type="module" module-name="projectModel-impl" /> <orderEntry type="module" module-name="indexing-impl" /> <orderEntry type="library" name="Xerces" level="project" /> - <orderEntry type="library" name="XmlBeans" level="project" /> </component> </module> |