[191483] JSP editor's include-prelude/coda support doesn't consider multiple jsp-property-groups
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/TLDCMDocumentManager.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/TLDCMDocumentManager.java index c63f44b..8e4ef9d 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/TLDCMDocumentManager.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/TLDCMDocumentManager.java
@@ -982,13 +982,13 @@ IStructuredDocumentRegion anchor = new ZeroStructuredDocumentRegion(null, -1); fProcessIncludes = false; - IPath currentBaseLocation = getCurrentBaseLocation(); - if (currentBaseLocation != null) { - PropertyGroup propertyGroup = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroup(currentBaseLocation); - if (propertyGroup != null) { - IPath[] preludes = propertyGroup.getIncludePrelude(); + IPath currentPath = getCurrentParserPath(); + if (currentPath != null) { + PropertyGroup[] propertyGroups = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroups(currentPath); + for(int k = 0; k < propertyGroups.length; k++) { + IPath[] preludes = propertyGroups[k].getIncludePrelude(); for (int i = 0; i < preludes.length; i++) { - if (!getIncludes().contains(preludes[i]) && !preludes[i].equals(currentBaseLocation)) { + if (!getIncludes().contains(preludes[i]) && !preludes[i].equals(currentPath)) { getIncludes().push(preludes[i]); if (getParser() != null) { IncludeHelper includeHelper = new IncludeHelper(anchor, getParser());
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java index 3e9ac49..cad9f0b 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java
@@ -61,6 +61,8 @@ * is not persisted. */ public class DeploymentDescriptorPropertyCache { + private static final PropertyGroup[] NO_PROPERTY_GROUPS = new PropertyGroup[0]; + private static class DeploymentDescriptor { PropertyGroup[] groups; long modificationStamp; @@ -77,8 +79,8 @@ * deployment descriptor. */ public static final class PropertyGroup { - static PropertyGroup createFrom(IPath path, Node propertyGroupNode) { - PropertyGroup group = new PropertyGroup(path); + static PropertyGroup createFrom(IPath path, Node propertyGroupNode, int groupNumber) { + PropertyGroup group = new PropertyGroup(path, groupNumber); Node propertyGroupID = propertyGroupNode.getAttributes().getNamedItem(ID); if (propertyGroupID != null) { group.setId(propertyGroupID.getNodeValue()); @@ -132,10 +134,13 @@ private boolean scripting_invalid; String url_pattern; private IPath webxmlPath; + + int number; - private PropertyGroup(IPath path) { + private PropertyGroup(IPath path, int number) { super(); this.webxmlPath = path; + this.number = number; } private void addCoda(String containedText) { @@ -220,6 +225,10 @@ this.matcher = new StringMatcher(url_pattern); } } + + public String toString() { + return number + ":" + url_pattern; + } } private static class ResourceChangeListener implements IResourceChangeListener { @@ -622,7 +631,7 @@ int length = propertyGroupElements.getLength(); subMonitor.beginTask("Reading Property Groups", length); for (int i = 0; i < length; i++) { - PropertyGroup group = PropertyGroup.createFrom(file.getFullPath(), propertyGroupElements.item(i)); + PropertyGroup group = PropertyGroup.createFrom(file.getFullPath(), propertyGroupElements.item(i), i); subMonitor.worked(1); if (group != null) { groupList.add(group); @@ -726,7 +735,7 @@ } if (groups == null) { - groups = new PropertyGroup[0]; + groups = NO_PROPERTY_GROUPS; } DeploymentDescriptor deploymentDescriptor = new DeploymentDescriptor(); @@ -845,21 +854,21 @@ /** * @param jspFilePath - * @return a PropertyGroup containing the property group information - * matching the file at the given path or null if no web.xml file - * exists or no matching property group was defined. A returned - * PropertyGroup object should be considered short-lived and not - * saved for later use. + * @return PropertyGroups matching the file at the given path or an empty + * array if no web.xml file exists or no matching property group + * was defined. A returned PropertyGroup object should be + * considered short-lived and not saved for later use. */ - public PropertyGroup getPropertyGroup(IPath jspFilePath) { + public PropertyGroup[] getPropertyGroups(IPath jspFilePath) { + List matchingGroups = new ArrayList(1); IPath contextRoot = TaglibIndex.getContextRoot(jspFilePath); if (contextRoot == null) - return null; + return NO_PROPERTY_GROUPS; IPath webxmlPath = contextRoot.append(WEB_INF_WEB_XML); IFile webxmlFile = ResourcesPlugin.getWorkspace().getRoot().getFile(webxmlPath); if (!webxmlFile.isAccessible()) - return null; + return NO_PROPERTY_GROUPS; Reference descriptorHolder = (Reference) fDeploymentDescriptors.get(webxmlPath); DeploymentDescriptor descriptor = null; @@ -868,19 +877,19 @@ descriptor = fetchDescriptor(webxmlFile, new NullProgressMonitor()); } - PropertyGroup matchingGroup = null; - - for (int i = 0; i < descriptor.groups.length && matchingGroup == null; i++) { - if (descriptor.groups[i].matches(jspFilePath.removeFirstSegments(contextRoot.segmentCount()).toString(), false)) { - matchingGroup = descriptor.groups[i]; + for (int i = 0; i < descriptor.groups.length; i++) { + if (descriptor.groups[i].matches(jspFilePath.removeFirstSegments(contextRoot.segmentCount()).makeAbsolute().toString(), false)) { + matchingGroups.add(descriptor.groups[i]); } } - for (int i = 0; i < descriptor.groups.length && matchingGroup == null; i++) { - if (descriptor.groups[i].matches(jspFilePath.removeFirstSegments(contextRoot.segmentCount()).toString(), true)) { - matchingGroup = descriptor.groups[i]; + if (matchingGroups.isEmpty()) { + for (int i = 0; i < descriptor.groups.length; i++) { + if (descriptor.groups[i].matches(jspFilePath.removeFirstSegments(contextRoot.segmentCount()).toString(), true)) { + matchingGroups.add(descriptor.groups[i]); + } } } - return matchingGroup; + return (PropertyGroup[]) matchingGroups.toArray(new PropertyGroup[matchingGroups.size()]); } private void updateCacheEntry(IPath fullPath) {
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java index 797b9ac..d98e091 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java
@@ -2595,16 +2595,30 @@ public IStructuredDocument getStructuredDocument() { return fStructuredDocument; } + + private IPath getModelPath() { + IPath path = null; + IStructuredModel sModel = StructuredModelManager.getModelManager().getModelForRead(getStructuredDocument()); + try { + if (sModel != null) + path = new Path(sModel.getBaseLocation()); + } + finally { + if (sModel != null) + sModel.releaseFromRead(); + } + return path; + } private void translateCodas() { fProcessIncludes = false; - if (getBaseLocation() != null) { - Path basePath = new Path(getBaseLocation()); - PropertyGroup propertyGroup = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroup(basePath); - if (propertyGroup != null) { - IPath[] codas = propertyGroup.getIncludeCoda(); + IPath modelpath = getModelPath(); + if (modelpath != null) { + PropertyGroup[] propertyGroups = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroups(modelpath); + for(int j = 0; j < propertyGroups.length; j++) { + IPath[] codas = propertyGroups[j].getIncludeCoda(); for (int i = 0; i < codas.length; i++) { - if (!getIncludes().contains(codas[i].toString()) && !codas[i].equals(basePath)) { + if (!getIncludes().contains(codas[i].toString()) && !codas[i].equals(modelpath)) { getIncludes().push(codas[i]); JSPIncludeRegionHelper helper = new JSPIncludeRegionHelper(this); helper.parse(codas[i].toString()); @@ -2618,13 +2632,13 @@ private void translatePreludes() { fProcessIncludes = false; - if (getBaseLocation() != null) { - Path basePath = new Path(getBaseLocation()); - PropertyGroup propertyGroup = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroup(basePath); - if (propertyGroup != null) { - IPath[] preludes = propertyGroup.getIncludePrelude(); + IPath modelpath = getModelPath(); + if (modelpath != null) { + PropertyGroup[] propertyGroups = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroups(modelpath); + for(int j = 0; j < propertyGroups.length; j++) { + IPath[] preludes = propertyGroups[j].getIncludePrelude(); for (int i = 0; i < preludes.length; i++) { - if (!getIncludes().contains(preludes[i].toString()) && !preludes[i].equals(basePath)) { + if (!getIncludes().contains(preludes[i].toString()) && !preludes[i].equals(modelpath)) { getIncludes().push(preludes[i]); JSPIncludeRegionHelper helper = new JSPIncludeRegionHelper(this); helper.parse(preludes[i].toString());