Bug 112586 [api] add support for toggling folding for IJavaElement's
For tools that want to use the IJavaFoldingStructureProviderExtension, but want finer-grained control of what to collapse, it would be useful to have the following methods: - collapseElements(List<IJavaElement> elements) - expandElements(List<IJavaElement> elements) My use case is Mylar, which currently needs to set it's own folding structure provider, but with this could simply use the default one and drive the folding based on selections. Note that for selections this would only be getting called with a single element, but when a file is opened it would need to be called with a list, hance the suggest to take lists (or arrays if JDT is not moving to Java 5).
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/folding/DefaultJavaFoldingStructureProvider.java
if (preRegion == null)
					return new IRegion[] { postRegion };
				return new IRegion[] { preRegion, postRegion };
			}
			if (preRegion != null)
				return new IRegion[] { preRegion };
			return null;
		}
		/**
		 * Finds the offset of the first identifier part within <code>content</code>.
		 * Returns 0 if none is found.
		 *
		 * @param content the content to search
		 * @return the first index of a unicode identifier part, or zero if none can
		 *         be found
		 */
		private int findFirstContent(final CharSequence content, int prefixEnd) {
			int lenght= content.length();
			for (int i= prefixEnd; i < lenght; i++) {
				if (Character.isUnicodeIdentifierPart(content.charAt(i)))
					return i;
			}
			return 0;
		}
		/*
		 * @see org.eclipse.jface.text.source.projection.IProjectionPosition#computeCaptionOffset(org.eclipse.jface.text.IDocument)
		 */
		public int computeCaptionOffset(IDocument document) {
			DocumentCharacterIterator sequence= new DocumentCharacterIterator(document, offset, offset + length);
			return findFirstContent(sequence, 0);