EclipseJsFormatterStepImpl { private String formatComments(String raw) { Document doc = new Document(raw); IDocumentPartitioner commentPartitioner = new FastPartitioner(new FastJavaPartitionScanner(), COMMENT_TYPES); doc.setDocumentPartitioner(IJavaScriptPartitions.JAVA_PARTITIONING, commentPartitioner); commentPartitioner.connect(doc); CommentFormattingStrategy commentFormatter = new CommentFormattingStrategy(); IFormattingContext context = new CommentFormattingContext(); context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, options); context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE); context.setProperty(FormattingContextProperties.CONTEXT_MEDIUM, doc); try { ITypedRegion[] regions = TextUtilities.computePartitioning(doc, IJavaScriptPartitions.JAVA_PARTITIONING, 0, doc.getLength(), false); MultiTextEdit resultEdit = new MultiTextEdit(); Arrays.asList(regions).stream().filter(reg -> commentTypesToBeFormatted.contains(reg.getType())).forEach(region -> { TypedPosition typedPosition = new TypedPosition(region.getOffset(), region.getLength(), region.getType()); context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, typedPosition); commentFormatter.formatterStarts(context); TextEdit edit = commentFormatter.calculateTextEdit(); commentFormatter.formatterStops(); if (null != edit && edit.hasChildren()) { resultEdit.addChild(edit); } }); resultEdit.apply(doc); return doc.get(); } catch (BadLocationException e) { return raw; } } EclipseJsFormatterStepImpl(Properties properties); String format(String raw);  }
@Test public void formatComments() throws Exception { String output = formatter.format(SINGLE_LINE_COMMENT + PRE_CODE_UNFORMATTED + UNFORMATTED); assertEquals("Invalid user configuration not treated on best effort basis.", SINGLE_LINE_COMMENT + PRE_CODE_FORMATTED + FORMATTED, output); }