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/JavaDocRegion.java
final IDocument document= getDocument();
				final Position[] positions= document.getPositions(CODE_POSITION_CATEGORY);
				if (positions.length > 0) {
					int begin= 0;
					int end= 0;
					final IFormattingContext context= new CommentFormattingContext();
					context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.valueOf(false));
					context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, getStrategy().getPreferences());
					for (int position= 0; position < positions.length - 1; position++) {
						begin= positions[position++].getOffset();
						end= positions[position].getOffset();
						context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(begin, end - begin, IDocument.DEFAULT_CONTENT_TYPE));
						formatter.format(document, context);
					}
				}
			} catch (BadPositionCategoryException exception) {
				
			}
		}
	}
	/*
	 * @see org.eclipse.jdt.internal.ui.text.comment.CommentRegion#canApply(org.eclipse.jdt.internal.ui.text.comment.CommentRange,org.eclipse.jdt.internal.ui.text.comment.CommentRange)
	 */
	protected boolean canApply(final CommentRange previous, final CommentRange next) {
		if (previous != null) {
			final boolean isCurrentCode= next.hasAttribute(COMMENT_CODE);
			final boolean isLastCode= previous.hasAttribute(COMMENT_CODE);
			try {
				final int index= getOffset();
				final IDocument document= getDocument();