import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
+
import net.sourceforge.phpdt.core.ICodeFormatter;
import net.sourceforge.phpdt.core.compiler.CharOperation;
import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
import net.sourceforge.phpdt.core.compiler.InvalidInputException;
import net.sourceforge.phpdt.internal.compiler.ConfigurableOption;
import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
+import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
+import net.sourceforge.phpdt.internal.corext.util.Strings;
import net.sourceforge.phpdt.internal.formatter.impl.FormatterOptions;
import net.sourceforge.phpdt.internal.formatter.impl.SplitLine;
+import net.sourceforge.phpdt.internal.ui.preferences.CodeFormatterPreferencePage;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.formatter.IContentFormatterExtension;
+import org.eclipse.jface.text.formatter.IFormattingContext;
/**
* <h2>How to format a piece of code ?</h2>
* <ul>
* </ul>
*/
public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
+ // IContentFormatterExtension {
public FormatterOptions options;
/**
* Represents a block in the <code>constructions</code> stack.
public void setInitialIndentationLevel(int newIndentationLevel) {
this.initialIndentationLevel = currentLineIndentationLevel = indentationLevel = newIndentationLevel;
}
+
}
\ No newline at end of file
/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
+ * (c) Copyright IBM Corp. 2000, 2001. All Rights Reserved.
*/
package net.sourceforge.phpdt.internal.ui.text.java;
import org.eclipse.jface.text.source.ISourceViewer;
public class JavaFormattingStrategy implements IFormattingStrategy {
-
- private String fInitialIndentation;
- private ISourceViewer fViewer;
-
- public JavaFormattingStrategy(ISourceViewer viewer) {
- fViewer = viewer;
- }
-
- /**
- * @see IFormattingStrategy#formatterStarts(String)
- */
- public void formatterStarts(String initialIndentation) {
- fInitialIndentation= initialIndentation;
- }
-
- /**
- * @see IFormattingStrategy#formatterStops()
- */
- public void formatterStops() {
- }
-
- /**
- * @see IFormattingStrategy#format(String, boolean, String, int[])
- */
- public String format(String content, boolean isLineStart, String indentation, int[] positions) {
- ICodeFormatter formatter= ToolFactory.createCodeFormatter();
-
- IDocument doc= fViewer.getDocument();
- String lineDelimiter= StubUtility.getLineDelimiterFor(doc);
-
- int indent= 0;
- if (fInitialIndentation != null) {
- indent= Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
- }
- return formatter.format(content, indent, positions, lineDelimiter);
- }
+
+ private String fInitialIndentation;
+
+ private ISourceViewer fViewer;
+
+ public JavaFormattingStrategy(ISourceViewer viewer) {
+ fViewer = viewer;
+ }
+
+ /**
+ * @see IFormattingStrategy#formatterStarts(String)
+ */
+ public void formatterStarts(String initialIndentation) {
+ fInitialIndentation = initialIndentation;
+ }
+
+ /**
+ * @see IFormattingStrategy#formatterStops()
+ */
+ public void formatterStops() {
+ }
+
+ /**
+ * @see IFormattingStrategy#format(String, boolean, String, int[])
+ */
+ public String format(String content, boolean isLineStart, String indentation,
+ int[] positions) {
+ ICodeFormatter formatter = ToolFactory.createCodeFormatter();
+
+ IDocument doc = fViewer.getDocument();
+ String lineDelimiter = StubUtility.getLineDelimiterFor(doc);
+
+ int indent = 0;
+ if (fInitialIndentation != null) {
+ indent = Strings.computeIndent(fInitialIndentation,
+ CodeFormatterPreferencePage.getTabSize());
+ }
+
+ return formatter.format(content, indent, positions, lineDelimiter);
+ }
}
\ No newline at end of file