2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.ui.text.java;
7 import net.sourceforge.phpdt.core.ICodeFormatter;
8 import net.sourceforge.phpdt.core.ToolFactory;
9 import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
10 import net.sourceforge.phpdt.internal.corext.util.Strings;
11 import net.sourceforge.phpdt.internal.ui.preferences.CodeFormatterPreferencePage;
13 import org.eclipse.jface.text.IDocument;
14 import org.eclipse.jface.text.formatter.IFormattingStrategy;
15 import org.eclipse.jface.text.source.ISourceViewer;
17 public class JavaFormattingStrategy implements IFormattingStrategy {
19 private String fInitialIndentation;
20 private ISourceViewer fViewer;
22 public JavaFormattingStrategy(ISourceViewer viewer) {
27 * @see IFormattingStrategy#formatterStarts(String)
29 public void formatterStarts(String initialIndentation) {
30 fInitialIndentation= initialIndentation;
34 * @see IFormattingStrategy#formatterStops()
36 public void formatterStops() {
40 * @see IFormattingStrategy#format(String, boolean, String, int[])
42 public String format(String content, boolean isLineStart, String indentation, int[] positions) {
43 ICodeFormatter formatter= ToolFactory.createCodeFormatter();
45 IDocument doc= fViewer.getDocument();
46 String lineDelimiter= StubUtility.getLineDelimiterFor(doc);
49 if (fInitialIndentation != null) {
50 indent= Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
52 return formatter.format(content, indent, positions, lineDelimiter);