X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java index 27e8037..09e3add 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java @@ -1,10 +1,11 @@ /******************************************************************************* * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v05.html - * + * * Contributors: * IBM Corporation - initial API and implementation ******************************************************************************/ @@ -23,15 +24,8 @@ 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; /** *
sourceString
, and returns a string containing the formatted version.
- *
+ *
* @return the formatted ouput.
*/
public String formatSourceString(String sourceString) {
@@ -927,7 +972,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* Formats the char array sourceString
, and returns a string containing the formatted version.
- *
+ *
* @param string
* the string to format
* @param indentationLevel
@@ -941,7 +986,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* Formats the char array sourceString
, and returns a string containing the formatted version. The positions array
* is modified to contain the mapped positions.
- *
+ *
* @param string
* the string to format
* @param indentationLevel
@@ -974,7 +1019,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* Formats the char array sourceString
, and returns a string containing the formatted version. The initial
* indentation level is 0.
- *
+ *
* @param string
* the string to format
* @return the formatted ouput.
@@ -985,7 +1030,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* Formats a given source string, starting indenting it at a particular depth and using the given options
- *
+ *
* @deprecated backport 1.0 internal functionality
*/
public static String format(String sourceString, int initialIndentationLevel, ConfigurableOption[] options) {
@@ -1037,7 +1082,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* Returns an array of descriptions for the configurable options. The descriptions may be changed and passed back to a different
* compiler.
- *
+ *
* @deprecated backport 1.0 internal functionality
*/
public static ConfigurableOption[] getDefaultOptions(Locale locale) {
@@ -1066,18 +1111,25 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* Returns the array of mapped positions. Returns null is no positions have been set.
- *
+ *
* @return int[]
* @deprecated There is no need to retrieve the mapped positions anymore.
*/
public int[] getMappedPositions() {
+ if (null!=mappedPositions) {
+ for (int i=0;itoken
* @param token
* the token of which the priority is requested
@@ -1260,7 +1312,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* If the length of oneLineBuffer
exceeds maxLineLength
, it is split and the result is dumped in
* formattedSource
- *
+ *
* @param newLineCount
* the number of new lines to append
*/
@@ -1331,7 +1383,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
return "==="; //$NON-NLS-1$
case TokenNameEQUAL_GREATER:
// -= (15.25.2)
- return "=>"; //$NON-NLS-1$
+ return "=>"; //$NON-NLS-1$
case TokenNameNOT_EQUAL:
// != (15.20, 15.20.1, 15.20.2, 15.20.3)
return "!="; //$NON-NLS-1$
@@ -1420,7 +1472,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
// |= (15.25.2)
return "|="; //$NON-NLS-1$
case TokenNameDOT_EQUAL:
- // .=
+ // .=
return ".="; //$NON-NLS-1$
case TokenNameDOT:
// .
@@ -1444,6 +1496,11 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
}
}
+ private void outputCurrentTokenWithoutIndent(int token, int newLineCount) {
+ newLine(newLineCount);
+ formattedSource.append(scanner.source, scanner.startPosition, scanner.currentPosition - scanner.startPosition);
+ }
+
/**
* Appends token
to the formatted output. \n
, append a LINE_SEPARATOR and indent after it.
@@ -1555,7 +1612,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
* token
.token
from the stack.
- *
+ *
* @param token
* the token to be left as the top of the stack
*/
@@ -1835,7 +1892,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* Pops elements until the stack is empty or the top element is token
.token
from the stack too.
- *
+ *
* @param token
* the token to remove from the stack
*/
@@ -1908,17 +1965,17 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
//return (currentToken == TokenNameCOMMA || currentToken ==
// TokenNameSEMICOLON);
return currentToken != TokenNameif && currentToken != TokenNameLPAREN && currentToken != TokenNameNOT
- && currentToken != TokenNamewhile && currentToken != TokenNamefor && currentToken != TokenNameforeach
+ && currentToken != TokenNamewhile && currentToken != TokenNamefor && currentToken != TokenNameforeach
&& currentToken != TokenNameswitch;
}
/**
* Set the positions to map. The mapped positions should be retrieved using the getMappedPositions() method.
- *
+ *
* @param positions
* int[]
* @deprecated Set the positions to map using the format(String, int, int[]) method.
- *
+ *
* @see #getMappedPositions()
*/
public void setPositionsToMap(int[] positions) {
@@ -1939,7 +1996,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
/**
* Splits stringToSplit
on the top level token stringToSplit
on the top level token