[281380] Code folding inefficient and broken
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/XMLFoldingStrategy.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/XMLFoldingStrategy.java
new file mode 100644
index 0000000..00e66cb
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/projection/XMLFoldingStrategy.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *     
+ *******************************************************************************/
+package org.eclipse.wst.xml.ui.internal.projection;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingStrategy;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
+
+
+/**
+ * A folding strategy for XML type structured documents.
+ * See AbstractStructuredFoldingStrategy for more details.
+ */
+public class XMLFoldingStrategy extends AbstractStructuredFoldingStrategy {
+
+	/**
+	 * Create an instance of the folding strategy.
+	 * Be sure to set the viewer and document after creation.
+	 */
+	public XMLFoldingStrategy() {
+		super();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy#calcNewFoldPosition(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)
+	 */
+	protected Position calcNewFoldPosition(IndexedRegion indexedRegion) {
+		Position retPos = null;
+		
+		if(indexedRegionValidType(indexedRegion)) {
+			IDOMNode node = (IDOMNode)indexedRegion;
+			IStructuredDocumentRegion startRegion = node.getStartStructuredDocumentRegion();
+			IStructuredDocumentRegion endRegion = node.getEndStructuredDocumentRegion();
+			
+			int start;
+			int length;
+			//if the node has an endRegion (end tag) then folding region is
+			//	between the start and end tag
+			//else if the region is only an open tag or an open/close tag then don't fold it
+			if(startRegion != null && endRegion != null) {
+				start = startRegion.getStartOffset();
+				length = endRegion.getStartOffset() - start;
+				
+				retPos = new Position(start, length);
+			} 
+		}
+		
+		return retPos;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy#indexedRegionValidType(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)
+	 */
+	protected boolean indexedRegionValidType(IndexedRegion indexedRegion) {
+		return (indexedRegion instanceof IDOMNode) && !(indexedRegion instanceof IDOMText);
+	}
+}