2 * (c) Copyright IBM Corp. 2000, 2001. All Rights Reserved.
4 package net.sourceforge.phpdt.internal.ui.text.java;
6 import net.sourceforge.phpdt.core.ICodeFormatter;
7 import net.sourceforge.phpdt.core.ToolFactory;
8 import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
9 import net.sourceforge.phpdt.internal.corext.util.Strings;
10 import net.sourceforge.phpdt.internal.ui.preferences.CodeFormatterPreferencePage;
12 import org.eclipse.jface.text.IDocument;
13 import org.eclipse.jface.text.formatter.IFormattingStrategy;
14 import org.eclipse.jface.text.source.ISourceViewer;
16 public class JavaFormattingStrategy implements IFormattingStrategy {
18 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,
43 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,
52 CodeFormatterPreferencePage.getTabSize());
55 return formatter.format(content, indent, positions, lineDelimiter);