* 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
+ *
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
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>
, false /* nls */
, false /* assert */
, true, /* tokenizeStrings */
- null, null); // regular scanner for forming lines
+ null, null, true /*taskCaseSensitive*/); // regular scanner for forming lines
scanner.recordLineSeparator = true;
+ scanner.ignorePHPOneLiner = true;
// to remind of the position of the beginning of the line.
splitScanner = new Scanner(true /* comment */
, true /* whitespace */
, false /* nls */
, false /* assert */
, true, /* tokenizeStrings */
- null, null);
+ null, null, true /*taskCaseSensitive*/);
+ splitScanner.ignorePHPOneLiner = true;
// secondary scanner to split long lines formed by primary scanning
// initialize current line buffer
currentLineBuffer = new StringBuffer();
}
token = 0;
}
- if (token == Scanner.TokenNameEOF)
+ if (token == Scanner.TokenNameEOF) {
break;
+ } else if (token == Scanner.TokenNameHEREDOC) {
+ // no indentation for heredocs and HTML !
+ outputCurrentTokenWithoutIndent(Scanner.TokenNameHEREDOC, 0);
+ continue;
+ } else if (token == Scanner.TokenNameINLINE_HTML) {
+ // no indentation for heredocs and HTML !
+ int newLineCount = 1;
+ if (scanner.startPosition==0) {
+ newLineCount = 0;
+ }
+ outputCurrentTokenWithoutIndent(Scanner.TokenNameINLINE_HTML, newLineCount);
+ int srcLen = scanner.source.length;
+ if (scanner.currentPosition < srcLen-1) {
+ newLine(1);
+ }
+ continue;
+ }
/*
* ## MODIFYING the indentation level before generating new lines and indentation in the output string
*/
// |= (15.25.2)
return "|="; //$NON-NLS-1$
case TokenNameDOT_EQUAL:
- // .=
+ // .=
return ".="; //$NON-NLS-1$
case TokenNameDOT:
// .
}
}
+ private void outputCurrentTokenWithoutIndent(int token, int newLineCount) {
+ newLine(newLineCount);
+ formattedSource.append(scanner.source, scanner.startPosition, scanner.currentPosition - scanner.startPosition);
+ }
+
/**
* Appends <code>token</code> to the formatted output. <br>
* If it contains <code>\n</code>, append a LINE_SEPARATOR and indent after it.
//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;
}