From ec8061af33c3650e89e2969e0d5e8f16ded6a4e7 Mon Sep 17 00:00:00 2001 From: Maxim Mossienko Date: Wed, 2 Feb 2005 21:52:17 +0300 Subject: [PATCH] jspx default xhtml namespace removed, fixed issue with no parent delegation for namespace that is declared in the parent --- .../psi/impl/source/xml/XmlTagImpl.java | 46 +++++++++++-------- source/com/intellij/xml/util/XmlUtil.java | 3 +- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/source/com/intellij/psi/impl/source/xml/XmlTagImpl.java b/source/com/intellij/psi/impl/source/xml/XmlTagImpl.java index b639a6e5a075..f7203321f18f 100644 --- a/source/com/intellij/psi/impl/source/xml/XmlTagImpl.java +++ b/source/com/intellij/psi/impl/source/xml/XmlTagImpl.java @@ -12,6 +12,7 @@ import com.intellij.pom.PomModel; import com.intellij.pom.event.PomModelEvent; import com.intellij.pom.impl.PomTransactionBase; import com.intellij.psi.*; +import com.intellij.psi.jsp.JspFile; import com.intellij.psi.impl.meta.MetaRegistry; import com.intellij.psi.impl.source.DummyHolder; import com.intellij.psi.impl.source.PsiFileImpl; @@ -112,11 +113,19 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag/*, Modification public XmlNSDescriptor getNSDescriptor(final String namespace, boolean strict) { initNSDescriptorsMap(); - if(myNSDescriptorsMap.isEmpty()) return ((XmlTag)getParent()).getNSDescriptor(namespace, strict); + + final XmlElement parent = getParent(); + + if(myNSDescriptorsMap.isEmpty()) { + return ((XmlTag)parent).getNSDescriptor(namespace, strict); + } + CachedValue descriptor = myNSDescriptorsMap.get(namespace); if(descriptor != null) { final XmlNSDescriptor value = descriptor.getValue(); if(value != null) return value; + } else if (parent instanceof XmlTag) { + return ((XmlTag)parent).getNSDescriptor(namespace, strict); } if(!strict) { @@ -165,18 +174,6 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag/*, Modification } } - final PsiFile containingFile = getContainingFile(); - if (containingFile!=null && containingFile.getFileType() == StdFileTypes.JSPX) { - initializeSchema(XmlUtil.XHTML_URI,XmlUtil.XHTML_URI); - final XmlNSDescriptor xhtmlDescriptor = myNSDescriptorsMap.get(XmlUtil.XHTML_URI).getValue(); - - myNSDescriptorsMap.put(XmlUtil.XHTML_URI, getManager().getCachedValuesManager().createCachedValue(new CachedValueProvider() { - public Result compute() { - final XmlNSDescriptor jspxNSDescriptor = new JspXHTMLDescriptor(xhtmlDescriptor); - return new Result(jspxNSDescriptor, jspxNSDescriptor.getDependences()); - } - }, false)); - } } } @@ -269,7 +266,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag/*, Modification return myNSDescriptorsMap; } - private boolean initializeSchema(String namespace, final String fileLocation) { + private boolean initializeSchema(final String namespace, final String fileLocation) { XmlNSDescriptor descriptor; if(myNSDescriptorsMap == null) myNSDescriptorsMap = new HashMap>(); @@ -280,7 +277,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag/*, Modification } if (file != null){ - descriptor = (XmlNSDescriptor)file.getDocument().getMetaData(); + descriptor = getMetaDataDescriptor(file,namespace); if(descriptor != null){ final XmlFile file1 = file; @@ -288,7 +285,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag/*, Modification myNSDescriptorsMap.put(namespace, getManager().getCachedValuesManager().createCachedValue(new CachedValueProvider() { public CachedValueProvider.Result compute() { return new Result( - (XmlNSDescriptor)file1.getDocument().getMetaData(), + getMetaDataDescriptor(file1,namespace), new Object[]{file1} ); } @@ -299,6 +296,19 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag/*, Modification return true; } + private XmlNSDescriptor getMetaDataDescriptor(final XmlFile file, String namespace) { + XmlNSDescriptor descriptor; + descriptor = (XmlNSDescriptor)file.getDocument().getMetaData(); + + PsiFile myContainingFile = getContainingFile(); + if (myContainingFile!=null) { + if(myContainingFile.getFileType() == StdFileTypes.JSPX && namespace.equals(XmlUtil.XHTML_URI)) { + descriptor = new JspXHTMLDescriptor(descriptor); + } + } + return descriptor; + } + public PsiReference getReference() { final PsiReference[] references = getReferences(); if (references != null && references.length > 0){ @@ -545,10 +555,6 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag/*, Modification } } - final PsiFile containingFile = parent.getContainingFile(); - if (containingFile!=null && containingFile.getFileType() == StdFileTypes.JSPX) { - myNamespaceMap.put("",XmlUtil.XHTML_URI); - } } if(parent instanceof XmlDocument && myNamespaceMap == null){ myNamespaceMap = new BidirectionalMap(); diff --git a/source/com/intellij/xml/util/XmlUtil.java b/source/com/intellij/xml/util/XmlUtil.java index 1490cacd54a1..488ca5981182 100644 --- a/source/com/intellij/xml/util/XmlUtil.java +++ b/source/com/intellij/xml/util/XmlUtil.java @@ -508,8 +508,7 @@ public class XmlUtil { final FileType fileType = file.getFileType(); if (fileType == StdFileTypes.HTML || - fileType == StdFileTypes.XHTML || - fileType == StdFileTypes.JSPX + fileType == StdFileTypes.XHTML ) { return XHTML_URI; }