2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.ui.text.java;
7 import org.eclipse.jface.text.IDocument;
8 import org.eclipse.jface.text.formatter.IFormattingStrategy;
9 import org.eclipse.jface.text.source.ISourceViewer;
11 import net.sourceforge.phpdt.core.ICodeFormatter;
12 import net.sourceforge.phpdt.core.ToolFactory;
14 import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
15 import net.sourceforge.phpdt.internal.corext.util.Strings;
16 import net.sourceforge.phpdt.internal.ui.preferences.CodeFormatterPreferencePage;
18 public class JavaFormattingStrategy implements IFormattingStrategy {
20 private String fInitialIndentation;
21 private ISourceViewer fViewer;
23 public JavaFormattingStrategy(ISourceViewer viewer) {
28 * @see IFormattingStrategy#formatterStarts(String)
30 public void formatterStarts(String initialIndentation) {
31 fInitialIndentation= initialIndentation;
35 * @see IFormattingStrategy#formatterStops()
37 public void formatterStops() {
41 * @see IFormattingStrategy#format(String, boolean, String, int[])
43 public String format(String content, boolean isLineStart, String indentation, int[] positions) {
44 ICodeFormatter formatter= ToolFactory.createCodeFormatter();
46 IDocument doc= fViewer.getDocument();
47 String lineDelimiter= StubUtility.getLineDelimiterFor(doc);
50 if (fInitialIndentation != null) {
51 indent= Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
53 return formatter.format(content, indent, positions, lineDelimiter);