Bug 44035 [formatting] Error in formatting parts of java code snippets in comment
This is for build I20030930. The Java code formatter options are set to Format java code snippets. Taking the following comment: /** * The following is a Java snipet. * * <pre> * while ((size = availableSize(stream, size)) > 0) { * System.out.println("available"); * } * </pre> */ public void test() { } And trying to format it here is what we got: /** * The following is a Java snipet. * * <pre> * while ((size = availableSize(stream, size)) > 0) { * System.out.println("available"); } * </pre> */ public void test() { }
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormattingStrategy.java
*                  The content formatter with which this formatting strategy has
	 *                  been registered
	 * @param viewer
	 *                  The source viewer where to apply the formatting strategy
	 */
	public CommentFormattingStrategy(final ContentFormatter2 formatter, final ISourceViewer viewer) {
		super(viewer);
		fFormatter= formatter;
	}
	/*
	 * @see org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy#format()
	 */
	public void format() {
		super.format();
		Assert.isLegal(fPartitions.size() > 0);
		final IDocument document= getViewer().getDocument();
		final TypedPosition position= (TypedPosition)fPartitions.removeFirst();
		try {
			final ITypedRegion partition= TextUtilities.getPartition(document, fFormatter.getDocumentPartitioning(), position.getOffset());
			final String type= partition.getType();
			position.offset= partition.getOffset();
			position.length= partition.getLength();
			final Map preferences= getPreferences();
			final boolean format= IPreferenceStore.TRUE.equals(preferences.get(PreferenceConstants.FORMATTER_COMMENT_FORMAT));
			final boolean header= IPreferenceStore.TRUE.equals(preferences.get(PreferenceConstants.FORMATTER_COMMENT_FORMATHEADER));
			if (format && (header || position.getOffset() != 0 || !type.equals(IJavaPartitions.JAVA_DOC) && !type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT))) {
				final CommentRegion region= CommentObjectFactory.createRegion(this, position, TextUtilities.getDefaultLineDelimiter(document));
				final String indentation= getLineIndentation(document, region, position.getOffset());
				region.format(indentation);
			}