From 21ded79e6ddd3fc0214620f099f144df86ad1763 Mon Sep 17 00:00:00 2001 From: axelcl Date: Mon, 8 Nov 2004 21:06:28 +0000 Subject: [PATCH 01/16] CVS test --- net.sourceforge.phpeclipse.tests/test.php | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) create mode 100644 net.sourceforge.phpeclipse.tests/test.php diff --git a/net.sourceforge.phpeclipse.tests/test.php b/net.sourceforge.phpeclipse.tests/test.php new file mode 100644 index 0000000..39be7ca --- /dev/null +++ b/net.sourceforge.phpeclipse.tests/test.php @@ -0,0 +1,5 @@ + \ No newline at end of file -- 1.7.1 From a8a642c1ad953d9c7fced468d56b55eaa641cf95 Mon Sep 17 00:00:00 2001 From: axelcl Date: Mon, 8 Nov 2004 21:07:36 +0000 Subject: [PATCH 02/16] CVS test --- net.sourceforge.phpeclipse.tests/test.php | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/net.sourceforge.phpeclipse.tests/test.php b/net.sourceforge.phpeclipse.tests/test.php index 39be7ca..5413c2e 100644 --- a/net.sourceforge.phpeclipse.tests/test.php +++ b/net.sourceforge.phpeclipse.tests/test.php @@ -2,4 +2,8 @@ // CVS commit tests phpinfo(); + + phpinfo(); + + //? ?> \ No newline at end of file -- 1.7.1 From 9f6e8fa708bd39146546ca7b42cb73849f6f336b Mon Sep 17 00:00:00 2001 From: axelcl Date: Tue, 9 Nov 2004 18:50:31 +0000 Subject: [PATCH 03/16] php5 compatible TOC file --- net.sourceforge.phpeclipse.phphelp/phphelp.xml | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/net.sourceforge.phpeclipse.phphelp/phphelp.xml b/net.sourceforge.phpeclipse.phphelp/phphelp.xml index 8e19278..bb6d67a 100644 --- a/net.sourceforge.phpeclipse.phphelp/phphelp.xml +++ b/net.sourceforge.phpeclipse.phphelp/phphelp.xml @@ -1,10 +1,13 @@ - - - - - - + + + + + + + + + \ No newline at end of file -- 1.7.1 From aa1940052bb5f93e310ebf89b304c3b004503ffe Mon Sep 17 00:00:00 2001 From: axelcl Date: Tue, 9 Nov 2004 21:45:12 +0000 Subject: [PATCH 04/16] no indentation of HTML and phpdocs --- .../phpdt/internal/formatter/CodeFormatter.java | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) 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..b272fbd 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 @@ -372,6 +372,11 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { } if (token == Scanner.TokenNameEOF) break; + if (token == Scanner.TokenNameHEREDOC || token == Scanner.TokenNameINLINE_HTML) { + // no indentation for heredocs and HTML ! + outputCurrentTokenWithoutIndent(Scanner.TokenNameHEREDOC); + continue; + } /* * ## MODIFYING the indentation level before generating new lines and indentation in the output string */ @@ -1420,7 +1425,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 +1449,11 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { } } + private void outputCurrentTokenWithoutIndent(int token) { + newLine(0); + formattedSource.append(scanner.source, scanner.startPosition, scanner.currentPosition - scanner.startPosition); + } + /** * Appends token to the formatted output.
* If it contains \n, append a LINE_SEPARATOR and indent after it. @@ -1908,7 +1918,7 @@ 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; } -- 1.7.1 From 39b9490e165600092f8692f4efc5fd482d28e98b Mon Sep 17 00:00:00 2001 From: axelcl Date: Tue, 9 Nov 2004 21:58:18 +0000 Subject: [PATCH 05/16] no indentation of HTML and phpdocs --- .../phpdt/internal/formatter/CodeFormatter.java | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) 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 b272fbd..bfb0e3b 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 @@ -370,11 +370,19 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { } token = 0; } - if (token == Scanner.TokenNameEOF) + if (token == Scanner.TokenNameEOF) { break; - if (token == Scanner.TokenNameHEREDOC || token == Scanner.TokenNameINLINE_HTML) { + } else if (token == Scanner.TokenNameHEREDOC) { // no indentation for heredocs and HTML ! - outputCurrentTokenWithoutIndent(Scanner.TokenNameHEREDOC); + 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); continue; } /* @@ -1449,8 +1457,8 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { } } - private void outputCurrentTokenWithoutIndent(int token) { - newLine(0); + private void outputCurrentTokenWithoutIndent(int token, int newLineCount) { + newLine(newLineCount); formattedSource.append(scanner.source, scanner.startPosition, scanner.currentPosition - scanner.startPosition); } -- 1.7.1 From a43b3163d63f2e190f4c49e37ec47d8866364dec Mon Sep 17 00:00:00 2001 From: axelcl Date: Wed, 10 Nov 2004 20:06:25 +0000 Subject: [PATCH 06/16] don't split one line PHP statements in CodeFormatter --- .../phpdt/internal/formatter/CodeFormatter.java | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) 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 bfb0e3b..7caa523 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 @@ -168,6 +168,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { , true, /* tokenizeStrings */ null, null); // 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 */ @@ -175,6 +176,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { , false /* assert */ , true, /* tokenizeStrings */ null, null); + splitScanner.ignorePHPOneLiner = true; // secondary scanner to split long lines formed by primary scanning // initialize current line buffer currentLineBuffer = new StringBuffer(); @@ -383,6 +385,10 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { newLineCount = 0; } outputCurrentTokenWithoutIndent(Scanner.TokenNameINLINE_HTML, newLineCount); + int srcLen = scanner.source.length; + if (scanner.currentPosition < srcLen-1) { + newLine(1); + } continue; } /* -- 1.7.1 From 35d4ea62beb9de311734cb61324aa6b6d73b08d0 Mon Sep 17 00:00:00 2001 From: axelcl Date: Wed, 10 Nov 2004 20:24:26 +0000 Subject: [PATCH 07/16] don't split one line PHP statements in CodeFormatter --- .../phpdt/internal/compiler/parser/Scanner.java | 4416 ++++++++++---------- 1 files changed, 2226 insertions(+), 2190 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java index 0997cb7..a8232c2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java @@ -1,14 +1,12 @@ -/******************************************************************************* - * 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 +/*********************************************************************************************************************************** + * 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 * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ + * Contributors: IBM Corporation - initial API and implementation + **********************************************************************************************************************************/ package net.sourceforge.phpdt.internal.compiler.parser; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -20,98 +18,144 @@ import net.sourceforge.phpdt.core.compiler.ITerminalSymbols; import net.sourceforge.phpdt.core.compiler.InvalidInputException; import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral; - public class Scanner implements IScanner, ITerminalSymbols { /* - * APIs ares - getNextToken() which return the current type of the token - * (this value is not memorized by the scanner) - getCurrentTokenSource() - * which provides with the token "REAL" source (aka all unicode have been - * transformed into a correct char) - sourceStart gives the position into the - * stream - currentPosition-1 gives the sourceEnd position into the stream + * APIs ares - getNextToken() which return the current type of the token (this value is not memorized by the scanner) - + * getCurrentTokenSource() which provides with the token "REAL" source (aka all unicode have been transformed into a correct char) - + * sourceStart gives the position into the stream - currentPosition-1 gives the sourceEnd position into the stream */ // 1.4 feature private boolean assertMode; + public boolean useAssertAsAnIndentifier = false; + //flag indicating if processed source contains occurrences of keyword assert public boolean containsAssertKeyword = false; + public boolean recordLineSeparator; + + public boolean ignorePHPOneLiner = false; + public boolean phpMode = false; + public Stack encapsedStringStack = null; + public char currentCharacter; + public int startPosition; + public int currentPosition; + public int initialPosition, eofPosition; + // after this position eof are generated instead of real token from the // source public boolean tokenizeComments; + public boolean tokenizeWhiteSpace; + public boolean tokenizeStrings; + //source should be viewed as a window (aka a part) //of a entire very large stream public char source[]; + //unicode support public char[] withoutUnicodeBuffer; + public int withoutUnicodePtr; + //when == 0 ==> no unicode in the current token public boolean unicodeAsBackSlash = false; + public boolean scanningFloatLiteral = false; -//support for /** comments - public int[] commentStops = new int[10]; - public int[] commentStarts = new int[10]; - public int commentPtr = -1; // no comment test with commentPtr value -1 - protected int lastCommentLinePosition = -1; + + //support for /** comments + public int[] commentStops = new int[10]; + + public int[] commentStarts = new int[10]; + + public int commentPtr = -1; // no comment test with commentPtr value -1 + + protected int lastCommentLinePosition = -1; + //diet parsing support - jump over some method body when requested public boolean diet = false; + //support for the poor-line-debuggers .... //remember the position of the cr/lf public int[] lineEnds = new int[250]; + public int linePtr = -1; + public boolean wasAcr = false; + public static final String END_OF_SOURCE = "End_Of_Source"; //$NON-NLS-1$ + public static final String INVALID_HEXA = "Invalid_Hexa_Literal"; //$NON-NLS-1$ + public static final String INVALID_OCTAL = "Invalid_Octal_Literal"; //$NON-NLS-1$ + public static final String INVALID_CHARACTER_CONSTANT = "Invalid_Character_Constant"; //$NON-NLS-1$ + public static final String INVALID_ESCAPE = "Invalid_Escape"; //$NON-NLS-1$ + public static final String INVALID_INPUT = "Invalid_Input"; //$NON-NLS-1$ + public static final String INVALID_UNICODE_ESCAPE = "Invalid_Unicode_Escape"; //$NON-NLS-1$ + public static final String INVALID_FLOAT = "Invalid_Float_Literal"; //$NON-NLS-1$ + public static final String NULL_SOURCE_STRING = "Null_Source_String"; //$NON-NLS-1$ + public static final String UNTERMINATED_STRING = "Unterminated_String"; //$NON-NLS-1$ + public static final String UNTERMINATED_COMMENT = "Unterminated_Comment"; //$NON-NLS-1$ + public static final String INVALID_CHAR_IN_STRING = "Invalid_Char_In_String"; //$NON-NLS-1$ + //----------------optimized identifier managment------------------ - static final char[] charArray_a = new char[]{'a'}, - charArray_b = new char[]{'b'}, charArray_c = new char[]{'c'}, - charArray_d = new char[]{'d'}, charArray_e = new char[]{'e'}, - charArray_f = new char[]{'f'}, charArray_g = new char[]{'g'}, - charArray_h = new char[]{'h'}, charArray_i = new char[]{'i'}, - charArray_j = new char[]{'j'}, charArray_k = new char[]{'k'}, - charArray_l = new char[]{'l'}, charArray_m = new char[]{'m'}, - charArray_n = new char[]{'n'}, charArray_o = new char[]{'o'}, - charArray_p = new char[]{'p'}, charArray_q = new char[]{'q'}, - charArray_r = new char[]{'r'}, charArray_s = new char[]{'s'}, - charArray_t = new char[]{'t'}, charArray_u = new char[]{'u'}, - charArray_v = new char[]{'v'}, charArray_w = new char[]{'w'}, - charArray_x = new char[]{'x'}, charArray_y = new char[]{'y'}, - charArray_z = new char[]{'z'}; - static final char[] initCharArray = new char[]{'\u0000', '\u0000', '\u0000', - '\u0000', '\u0000', '\u0000'}; + static final char[] charArray_a = new char[] { 'a' }, charArray_b = new char[] { 'b' }, charArray_c = new char[] { 'c' }, + charArray_d = new char[] { 'd' }, charArray_e = new char[] { 'e' }, charArray_f = new char[] { 'f' }, + charArray_g = new char[] { 'g' }, charArray_h = new char[] { 'h' }, charArray_i = new char[] { 'i' }, + charArray_j = new char[] { 'j' }, charArray_k = new char[] { 'k' }, charArray_l = new char[] { 'l' }, + charArray_m = new char[] { 'm' }, charArray_n = new char[] { 'n' }, charArray_o = new char[] { 'o' }, + charArray_p = new char[] { 'p' }, charArray_q = new char[] { 'q' }, charArray_r = new char[] { 'r' }, + charArray_s = new char[] { 's' }, charArray_t = new char[] { 't' }, charArray_u = new char[] { 'u' }, + charArray_v = new char[] { 'v' }, charArray_w = new char[] { 'w' }, charArray_x = new char[] { 'x' }, + charArray_y = new char[] { 'y' }, charArray_z = new char[] { 'z' }; + + static final char[] initCharArray = new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' }; + static final int TableSize = 30, InternalTableSize = 6; + //30*6 = 180 entries public static final int OptimizedLength = 6; + public/* static */ final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][]; + // support for detecting non-externalized string literals int currentLineNr = -1; + int previousLineNr = -1; + NLSLine currentLine = null; + List lines = new ArrayList(); + public static final String TAG_PREFIX = "//$NON-NLS-"; //$NON-NLS-1$ + public static final int TAG_PREFIX_LENGTH = TAG_PREFIX.length(); + public static final String TAG_POSTFIX = "$"; //$NON-NLS-1$ + public static final int TAG_POSTFIX_LENGTH = TAG_POSTFIX.length(); + public StringLiteral[] nonNLSStrings = null; + public boolean checkNonExternalizedStringLiterals = true; + public boolean wasNonExternalizedStringLiteral = false; /* static */{ for (int i = 0; i < 6; i++) { @@ -122,43 +166,56 @@ public class Scanner implements IScanner, ITerminalSymbols { } } } - static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0, - newEntry6 = 0; + + static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0, newEntry6 = 0; + public static final int RoundBracket = 0; + public static final int SquareBracket = 1; + public static final int CurlyBracket = 2; + public static final int BracketKinds = 3; + // task tag support public char[][] foundTaskTags = null; + public char[][] foundTaskMessages; + public char[][] foundTaskPriorities = null; + public int[][] foundTaskPositions; + public int foundTaskCount = 0; + public char[][] taskTags = null; + public char[][] taskPriorities = null; + public static final boolean DEBUG = false; + public static final boolean TRACE = false; /** - * Determines if the specified character is permissible as the first - * character in a PHP identifier + * Determines if the specified character is permissible as the first character in a PHP identifier */ public static boolean isPHPIdentifierStart(char ch) { return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF); } + /** - * Determines if the specified character may be part of a PHP identifier as - * other than the first character + * Determines if the specified character may be part of a PHP identifier as other than the first character */ public static boolean isPHPIdentifierPart(char ch) { - return Character.isLetterOrDigit(ch) || (ch == '_') - || (0x7F <= ch && ch <= 0xFF); + return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF); } + public final boolean atEnd() { // This code is not relevant if source is // Only a part of the real stream input return source.length == currentPosition; } + public char[] getCurrentIdentifierSource() { //return the token REAL source (aka unicodes are precomputed) char[] result; @@ -173,28 +230,29 @@ public class Scanner implements IScanner, ITerminalSymbols { // else { int length = currentPosition - startPosition; switch (length) { // see OptimizedLength - case 1 : - return optimizedCurrentTokenSource1(); - case 2 : - return optimizedCurrentTokenSource2(); - case 3 : - return optimizedCurrentTokenSource3(); - case 4 : - return optimizedCurrentTokenSource4(); - case 5 : - return optimizedCurrentTokenSource5(); - case 6 : - return optimizedCurrentTokenSource6(); + case 1: + return optimizedCurrentTokenSource1(); + case 2: + return optimizedCurrentTokenSource2(); + case 3: + return optimizedCurrentTokenSource3(); + case 4: + return optimizedCurrentTokenSource4(); + case 5: + return optimizedCurrentTokenSource5(); + case 6: + return optimizedCurrentTokenSource6(); } //no optimization - System.arraycopy(source, startPosition, result = new char[length], 0, - length); + System.arraycopy(source, startPosition, result = new char[length], 0, length); // } return result; } + public int getCurrentTokenEndPosition() { return this.currentPosition - 1; } + public final char[] getCurrentTokenSource() { // Return the token REAL source (aka unicodes are precomputed) char[] result; @@ -208,11 +266,11 @@ public class Scanner implements IScanner, ITerminalSymbols { // withoutUnicodePtr); // else { int length; - System.arraycopy(source, startPosition, - result = new char[length = currentPosition - startPosition], 0, length); + System.arraycopy(source, startPosition, result = new char[length = currentPosition - startPosition], 0, length); // } return result; } + public final char[] getCurrentTokenSource(int startPos) { // Return the token REAL source (aka unicodes are precomputed) char[] result; @@ -226,46 +284,44 @@ public class Scanner implements IScanner, ITerminalSymbols { // withoutUnicodePtr); // else { int length; - System.arraycopy(source, startPos, - result = new char[length = currentPosition - startPos], 0, length); + System.arraycopy(source, startPos, result = new char[length = currentPosition - startPos], 0, length); // } return result; } + public final char[] getCurrentTokenSourceString() { //return the token REAL source (aka unicodes are precomputed). //REMOVE the two " that are at the beginning and the end. char[] result; if (withoutUnicodePtr != 0) //0 is used as a fast test flag so the real first char is in position 1 - System.arraycopy(withoutUnicodeBuffer, 2, + System.arraycopy(withoutUnicodeBuffer, 2, //2 is 1 (real start) + 1 (to jump over the ") result = new char[withoutUnicodePtr - 2], 0, withoutUnicodePtr - 2); else { int length; - System.arraycopy(source, startPosition + 1, - result = new char[length = currentPosition - startPosition - 2], 0, - length); + System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length); } return result; } + public int getCurrentTokenStartPosition() { return this.startPosition; } + public final char[] getCurrentStringLiteralSource() { // Return the token REAL source (aka unicodes are precomputed) char[] result; int length; - System.arraycopy(source, startPosition + 1, - result = new char[length = currentPosition - startPosition - 2], 0, - length); + System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length); // } return result; } + /* * Search the source position corresponding to the end of a given line number * - * Line numbers are 1-based, and relative to the scanner initialPosition. - * Character positions are 0-based. + * Line numbers are 1-based, and relative to the scanner initialPosition. Character positions are 0-based. * * In case the given line number is inconsistent, answers -1. */ @@ -281,12 +337,11 @@ public class Scanner implements IScanner, ITerminalSymbols { return lineEnds[lineNumber - 1]; // next line start one character behind the lineEnd of the previous line } + /** - * Search the source position corresponding to the beginning of a given line - * number + * Search the source position corresponding to the beginning of a given line number * - * Line numbers are 1-based, and relative to the scanner initialPosition. - * Character positions are 0-based. + * Line numbers are 1-based, and relative to the scanner initialPosition. Character positions are 0-based. * * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0. * @@ -304,6 +359,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return lineEnds[lineNumber - 2] + 1; // next line start one character behind the lineEnd of the previous line } + public final boolean getNextChar(char testedChar) { //BOOLEAN //handle the case of unicode. @@ -380,6 +436,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return false; } } + public final int getNextChar(char testedChar1, char testedChar2) { //INT 0 : testChar1 \\\\///\\\\ 1 : testedChar2 \\\\///\\\\ -1 : others //test can be done with (x==0) for the first and (x>0) for the second @@ -462,6 +519,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return -1; } } + public final boolean getNextCharAsDigit() { //BOOLEAN //handle the case of unicode. @@ -533,6 +591,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return false; } } + public final boolean getNextCharAsDigit(int radix) { //BOOLEAN //handle the case of unicode. @@ -605,6 +664,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return false; } } + public boolean getNextCharAsJavaIdentifierPart() { //BOOLEAN //handle the case of unicode. @@ -677,6 +737,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return false; } } + public int getCastOrParen() { int tempPosition = currentPosition; char tempCharacter = currentCharacter; @@ -687,8 +748,7 @@ public class Scanner implements IScanner, ITerminalSymbols { do { currentCharacter = source[currentPosition++]; } while (currentCharacter == ' ' || currentCharacter == '\t'); - while ((currentCharacter >= 'a' && currentCharacter <= 'z') - || (currentCharacter >= 'A' && currentCharacter <= 'Z')) { + while ((currentCharacter >= 'a' && currentCharacter <= 'z') || (currentCharacter >= 'A' && currentCharacter <= 'Z')) { buf.append(currentCharacter); currentCharacter = source[currentPosition++]; } @@ -696,98 +756,85 @@ public class Scanner implements IScanner, ITerminalSymbols { char[] data = buf.toString().toCharArray(); int index = 0; switch (data.length) { - case 3 : - // int - if ((data[index] == 'i') && (data[++index] == 'n') - && (data[++index] == 't')) { - found = true; - tempToken = TokenNameintCAST; - } - break; - case 4 : - // bool real - if ((data[index] == 'b') && (data[++index] == 'o') - && (data[++index] == 'o') && (data[++index] == 'l')) { + case 3: + // int + if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) { + found = true; + tempToken = TokenNameintCAST; + } + break; + case 4: + // bool real + if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')) { + found = true; + tempToken = TokenNameboolCAST; + } else { + index = 0; + if ((data[index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'l')) { found = true; - tempToken = TokenNameboolCAST; - } else { - index = 0; - if ((data[index] == 'r') && (data[++index] == 'e') - && (data[++index] == 'a') && (data[++index] == 'l')) { - found = true; - tempToken = TokenNamedoubleCAST; - } + tempToken = TokenNamedoubleCAST; } - break; - case 5 : - // array unset float - if ((data[index] == 'a') && (data[++index] == 'r') - && (data[++index] == 'r') && (data[++index] == 'a') - && (data[++index] == 'y')) { + } + break; + case 5: + // array unset float + if ((data[index] == 'a') && (data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') + && (data[++index] == 'y')) { + found = true; + tempToken = TokenNamearrayCAST; + } else { + index = 0; + if ((data[index] == 'u') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') + && (data[++index] == 't')) { found = true; - tempToken = TokenNamearrayCAST; + tempToken = TokenNameunsetCAST; } else { index = 0; - if ((data[index] == 'u') && (data[++index] == 'n') - && (data[++index] == 's') && (data[++index] == 'e') + if ((data[index] == 'f') && (data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'a') && (data[++index] == 't')) { found = true; - tempToken = TokenNameunsetCAST; - } else { - index = 0; - if ((data[index] == 'f') && (data[++index] == 'l') - && (data[++index] == 'o') && (data[++index] == 'a') - && (data[++index] == 't')) { - found = true; - tempToken = TokenNamedoubleCAST; - } + tempToken = TokenNamedoubleCAST; } } - break; - case 6 : - // object string double - if ((data[index] == 'o') && (data[++index] == 'b') - && (data[++index] == 'j') && (data[++index] == 'e') - && (data[++index] == 'c') && (data[++index] == 't')) { + } + break; + case 6: + // object string double + if ((data[index] == 'o') && (data[++index] == 'b') && (data[++index] == 'j') && (data[++index] == 'e') + && (data[++index] == 'c') && (data[++index] == 't')) { + found = true; + tempToken = TokenNameobjectCAST; + } else { + index = 0; + if ((data[index] == 's') && (data[++index] == 't') && (data[++index] == 'r') && (data[++index] == 'i') + && (data[++index] == 'n') && (data[++index] == 'g')) { found = true; - tempToken = TokenNameobjectCAST; + tempToken = TokenNamestringCAST; } else { index = 0; - if ((data[index] == 's') && (data[++index] == 't') - && (data[++index] == 'r') && (data[++index] == 'i') - && (data[++index] == 'n') && (data[++index] == 'g')) { + if ((data[index] == 'd') && (data[++index] == 'o') && (data[++index] == 'u') && (data[++index] == 'b') + && (data[++index] == 'l') && (data[++index] == 'e')) { found = true; - tempToken = TokenNamestringCAST; - } else { - index = 0; - if ((data[index] == 'd') && (data[++index] == 'o') - && (data[++index] == 'u') && (data[++index] == 'b') - && (data[++index] == 'l') && (data[++index] == 'e')) { - found = true; - tempToken = TokenNamedoubleCAST; - } + tempToken = TokenNamedoubleCAST; } } - break; - case 7 : - // boolean integer - if ((data[index] == 'b') && (data[++index] == 'o') - && (data[++index] == 'o') && (data[++index] == 'l') - && (data[++index] == 'e') && (data[++index] == 'a') - && (data[++index] == 'n')) { + } + break; + case 7: + // boolean integer + if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l') + && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'n')) { + found = true; + tempToken = TokenNameboolCAST; + } else { + index = 0; + if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') + && (data[++index] == 'g') && (data[++index] == 'e') && (data[++index] == 'r')) { found = true; - tempToken = TokenNameboolCAST; - } else { - index = 0; - if ((data[index] == 'i') && (data[++index] == 'n') - && (data[++index] == 't') && (data[++index] == 'e') - && (data[++index] == 'g') && (data[++index] == 'e') - && (data[++index] == 'r')) { - found = true; - tempToken = TokenNameintCAST; - } + tempToken = TokenNameintCAST; } - break; + } + break; } if (found) { while (currentCharacter == ' ' || currentCharacter == '\t') { @@ -804,6 +851,7 @@ public class Scanner implements IScanner, ITerminalSymbols { currentPosition = tempPosition; return TokenNameLPAREN; } + public void consumeStringInterpolated() throws InvalidInputException { try { // consume next character @@ -845,15 +893,13 @@ public class Scanner implements IScanner, ITerminalSymbols { escapeSize = currentPosition - escapeSize; if (withoutUnicodePtr == 0) { //buffer all the entries that have been left aside.... - withoutUnicodePtr = currentPosition - escapeSize - 1 - - startPosition; - System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, - withoutUnicodePtr); + withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition; + System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr); withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } else { //overwrite the / in the buffer withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter; if (backSlashAsUnicodeInString) { //there are TWO \ in the stream - // where only one is correct + // where only one is correct withoutUnicodePtr--; } } @@ -871,8 +917,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // } } } catch (IndexOutOfBoundsException e) { -// reset end position for error reporting - currentPosition-=2; + // reset end position for error reporting + currentPosition -= 2; throw new InvalidInputException(UNTERMINATED_STRING); } catch (InvalidInputException e) { if (e.getMessage().equals(INVALID_ESCAPE)) { @@ -892,16 +938,16 @@ public class Scanner implements IScanner, ITerminalSymbols { throw e; // rethrow } if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags - // //$NON-NLS-?$ where ? is an - // int. + // //$NON-NLS-?$ where ? is an + // int. if (currentLine == null) { currentLine = new NLSLine(); lines.add(currentLine); } - currentLine.add(new StringLiteral(getCurrentTokenSourceString(), - startPosition, currentPosition - 1)); + currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1)); } } + public void consumeStringConstant() throws InvalidInputException { try { // consume next character @@ -943,15 +989,13 @@ public class Scanner implements IScanner, ITerminalSymbols { escapeSize = currentPosition - escapeSize; if (withoutUnicodePtr == 0) { //buffer all the entries that have been left aside.... - withoutUnicodePtr = currentPosition - escapeSize - 1 - - startPosition; - System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, - withoutUnicodePtr); + withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition; + System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr); withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } else { //overwrite the / in the buffer withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter; if (backSlashAsUnicodeInString) { //there are TWO \ in the stream - // where only one is correct + // where only one is correct withoutUnicodePtr--; } } @@ -970,7 +1014,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } } catch (IndexOutOfBoundsException e) { // reset end position for error reporting - currentPosition-=2; + currentPosition -= 2; throw new InvalidInputException(UNTERMINATED_STRING); } catch (InvalidInputException e) { if (e.getMessage().equals(INVALID_ESCAPE)) { @@ -990,16 +1034,16 @@ public class Scanner implements IScanner, ITerminalSymbols { throw e; // rethrow } if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags - // //$NON-NLS-?$ where ? is an - // int. + // //$NON-NLS-?$ where ? is an + // int. if (currentLine == null) { currentLine = new NLSLine(); lines.add(currentLine); } - currentLine.add(new StringLiteral(getCurrentTokenSourceString(), - startPosition, currentPosition - 1)); + currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1)); } } + public void consumeStringLiteral() throws InvalidInputException { try { // consume next character @@ -1041,15 +1085,13 @@ public class Scanner implements IScanner, ITerminalSymbols { escapeSize = currentPosition - escapeSize; if (withoutUnicodePtr == 0) { //buffer all the entries that have been left aside.... - withoutUnicodePtr = currentPosition - escapeSize - 1 - - startPosition; - System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, - withoutUnicodePtr); + withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition; + System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr); withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } else { //overwrite the / in the buffer withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter; if (backSlashAsUnicodeInString) { //there are TWO \ in the stream - // where only one is correct + // where only one is correct withoutUnicodePtr--; } } @@ -1067,8 +1109,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // } } } catch (IndexOutOfBoundsException e) { -// reset end position for error reporting - currentPosition-=2; + // reset end position for error reporting + currentPosition -= 2; throw new InvalidInputException(UNTERMINATED_STRING); } catch (InvalidInputException e) { if (e.getMessage().equals(INVALID_ESCAPE)) { @@ -1088,16 +1130,16 @@ public class Scanner implements IScanner, ITerminalSymbols { throw e; // rethrow } if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags - // //$NON-NLS-?$ where ? is an - // int. + // //$NON-NLS-?$ where ? is an + // int. if (currentLine == null) { currentLine = new NLSLine(); lines.add(currentLine); } - currentLine.add(new StringLiteral(getCurrentTokenSourceString(), - startPosition, currentPosition - 1)); + currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1)); } } + public int getNextToken() throws InvalidInputException { if (!phpMode) { return getInlinedHTML(currentPosition); @@ -1121,52 +1163,49 @@ public class Scanner implements IScanner, ITerminalSymbols { currentCharacter = source[currentPosition++]; if (currentCharacter == encapsedChar) { switch (currentCharacter) { - case '`' : - return TokenNameEncapsedString0; - case '\'' : - return TokenNameEncapsedString1; - case '"' : - return TokenNameEncapsedString2; + case '`': + return TokenNameEncapsedString0; + case '\'': + return TokenNameEncapsedString1; + case '"': + return TokenNameEncapsedString2; } } while (currentCharacter != encapsedChar) { /** ** in PHP \r and \n are valid in string literals *** */ switch (currentCharacter) { - case '\\' : - int escapeSize = currentPosition; - boolean backSlashAsUnicodeInString = unicodeAsBackSlash; - //scanEscapeCharacter make a side effect on this value and - // we need the previous value few lines down this one - scanDoubleQuotedEscapeCharacter(); - escapeSize = currentPosition - escapeSize; - if (withoutUnicodePtr == 0) { - //buffer all the entries that have been left aside.... - withoutUnicodePtr = currentPosition - escapeSize - 1 - - startPosition; - System.arraycopy(source, startPosition, - withoutUnicodeBuffer, 1, withoutUnicodePtr); - withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; - } else { //overwrite the / in the buffer - withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter; - if (backSlashAsUnicodeInString) { //there are TWO \ in - withoutUnicodePtr--; - } - } - break; - case '$' : - if (isPHPIdentifierStart(source[currentPosition]) - || source[currentPosition] == '{') { - currentPosition--; - encapsedStringStack.push(new Character('$')); - return TokenNameSTRING; - } - break; - case '{' : - if (source[currentPosition] == '$') { // CURLY_OPEN - currentPosition--; - encapsedStringStack.push(new Character('$')); - return TokenNameSTRING; + case '\\': + int escapeSize = currentPosition; + boolean backSlashAsUnicodeInString = unicodeAsBackSlash; + //scanEscapeCharacter make a side effect on this value and + // we need the previous value few lines down this one + scanDoubleQuotedEscapeCharacter(); + escapeSize = currentPosition - escapeSize; + if (withoutUnicodePtr == 0) { + //buffer all the entries that have been left aside.... + withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition; + System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr); + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } else { //overwrite the / in the buffer + withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter; + if (backSlashAsUnicodeInString) { //there are TWO \ in + withoutUnicodePtr--; } + } + break; + case '$': + if (isPHPIdentifierStart(source[currentPosition]) || source[currentPosition] == '{') { + currentPosition--; + encapsedStringStack.push(new Character('$')); + return TokenNameSTRING; + } + break; + case '{': + if (source[currentPosition] == '$') { // CURLY_OPEN + currentPosition--; + encapsedStringStack.push(new Character('$')); + return TokenNameSTRING; + } } // consume next character unicodeAsBackSlash = false; @@ -1185,69 +1224,68 @@ public class Scanner implements IScanner, ITerminalSymbols { currentCharacter = source[currentPosition++]; if (encapsedChar == '$') { switch (currentCharacter) { - case '\\' : - currentCharacter = source[currentPosition++]; - return TokenNameSTRING; - case '{' : - if (encapsedChar == '$') { - if (getNextChar('$')) - return TokenNameLBRACE_DOLLAR; - } - return TokenNameLBRACE; - case '}' : - return TokenNameRBRACE; - case '[' : - return TokenNameLBRACKET; - case ']' : - return TokenNameRBRACKET; - case '\'' : - if (tokenizeStrings) { - consumeStringConstant(); - return TokenNameStringSingleQuote; - } - return TokenNameEncapsedString1; - case '"' : - return TokenNameEncapsedString2; - case '`' : - if (tokenizeStrings) { - consumeStringInterpolated(); - return TokenNameStringInterpolated; - } - return TokenNameEncapsedString0; - case '-' : - if (getNextChar('>')) - return TokenNameMINUS_GREATER; - return TokenNameSTRING; - default : - if (currentCharacter == '$') { - int oldPosition = currentPosition; - try { - currentCharacter = source[currentPosition++]; - if (currentCharacter == '{') { - return TokenNameDOLLAR_LBRACE; - } - if (isPHPIdentifierStart(currentCharacter)) { - return scanIdentifierOrKeyword(true); - } else { - currentPosition = oldPosition; - return TokenNameSTRING; - } - } catch (IndexOutOfBoundsException e) { + case '\\': + currentCharacter = source[currentPosition++]; + return TokenNameSTRING; + case '{': + if (encapsedChar == '$') { + if (getNextChar('$')) + return TokenNameLBRACE_DOLLAR; + } + return TokenNameLBRACE; + case '}': + return TokenNameRBRACE; + case '[': + return TokenNameLBRACKET; + case ']': + return TokenNameRBRACKET; + case '\'': + if (tokenizeStrings) { + consumeStringConstant(); + return TokenNameStringSingleQuote; + } + return TokenNameEncapsedString1; + case '"': + return TokenNameEncapsedString2; + case '`': + if (tokenizeStrings) { + consumeStringInterpolated(); + return TokenNameStringInterpolated; + } + return TokenNameEncapsedString0; + case '-': + if (getNextChar('>')) + return TokenNameMINUS_GREATER; + return TokenNameSTRING; + default: + if (currentCharacter == '$') { + int oldPosition = currentPosition; + try { + currentCharacter = source[currentPosition++]; + if (currentCharacter == '{') { + return TokenNameDOLLAR_LBRACE; + } + if (isPHPIdentifierStart(currentCharacter)) { + return scanIdentifierOrKeyword(true); + } else { currentPosition = oldPosition; return TokenNameSTRING; } + } catch (IndexOutOfBoundsException e) { + currentPosition = oldPosition; + return TokenNameSTRING; } - if (isPHPIdentifierStart(currentCharacter)) - return scanIdentifierOrKeyword(false); - if (Character.isDigit(currentCharacter)) - return scanNumber(false); - return TokenNameERROR; + } + if (isPHPIdentifierStart(currentCharacter)) + return scanIdentifierOrKeyword(false); + if (Character.isDigit(currentCharacter)) + return scanNumber(false); + return TokenNameERROR; } } // boolean isWhiteSpace; - - while ((currentCharacter == ' ') - || Character.isWhitespace(currentCharacter)) { + + while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) { startPosition = currentPosition; currentCharacter = source[currentPosition++]; // if (((currentCharacter = source[currentPosition++]) == '\\') @@ -1277,374 +1315,394 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameEOF; // ---------Identify the next token------------- switch (currentCharacter) { - case '(' : - return getCastOrParen(); - case ')' : - return TokenNameRPAREN; - case '{' : - return TokenNameLBRACE; - case '}' : - return TokenNameRBRACE; - case '[' : - return TokenNameLBRACKET; - case ']' : - return TokenNameRBRACKET; - case ';' : - return TokenNameSEMICOLON; - case ',' : - return TokenNameCOMMA; - case '.' : - if (getNextChar('=')) - return TokenNameDOT_EQUAL; - if (getNextCharAsDigit()) - return scanNumber(true); - return TokenNameDOT; - case '+' : - { - int test; - if ((test = getNextChar('+', '=')) == 0) - return TokenNamePLUS_PLUS; - if (test > 0) - return TokenNamePLUS_EQUAL; - return TokenNamePLUS; - } - case '-' : - { - int test; - if ((test = getNextChar('-', '=')) == 0) - return TokenNameMINUS_MINUS; - if (test > 0) - return TokenNameMINUS_EQUAL; - if (getNextChar('>')) - return TokenNameMINUS_GREATER; - return TokenNameMINUS; - } - case '~' : - if (getNextChar('=')) - return TokenNameTWIDDLE_EQUAL; - return TokenNameTWIDDLE; - case '!' : + case '(': + return getCastOrParen(); + case ')': + return TokenNameRPAREN; + case '{': + return TokenNameLBRACE; + case '}': + return TokenNameRBRACE; + case '[': + return TokenNameLBRACKET; + case ']': + return TokenNameRBRACKET; + case ';': + return TokenNameSEMICOLON; + case ',': + return TokenNameCOMMA; + case '.': + if (getNextChar('=')) + return TokenNameDOT_EQUAL; + if (getNextCharAsDigit()) + return scanNumber(true); + return TokenNameDOT; + case '+': { + int test; + if ((test = getNextChar('+', '=')) == 0) + return TokenNamePLUS_PLUS; + if (test > 0) + return TokenNamePLUS_EQUAL; + return TokenNamePLUS; + } + case '-': { + int test; + if ((test = getNextChar('-', '=')) == 0) + return TokenNameMINUS_MINUS; + if (test > 0) + return TokenNameMINUS_EQUAL; + if (getNextChar('>')) + return TokenNameMINUS_GREATER; + return TokenNameMINUS; + } + case '~': + if (getNextChar('=')) + return TokenNameTWIDDLE_EQUAL; + return TokenNameTWIDDLE; + case '!': + if (getNextChar('=')) { if (getNextChar('=')) { - if (getNextChar('=')) { - return TokenNameNOT_EQUAL_EQUAL; - } - return TokenNameNOT_EQUAL; + return TokenNameNOT_EQUAL_EQUAL; } - return TokenNameNOT; - case '*' : - if (getNextChar('=')) - return TokenNameMULTIPLY_EQUAL; - return TokenNameMULTIPLY; - case '%' : + return TokenNameNOT_EQUAL; + } + return TokenNameNOT; + case '*': + if (getNextChar('=')) + return TokenNameMULTIPLY_EQUAL; + return TokenNameMULTIPLY; + case '%': + if (getNextChar('=')) + return TokenNameREMAINDER_EQUAL; + return TokenNameREMAINDER; + case '<': { + int oldPosition = currentPosition; + try { + currentCharacter = source[currentPosition++]; + } catch (IndexOutOfBoundsException e) { + currentPosition = oldPosition; + return TokenNameLESS; + } + switch (currentCharacter) { + case '=': + return TokenNameLESS_EQUAL; + case '>': + return TokenNameNOT_EQUAL; + case '<': if (getNextChar('=')) - return TokenNameREMAINDER_EQUAL; - return TokenNameREMAINDER; - case '<' : - { - int oldPosition = currentPosition; - try { + return TokenNameLEFT_SHIFT_EQUAL; + if (getNextChar('<')) { + currentCharacter = source[currentPosition++]; + while (Character.isWhitespace(currentCharacter)) { currentCharacter = source[currentPosition++]; - } catch (IndexOutOfBoundsException e) { - currentPosition = oldPosition; - return TokenNameLESS; } - switch (currentCharacter) { - case '=' : - return TokenNameLESS_EQUAL; - case '>' : - return TokenNameNOT_EQUAL; - case '<' : - if (getNextChar('=')) - return TokenNameLEFT_SHIFT_EQUAL; - if (getNextChar('<')) { - currentCharacter = source[currentPosition++]; - while (Character.isWhitespace(currentCharacter)) { - currentCharacter = source[currentPosition++]; - } - int heredocStart = currentPosition - 1; - int heredocLength = 0; - if (isPHPIdentifierStart(currentCharacter)) { - currentCharacter = source[currentPosition++]; - } else { - return TokenNameERROR; - } - while (isPHPIdentifierPart(currentCharacter)) { - currentCharacter = source[currentPosition++]; - } - heredocLength = currentPosition - heredocStart - 1; - // heredoc end-tag determination - boolean endTag = true; - char ch; - do { - ch = source[currentPosition++]; - if (ch == '\r' || ch == '\n') { - if (recordLineSeparator) { - pushLineSeparator(); - } else { - currentLine = null; - } - for (int i = 0; i < heredocLength; i++) { - if (source[currentPosition + i] != source[heredocStart - + i]) { - endTag = false; - break; - } - } - if (endTag) { - currentPosition += heredocLength - 1; - currentCharacter = source[currentPosition++]; - break; // do...while loop - } else { - endTag = true; - } - } - } while (true); - return TokenNameHEREDOC; - } - return TokenNameLEFT_SHIFT; + int heredocStart = currentPosition - 1; + int heredocLength = 0; + if (isPHPIdentifierStart(currentCharacter)) { + currentCharacter = source[currentPosition++]; + } else { + return TokenNameERROR; } - currentPosition = oldPosition; - return TokenNameLESS; - } - case '>' : - { - int test; - if ((test = getNextChar('=', '>')) == 0) - return TokenNameGREATER_EQUAL; - if (test > 0) { - if ((test = getNextChar('=', '>')) == 0) - return TokenNameRIGHT_SHIFT_EQUAL; - return TokenNameRIGHT_SHIFT; + while (isPHPIdentifierPart(currentCharacter)) { + currentCharacter = source[currentPosition++]; } - return TokenNameGREATER; + heredocLength = currentPosition - heredocStart - 1; + // heredoc end-tag determination + boolean endTag = true; + char ch; + do { + ch = source[currentPosition++]; + if (ch == '\r' || ch == '\n') { + if (recordLineSeparator) { + pushLineSeparator(); + } else { + currentLine = null; + } + for (int i = 0; i < heredocLength; i++) { + if (source[currentPosition + i] != source[heredocStart + i]) { + endTag = false; + break; + } + } + if (endTag) { + currentPosition += heredocLength - 1; + currentCharacter = source[currentPosition++]; + break; // do...while loop + } else { + endTag = true; + } + } + } while (true); + return TokenNameHEREDOC; } - case '=' : + return TokenNameLEFT_SHIFT; + } + currentPosition = oldPosition; + return TokenNameLESS; + } + case '>': { + int test; + if ((test = getNextChar('=', '>')) == 0) + return TokenNameGREATER_EQUAL; + if (test > 0) { + if ((test = getNextChar('=', '>')) == 0) + return TokenNameRIGHT_SHIFT_EQUAL; + return TokenNameRIGHT_SHIFT; + } + return TokenNameGREATER; + } + case '=': + if (getNextChar('=')) { if (getNextChar('=')) { - if (getNextChar('=')) { - return TokenNameEQUAL_EQUAL_EQUAL; - } - return TokenNameEQUAL_EQUAL; - } - if (getNextChar('>')) - return TokenNameEQUAL_GREATER; - return TokenNameEQUAL; - case '&' : - { - int test; - if ((test = getNextChar('&', '=')) == 0) - return TokenNameAND_AND; - if (test > 0) - return TokenNameAND_EQUAL; - return TokenNameAND; + return TokenNameEQUAL_EQUAL_EQUAL; } - case '|' : - { - int test; - if ((test = getNextChar('|', '=')) == 0) - return TokenNameOR_OR; - if (test > 0) - return TokenNameOR_EQUAL; - return TokenNameOR; + return TokenNameEQUAL_EQUAL; + } + if (getNextChar('>')) + return TokenNameEQUAL_GREATER; + return TokenNameEQUAL; + case '&': { + int test; + if ((test = getNextChar('&', '=')) == 0) + return TokenNameAND_AND; + if (test > 0) + return TokenNameAND_EQUAL; + return TokenNameAND; + } + case '|': { + int test; + if ((test = getNextChar('|', '=')) == 0) + return TokenNameOR_OR; + if (test > 0) + return TokenNameOR_EQUAL; + return TokenNameOR; + } + case '^': + if (getNextChar('=')) + return TokenNameXOR_EQUAL; + return TokenNameXOR; + case '?': + if (getNextChar('>')) { + phpMode = false; + if (currentPosition == source.length) { + phpMode = true; + return TokenNameINLINE_HTML; } - case '^' : - if (getNextChar('=')) - return TokenNameXOR_EQUAL; - return TokenNameXOR; - case '?' : - if (getNextChar('>')) { - phpMode = false; - if (currentPosition == source.length) { - phpMode = true; - return TokenNameINLINE_HTML; + return getInlinedHTML(currentPosition - 2); + } + return TokenNameQUESTION; + case ':': + if (getNextChar(':')) + return TokenNamePAAMAYIM_NEKUDOTAYIM; + return TokenNameCOLON; + case '@': + return TokenNameAT; + case '\'': + consumeStringConstant(); + return TokenNameStringSingleQuote; + case '"': + if (tokenizeStrings) { + consumeStringLiteral(); + return TokenNameStringDoubleQuote; + } + return TokenNameEncapsedString2; + case '`': + if (tokenizeStrings) { + consumeStringInterpolated(); + return TokenNameStringInterpolated; + } + return TokenNameEncapsedString0; + case '#': + case '/': { + char startChar = currentCharacter; + if (getNextChar('=')) { + return TokenNameDIVIDE_EQUAL; + } + int test; + if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) { + //line comment + this.lastCommentLinePosition = this.currentPosition; + int endPositionForLineComment = 0; + try { //get the next char + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // throw new + // InvalidInputException(INVALID_UNICODE_ESCAPE); + // } else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } + //handle the \\u case manually into comment + // if (currentCharacter == '\\') { + // if (source[currentPosition] == '\\') + // currentPosition++; + // } //jump over the \\ + boolean isUnicode = false; + while (currentCharacter != '\r' && currentCharacter != '\n') { + this.lastCommentLinePosition = this.currentPosition; + if (currentCharacter == '?') { + if (getNextChar('>')) { + startPosition = currentPosition - 2; + phpMode = false; + return TokenNameINLINE_HTML; + } + } + //get the next char + isUnicode = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // isUnicode = true; + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue( + // source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue( + // source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue( + // source[currentPosition++])) + // > 15 + // || c4 < 0) { + // throw new + // InvalidInputException(INVALID_UNICODE_ESCAPE); + // } else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } + //handle the \\u case manually into comment + // if (currentCharacter == '\\') { + // if (source[currentPosition] == '\\') + // currentPosition++; + // } //jump over the \\ } - return getInlinedHTML(currentPosition - 2); - } - return TokenNameQUESTION; - case ':' : - if (getNextChar(':')) - return TokenNamePAAMAYIM_NEKUDOTAYIM; - return TokenNameCOLON; - case '@' : - return TokenNameAT; - case '\'' : - consumeStringConstant(); - return TokenNameStringSingleQuote; - case '"' : - if (tokenizeStrings) { - consumeStringLiteral(); - return TokenNameStringDoubleQuote; - } - return TokenNameEncapsedString2; - case '`' : - if (tokenizeStrings) { - consumeStringInterpolated(); - return TokenNameStringInterpolated; - } - return TokenNameEncapsedString0; - case '#' : - case '/' : - { - char startChar = currentCharacter; - if (getNextChar('=')) { - return TokenNameDIVIDE_EQUAL; + if (isUnicode) { + endPositionForLineComment = currentPosition - 6; + } else { + endPositionForLineComment = currentPosition - 1; } - int test; - if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) { - //line comment - this.lastCommentLinePosition = this.currentPosition; - int endPositionForLineComment = 0; - try { //get the next char - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) - // == '\\') - // && (source[currentPosition] == 'u')) { - // //-------------unicode traitement ------------ - // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; - // currentPosition++; - // while (source[currentPosition] == 'u') { - // currentPosition++; - // } - // if ((c1 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c1 < 0 - // || (c2 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c2 < 0 - // || (c3 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c3 < 0 - // || (c4 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c4 < 0) { - // throw new - // InvalidInputException(INVALID_UNICODE_ESCAPE); - // } else { - // currentCharacter = - // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); - // } - // } - //handle the \\u case manually into comment - // if (currentCharacter == '\\') { - // if (source[currentPosition] == '\\') - // currentPosition++; - // } //jump over the \\ - boolean isUnicode = false; - while (currentCharacter != '\r' && currentCharacter != '\n') { - this.lastCommentLinePosition = this.currentPosition; - if (currentCharacter == '?') { - if (getNextChar('>')) { - startPosition = currentPosition - 2; - phpMode = false; - return TokenNameINLINE_HTML; - } - } - //get the next char - isUnicode = false; - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) - // == '\\') - // && (source[currentPosition] == 'u')) { - // isUnicode = true; - // //-------------unicode traitement ------------ - // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; - // currentPosition++; - // while (source[currentPosition] == 'u') { - // currentPosition++; - // } - // if ((c1 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c1 < 0 - // || (c2 = - // Character.getNumericValue( - // source[currentPosition++])) - // > 15 - // || c2 < 0 - // || (c3 = - // Character.getNumericValue( - // source[currentPosition++])) - // > 15 - // || c3 < 0 - // || (c4 = - // Character.getNumericValue( - // source[currentPosition++])) - // > 15 - // || c4 < 0) { - // throw new - // InvalidInputException(INVALID_UNICODE_ESCAPE); - // } else { - // currentCharacter = - // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); - // } - // } - //handle the \\u case manually into comment - // if (currentCharacter == '\\') { - // if (source[currentPosition] == '\\') - // currentPosition++; - // } //jump over the \\ - } + // recordComment(false); + recordComment(TokenNameCOMMENT_LINE); + if (this.taskTags != null) + checkTaskTag(this.startPosition, this.currentPosition); + if ((currentCharacter == '\r') || (currentCharacter == '\n')) { + checkNonExternalizeString(); + if (recordLineSeparator) { if (isUnicode) { - endPositionForLineComment = currentPosition - 6; + pushUnicodeLineSeparator(); } else { - endPositionForLineComment = currentPosition - 1; - } -// recordComment(false); - recordComment(TokenNameCOMMENT_LINE); - if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition); - if ((currentCharacter == '\r') - || (currentCharacter == '\n')) { - checkNonExternalizeString(); - if (recordLineSeparator) { - if (isUnicode) { - pushUnicodeLineSeparator(); - } else { - pushLineSeparator(); - } - } else { - currentLine = null; - } - } - if (tokenizeComments) { - if (!isUnicode) { - currentPosition = endPositionForLineComment; - // reset one character behind - } - return TokenNameCOMMENT_LINE; - } - } catch (IndexOutOfBoundsException e) { //an eof will them - // be generated - if (tokenizeComments) { - currentPosition--; - // reset one character behind - return TokenNameCOMMENT_LINE; + pushLineSeparator(); } + } else { + currentLine = null; } - break; } - if (test > 0) { - //traditional and annotation comment - boolean isJavadoc = false, star = false; - // consume next character - unicodeAsBackSlash = false; - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == - // '\\') - // && (source[currentPosition] == 'u')) { - // getNextUnicodeChar(); - // } else { - // if (withoutUnicodePtr != 0) { - // withoutUnicodeBuffer[++withoutUnicodePtr] = - // currentCharacter; - // } - // } - if (currentCharacter == '*') { - isJavadoc = true; - star = true; + if (tokenizeComments) { + if (!isUnicode) { + currentPosition = endPositionForLineComment; + // reset one character behind } + return TokenNameCOMMENT_LINE; + } + } catch (IndexOutOfBoundsException e) { //an eof will them + // be generated + if (tokenizeComments) { + currentPosition--; + // reset one character behind + return TokenNameCOMMENT_LINE; + } + } + break; + } + if (test > 0) { + //traditional and annotation comment + boolean isJavadoc = false, star = false; + // consume next character + unicodeAsBackSlash = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == + // '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = + // currentCharacter; + // } + // } + if (currentCharacter == '*') { + isJavadoc = true; + star = true; + } + if ((currentCharacter == '\r') || (currentCharacter == '\n')) { + checkNonExternalizeString(); + if (recordLineSeparator) { + pushLineSeparator(); + } else { + currentLine = null; + } + } + try { //get the next char + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // getNextUnicodeChar(); + // } + //handle the \\u case manually into comment + // if (currentCharacter == '\\') { + // if (source[currentPosition] == '\\') + // currentPosition++; + // //jump over the \\ + // } + // empty comment is not a javadoc /**/ + if (currentCharacter == '/') { + isJavadoc = false; + } + //loop until end of comment */ + while ((currentCharacter != '/') || (!star)) { if ((currentCharacter == '\r') || (currentCharacter == '\n')) { checkNonExternalizeString(); if (recordLineSeparator) { @@ -1653,98 +1711,69 @@ public class Scanner implements IScanner, ITerminalSymbols { currentLine = null; } } - try { //get the next char - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) - // == '\\') - // && (source[currentPosition] == 'u')) { - // //-------------unicode traitement ------------ - // getNextUnicodeChar(); - // } - //handle the \\u case manually into comment - // if (currentCharacter == '\\') { - // if (source[currentPosition] == '\\') - // currentPosition++; - // //jump over the \\ - // } - // empty comment is not a javadoc /**/ - if (currentCharacter == '/') { - isJavadoc = false; - } - //loop until end of comment */ - while ((currentCharacter != '/') || (!star)) { - if ((currentCharacter == '\r') - || (currentCharacter == '\n')) { - checkNonExternalizeString(); - if (recordLineSeparator) { - pushLineSeparator(); - } else { - currentLine = null; - } - } - star = currentCharacter == '*'; - //get next char - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) - // == '\\') - // && (source[currentPosition] == 'u')) { - // //-------------unicode traitement ------------ - // getNextUnicodeChar(); - // } - //handle the \\u case manually into comment - // if (currentCharacter == '\\') { - // if (source[currentPosition] == '\\') - // currentPosition++; - // } //jump over the \\ - } - //recordComment(isJavadoc); - if (isJavadoc) { - recordComment(TokenNameCOMMENT_PHPDOC); - } else { - recordComment(TokenNameCOMMENT_BLOCK); - } - - if (tokenizeComments) { - if (isJavadoc) - return TokenNameCOMMENT_PHPDOC; - return TokenNameCOMMENT_BLOCK; - } - } catch (IndexOutOfBoundsException e) { -// reset end position for error reporting - currentPosition-=2; - throw new InvalidInputException(UNTERMINATED_COMMENT); - } - break; + star = currentCharacter == '*'; + //get next char + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // getNextUnicodeChar(); + // } + //handle the \\u case manually into comment + // if (currentCharacter == '\\') { + // if (source[currentPosition] == '\\') + // currentPosition++; + // } //jump over the \\ + } + //recordComment(isJavadoc); + if (isJavadoc) { + recordComment(TokenNameCOMMENT_PHPDOC); + } else { + recordComment(TokenNameCOMMENT_BLOCK); } - return TokenNameDIVIDE; + + if (tokenizeComments) { + if (isJavadoc) + return TokenNameCOMMENT_PHPDOC; + return TokenNameCOMMENT_BLOCK; + } + } catch (IndexOutOfBoundsException e) { + // reset end position for error reporting + currentPosition -= 2; + throw new InvalidInputException(UNTERMINATED_COMMENT); } - case '\u001a' : - if (atEnd()) - return TokenNameEOF; - //the atEnd may not be if - // source is only some part of a real (external) stream - throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$ - default : - if (currentCharacter == '$') { - int oldPosition = currentPosition; - try { - currentCharacter = source[currentPosition++]; - if (isPHPIdentifierStart(currentCharacter)) { - return scanIdentifierOrKeyword(true); - } else { - currentPosition = oldPosition; - return TokenNameDOLLAR; - } - } catch (IndexOutOfBoundsException e) { + break; + } + return TokenNameDIVIDE; + } + case '\u001a': + if (atEnd()) + return TokenNameEOF; + //the atEnd may not be if + // source is only some part of a real (external) stream + throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$ + default: + if (currentCharacter == '$') { + int oldPosition = currentPosition; + try { + currentCharacter = source[currentPosition++]; + if (isPHPIdentifierStart(currentCharacter)) { + return scanIdentifierOrKeyword(true); + } else { currentPosition = oldPosition; return TokenNameDOLLAR; } + } catch (IndexOutOfBoundsException e) { + currentPosition = oldPosition; + return TokenNameDOLLAR; } - if (isPHPIdentifierStart(currentCharacter)) - return scanIdentifierOrKeyword(false); - if (Character.isDigit(currentCharacter)) - return scanNumber(false); - return TokenNameERROR; + } + if (isPHPIdentifierStart(currentCharacter)) + return scanIdentifierOrKeyword(false); + if (Character.isDigit(currentCharacter)) + return scanNumber(false); + return TokenNameERROR; } } } //-----------------end switch while try-------------------- @@ -1753,42 +1782,43 @@ public class Scanner implements IScanner, ITerminalSymbols { } return TokenNameEOF; } - + private int getInlinedHTML(int start) throws InvalidInputException { - int token = getInlinedHTMLToken(start); - if (token == TokenNameINLINE_HTML) { -// Stack stack = new Stack(); -// // scan html for errors -// Source inlinedHTMLSource = new Source(new String(source, startPosition, currentPosition - startPosition)); -// int lastPHPEndPos=0; -// for (Iterator i=inlinedHTMLSource.getNextTagIterator(0); i.hasNext();) { -// Tag tag=(Tag)i.next(); -// -// if (tag instanceof StartTag) { -// StartTag startTag=(StartTag)tag; -// // System.out.println("startTag: "+tag); -// if (startTag.isServerTag()) { -// // TODO : what to do with a server tag ? -// } else { -// // do whatever with HTML start tag -// // use startTag.getElement() to find the element corresponding -// // to this start tag which may be useful if you implement code -// // folding etc -// stack.push(startTag); -// } -// } else { -// EndTag endTag=(EndTag)tag; -// StartTag stag = (StartTag) stack.peek(); -//// System.out.println("endTag: "+tag); -// // do whatever with HTML end tag. -// } -// } - } - return token; + int token = getInlinedHTMLToken(start); + if (token == TokenNameINLINE_HTML) { + // Stack stack = new Stack(); + // // scan html for errors + // Source inlinedHTMLSource = new Source(new String(source, startPosition, currentPosition - startPosition)); + // int lastPHPEndPos=0; + // for (Iterator i=inlinedHTMLSource.getNextTagIterator(0); i.hasNext();) { + // Tag tag=(Tag)i.next(); + // + // if (tag instanceof StartTag) { + // StartTag startTag=(StartTag)tag; + // // System.out.println("startTag: "+tag); + // if (startTag.isServerTag()) { + // // TODO : what to do with a server tag ? + // } else { + // // do whatever with HTML start tag + // // use startTag.getElement() to find the element corresponding + // // to this start tag which may be useful if you implement code + // // folding etc + // stack.push(startTag); + // } + // } else { + // EndTag endTag=(EndTag)tag; + // StartTag stag = (StartTag) stack.peek(); + //// System.out.println("endTag: "+tag); + // // do whatever with HTML end tag. + // } + // } + } + return token; } + /** - * @return @throws - * InvalidInputException + * @return + * @throws InvalidInputException */ private int getInlinedHTMLToken(int start) throws InvalidInputException { // int htmlPosition = start; @@ -1803,22 +1833,34 @@ public class Scanner implements IScanner, ITerminalSymbols { if (currentCharacter == '<') { if (getNextChar('?')) { currentCharacter = source[currentPosition++]; - if ((currentCharacter == ' ') - || Character.isWhitespace(currentCharacter)) { + if ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) { // = 0) { test = getNextChar('P', 'p'); if (test >= 0) { // ': + if (previousCharInLine == '?') { + // update the scanner's current Position in the source + currentPosition = currentPositionInLine; + // use as "dummy" token + return TokenNameEOF; + } + break; + case '\"': + if (doubleQuotedStringActive) { + if (previousCharInLine != '\\') { + doubleQuotedStringActive = false; + } + } else { + if (!singleQuotedStringActive) { + doubleQuotedStringActive = true; + } + } + break; + case '\'': + if (singleQuotedStringActive) { + if (previousCharInLine != '\\') { + singleQuotedStringActive = false; + } + } else { + if (!doubleQuotedStringActive) { + singleQuotedStringActive = true; + } + } + break; + case '\n': + phpMode = true; + return TokenNameINLINE_HTML; + case '#': + if (!singleQuotedStringActive && !doubleQuotedStringActive) { + phpMode = true; + return TokenNameINLINE_HTML; + } + break; + case '/': + if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) { + phpMode = true; + return TokenNameINLINE_HTML; + } + break; + case '*': + if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) { + phpMode = true; + return TokenNameINLINE_HTML; + } + break; + } + } + } catch (IndexOutOfBoundsException e) { + phpMode = true; + currentPosition = currentPositionInLine; + return TokenNameINLINE_HTML; + } + } + // public final void getNextUnicodeChar() // throws IndexOutOfBoundsException, InvalidInputException { // //VOID @@ -1889,8 +2009,7 @@ public class Scanner implements IScanner, ITerminalSymbols { // unicodeAsBackSlash = currentCharacter == '\\'; // } /* - * Tokenize a method body, assuming that curly brackets are properly - * balanced. + * Tokenize a method body, assuming that curly brackets are properly balanced. */ public final void jumpOverMethodBody() { this.wasAcr = false; @@ -1906,306 +2025,303 @@ public class Scanner implements IScanner, ITerminalSymbols { // && (source[currentPosition] == 'u')) { // isWhiteSpace = jumpOverUnicodeWhiteSpace(); // } else { - if (recordLineSeparator - && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) pushLineSeparator(); isWhiteSpace = Character.isWhitespace(currentCharacter); // } } while (isWhiteSpace); // -------consume token until } is found--------- switch (currentCharacter) { - case '{' : - found++; - break; - case '}' : - found--; - if (found == 0) - return; - break; - case '\'' : - { - boolean test; - test = getNextChar('\\'); - if (test) { + case '{': + found++; + break; + case '}': + found--; + if (found == 0) + return; + break; + case '\'': { + boolean test; + test = getNextChar('\\'); + if (test) { + try { + scanDoubleQuotedEscapeCharacter(); + } catch (InvalidInputException ex) { + } + ; + } else { + // try { // consume next character + unicodeAsBackSlash = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // } + // } catch (InvalidInputException ex) { + // }; + } + getNextChar('\''); + break; + } + case '"': + try { + // try { // consume next character + unicodeAsBackSlash = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // } + // } catch (InvalidInputException ex) { + // }; + while (currentCharacter != '"') { + if (currentCharacter == '\r') { + if (source[currentPosition] == '\n') + currentPosition++; + break; + // the string cannot go further that the line + } + if (currentCharacter == '\n') { + break; + // the string cannot go further that the line + } + if (currentCharacter == '\\') { try { scanDoubleQuotedEscapeCharacter(); } catch (InvalidInputException ex) { - }; - } else { - // try { // consume next character - unicodeAsBackSlash = false; - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') - // && (source[currentPosition] == 'u')) { - // getNextUnicodeChar(); - // } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } - // } - // } catch (InvalidInputException ex) { - // }; + ; } - getNextChar('\''); - break; - } - case '"' : - try { - // try { // consume next character + // try { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') - // && (source[currentPosition] == 'u')) { - // getNextUnicodeChar(); - // } else { + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { if (withoutUnicodePtr != 0) { withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } - // } - // } catch (InvalidInputException ex) { - // }; - while (currentCharacter != '"') { - if (currentCharacter == '\r') { - if (source[currentPosition] == '\n') - currentPosition++; - break; - // the string cannot go further that the line - } - if (currentCharacter == '\n') { - break; - // the string cannot go further that the line - } - if (currentCharacter == '\\') { - try { - scanDoubleQuotedEscapeCharacter(); - } catch (InvalidInputException ex) { - }; - } - // try { // consume next character - unicodeAsBackSlash = false; + // } + // } catch (InvalidInputException ex) { + // }; + } + } catch (IndexOutOfBoundsException e) { + return; + } + break; + case '/': { + int test; + if ((test = getNextChar('/', '*')) == 0) { + //line comment + try { + //get the next char + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == + // '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // //error don't care of the value + // currentCharacter = 'A'; + // } //something different from \n and \r + // else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } + while (currentCharacter != '\r' && currentCharacter != '\n') { + //get the next char currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') - // && (source[currentPosition] == 'u')) { - // getNextUnicodeChar(); - // } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; - } - // } - // } catch (InvalidInputException ex) { - // }; + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // //error don't care of the value + // currentCharacter = 'A'; + // } //something different from \n and \r + // else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } } + if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + pushLineSeparator(); } catch (IndexOutOfBoundsException e) { - return; - } + } //an eof will them be generated break; - case '/' : - { - int test; - if ((test = getNextChar('/', '*')) == 0) { - //line comment - try { - //get the next char - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == - // '\\') - // && (source[currentPosition] == 'u')) { - // //-------------unicode traitement ------------ - // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; - // currentPosition++; - // while (source[currentPosition] == 'u') { - // currentPosition++; - // } - // if ((c1 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c1 < 0 - // || (c2 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c2 < 0 - // || (c3 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c3 < 0 - // || (c4 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c4 < 0) { - // //error don't care of the value - // currentCharacter = 'A'; - // } //something different from \n and \r - // else { - // currentCharacter = - // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); - // } - // } - while (currentCharacter != '\r' && currentCharacter != '\n') { - //get the next char - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) - // == '\\') - // && (source[currentPosition] == 'u')) { - // //-------------unicode traitement ------------ - // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; - // currentPosition++; - // while (source[currentPosition] == 'u') { - // currentPosition++; - // } - // if ((c1 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c1 < 0 - // || (c2 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c2 < 0 - // || (c3 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c3 < 0 - // || (c4 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c4 < 0) { - // //error don't care of the value - // currentCharacter = 'A'; - // } //something different from \n and \r - // else { - // currentCharacter = - // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); - // } - // } - } - if (recordLineSeparator - && ((currentCharacter == '\r') || (currentCharacter == '\n'))) - pushLineSeparator(); - } catch (IndexOutOfBoundsException e) { - } //an eof will them be generated - break; - } - if (test > 0) { - //traditional and annotation comment - boolean star = false; - // try { // consume next character - unicodeAsBackSlash = false; - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') - // && (source[currentPosition] == 'u')) { - // getNextUnicodeChar(); - // } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; - } - // }; - // } catch (InvalidInputException ex) { - // }; - if (currentCharacter == '*') { - star = true; - } - if (recordLineSeparator - && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + } + if (test > 0) { + //traditional and annotation comment + boolean star = false; + // try { // consume next character + unicodeAsBackSlash = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // }; + // } catch (InvalidInputException ex) { + // }; + if (currentCharacter == '*') { + star = true; + } + if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + pushLineSeparator(); + try { //get the next char + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == + // '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // //error don't care of the value + // currentCharacter = 'A'; + // } //something different from * and / + // else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } + //loop until end of comment */ + while ((currentCharacter != '/') || (!star)) { + if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) pushLineSeparator(); - try { //get the next char - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == - // '\\') - // && (source[currentPosition] == 'u')) { - // //-------------unicode traitement ------------ - // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; - // currentPosition++; - // while (source[currentPosition] == 'u') { - // currentPosition++; - // } - // if ((c1 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c1 < 0 - // || (c2 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c2 < 0 - // || (c3 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c3 < 0 - // || (c4 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c4 < 0) { - // //error don't care of the value - // currentCharacter = 'A'; - // } //something different from * and / - // else { - // currentCharacter = - // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); - // } - // } - //loop until end of comment */ - while ((currentCharacter != '/') || (!star)) { - if (recordLineSeparator - && ((currentCharacter == '\r') || (currentCharacter == '\n'))) - pushLineSeparator(); - star = currentCharacter == '*'; - //get next char - currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) - // == '\\') - // && (source[currentPosition] == 'u')) { - // //-------------unicode traitement ------------ - // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; - // currentPosition++; - // while (source[currentPosition] == 'u') { - // currentPosition++; - // } - // if ((c1 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c1 < 0 - // || (c2 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c2 < 0 - // || (c3 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c3 < 0 - // || (c4 = - // Character.getNumericValue(source[currentPosition++])) - // > 15 - // || c4 < 0) { - // //error don't care of the value - // currentCharacter = 'A'; - // } //something different from * and / - // else { - // currentCharacter = - // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); - // } - // } - } - } catch (IndexOutOfBoundsException e) { - return; - } - break; + star = currentCharacter == '*'; + //get next char + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // //error don't care of the value + // currentCharacter = 'A'; + // } //something different from * and / + // else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } } - break; + } catch (IndexOutOfBoundsException e) { + return; } - default : - if (isPHPIdentifierStart(currentCharacter) - || currentCharacter == '$') { - try { - scanIdentifierOrKeyword((currentCharacter == '$')); - } catch (InvalidInputException ex) { - }; - break; + break; + } + break; + } + default: + if (isPHPIdentifierStart(currentCharacter) || currentCharacter == '$') { + try { + scanIdentifierOrKeyword((currentCharacter == '$')); + } catch (InvalidInputException ex) { } - if (Character.isDigit(currentCharacter)) { - try { - scanNumber(false); - } catch (InvalidInputException ex) { - }; - break; + ; + break; + } + if (Character.isDigit(currentCharacter)) { + try { + scanNumber(false); + } catch (InvalidInputException ex) { } + ; + break; + } } } //-----------------end switch while try-------------------- @@ -2214,6 +2330,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } return; } + // public final boolean jumpOverUnicodeWhiteSpace() // throws InvalidInputException { // //BOOLEAN @@ -2264,78 +2381,81 @@ public class Scanner implements IScanner, ITerminalSymbols { System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1); return copy; } + public char[] getSource() { return this.source; } + public static boolean isIdentifierOrKeyword(int token) { return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD); } + final char[] optimizedCurrentTokenSource1() { //return always the same char[] build only once //optimization at no speed cost of 99.5 % of the singleCharIdentifier char charOne = source[startPosition]; switch (charOne) { - case 'a' : - return charArray_a; - case 'b' : - return charArray_b; - case 'c' : - return charArray_c; - case 'd' : - return charArray_d; - case 'e' : - return charArray_e; - case 'f' : - return charArray_f; - case 'g' : - return charArray_g; - case 'h' : - return charArray_h; - case 'i' : - return charArray_i; - case 'j' : - return charArray_j; - case 'k' : - return charArray_k; - case 'l' : - return charArray_l; - case 'm' : - return charArray_m; - case 'n' : - return charArray_n; - case 'o' : - return charArray_o; - case 'p' : - return charArray_p; - case 'q' : - return charArray_q; - case 'r' : - return charArray_r; - case 's' : - return charArray_s; - case 't' : - return charArray_t; - case 'u' : - return charArray_u; - case 'v' : - return charArray_v; - case 'w' : - return charArray_w; - case 'x' : - return charArray_x; - case 'y' : - return charArray_y; - case 'z' : - return charArray_z; - default : - return new char[]{charOne}; + case 'a': + return charArray_a; + case 'b': + return charArray_b; + case 'c': + return charArray_c; + case 'd': + return charArray_d; + case 'e': + return charArray_e; + case 'f': + return charArray_f; + case 'g': + return charArray_g; + case 'h': + return charArray_h; + case 'i': + return charArray_i; + case 'j': + return charArray_j; + case 'k': + return charArray_k; + case 'l': + return charArray_l; + case 'm': + return charArray_m; + case 'n': + return charArray_n; + case 'o': + return charArray_o; + case 'p': + return charArray_p; + case 'q': + return charArray_q; + case 'r': + return charArray_r; + case 's': + return charArray_s; + case 't': + return charArray_t; + case 'u': + return charArray_u; + case 'v': + return charArray_v; + case 'w': + return charArray_w; + case 'x': + return charArray_x; + case 'y': + return charArray_y; + case 'z': + return charArray_z; + default: + return new char[] { charOne }; } } + final char[] optimizedCurrentTokenSource2() { //try to return the same char[] build only once char c0, c1; - int hash = (((c0 = source[startPosition]) << 6) + (c1 = source[startPosition + 1])) - % TableSize; + int hash = (((c0 = source[startPosition]) << 6) + (c1 = source[startPosition + 1])) % TableSize; char[][] table = charArray_length[0][hash]; int i = newEntry2; while (++i < InternalTableSize) { @@ -2355,15 +2475,15 @@ public class Scanner implements IScanner, ITerminalSymbols { if (++max >= InternalTableSize) max = 0; char[] r; - table[max] = (r = new char[]{c0, c1}); + table[max] = (r = new char[] { c0, c1 }); newEntry2 = max; return r; } + final char[] optimizedCurrentTokenSource3() { //try to return the same char[] build only once char c0, c1, c2; - int hash = (((c0 = source[startPosition]) << 12) - + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2])) + int hash = (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2])) % TableSize; char[][] table = charArray_length[1][hash]; int i = newEntry3; @@ -2384,23 +2504,22 @@ public class Scanner implements IScanner, ITerminalSymbols { if (++max >= InternalTableSize) max = 0; char[] r; - table[max] = (r = new char[]{c0, c1, c2}); + table[max] = (r = new char[] { c0, c1, c2 }); newEntry3 = max; return r; } + final char[] optimizedCurrentTokenSource4() { //try to return the same char[] build only once char c0, c1, c2, c3; - long hash = ((((long) (c0 = source[startPosition])) << 18) - + ((c1 = source[startPosition + 1]) << 12) + long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12) + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3])) % TableSize; char[][] table = charArray_length[2][(int) hash]; int i = newEntry4; while (++i < InternalTableSize) { char[] charArray = table[i]; - if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) - && (c3 == charArray[3])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3])) return charArray; } //---------other side--------- @@ -2408,32 +2527,29 @@ public class Scanner implements IScanner, ITerminalSymbols { int max = newEntry4; while (++i <= max) { char[] charArray = table[i]; - if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) - && (c3 == charArray[3])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3])) return charArray; } //--------add the entry------- if (++max >= InternalTableSize) max = 0; char[] r; - table[max] = (r = new char[]{c0, c1, c2, c3}); + table[max] = (r = new char[] { c0, c1, c2, c3 }); newEntry4 = max; return r; } + final char[] optimizedCurrentTokenSource5() { //try to return the same char[] build only once char c0, c1, c2, c3, c4; - long hash = ((((long) (c0 = source[startPosition])) << 24) - + (((long) (c1 = source[startPosition + 1])) << 18) - + ((c2 = source[startPosition + 2]) << 12) - + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4])) + long hash = ((((long) (c0 = source[startPosition])) << 24) + (((long) (c1 = source[startPosition + 1])) << 18) + + ((c2 = source[startPosition + 2]) << 12) + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4])) % TableSize; char[][] table = charArray_length[3][(int) hash]; int i = newEntry5; while (++i < InternalTableSize) { char[] charArray = table[i]; - if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) - && (c3 == charArray[3]) && (c4 == charArray[4])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])) return charArray; } //---------other side--------- @@ -2441,33 +2557,30 @@ public class Scanner implements IScanner, ITerminalSymbols { int max = newEntry5; while (++i <= max) { char[] charArray = table[i]; - if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) - && (c3 == charArray[3]) && (c4 == charArray[4])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])) return charArray; } //--------add the entry------- if (++max >= InternalTableSize) max = 0; char[] r; - table[max] = (r = new char[]{c0, c1, c2, c3, c4}); + table[max] = (r = new char[] { c0, c1, c2, c3, c4 }); newEntry5 = max; return r; } + final char[] optimizedCurrentTokenSource6() { //try to return the same char[] build only once char c0, c1, c2, c3, c4, c5; - long hash = ((((long) (c0 = source[startPosition])) << 32) - + (((long) (c1 = source[startPosition + 1])) << 24) - + (((long) (c2 = source[startPosition + 2])) << 18) - + ((c3 = source[startPosition + 3]) << 12) + long hash = ((((long) (c0 = source[startPosition])) << 32) + (((long) (c1 = source[startPosition + 1])) << 24) + + (((long) (c2 = source[startPosition + 2])) << 18) + ((c3 = source[startPosition + 3]) << 12) + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5])) % TableSize; char[][] table = charArray_length[4][(int) hash]; int i = newEntry6; while (++i < InternalTableSize) { char[] charArray = table[i]; - if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) - && (c3 == charArray[3]) && (c4 == charArray[4]) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]) && (c5 == charArray[5])) return charArray; } @@ -2476,8 +2589,7 @@ public class Scanner implements IScanner, ITerminalSymbols { int max = newEntry6; while (++i <= max) { char[] charArray = table[i]; - if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) - && (c3 == charArray[3]) && (c4 == charArray[4]) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]) && (c5 == charArray[5])) return charArray; } @@ -2485,10 +2597,11 @@ public class Scanner implements IScanner, ITerminalSymbols { if (++max >= InternalTableSize) max = 0; char[] r; - table[max] = (r = new char[]{c0, c1, c2, c3, c4, c5}); + table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 }); newEntry6 = max; return r; } + public final void pushLineSeparator() throws InvalidInputException { //see comment on isLineDelimiter(char) for the use of '\n' and '\r' final int INCREMENT = 250; @@ -2553,6 +2666,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } } } + public final void pushUnicodeLineSeparator() { // isUnicode means that the \r or \n has been read as a unicode character //see comment on isLineDelimiter(char) for the use of '\n' and '\r' @@ -2614,48 +2728,50 @@ public class Scanner implements IScanner, ITerminalSymbols { } } } + public void recordComment(int token) { - // compute position - int stopPosition = this.currentPosition; - switch (token) { - case TokenNameCOMMENT_LINE: - stopPosition = -this.lastCommentLinePosition; - break; - case TokenNameCOMMENT_BLOCK: - stopPosition = -this.currentPosition; - break; - } - - // a new comment is recorded - int length = this.commentStops.length; - if (++this.commentPtr >= length) { - System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length); - //grows the positions buffers too - System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length); - } - this.commentStops[this.commentPtr] = stopPosition; - this.commentStarts[this.commentPtr] = this.startPosition; -} -// public final void recordComment(boolean isJavadoc) { -// // a new annotation comment is recorded -// try { -// commentStops[++commentPtr] = isJavadoc -// ? currentPosition -// : -currentPosition; -// } catch (IndexOutOfBoundsException e) { -// int oldStackLength = commentStops.length; -// int[] oldStack = commentStops; -// commentStops = new int[oldStackLength + 30]; -// System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength); -// commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition; -// //grows the positions buffers too -// int[] old = commentStarts; -// commentStarts = new int[oldStackLength + 30]; -// System.arraycopy(old, 0, commentStarts, 0, oldStackLength); -// } -// //the buffer is of a correct size here -// commentStarts[commentPtr] = startPosition; -// } + // compute position + int stopPosition = this.currentPosition; + switch (token) { + case TokenNameCOMMENT_LINE: + stopPosition = -this.lastCommentLinePosition; + break; + case TokenNameCOMMENT_BLOCK: + stopPosition = -this.currentPosition; + break; + } + + // a new comment is recorded + int length = this.commentStops.length; + if (++this.commentPtr >= length) { + System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length); + //grows the positions buffers too + System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length); + } + this.commentStops[this.commentPtr] = stopPosition; + this.commentStarts[this.commentPtr] = this.startPosition; + } + + // public final void recordComment(boolean isJavadoc) { + // // a new annotation comment is recorded + // try { + // commentStops[++commentPtr] = isJavadoc + // ? currentPosition + // : -currentPosition; + // } catch (IndexOutOfBoundsException e) { + // int oldStackLength = commentStops.length; + // int[] oldStack = commentStops; + // commentStops = new int[oldStackLength + 30]; + // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength); + // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition; + // //grows the positions buffers too + // int[] old = commentStarts; + // commentStarts = new int[oldStackLength + 30]; + // System.arraycopy(old, 0, commentStarts, 0, oldStackLength); + // } + // //the buffer is of a correct size here + // commentStarts[commentPtr] = startPosition; + // } public void resetTo(int begin, int end) { //reset the scanner to a given position where it may rescan again diet = false; @@ -2663,8 +2779,8 @@ public class Scanner implements IScanner, ITerminalSymbols { eofPosition = end < Integer.MAX_VALUE ? end + 1 : end; commentPtr = -1; // reset comment stack } - public final void scanSingleQuotedEscapeCharacter() - throws InvalidInputException { + + public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException { // the string with "\\u" is a legal string of two chars \ and u //thus we use a direct access to the source (for regular cases). // if (unicodeAsBackSlash) { @@ -2681,19 +2797,19 @@ public class Scanner implements IScanner, ITerminalSymbols { // } else currentCharacter = source[currentPosition++]; switch (currentCharacter) { - case '\'' : - currentCharacter = '\''; - break; - case '\\' : - currentCharacter = '\\'; - break; - default : - currentCharacter = '\\'; - currentPosition--; + case '\'': + currentCharacter = '\''; + break; + case '\\': + currentCharacter = '\\'; + break; + default: + currentCharacter = '\\'; + currentPosition--; } } - public final void scanDoubleQuotedEscapeCharacter() - throws InvalidInputException { + + public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException { // the string with "\\u" is a legal string of two chars \ and u //thus we use a direct access to the source (for regular cases). // if (unicodeAsBackSlash) { @@ -2710,84 +2826,83 @@ public class Scanner implements IScanner, ITerminalSymbols { // } else currentCharacter = source[currentPosition++]; switch (currentCharacter) { - // case 'b' : - // currentCharacter = '\b'; - // break; - case 't' : - currentCharacter = '\t'; - break; - case 'n' : - currentCharacter = '\n'; - break; - // case 'f' : - // currentCharacter = '\f'; - // break; - case 'r' : - currentCharacter = '\r'; - break; - case '\"' : - currentCharacter = '\"'; - break; - case '\'' : - currentCharacter = '\''; - break; - case '\\' : - currentCharacter = '\\'; - break; - case '$' : - currentCharacter = '$'; - break; - default : - // -----------octal escape-------------- - // OctalDigit - // OctalDigit OctalDigit - // ZeroToThree OctalDigit OctalDigit - int number = Character.getNumericValue(currentCharacter); - if (number >= 0 && number <= 7) { - boolean zeroToThreeNot = number > 3; - if (Character.isDigit(currentCharacter = source[currentPosition++])) { - int digit = Character.getNumericValue(currentCharacter); - if (digit >= 0 && digit <= 7) { - number = (number * 8) + digit; - if (Character - .isDigit(currentCharacter = source[currentPosition++])) { - if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit - // Digit --> ignore last character + // case 'b' : + // currentCharacter = '\b'; + // break; + case 't': + currentCharacter = '\t'; + break; + case 'n': + currentCharacter = '\n'; + break; + // case 'f' : + // currentCharacter = '\f'; + // break; + case 'r': + currentCharacter = '\r'; + break; + case '\"': + currentCharacter = '\"'; + break; + case '\'': + currentCharacter = '\''; + break; + case '\\': + currentCharacter = '\\'; + break; + case '$': + currentCharacter = '$'; + break; + default: + // -----------octal escape-------------- + // OctalDigit + // OctalDigit OctalDigit + // ZeroToThree OctalDigit OctalDigit + int number = Character.getNumericValue(currentCharacter); + if (number >= 0 && number <= 7) { + boolean zeroToThreeNot = number > 3; + if (Character.isDigit(currentCharacter = source[currentPosition++])) { + int digit = Character.getNumericValue(currentCharacter); + if (digit >= 0 && digit <= 7) { + number = (number * 8) + digit; + if (Character.isDigit(currentCharacter = source[currentPosition++])) { + if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit + // Digit --> ignore last character + currentPosition--; + } else { + digit = Character.getNumericValue(currentCharacter); + if (digit >= 0 && digit <= 7) { + // has read \ZeroToThree OctalDigit OctalDigit + number = (number * 8) + digit; + } else { // has read \ZeroToThree OctalDigit NonOctalDigit + // --> ignore last character currentPosition--; - } else { - digit = Character.getNumericValue(currentCharacter); - if (digit >= 0 && digit <= 7) { - // has read \ZeroToThree OctalDigit OctalDigit - number = (number * 8) + digit; - } else { // has read \ZeroToThree OctalDigit NonOctalDigit - // --> ignore last character - currentPosition--; - } } - } else { // has read \OctalDigit NonDigit--> ignore last - // character - currentPosition--; } - } else { // has read \OctalDigit NonOctalDigit--> ignore last + } else { // has read \OctalDigit NonDigit--> ignore last // character currentPosition--; } - } else { // has read \OctalDigit --> ignore last character + } else { // has read \OctalDigit NonOctalDigit--> ignore last + // character currentPosition--; } - if (number > 255) - throw new InvalidInputException(INVALID_ESCAPE); - currentCharacter = (char) number; + } else { // has read \OctalDigit --> ignore last character + currentPosition--; } + if (number > 255) + throw new InvalidInputException(INVALID_ESCAPE); + currentCharacter = (char) number; + } //else // throw new InvalidInputException(INVALID_ESCAPE); } } + // public int scanIdentifierOrKeyword() throws InvalidInputException { // return scanIdentifierOrKeyword( false ); // } - public int scanIdentifierOrKeyword(boolean isVariable) - throws InvalidInputException { + public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException { //test keywords //first dispatch on the first char. //then the length. If there are several @@ -2795,7 +2910,8 @@ public class Scanner implements IScanner, ITerminalSymbols { //disptach on the second char :-)...cool....but fast ! useAssertAsAnIndentifier = false; while (getNextCharAsJavaIdentifierPart()) { - }; + } + ; if (isVariable) { // if (new String(getCurrentTokenSource()).equals("$this")) { // return TokenNamethis; @@ -2831,575 +2947,503 @@ public class Scanner implements IScanner, ITerminalSymbols { // } firstLetter = data[index]; switch (firstLetter) { - case '_' : - switch (length) { - case 8 : - //__FILE__ - if ((data[++index] == '_') && (data[++index] == 'f') - && (data[++index] == 'i') && (data[++index] == 'l') - && (data[++index] == 'e') && (data[++index] == '_') - && (data[++index] == '_')) - return TokenNameFILE; - index = 0; //__LINE__ - if ((data[++index] == '_') && (data[++index] == 'l') - && (data[++index] == 'i') && (data[++index] == 'n') - && (data[++index] == 'e') && (data[++index] == '_') - && (data[++index] == '_')) - return TokenNameLINE; - break; - case 9 : - //__CLASS__ - if ((data[++index] == '_') && (data[++index] == 'c') - && (data[++index] == 'l') && (data[++index] == 'a') - && (data[++index] == 's') && (data[++index] == 's') - && (data[++index] == '_') && (data[++index] == '_')) - return TokenNameCLASS_C; - break; - case 11 : - //__METHOD__ - if ((data[++index] == '_') && (data[++index] == 'm') - && (data[++index] == 'e') && (data[++index] == 't') - && (data[++index] == 'h') && (data[++index] == 'o') - && (data[++index] == 'd') && (data[++index] == '_') - && (data[++index] == '_')) - return TokenNameMETHOD_C; - break; - case 12 : - //__FUNCTION__ - if ((data[++index] == '_') && (data[++index] == 'f') - && (data[++index] == 'u') && (data[++index] == 'n') - && (data[++index] == 'c') && (data[++index] == 't') - && (data[++index] == 'i') && (data[++index] == 'o') - && (data[++index] == 'n') && (data[++index] == '_') - && (data[++index] == '_')) - return TokenNameFUNC_C; - break; - } - return TokenNameIdentifier; - case 'a' : - // as and array abstract - switch (length) { - case 2 : - //as - if ((data[++index] == 's')) { - return TokenNameas; - } else { - return TokenNameIdentifier; - } - case 3 : - //and - if ((data[++index] == 'n') && (data[++index] == 'd')) { - return TokenNameand; - } else { - return TokenNameIdentifier; - } - case 5 : - // array - if ((data[++index] == 'r') && (data[++index] == 'r') - && (data[++index] == 'a') && (data[++index] == 'y')) - return TokenNamearray; - else - return TokenNameIdentifier; - case 8 : - if ((data[++index] == 'b') && (data[++index] == 's') - && (data[++index] == 't') && (data[++index] == 'r') - && (data[++index] == 'a') && (data[++index] == 'c') - && (data[++index] == 't')) - return TokenNameabstract; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 'b' : - //break - switch (length) { - case 5 : - if ((data[++index] == 'r') && (data[++index] == 'e') - && (data[++index] == 'a') && (data[++index] == 'k')) - return TokenNamebreak; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 'c' : - //case catch class clone const continue - switch (length) { - case 4 : - if ((data[++index] == 'a') && (data[++index] == 's') - && (data[++index] == 'e')) - return TokenNamecase; - else - return TokenNameIdentifier; - case 5 : - if ((data[++index] == 'a') && (data[++index] == 't') - && (data[++index] == 'c') && (data[++index] == 'h')) - return TokenNamecatch; - index = 0; - if ((data[++index] == 'l') && (data[++index] == 'a') - && (data[++index] == 's') && (data[++index] == 's')) - return TokenNameclass; - index = 0; - if ((data[++index] == 'l') && (data[++index] == 'o') - && (data[++index] == 'n') && (data[++index] == 'e')) - return TokenNameclone; - index = 0; - if ((data[++index] == 'o') && (data[++index] == 'n') - && (data[++index] == 's') && (data[++index] == 't')) - return TokenNameconst; - else - return TokenNameIdentifier; - case 8 : - if ((data[++index] == 'o') && (data[++index] == 'n') - && (data[++index] == 't') && (data[++index] == 'i') - && (data[++index] == 'n') && (data[++index] == 'u') - && (data[++index] == 'e')) - return TokenNamecontinue; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 'd' : - // declare default do die - // TODO delete define ==> no keyword ! - switch (length) { - case 2 : - if ((data[++index] == 'o')) - return TokenNamedo; - else - return TokenNameIdentifier; - // case 6 : - // if ((data[++index] == 'e') - // && (data[++index] == 'f') - // && (data[++index] == 'i') - // && (data[++index] == 'n') - // && (data[++index] == 'e')) - // return TokenNamedefine; - // else - // return TokenNameIdentifier; - case 7 : - if ((data[++index] == 'e') && (data[++index] == 'c') - && (data[++index] == 'l') && (data[++index] == 'a') - && (data[++index] == 'r') && (data[++index] == 'e')) - return TokenNamedeclare; - index = 0; - if ((data[++index] == 'e') && (data[++index] == 'f') - && (data[++index] == 'a') && (data[++index] == 'u') - && (data[++index] == 'l') && (data[++index] == 't')) - return TokenNamedefault; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 'e' : - //echo else exit elseif extends eval - switch (length) { - case 4 : - if ((data[++index] == 'c') && (data[++index] == 'h') - && (data[++index] == 'o')) - return TokenNameecho; - else if ((data[index] == 'l') && (data[++index] == 's') - && (data[++index] == 'e')) - return TokenNameelse; - else if ((data[index] == 'x') && (data[++index] == 'i') - && (data[++index] == 't')) - return TokenNameexit; - else if ((data[index] == 'v') && (data[++index] == 'a') - && (data[++index] == 'l')) - return TokenNameeval; - else - return TokenNameIdentifier; - case 5 : - // endif empty - if ((data[++index] == 'n') && (data[++index] == 'd') - && (data[++index] == 'i') && (data[++index] == 'f')) - return TokenNameendif; - if ((data[index] == 'm') && (data[++index] == 'p') - && (data[++index] == 't') && (data[++index] == 'y')) - return TokenNameempty; - else - return TokenNameIdentifier; - case 6 : - // endfor - if ((data[++index] == 'n') && (data[++index] == 'd') - && (data[++index] == 'f') && (data[++index] == 'o') - && (data[++index] == 'r')) - return TokenNameendfor; - else if ((data[index] == 'l') && (data[++index] == 's') - && (data[++index] == 'e') && (data[++index] == 'i') - && (data[++index] == 'f')) - return TokenNameelseif; - else - return TokenNameIdentifier; - case 7 : - if ((data[++index] == 'x') && (data[++index] == 't') - && (data[++index] == 'e') && (data[++index] == 'n') - && (data[++index] == 'd') && (data[++index] == 's')) - return TokenNameextends; - else - return TokenNameIdentifier; - case 8 : - // endwhile - if ((data[++index] == 'n') && (data[++index] == 'd') - && (data[++index] == 'w') && (data[++index] == 'h') - && (data[++index] == 'i') && (data[++index] == 'l') - && (data[++index] == 'e')) - return TokenNameendwhile; - else - return TokenNameIdentifier; - case 9 : - // endswitch - if ((data[++index] == 'n') && (data[++index] == 'd') - && (data[++index] == 's') && (data[++index] == 'w') - && (data[++index] == 'i') && (data[++index] == 't') - && (data[++index] == 'c') && (data[++index] == 'h')) - return TokenNameendswitch; - else - return TokenNameIdentifier; - case 10 : - // enddeclare - if ((data[++index] == 'n') && (data[++index] == 'd') - && (data[++index] == 'd') && (data[++index] == 'e') - && (data[++index] == 'c') && (data[++index] == 'l') - && (data[++index] == 'a') && (data[++index] == 'r') - && (data[++index] == 'e')) - return TokenNameendforeach; - index = 0; - if ((data[++index] == 'n') // endforeach - && (data[++index] == 'd') && (data[++index] == 'f') - && (data[++index] == 'o') && (data[++index] == 'r') - && (data[++index] == 'e') && (data[++index] == 'a') - && (data[++index] == 'c') && (data[++index] == 'h')) - return TokenNameendforeach; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 'f' : - //for false final function - switch (length) { - case 3 : - if ((data[++index] == 'o') && (data[++index] == 'r')) - return TokenNamefor; - else - return TokenNameIdentifier; - case 5 : - // if ((data[++index] == 'a') && (data[++index] == 'l') - // && (data[++index] == 's') && (data[++index] == 'e')) - // return TokenNamefalse; - if ((data[++index] == 'i') && (data[++index] == 'n') - && (data[++index] == 'a') && (data[++index] == 'l')) - return TokenNamefinal; - else - return TokenNameIdentifier; - case 7 : - // foreach - if ((data[++index] == 'o') && (data[++index] == 'r') - && (data[++index] == 'e') && (data[++index] == 'a') - && (data[++index] == 'c') && (data[++index] == 'h')) - return TokenNameforeach; - else - return TokenNameIdentifier; - case 8 : - // function - if ((data[++index] == 'u') && (data[++index] == 'n') - && (data[++index] == 'c') && (data[++index] == 't') - && (data[++index] == 'i') && (data[++index] == 'o') - && (data[++index] == 'n')) - return TokenNamefunction; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; + case '_': + switch (length) { + case 8: + //__FILE__ + if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'i') && (data[++index] == 'l') + && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_')) + return TokenNameFILE; + index = 0; //__LINE__ + if ((data[++index] == '_') && (data[++index] == 'l') && (data[++index] == 'i') && (data[++index] == 'n') + && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_')) + return TokenNameLINE; + break; + case 9: + //__CLASS__ + if ((data[++index] == '_') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') + && (data[++index] == 's') && (data[++index] == 's') && (data[++index] == '_') && (data[++index] == '_')) + return TokenNameCLASS_C; + break; + case 11: + //__METHOD__ + if ((data[++index] == '_') && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 't') + && (data[++index] == 'h') && (data[++index] == 'o') && (data[++index] == 'd') && (data[++index] == '_') + && (data[++index] == '_')) + return TokenNameMETHOD_C; + break; + case 12: + //__FUNCTION__ + if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'u') && (data[++index] == 'n') + && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'o') + && (data[++index] == 'n') && (data[++index] == '_') && (data[++index] == '_')) + return TokenNameFUNC_C; + break; + } + return TokenNameIdentifier; + case 'a': + // as and array abstract + switch (length) { + case 2: + //as + if ((data[++index] == 's')) { + return TokenNameas; + } else { + return TokenNameIdentifier; } - case 'g' : - //global - if (length == 6) { - if ((data[++index] == 'l') && (data[++index] == 'o') - && (data[++index] == 'b') && (data[++index] == 'a') - && (data[++index] == 'l')) { - return TokenNameglobal; - } + case 3: + //and + if ((data[++index] == 'n') && (data[++index] == 'd')) { + return TokenNameand; + } else { + return TokenNameIdentifier; } + case 5: + // array + if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y')) + return TokenNamearray; + else + return TokenNameIdentifier; + case 8: + if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r') + && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't')) + return TokenNameabstract; + else + return TokenNameIdentifier; + default: return TokenNameIdentifier; - case 'i' : - //if int isset include include_once instanceof interface implements - switch (length) { - case 2 : - if (data[++index] == 'f') - return TokenNameif; - else - return TokenNameIdentifier; - // case 3 : - // if ((data[++index] == 'n') && (data[++index] == 't')) - // return TokenNameint; - // else - // return TokenNameIdentifier; - case 5 : - if ((data[++index] == 's') && (data[++index] == 's') - && (data[++index] == 'e') && (data[++index] == 't')) - return TokenNameisset; - else - return TokenNameIdentifier; - case 7 : - if ((data[++index] == 'n') && (data[++index] == 'c') - && (data[++index] == 'l') && (data[++index] == 'u') - && (data[++index] == 'd') && (data[++index] == 'e')) - return TokenNameinclude; - else - return TokenNameIdentifier; - case 9 : - // interface - if ((data[++index] == 'n') && (data[++index] == 't') - && (data[++index] == 'e') && (data[++index] == 'r') - && (data[++index] == 'f') && (data[++index] == 'a') - && (data[++index] == 'c') && (data[++index] == 'e')) - return TokenNameinterface; - else - return TokenNameIdentifier; - case 10 : - // instanceof - if ((data[++index] == 'n') && (data[++index] == 's') - && (data[++index] == 't') && (data[++index] == 'a') - && (data[++index] == 'n') && (data[++index] == 'c') - && (data[++index] == 'e') && (data[++index] == 'o') - && (data[++index] == 'f')) - return TokenNameinstanceof; - if ((data[index] == 'm') && (data[++index] == 'p') - && (data[++index] == 'l') && (data[++index] == 'e') - && (data[++index] == 'm') && (data[++index] == 'e') - && (data[++index] == 'n') && (data[++index] == 't') - && (data[++index] == 's')) - return TokenNameimplements; - else - return TokenNameIdentifier; - case 12 : - if ((data[++index] == 'n') && (data[++index] == 'c') - && (data[++index] == 'l') && (data[++index] == 'u') - && (data[++index] == 'd') && (data[++index] == 'e') - && (data[++index] == '_') && (data[++index] == 'o') - && (data[++index] == 'n') && (data[++index] == 'c') - && (data[++index] == 'e')) - return TokenNameinclude_once; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 'l' : - //list - if (length == 4) { - if ((data[++index] == 'i') && (data[++index] == 's') - && (data[++index] == 't')) { - return TokenNamelist; - } - } + } + case 'b': + //break + switch (length) { + case 5: + if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k')) + return TokenNamebreak; + else + return TokenNameIdentifier; + default: return TokenNameIdentifier; - case 'n' : - // new null - switch (length) { - case 3 : - if ((data[++index] == 'e') && (data[++index] == 'w')) - return TokenNamenew; - else - return TokenNameIdentifier; - // case 4 : - // if ((data[++index] == 'u') && (data[++index] == 'l') - // && (data[++index] == 'l')) - // return TokenNamenull; - // else - // return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 'o' : - // or old_function - if (length == 2) { - if (data[++index] == 'r') { - return TokenNameor; - } + } + case 'c': + //case catch class clone const continue + switch (length) { + case 4: + if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e')) + return TokenNamecase; + else + return TokenNameIdentifier; + case 5: + if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h')) + return TokenNamecatch; + index = 0; + if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's')) + return TokenNameclass; + index = 0; + if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e')) + return TokenNameclone; + index = 0; + if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't')) + return TokenNameconst; + else + return TokenNameIdentifier; + case 8: + if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i') + && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e')) + return TokenNamecontinue; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + case 'd': + // declare default do die + // TODO delete define ==> no keyword ! + switch (length) { + case 2: + if ((data[++index] == 'o')) + return TokenNamedo; + else + return TokenNameIdentifier; + // case 6 : + // if ((data[++index] == 'e') + // && (data[++index] == 'f') + // && (data[++index] == 'i') + // && (data[++index] == 'n') + // && (data[++index] == 'e')) + // return TokenNamedefine; + // else + // return TokenNameIdentifier; + case 7: + if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') + && (data[++index] == 'r') && (data[++index] == 'e')) + return TokenNamedeclare; + index = 0; + if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u') + && (data[++index] == 'l') && (data[++index] == 't')) + return TokenNamedefault; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + case 'e': + //echo else exit elseif extends eval + switch (length) { + case 4: + if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o')) + return TokenNameecho; + else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e')) + return TokenNameelse; + else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't')) + return TokenNameexit; + else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l')) + return TokenNameeval; + else + return TokenNameIdentifier; + case 5: + // endif empty + if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f')) + return TokenNameendif; + if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y')) + return TokenNameempty; + else + return TokenNameIdentifier; + case 6: + // endfor + if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') + && (data[++index] == 'r')) + return TokenNameendfor; + else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i') + && (data[++index] == 'f')) + return TokenNameelseif; + else + return TokenNameIdentifier; + case 7: + if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n') + && (data[++index] == 'd') && (data[++index] == 's')) + return TokenNameextends; + else + return TokenNameIdentifier; + case 8: + // endwhile + if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h') + && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e')) + return TokenNameendwhile; + else + return TokenNameIdentifier; + case 9: + // endswitch + if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w') + && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h')) + return TokenNameendswitch; + else + return TokenNameIdentifier; + case 10: + // enddeclare + if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e') + && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r') + && (data[++index] == 'e')) + return TokenNameendforeach; + index = 0; + if ((data[++index] == 'n') // endforeach + && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r') + && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h')) + return TokenNameendforeach; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + case 'f': + //for false final function + switch (length) { + case 3: + if ((data[++index] == 'o') && (data[++index] == 'r')) + return TokenNamefor; + else + return TokenNameIdentifier; + case 5: + // if ((data[++index] == 'a') && (data[++index] == 'l') + // && (data[++index] == 's') && (data[++index] == 'e')) + // return TokenNamefalse; + if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l')) + return TokenNamefinal; + else + return TokenNameIdentifier; + case 7: + // foreach + if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') + && (data[++index] == 'c') && (data[++index] == 'h')) + return TokenNameforeach; + else + return TokenNameIdentifier; + case 8: + // function + if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't') + && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n')) + return TokenNamefunction; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + case 'g': + //global + if (length == 6) { + if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a') + && (data[++index] == 'l')) { + return TokenNameglobal; } - // if (length == 12) { - // if ((data[++index] == 'l') - // && (data[++index] == 'd') - // && (data[++index] == '_') - // && (data[++index] == 'f') - // && (data[++index] == 'u') - // && (data[++index] == 'n') - // && (data[++index] == 'c') - // && (data[++index] == 't') - // && (data[++index] == 'i') - // && (data[++index] == 'o') - // && (data[++index] == 'n')) { - // return TokenNameold_function; - // } - // } + } + return TokenNameIdentifier; + case 'i': + //if int isset include include_once instanceof interface implements + switch (length) { + case 2: + if (data[++index] == 'f') + return TokenNameif; + else + return TokenNameIdentifier; + // case 3 : + // if ((data[++index] == 'n') && (data[++index] == 't')) + // return TokenNameint; + // else + // return TokenNameIdentifier; + case 5: + if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't')) + return TokenNameisset; + else + return TokenNameIdentifier; + case 7: + if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u') + && (data[++index] == 'd') && (data[++index] == 'e')) + return TokenNameinclude; + else + return TokenNameIdentifier; + case 9: + // interface + if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r') + && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e')) + return TokenNameinterface; + else + return TokenNameIdentifier; + case 10: + // instanceof + if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a') + && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o') + && (data[++index] == 'f')) + return TokenNameinstanceof; + if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e') + && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't') + && (data[++index] == 's')) + return TokenNameimplements; + else + return TokenNameIdentifier; + case 12: + if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u') + && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o') + && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) + return TokenNameinclude_once; + else + return TokenNameIdentifier; + default: return TokenNameIdentifier; - case 'p' : - // print public private protected - switch (length) { - case 5 : - if ((data[++index] == 'r') && (data[++index] == 'i') - && (data[++index] == 'n') && (data[++index] == 't')) { - return TokenNameprint; - } else - return TokenNameIdentifier; - case 6 : - if ((data[++index] == 'u') && (data[++index] == 'b') - && (data[++index] == 'l') && (data[++index] == 'i') - && (data[++index] == 'c')) { - return TokenNamepublic; - } else - return TokenNameIdentifier; - case 7 : - if ((data[++index] == 'r') && (data[++index] == 'i') - && (data[++index] == 'v') && (data[++index] == 'a') - && (data[++index] == 't') && (data[++index] == 'e')) { - return TokenNameprivate; - } else - return TokenNameIdentifier; - case 9 : - if ((data[++index] == 'r') && (data[++index] == 'o') - && (data[++index] == 't') && (data[++index] == 'e') - && (data[++index] == 'c') && (data[++index] == 't') - && (data[++index] == 'e') && (data[++index] == 'd')) { - return TokenNameprotected; - } else - return TokenNameIdentifier; + } + case 'l': + //list + if (length == 4) { + if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) { + return TokenNamelist; } + } + return TokenNameIdentifier; + case 'n': + // new null + switch (length) { + case 3: + if ((data[++index] == 'e') && (data[++index] == 'w')) + return TokenNamenew; + else + return TokenNameIdentifier; + // case 4 : + // if ((data[++index] == 'u') && (data[++index] == 'l') + // && (data[++index] == 'l')) + // return TokenNamenull; + // else + // return TokenNameIdentifier; + default: return TokenNameIdentifier; - case 'r' : - //return require require_once - if (length == 6) { - if ((data[++index] == 'e') && (data[++index] == 't') - && (data[++index] == 'u') && (data[++index] == 'r') - && (data[++index] == 'n')) { - return TokenNamereturn; - } - } else if (length == 7) { - if ((data[++index] == 'e') && (data[++index] == 'q') - && (data[++index] == 'u') && (data[++index] == 'i') - && (data[++index] == 'r') && (data[++index] == 'e')) { - return TokenNamerequire; - } - } else if (length == 12) { - if ((data[++index] == 'e') && (data[++index] == 'q') - && (data[++index] == 'u') && (data[++index] == 'i') - && (data[++index] == 'r') && (data[++index] == 'e') - && (data[++index] == '_') && (data[++index] == 'o') - && (data[++index] == 'n') && (data[++index] == 'c') - && (data[++index] == 'e')) { - return TokenNamerequire_once; - } + } + case 'o': + // or old_function + if (length == 2) { + if (data[++index] == 'r') { + return TokenNameor; + } + } + // if (length == 12) { + // if ((data[++index] == 'l') + // && (data[++index] == 'd') + // && (data[++index] == '_') + // && (data[++index] == 'f') + // && (data[++index] == 'u') + // && (data[++index] == 'n') + // && (data[++index] == 'c') + // && (data[++index] == 't') + // && (data[++index] == 'i') + // && (data[++index] == 'o') + // && (data[++index] == 'n')) { + // return TokenNameold_function; + // } + // } + return TokenNameIdentifier; + case 'p': + // print public private protected + switch (length) { + case 5: + if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) { + return TokenNameprint; } else return TokenNameIdentifier; - case 's' : - //static switch - switch (length) { - case 6 : - if (data[++index] == 't') - if ((data[++index] == 'a') && (data[++index] == 't') - && (data[++index] == 'i') && (data[++index] == 'c')) { - return TokenNamestatic; - } else - return TokenNameIdentifier; - else if ((data[index] == 'w') && (data[++index] == 'i') - && (data[++index] == 't') && (data[++index] == 'c') - && (data[++index] == 'h')) - return TokenNameswitch; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 't' : - // try true throw - switch (length) { - case 3 : - if ((data[++index] == 'r') && (data[++index] == 'y')) - return TokenNametry; - else - return TokenNameIdentifier; - // case 4 : - // if ((data[++index] == 'r') && (data[++index] == 'u') - // && (data[++index] == 'e')) - // return TokenNametrue; - // else - // return TokenNameIdentifier; - case 5 : - if ((data[++index] == 'h') && (data[++index] == 'r') - && (data[++index] == 'o') && (data[++index] == 'w')) - return TokenNamethrow; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; - } - case 'u' : - //use unset - switch (length) { - case 3 : - if ((data[++index] == 's') && (data[++index] == 'e')) - return TokenNameuse; - else - return TokenNameIdentifier; - case 5 : - if ((data[++index] == 'n') && (data[++index] == 's') - && (data[++index] == 'e') && (data[++index] == 't')) - return TokenNameunset; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; + case 6: + if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i') + && (data[++index] == 'c')) { + return TokenNamepublic; + } else + return TokenNameIdentifier; + case 7: + if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a') + && (data[++index] == 't') && (data[++index] == 'e')) { + return TokenNameprivate; + } else + return TokenNameIdentifier; + case 9: + if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e') + && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) { + return TokenNameprotected; + } else + return TokenNameIdentifier; + } + return TokenNameIdentifier; + case 'r': + //return require require_once + if (length == 6) { + if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r') + && (data[++index] == 'n')) { + return TokenNamereturn; } - case 'v' : - //var - switch (length) { - case 3 : - if ((data[++index] == 'a') && (data[++index] == 'r')) - return TokenNamevar; - else - return TokenNameIdentifier; - default : - return TokenNameIdentifier; + } else if (length == 7) { + if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i') + && (data[++index] == 'r') && (data[++index] == 'e')) { + return TokenNamerequire; } - case 'w' : - //while - switch (length) { - case 5 : - if ((data[++index] == 'h') && (data[++index] == 'i') - && (data[++index] == 'l') && (data[++index] == 'e')) - return TokenNamewhile; - else - return TokenNameIdentifier; - //case 6:if ( (data[++index] =='i') && (data[++index]=='d') && - // (data[++index]=='e') && (data[++index]=='f')&& - // (data[++index]=='p')) - //return TokenNamewidefp ; - //else - //return TokenNameIdentifier; - default : - return TokenNameIdentifier; + } else if (length == 12) { + if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i') + && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o') + && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) { + return TokenNamerequire_once; } - case 'x' : - //xor - switch (length) { - case 3 : - if ((data[++index] == 'o') && (data[++index] == 'r')) - return TokenNamexor; - else - return TokenNameIdentifier; - default : + } else + return TokenNameIdentifier; + case 's': + //static switch + switch (length) { + case 6: + if (data[++index] == 't') + if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) { + return TokenNamestatic; + } else return TokenNameIdentifier; - } - default : + else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') + && (data[++index] == 'h')) + return TokenNameswitch; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + case 't': + // try true throw + switch (length) { + case 3: + if ((data[++index] == 'r') && (data[++index] == 'y')) + return TokenNametry; + else + return TokenNameIdentifier; + // case 4 : + // if ((data[++index] == 'r') && (data[++index] == 'u') + // && (data[++index] == 'e')) + // return TokenNametrue; + // else + // return TokenNameIdentifier; + case 5: + if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w')) + return TokenNamethrow; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + case 'u': + //use unset + switch (length) { + case 3: + if ((data[++index] == 's') && (data[++index] == 'e')) + return TokenNameuse; + else + return TokenNameIdentifier; + case 5: + if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't')) + return TokenNameunset; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + case 'v': + //var + switch (length) { + case 3: + if ((data[++index] == 'a') && (data[++index] == 'r')) + return TokenNamevar; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + case 'w': + //while + switch (length) { + case 5: + if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e')) + return TokenNamewhile; + else + return TokenNameIdentifier; + //case 6:if ( (data[++index] =='i') && (data[++index]=='d') && + // (data[++index]=='e') && (data[++index]=='f')&& + // (data[++index]=='p')) + //return TokenNamewidefp ; + //else + //return TokenNameIdentifier; + default: return TokenNameIdentifier; + } + case 'x': + //xor + switch (length) { + case 3: + if ((data[++index] == 'o') && (data[++index] == 'r')) + return TokenNamexor; + else + return TokenNameIdentifier; + default: + return TokenNameIdentifier; + } + default: + return TokenNameIdentifier; } } + public int scanNumber(boolean dotPrefix) throws InvalidInputException { //when entering this method the currentCharacter is the firt //digit of the number , i.e. it may be preceeded by a . when @@ -3423,7 +3467,8 @@ public class Scanner implements IScanner, ITerminalSymbols { throw new InvalidInputException(INVALID_HEXA); //---end forcing-- while (getNextCharAsDigit(16)) { - }; + } + ; // if (getNextChar('l', 'L') >= 0) // return TokenNameLongLiteral; // else @@ -3435,7 +3480,8 @@ public class Scanner implements IScanner, ITerminalSymbols { if (getNextCharAsDigit()) { //-------------potential octal----------------- while (getNextCharAsDigit()) { - }; + } + ; // if (getNextChar('l', 'L') >= 0) { // return TokenNameLongLiteral; // } @@ -3448,7 +3494,8 @@ public class Scanner implements IScanner, ITerminalSymbols { } else { //make the distinction between octal and float .... if (getNextChar('.')) { //bingo ! .... while (getNextCharAsDigit()) { - }; + } + ; if (getNextChar('e', 'E') >= 0) { // consume next character unicodeAsBackSlash = false; @@ -3478,7 +3525,8 @@ public class Scanner implements IScanner, ITerminalSymbols { if (!Character.isDigit(currentCharacter)) throw new InvalidInputException(INVALID_FLOAT); while (getNextCharAsDigit()) { - }; + } + ; } // if (getNextChar('f', 'F') >= 0) // return TokenNameFloatingPointLiteral; @@ -3493,12 +3541,14 @@ public class Scanner implements IScanner, ITerminalSymbols { } } while (getNextCharAsDigit()) { - }; + } + ; // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0)) // return TokenNameLongLiteral; if ((!dotPrefix) && (getNextChar('.'))) { //decimal part that can be empty while (getNextCharAsDigit()) { - }; + } + ; floating = true; } //if floating is true both exponant and suffix may be optional @@ -3532,7 +3582,8 @@ public class Scanner implements IScanner, ITerminalSymbols { if (!Character.isDigit(currentCharacter)) throw new InvalidInputException(INVALID_FLOAT); while (getNextCharAsDigit()) { - }; + } + ; } if (getNextChar('d', 'D') >= 0) return TokenNameDoubleLiteral; @@ -3541,6 +3592,7 @@ public class Scanner implements IScanner, ITerminalSymbols { //the long flag has been tested before return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral; } + /** * Search the line number corresponding to a specific position * @@ -3568,9 +3620,11 @@ public class Scanner implements IScanner, ITerminalSymbols { } return m + 2; } + public void setPHPMode(boolean mode) { phpMode = mode; } + public final void setSource(char[] source) { //the source-buffer is set to sourceString if (source == null) { @@ -3584,6 +3638,7 @@ public class Scanner implements IScanner, ITerminalSymbols { withoutUnicodeBuffer = new char[this.source.length]; encapsedStringStack = new Stack(); } + public String toString() { if (startPosition == source.length) return "EOF\n\n" + new String(source); //$NON-NLS-1$ @@ -3600,328 +3655,322 @@ public class Scanner implements IScanner, ITerminalSymbols { middle = new char[0]; } char end[] = new char[source.length - (currentPosition - 1)]; - System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - - (currentPosition - 1) - 1); - return new String(front) - + "\n===============================\nStarts here -->" //$NON-NLS-1$ - + new String(middle) - + "<-- Ends here\n===============================\n" //$NON-NLS-1$ + System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1); + return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$ + + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$ + new String(end); } + public final String toStringAction(int act) { switch (act) { - case TokenNameERROR : - return "ScannerError"; // + new String(getCurrentTokenSource()) + ")"; - // //$NON-NLS-1$ - case TokenNameINLINE_HTML : - return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameIdentifier : - return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameVariable : - return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameabstract : - return "abstract"; //$NON-NLS-1$ - case TokenNameand : - return "AND"; //$NON-NLS-1$ - case TokenNamearray : - return "array"; //$NON-NLS-1$ - case TokenNameas : - return "as"; //$NON-NLS-1$ - case TokenNamebreak : - return "break"; //$NON-NLS-1$ - case TokenNamecase : - return "case"; //$NON-NLS-1$ - case TokenNameclass : - return "class"; //$NON-NLS-1$ - case TokenNamecatch : - return "catch"; //$NON-NLS-1$ - case TokenNameclone : - //$NON-NLS-1$ - return "clone"; - case TokenNameconst : - //$NON-NLS-1$ - return "const"; - case TokenNamecontinue : - return "continue"; //$NON-NLS-1$ - case TokenNamedefault : - return "default"; //$NON-NLS-1$ - // case TokenNamedefine : - // return "define"; //$NON-NLS-1$ - case TokenNamedo : - return "do"; //$NON-NLS-1$ - case TokenNameecho : - return "echo"; //$NON-NLS-1$ - case TokenNameelse : - return "else"; //$NON-NLS-1$ - case TokenNameelseif : - return "elseif"; //$NON-NLS-1$ - case TokenNameendfor : - return "endfor"; //$NON-NLS-1$ - case TokenNameendforeach : - return "endforeach"; //$NON-NLS-1$ - case TokenNameendif : - return "endif"; //$NON-NLS-1$ - case TokenNameendswitch : - return "endswitch"; //$NON-NLS-1$ - case TokenNameendwhile : - return "endwhile"; //$NON-NLS-1$ - case TokenNameexit: - return "exit"; - case TokenNameextends : - return "extends"; //$NON-NLS-1$ - // case TokenNamefalse : - // return "false"; //$NON-NLS-1$ - case TokenNamefinal : - return "final"; //$NON-NLS-1$ - case TokenNamefor : - return "for"; //$NON-NLS-1$ - case TokenNameforeach : - return "foreach"; //$NON-NLS-1$ - case TokenNamefunction : - return "function"; //$NON-NLS-1$ - case TokenNameglobal : - return "global"; //$NON-NLS-1$ - case TokenNameif : - return "if"; //$NON-NLS-1$ - case TokenNameimplements : - return "implements"; //$NON-NLS-1$ - case TokenNameinclude : - return "include"; //$NON-NLS-1$ - case TokenNameinclude_once : - return "include_once"; //$NON-NLS-1$ - case TokenNameinstanceof : - return "instanceof"; //$NON-NLS-1$ - case TokenNameinterface : - return "interface"; //$NON-NLS-1$ - case TokenNameisset : - return "isset"; //$NON-NLS-1$ - case TokenNamelist : - return "list"; //$NON-NLS-1$ - case TokenNamenew : - return "new"; //$NON-NLS-1$ - // case TokenNamenull : - // return "null"; //$NON-NLS-1$ - case TokenNameor : - return "OR"; //$NON-NLS-1$ - case TokenNameprint : - return "print"; //$NON-NLS-1$ - case TokenNameprivate : - return "private"; //$NON-NLS-1$ - case TokenNameprotected : - return "protected"; //$NON-NLS-1$ - case TokenNamepublic : - return "public"; //$NON-NLS-1$ - case TokenNamerequire : - return "require"; //$NON-NLS-1$ - case TokenNamerequire_once : - return "require_once"; //$NON-NLS-1$ - case TokenNamereturn : - return "return"; //$NON-NLS-1$ - case TokenNamestatic : - return "static"; //$NON-NLS-1$ - case TokenNameswitch : - return "switch"; //$NON-NLS-1$ - // case TokenNametrue : - // return "true"; //$NON-NLS-1$ - case TokenNameunset : - return "unset"; //$NON-NLS-1$ - case TokenNamevar : - return "var"; //$NON-NLS-1$ - case TokenNamewhile : - return "while"; //$NON-NLS-1$ - case TokenNamexor : - return "XOR"; //$NON-NLS-1$ - // case TokenNamethis : - // return "$this"; //$NON-NLS-1$ - case TokenNameIntegerLiteral : - return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameDoubleLiteral : - return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameStringDoubleQuote : - return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameStringSingleQuote : - return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameStringInterpolated : - return "StringInterpolated(" + new String(getCurrentTokenSource()) - + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameEncapsedString0 : - return "`"; //$NON-NLS-1$ - case TokenNameEncapsedString1 : - return "\'"; //$NON-NLS-1$ - case TokenNameEncapsedString2 : - return "\""; //$NON-NLS-1$ - case TokenNameSTRING : - return "STRING(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - case TokenNameHEREDOC : - return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ - case TokenNamePLUS_PLUS : - return "++"; //$NON-NLS-1$ - case TokenNameMINUS_MINUS : - return "--"; //$NON-NLS-1$ - case TokenNameEQUAL_EQUAL : - return "=="; //$NON-NLS-1$ - case TokenNameEQUAL_EQUAL_EQUAL : - return "==="; //$NON-NLS-1$ - case TokenNameEQUAL_GREATER : - return "=>"; //$NON-NLS-1$ - case TokenNameLESS_EQUAL : - return "<="; //$NON-NLS-1$ - case TokenNameGREATER_EQUAL : - return ">="; //$NON-NLS-1$ - case TokenNameNOT_EQUAL : - return "!="; //$NON-NLS-1$ - case TokenNameNOT_EQUAL_EQUAL : - return "!=="; //$NON-NLS-1$ - case TokenNameLEFT_SHIFT : - return "<<"; //$NON-NLS-1$ - case TokenNameRIGHT_SHIFT : - return ">>"; //$NON-NLS-1$ - case TokenNamePLUS_EQUAL : - return "+="; //$NON-NLS-1$ - case TokenNameMINUS_EQUAL : - return "-="; //$NON-NLS-1$ - case TokenNameMULTIPLY_EQUAL : - return "*="; //$NON-NLS-1$ - case TokenNameDIVIDE_EQUAL : - return "/="; //$NON-NLS-1$ - case TokenNameAND_EQUAL : - return "&="; //$NON-NLS-1$ - case TokenNameOR_EQUAL : - return "|="; //$NON-NLS-1$ - case TokenNameXOR_EQUAL : - return "^="; //$NON-NLS-1$ - case TokenNameREMAINDER_EQUAL : - return "%="; //$NON-NLS-1$ - case TokenNameDOT_EQUAL : - return ".="; //$NON-NLS-1$ - case TokenNameLEFT_SHIFT_EQUAL : - return "<<="; //$NON-NLS-1$ - case TokenNameRIGHT_SHIFT_EQUAL : - return ">>="; //$NON-NLS-1$ - case TokenNameOR_OR : - return "||"; //$NON-NLS-1$ - case TokenNameAND_AND : - return "&&"; //$NON-NLS-1$ - case TokenNamePLUS : - return "+"; //$NON-NLS-1$ - case TokenNameMINUS : - return "-"; //$NON-NLS-1$ - case TokenNameMINUS_GREATER : - return "->"; - case TokenNameNOT : - return "!"; //$NON-NLS-1$ - case TokenNameREMAINDER : - return "%"; //$NON-NLS-1$ - case TokenNameXOR : - return "^"; //$NON-NLS-1$ - case TokenNameAND : - return "&"; //$NON-NLS-1$ - case TokenNameMULTIPLY : - return "*"; //$NON-NLS-1$ - case TokenNameOR : - return "|"; //$NON-NLS-1$ - case TokenNameTWIDDLE : - return "~"; //$NON-NLS-1$ - case TokenNameTWIDDLE_EQUAL : - return "~="; //$NON-NLS-1$ - case TokenNameDIVIDE : - return "/"; //$NON-NLS-1$ - case TokenNameGREATER : - return ">"; //$NON-NLS-1$ - case TokenNameLESS : - return "<"; //$NON-NLS-1$ - case TokenNameLPAREN : - return "("; //$NON-NLS-1$ - case TokenNameRPAREN : - return ")"; //$NON-NLS-1$ - case TokenNameLBRACE : - return "{"; //$NON-NLS-1$ - case TokenNameRBRACE : - return "}"; //$NON-NLS-1$ - case TokenNameLBRACKET : - return "["; //$NON-NLS-1$ - case TokenNameRBRACKET : - return "]"; //$NON-NLS-1$ - case TokenNameSEMICOLON : - return ";"; //$NON-NLS-1$ - case TokenNameQUESTION : - return "?"; //$NON-NLS-1$ - case TokenNameCOLON : - return ":"; //$NON-NLS-1$ - case TokenNameCOMMA : - return ","; //$NON-NLS-1$ - case TokenNameDOT : - return "."; //$NON-NLS-1$ - case TokenNameEQUAL : - return "="; //$NON-NLS-1$ - case TokenNameAT : - return "@"; - case TokenNameDOLLAR : - return "$"; - case TokenNameDOLLAR_LBRACE : - return "${"; - case TokenNameLBRACE_DOLLAR : - return "{$"; - case TokenNameEOF : - return "EOF"; //$NON-NLS-1$ - case TokenNameWHITESPACE : - return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ - case TokenNameCOMMENT_LINE : - return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ - case TokenNameCOMMENT_BLOCK : - return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ - case TokenNameCOMMENT_PHPDOC : - return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ - // case TokenNameHTML : - // return "HTML(" + new String(getCurrentTokenSource()) + ")"; - // //$NON-NLS-1$ - case TokenNameFILE : - return "__FILE__"; //$NON-NLS-1$ - case TokenNameLINE : - return "__LINE__"; //$NON-NLS-1$ - case TokenNameCLASS_C : - return "__CLASS__"; //$NON-NLS-1$ - case TokenNameMETHOD_C : - return "__METHOD__"; //$NON-NLS-1$ - case TokenNameFUNC_C : - return "__FUNCTION__"; //$NON-NLS-1 - case TokenNameboolCAST : - return "( bool )"; //$NON-NLS-1$ - case TokenNameintCAST : - return "( int )"; //$NON-NLS-1$ - case TokenNamedoubleCAST : - return "( double )"; //$NON-NLS-1$ - case TokenNameobjectCAST : - return "( object )"; //$NON-NLS-1$ - case TokenNamestringCAST : - return "( string )"; //$NON-NLS-1$ - default : - return "not-a-token(" + (new Integer(act)) + ") " - + new String(getCurrentTokenSource()); //$NON-NLS-1$ + case TokenNameERROR: + return "ScannerError"; // + new String(getCurrentTokenSource()) + ")"; + // //$NON-NLS-1$ + case TokenNameINLINE_HTML: + return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameIdentifier: + return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameVariable: + return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameabstract: + return "abstract"; //$NON-NLS-1$ + case TokenNameand: + return "AND"; //$NON-NLS-1$ + case TokenNamearray: + return "array"; //$NON-NLS-1$ + case TokenNameas: + return "as"; //$NON-NLS-1$ + case TokenNamebreak: + return "break"; //$NON-NLS-1$ + case TokenNamecase: + return "case"; //$NON-NLS-1$ + case TokenNameclass: + return "class"; //$NON-NLS-1$ + case TokenNamecatch: + return "catch"; //$NON-NLS-1$ + case TokenNameclone: + //$NON-NLS-1$ + return "clone"; + case TokenNameconst: + //$NON-NLS-1$ + return "const"; + case TokenNamecontinue: + return "continue"; //$NON-NLS-1$ + case TokenNamedefault: + return "default"; //$NON-NLS-1$ + // case TokenNamedefine : + // return "define"; //$NON-NLS-1$ + case TokenNamedo: + return "do"; //$NON-NLS-1$ + case TokenNameecho: + return "echo"; //$NON-NLS-1$ + case TokenNameelse: + return "else"; //$NON-NLS-1$ + case TokenNameelseif: + return "elseif"; //$NON-NLS-1$ + case TokenNameendfor: + return "endfor"; //$NON-NLS-1$ + case TokenNameendforeach: + return "endforeach"; //$NON-NLS-1$ + case TokenNameendif: + return "endif"; //$NON-NLS-1$ + case TokenNameendswitch: + return "endswitch"; //$NON-NLS-1$ + case TokenNameendwhile: + return "endwhile"; //$NON-NLS-1$ + case TokenNameexit: + return "exit"; + case TokenNameextends: + return "extends"; //$NON-NLS-1$ + // case TokenNamefalse : + // return "false"; //$NON-NLS-1$ + case TokenNamefinal: + return "final"; //$NON-NLS-1$ + case TokenNamefor: + return "for"; //$NON-NLS-1$ + case TokenNameforeach: + return "foreach"; //$NON-NLS-1$ + case TokenNamefunction: + return "function"; //$NON-NLS-1$ + case TokenNameglobal: + return "global"; //$NON-NLS-1$ + case TokenNameif: + return "if"; //$NON-NLS-1$ + case TokenNameimplements: + return "implements"; //$NON-NLS-1$ + case TokenNameinclude: + return "include"; //$NON-NLS-1$ + case TokenNameinclude_once: + return "include_once"; //$NON-NLS-1$ + case TokenNameinstanceof: + return "instanceof"; //$NON-NLS-1$ + case TokenNameinterface: + return "interface"; //$NON-NLS-1$ + case TokenNameisset: + return "isset"; //$NON-NLS-1$ + case TokenNamelist: + return "list"; //$NON-NLS-1$ + case TokenNamenew: + return "new"; //$NON-NLS-1$ + // case TokenNamenull : + // return "null"; //$NON-NLS-1$ + case TokenNameor: + return "OR"; //$NON-NLS-1$ + case TokenNameprint: + return "print"; //$NON-NLS-1$ + case TokenNameprivate: + return "private"; //$NON-NLS-1$ + case TokenNameprotected: + return "protected"; //$NON-NLS-1$ + case TokenNamepublic: + return "public"; //$NON-NLS-1$ + case TokenNamerequire: + return "require"; //$NON-NLS-1$ + case TokenNamerequire_once: + return "require_once"; //$NON-NLS-1$ + case TokenNamereturn: + return "return"; //$NON-NLS-1$ + case TokenNamestatic: + return "static"; //$NON-NLS-1$ + case TokenNameswitch: + return "switch"; //$NON-NLS-1$ + // case TokenNametrue : + // return "true"; //$NON-NLS-1$ + case TokenNameunset: + return "unset"; //$NON-NLS-1$ + case TokenNamevar: + return "var"; //$NON-NLS-1$ + case TokenNamewhile: + return "while"; //$NON-NLS-1$ + case TokenNamexor: + return "XOR"; //$NON-NLS-1$ + // case TokenNamethis : + // return "$this"; //$NON-NLS-1$ + case TokenNameIntegerLiteral: + return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameDoubleLiteral: + return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameStringDoubleQuote: + return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameStringSingleQuote: + return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameStringInterpolated: + return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameEncapsedString0: + return "`"; //$NON-NLS-1$ + case TokenNameEncapsedString1: + return "\'"; //$NON-NLS-1$ + case TokenNameEncapsedString2: + return "\""; //$NON-NLS-1$ + case TokenNameSTRING: + return "STRING(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + case TokenNameHEREDOC: + return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + case TokenNamePLUS_PLUS: + return "++"; //$NON-NLS-1$ + case TokenNameMINUS_MINUS: + return "--"; //$NON-NLS-1$ + case TokenNameEQUAL_EQUAL: + return "=="; //$NON-NLS-1$ + case TokenNameEQUAL_EQUAL_EQUAL: + return "==="; //$NON-NLS-1$ + case TokenNameEQUAL_GREATER: + return "=>"; //$NON-NLS-1$ + case TokenNameLESS_EQUAL: + return "<="; //$NON-NLS-1$ + case TokenNameGREATER_EQUAL: + return ">="; //$NON-NLS-1$ + case TokenNameNOT_EQUAL: + return "!="; //$NON-NLS-1$ + case TokenNameNOT_EQUAL_EQUAL: + return "!=="; //$NON-NLS-1$ + case TokenNameLEFT_SHIFT: + return "<<"; //$NON-NLS-1$ + case TokenNameRIGHT_SHIFT: + return ">>"; //$NON-NLS-1$ + case TokenNamePLUS_EQUAL: + return "+="; //$NON-NLS-1$ + case TokenNameMINUS_EQUAL: + return "-="; //$NON-NLS-1$ + case TokenNameMULTIPLY_EQUAL: + return "*="; //$NON-NLS-1$ + case TokenNameDIVIDE_EQUAL: + return "/="; //$NON-NLS-1$ + case TokenNameAND_EQUAL: + return "&="; //$NON-NLS-1$ + case TokenNameOR_EQUAL: + return "|="; //$NON-NLS-1$ + case TokenNameXOR_EQUAL: + return "^="; //$NON-NLS-1$ + case TokenNameREMAINDER_EQUAL: + return "%="; //$NON-NLS-1$ + case TokenNameDOT_EQUAL: + return ".="; //$NON-NLS-1$ + case TokenNameLEFT_SHIFT_EQUAL: + return "<<="; //$NON-NLS-1$ + case TokenNameRIGHT_SHIFT_EQUAL: + return ">>="; //$NON-NLS-1$ + case TokenNameOR_OR: + return "||"; //$NON-NLS-1$ + case TokenNameAND_AND: + return "&&"; //$NON-NLS-1$ + case TokenNamePLUS: + return "+"; //$NON-NLS-1$ + case TokenNameMINUS: + return "-"; //$NON-NLS-1$ + case TokenNameMINUS_GREATER: + return "->"; + case TokenNameNOT: + return "!"; //$NON-NLS-1$ + case TokenNameREMAINDER: + return "%"; //$NON-NLS-1$ + case TokenNameXOR: + return "^"; //$NON-NLS-1$ + case TokenNameAND: + return "&"; //$NON-NLS-1$ + case TokenNameMULTIPLY: + return "*"; //$NON-NLS-1$ + case TokenNameOR: + return "|"; //$NON-NLS-1$ + case TokenNameTWIDDLE: + return "~"; //$NON-NLS-1$ + case TokenNameTWIDDLE_EQUAL: + return "~="; //$NON-NLS-1$ + case TokenNameDIVIDE: + return "/"; //$NON-NLS-1$ + case TokenNameGREATER: + return ">"; //$NON-NLS-1$ + case TokenNameLESS: + return "<"; //$NON-NLS-1$ + case TokenNameLPAREN: + return "("; //$NON-NLS-1$ + case TokenNameRPAREN: + return ")"; //$NON-NLS-1$ + case TokenNameLBRACE: + return "{"; //$NON-NLS-1$ + case TokenNameRBRACE: + return "}"; //$NON-NLS-1$ + case TokenNameLBRACKET: + return "["; //$NON-NLS-1$ + case TokenNameRBRACKET: + return "]"; //$NON-NLS-1$ + case TokenNameSEMICOLON: + return ";"; //$NON-NLS-1$ + case TokenNameQUESTION: + return "?"; //$NON-NLS-1$ + case TokenNameCOLON: + return ":"; //$NON-NLS-1$ + case TokenNameCOMMA: + return ","; //$NON-NLS-1$ + case TokenNameDOT: + return "."; //$NON-NLS-1$ + case TokenNameEQUAL: + return "="; //$NON-NLS-1$ + case TokenNameAT: + return "@"; + case TokenNameDOLLAR: + return "$"; + case TokenNameDOLLAR_LBRACE: + return "${"; + case TokenNameLBRACE_DOLLAR: + return "{$"; + case TokenNameEOF: + return "EOF"; //$NON-NLS-1$ + case TokenNameWHITESPACE: + return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + case TokenNameCOMMENT_LINE: + return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + case TokenNameCOMMENT_BLOCK: + return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + case TokenNameCOMMENT_PHPDOC: + return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + // case TokenNameHTML : + // return "HTML(" + new String(getCurrentTokenSource()) + ")"; + // //$NON-NLS-1$ + case TokenNameFILE: + return "__FILE__"; //$NON-NLS-1$ + case TokenNameLINE: + return "__LINE__"; //$NON-NLS-1$ + case TokenNameCLASS_C: + return "__CLASS__"; //$NON-NLS-1$ + case TokenNameMETHOD_C: + return "__METHOD__"; //$NON-NLS-1$ + case TokenNameFUNC_C: + return "__FUNCTION__"; //$NON-NLS-1 + case TokenNameboolCAST: + return "( bool )"; //$NON-NLS-1$ + case TokenNameintCAST: + return "( int )"; //$NON-NLS-1$ + case TokenNamedoubleCAST: + return "( double )"; //$NON-NLS-1$ + case TokenNameobjectCAST: + return "( object )"; //$NON-NLS-1$ + case TokenNamestringCAST: + return "( string )"; //$NON-NLS-1$ + default: + return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$ } } - + public Scanner() { this(false, false); } + public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) { this(tokenizeComments, tokenizeWhiteSpace, false); } - public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, - boolean checkNonExternalizedStringLiterals) { - this(tokenizeComments, tokenizeWhiteSpace, - checkNonExternalizedStringLiterals, false); + + public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) { + this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false); } - public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, - boolean checkNonExternalizedStringLiterals, boolean assertMode) { - this(tokenizeComments, tokenizeWhiteSpace, - checkNonExternalizedStringLiterals, assertMode, false, null, null); + + public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals, + boolean assertMode) { + this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null); } - public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, - boolean checkNonExternalizedStringLiterals, boolean assertMode, - boolean tokenizeStrings, - char[][] taskTags, - char[][] taskPriorities) { + + public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals, + boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities) { this.eofPosition = Integer.MAX_VALUE; this.tokenizeComments = tokenizeComments; this.tokenizeWhiteSpace = tokenizeWhiteSpace; @@ -3930,13 +3979,15 @@ public class Scanner implements IScanner, ITerminalSymbols { this.assertMode = assertMode; this.encapsedStringStack = null; this.taskTags = taskTags; - this.taskPriorities = taskPriorities; + this.taskPriorities = taskPriorities; } + private void checkNonExternalizeString() throws InvalidInputException { if (currentLine == null) return; parseTags(currentLine); } + private void parseTags(NLSLine line) throws InvalidInputException { String s = new String(getCurrentTokenSource()); int pos = s.indexOf(TAG_PREFIX); @@ -3972,12 +4023,11 @@ public class Scanner implements IScanner, ITerminalSymbols { } this.wasNonExternalizedStringLiteral = true; if (nonNLSCounter != lineLength) { - System.arraycopy(this.nonNLSStrings, 0, - (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, - nonNLSCounter); + System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter); } currentLine = null; } + public final void scanEscapeCharacter() throws InvalidInputException { // the string with "\\u" is a legal string of two chars \ and u //thus we use a direct access to the source (for regular cases). @@ -3995,94 +4045,89 @@ public class Scanner implements IScanner, ITerminalSymbols { } else currentCharacter = source[currentPosition++]; switch (currentCharacter) { - case 'b' : - currentCharacter = '\b'; - break; - case 't' : - currentCharacter = '\t'; - break; - case 'n' : - currentCharacter = '\n'; - break; - case 'f' : - currentCharacter = '\f'; - break; - case 'r' : - currentCharacter = '\r'; - break; - case '\"' : - currentCharacter = '\"'; - break; - case '\'' : - currentCharacter = '\''; - break; - case '\\' : - currentCharacter = '\\'; - break; - default : - // -----------octal escape-------------- - // OctalDigit - // OctalDigit OctalDigit - // ZeroToThree OctalDigit OctalDigit - int number = Character.getNumericValue(currentCharacter); - if (number >= 0 && number <= 7) { - boolean zeroToThreeNot = number > 3; - if (Character.isDigit(currentCharacter = source[currentPosition++])) { - int digit = Character.getNumericValue(currentCharacter); - if (digit >= 0 && digit <= 7) { - number = (number * 8) + digit; - if (Character - .isDigit(currentCharacter = source[currentPosition++])) { - if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit - // Digit --> ignore last character + case 'b': + currentCharacter = '\b'; + break; + case 't': + currentCharacter = '\t'; + break; + case 'n': + currentCharacter = '\n'; + break; + case 'f': + currentCharacter = '\f'; + break; + case 'r': + currentCharacter = '\r'; + break; + case '\"': + currentCharacter = '\"'; + break; + case '\'': + currentCharacter = '\''; + break; + case '\\': + currentCharacter = '\\'; + break; + default: + // -----------octal escape-------------- + // OctalDigit + // OctalDigit OctalDigit + // ZeroToThree OctalDigit OctalDigit + int number = Character.getNumericValue(currentCharacter); + if (number >= 0 && number <= 7) { + boolean zeroToThreeNot = number > 3; + if (Character.isDigit(currentCharacter = source[currentPosition++])) { + int digit = Character.getNumericValue(currentCharacter); + if (digit >= 0 && digit <= 7) { + number = (number * 8) + digit; + if (Character.isDigit(currentCharacter = source[currentPosition++])) { + if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit + // Digit --> ignore last character + currentPosition--; + } else { + digit = Character.getNumericValue(currentCharacter); + if (digit >= 0 && digit <= 7) { // has read \ZeroToThree + // OctalDigit OctalDigit + number = (number * 8) + digit; + } else { // has read \ZeroToThree OctalDigit NonOctalDigit + // --> ignore last character currentPosition--; - } else { - digit = Character.getNumericValue(currentCharacter); - if (digit >= 0 && digit <= 7) { // has read \ZeroToThree - // OctalDigit OctalDigit - number = (number * 8) + digit; - } else { // has read \ZeroToThree OctalDigit NonOctalDigit - // --> ignore last character - currentPosition--; - } } - } else { // has read \OctalDigit NonDigit--> ignore last - // character - currentPosition--; } - } else { // has read \OctalDigit NonOctalDigit--> ignore last + } else { // has read \OctalDigit NonDigit--> ignore last // character currentPosition--; } - } else { // has read \OctalDigit --> ignore last character + } else { // has read \OctalDigit NonOctalDigit--> ignore last + // character currentPosition--; } - if (number > 255) - throw new InvalidInputException(INVALID_ESCAPE); - currentCharacter = (char) number; - } else + } else { // has read \OctalDigit --> ignore last character + currentPosition--; + } + if (number > 255) throw new InvalidInputException(INVALID_ESCAPE); + currentCharacter = (char) number; + } else + throw new InvalidInputException(INVALID_ESCAPE); } } + // chech presence of task: tags public void checkTaskTag(int commentStart, int commentEnd) { // only look for newer task: tags - if (this.foundTaskCount > 0 - && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) { + if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) { return; } int foundTaskIndex = this.foundTaskCount; - nextChar : for (int i = commentStart; i < commentEnd - && i < this.eofPosition; i++) { + nextChar: for (int i = commentStart; i < commentEnd && i < this.eofPosition; i++) { char[] tag = null; char[] priority = null; // check for tag occurrence - nextTag : for (int itag = 0; itag < this.taskTags.length; itag++) { + nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) { tag = this.taskTags[itag]; - priority = this.taskPriorities != null - && itag < this.taskPriorities.length - ? this.taskPriorities[itag] - : null; + priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null; int tagLength = tag.length; for (int t = 0; t < tagLength; t++) { if (this.source[i + t] != tag[t]) @@ -4094,23 +4139,17 @@ public class Scanner implements IScanner, ITerminalSymbols { this.foundTaskPriorities = new char[5][]; this.foundTaskPositions = new int[5][]; } else if (this.foundTaskCount == this.foundTaskTags.length) { - System.arraycopy(this.foundTaskTags, 0, - this.foundTaskTags = new char[this.foundTaskCount * 2][], 0, + System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0, this.foundTaskCount); + System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0, this.foundTaskCount); - System.arraycopy(this.foundTaskMessages, 0, - this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0, + System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0, this.foundTaskCount); - System.arraycopy(this.foundTaskPriorities, 0, - this.foundTaskPriorities = new char[this.foundTaskCount * 2][], - 0, this.foundTaskCount); - System.arraycopy(this.foundTaskPositions, 0, - this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0, + System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0, this.foundTaskCount); } this.foundTaskTags[this.foundTaskCount] = tag; this.foundTaskPriorities[this.foundTaskCount] = priority; - this.foundTaskPositions[this.foundTaskCount] = new int[]{i, - i + tagLength - 1}; + this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 }; this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR; this.foundTaskCount++; i += tagLength - 1; // will be incremented when looping @@ -4118,11 +4157,8 @@ public class Scanner implements IScanner, ITerminalSymbols { } for (int i = foundTaskIndex; i < this.foundTaskCount; i++) { // retrieve message start and end positions - int msgStart = this.foundTaskPositions[i][0] - + this.foundTaskTags[i].length; - int max_value = i + 1 < this.foundTaskCount - ? this.foundTaskPositions[i + 1][0] - 1 - : commentEnd - 1; + int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length; + int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1; // at most beginning of next task if (max_value < msgStart) max_value = msgStart; // would only occur if tag is before EOF. @@ -4160,4 +4196,4 @@ public class Scanner implements IScanner, ITerminalSymbols { this.foundTaskMessages[i] = message; } } -} +} \ No newline at end of file -- 1.7.1 From 629cd9e25ebed77406bce8679dd45f7f17ebc67f Mon Sep 17 00:00:00 2001 From: axelcl Date: Wed, 10 Nov 2004 20:26:44 +0000 Subject: [PATCH 08/16] misc --- .../internal/corext/template/php/JavaContext.java | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/JavaContext.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/JavaContext.java index 2ce6d3e..09b5fb0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/JavaContext.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/php/JavaContext.java @@ -120,7 +120,7 @@ public class JavaContext extends CompilationUnitContext { JavaFormatter formatter = new JavaFormatter(lineDelimiter, getIndentation(), useCodeFormatter); formatter.format(buffer, this); - // debug start + // debug start // String res = buffer.getString(); // res = res.replaceAll("\n","/n"); // res = res.replaceAll("\t","/t"); -- 1.7.1 From a006c2ae0f319eb7cf1a96ee98cadf9a61589bca Mon Sep 17 00:00:00 2001 From: axelcl Date: Wed, 10 Nov 2004 20:39:32 +0000 Subject: [PATCH 09/16] misc --- .../ui/text/rules/MultiViewPartitioner.java | 48 +++++++++++++------ 1 files changed, 33 insertions(+), 15 deletions(-) diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java index 204c16c..d04d657 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java @@ -8,7 +8,7 @@ * Contributors: * Igor Malinin - initial contribution * - * $Id: MultiViewPartitioner.java,v 1.4 2004-10-25 17:03:28 axelcl Exp $ + * $Id: MultiViewPartitioner.java,v 1.5 2004-11-10 20:39:32 axelcl Exp $ */ package net.sourceforge.phpeclipse.ui.text.rules; @@ -116,11 +116,21 @@ public abstract class MultiViewPartitioner extends AbstractPartitioner { if (DEBUG) { Assert.isTrue(position.offset >= 0, Integer.toString(position.offset)); } - DocumentEvent event = new DocumentEvent(outerDocument, outerDocument.getLocalOffset(position.offset), position.length, null); - - outerDocument.fireDocumentAboutToBeChanged(event); + int outerOffset = outerDocument.getLocalOffset(position.offset); + // axelcl start + DocumentEvent event = null; + if (outerOffset>=0) { + // axelcl end + event = new DocumentEvent(outerDocument, outerOffset, position.length, null); + + outerDocument.fireDocumentAboutToBeChanged(event); + } super.addInnerRegion(position); - outerDocument.fireDocumentChanged(event); +// axelcl start + if (event != null) { + // axelcl end + outerDocument.fireDocumentChanged(event); + } } else { super.addInnerRegion(position); } @@ -147,15 +157,14 @@ public abstract class MultiViewPartitioner extends AbstractPartitioner { if (position.offset >= 0 && position.length >= 0) { int outerOffset = outerDocument.getLocalOffset(position.offset); if (outerOffset > 0) { - event = new DocumentEvent(outerDocument, outerOffset, 0, document.get( - position.offset, position.length)); + event = new DocumentEvent(outerDocument, outerOffset, 0, document.get(position.offset, position.length)); outerDocument.fireDocumentAboutToBeChanged(event); } } super.removeInnerRegion(position); if (position.offset >= 0) { - if (event!=null) { + if (event != null) { outerDocument.fireDocumentChanged(event); } } @@ -603,16 +612,25 @@ public abstract class MultiViewPartitioner extends AbstractPartitioner { end = document.getLength(); type = getContentType(null, IDocument.DEFAULT_CONTENT_TYPE); } else { - ITypedRegion region = outerDocument.getPartition(outerDocument.getLocalOffset(offset)); + int outerOffset = outerDocument.getLocalOffset(offset); + //axelcl start + if (outerOffset < 0) { + start = 0; + end = document.getLength(); + type = getContentType(null, IDocument.DEFAULT_CONTENT_TYPE); + } else { +// axelcl end + ITypedRegion region = outerDocument.getPartition(outerOffset); - start = region.getOffset(); - end = start + region.getLength(); + start = region.getOffset(); + end = start + region.getLength(); - // convert to parent offset - start = outerDocument.getParentOffset(start); - end = outerDocument.getParentOffset(end); + // convert to parent offset + start = outerDocument.getParentOffset(start); + end = outerDocument.getParentOffset(end); - type = getContentType(null, region.getType()); + type = getContentType(null, region.getType()); + } } if (prev != null) { -- 1.7.1 From 6a37bf4ee6752aaedd465900e17a850a98353daa Mon Sep 17 00:00:00 2001 From: axelcl Date: Thu, 11 Nov 2004 16:54:55 +0000 Subject: [PATCH 10/16] CVS test --- net.sourceforge.phpeclipse.tests/test.php | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/net.sourceforge.phpeclipse.tests/test.php b/net.sourceforge.phpeclipse.tests/test.php index 5413c2e..399e711 100644 --- a/net.sourceforge.phpeclipse.tests/test.php +++ b/net.sourceforge.phpeclipse.tests/test.php @@ -2,8 +2,6 @@ // CVS commit tests phpinfo(); - - phpinfo(); - + // test //? ?> \ No newline at end of file -- 1.7.1 From 5e83139b115810919aae938dcbafd8f2535e21c2 Mon Sep 17 00:00:00 2001 From: axelcl Date: Thu, 11 Nov 2004 16:55:31 +0000 Subject: [PATCH 11/16] CVS test --- net.sourceforge.phpeclipse.tests/test.php | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/net.sourceforge.phpeclipse.tests/test.php b/net.sourceforge.phpeclipse.tests/test.php index 399e711..1073d68 100644 --- a/net.sourceforge.phpeclipse.tests/test.php +++ b/net.sourceforge.phpeclipse.tests/test.php @@ -2,6 +2,6 @@ // CVS commit tests phpinfo(); - // test + //? ?> \ No newline at end of file -- 1.7.1 From e049c859efd713a5320f2980ec760cf87d2da302 Mon Sep 17 00:00:00 2001 From: axelcl Date: Thu, 11 Nov 2004 16:55:52 +0000 Subject: [PATCH 12/16] CVS test --- net.sourceforge.phpeclipse.tests/test.php | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net.sourceforge.phpeclipse.tests/test.php b/net.sourceforge.phpeclipse.tests/test.php index 1073d68..fa733f2 100644 --- a/net.sourceforge.phpeclipse.tests/test.php +++ b/net.sourceforge.phpeclipse.tests/test.php @@ -2,6 +2,6 @@ // CVS commit tests phpinfo(); - + // safsadfas //? -?> \ No newline at end of file +?> \ No newline at end of file -- 1.7.1 From b5245aee3b6e499bace2810f8bd50b6d93ea228a Mon Sep 17 00:00:00 2001 From: axelcl Date: Thu, 11 Nov 2004 16:56:11 +0000 Subject: [PATCH 13/16] CVS test --- net.sourceforge.phpeclipse.tests/test.php | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/net.sourceforge.phpeclipse.tests/test.php b/net.sourceforge.phpeclipse.tests/test.php index fa733f2..e12766c 100644 --- a/net.sourceforge.phpeclipse.tests/test.php +++ b/net.sourceforge.phpeclipse.tests/test.php @@ -2,6 +2,6 @@ // CVS commit tests phpinfo(); - // safsadfas + //? ?> \ No newline at end of file -- 1.7.1 From 403f1e605308d6fd24532d7e09cb97bb2fdfe241 Mon Sep 17 00:00:00 2001 From: axelcl Date: Fri, 12 Nov 2004 13:06:39 +0000 Subject: [PATCH 14/16] fixed update conflict and outline update bug --- .../src/net/sourceforge/phpdt/core/JavaCore.java | 16 + .../phpdt/core/util/ICacheEnumeration.java | 39 - .../sourceforge/phpdt/core/util/ILRUCacheable.java | 28 - .../net/sourceforge/phpdt/core/util/LRUCache.java | 499 ------------- .../phpdt/core/util/ToStringSorter.java | 75 -- .../internal/core/CommitWorkingCopyOperation.java | 355 +++++----- .../phpdt/internal/core/CompilationUnit.java | 70 ++- .../phpdt/internal/core/DeltaProcessor.java | 738 +++++++++++++------- .../phpdt/internal/core/JavaElementDelta.java | 7 +- .../phpdt/internal/core/builder/PHPBuilder.java | 16 + .../phpdt/internal/corext/util/Resources.java | 188 +++++ .../sourceforge/phpeclipse/PHPeclipsePlugin.java | 14 +- .../ICompilationUnitDocumentProvider.java | 84 +++ .../phpeclipse/phpeditor/PHPDocumentProvider.java | 148 +++-- .../phpeclipse/phpeditor/PHPUnitEditor.java | 69 ++- .../phpeclipse/phpeditor/WorkingCopyManager.java | 5 +- 16 files changed, 1184 insertions(+), 1167 deletions(-) delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ICacheEnumeration.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ILRUCacheable.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/LRUCache.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ToStringSorter.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/Resources.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ICompilationUnitDocumentProvider.java diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java index 9ae3318..64872e2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java @@ -26,6 +26,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.ISavedState; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; @@ -1610,6 +1611,21 @@ public class JavaCore { } /** + * Adds the given listener for POST_CHANGE resource change events to the Java core. + * The listener is guarantied to be notified of the POST_CHANGE resource change event before + * the Java core starts processing the resource change event itself. + *

+ * Has no effect if an identical listener is already registered. + *

+ * + * @param listener the listener + * @see #removePreProcessingResourceChangedListener(IResourceChangeListener) + * @since 3.0 + */ + public static void addPreProcessingResourceChangedListener(IResourceChangeListener listener) { + JavaModelManager.getJavaModelManager().deltaState.addPreResourceChangedListener(listener); + } + /** * Configures the given marker for the given Java element. Used for markers, * which denote a Java element rather than a resource. * diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ICacheEnumeration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ICacheEnumeration.java deleted file mode 100644 index c1cbc30..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ICacheEnumeration.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpdt.core.util; - -import java.util.Enumeration; - -/** - * The ICacheEnumeration is used to iterate over both the keys - * and values in an LRUCache. The getValue() method returns the - * value of the last key to be retrieved using nextElement(). - * The nextElement() method must be called before the - * getValue() method. - * - *

The iteration can be made efficient by making use of the fact that values in - * the cache (instances of LRUCacheEntry), know their key. For this reason, - * Hashtable lookups don't have to be made at each step of the iteration. - * - *

Modifications to the cache must not be performed while using the - * enumeration. Doing so will lead to an illegal state. - * - * @see LRUCache - */ -public interface ICacheEnumeration extends Enumeration { - /** - * Returns the value of the previously accessed key in the enumeration. - * Must be called after a call to nextElement(). - * - * @return Value of current cache entry - */ - public Object getValue(); -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ILRUCacheable.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ILRUCacheable.java deleted file mode 100644 index d6da8b9..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ILRUCacheable.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpdt.core.util; - -/** - * Types implementing this interface can occupy a variable amount of space - * in an LRUCache. Cached items that do not implement this interface are - * considered to occupy one unit of space. - * - * @see LRUCache - */ -public interface ILRUCacheable { - /** - * Returns the space the receiver consumes in an LRU Cache. The default space - * value is 1. - * - * @return int Amount of cache space taken by the receiver - */ - public int getCacheFootprint(); -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/LRUCache.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/LRUCache.java deleted file mode 100644 index 5d715ce..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/LRUCache.java +++ /dev/null @@ -1,499 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpdt.core.util; - -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * The LRUCache is a hashtable that stores a finite number of elements. - * When an attempt is made to add values to a full cache, the least recently used values - * in the cache are discarded to make room for the new values as necessary. - * - *

The data structure is based on the LRU virtual memory paging scheme. - * - *

Objects can take up a variable amount of cache space by implementing - * the ILRUCacheable interface. - * - *

This implementation is NOT thread-safe. Synchronization wrappers would - * have to be added to ensure atomic insertions and deletions from the cache. - * - * @see org.eclipse.jdt.internal.core.util.ILRUCacheable - */ -public class LRUCache implements Cloneable { - - /** - * This type is used internally by the LRUCache to represent entries - * stored in the cache. - * It is static because it does not require a pointer to the cache - * which contains it. - * - * @see LRUCache - */ - protected static class LRUCacheEntry { - - /** - * Hash table key - */ - public Object _fKey; - - /** - * Hash table value (an LRUCacheEntry object) - */ - public Object _fValue; - - /** - * Time value for queue sorting - */ - public int _fTimestamp; - - /** - * Cache footprint of this entry - */ - public int _fSpace; - - /** - * Previous entry in queue - */ - public LRUCacheEntry _fPrevious; - - /** - * Next entry in queue - */ - public LRUCacheEntry _fNext; - - /** - * Creates a new instance of the receiver with the provided values - * for key, value, and space. - */ - public LRUCacheEntry (Object key, Object value, int space) { - _fKey = key; - _fValue = value; - _fSpace = space; - } - - /** - * Returns a String that represents the value of this object. - */ - public String toString() { - - return "LRUCacheEntry [" + _fKey + "-->" + _fValue + "]"; //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Amount of cache space used so far - */ - protected int fCurrentSpace; - - /** - * Maximum space allowed in cache - */ - protected int fSpaceLimit; - - /** - * Counter for handing out sequential timestamps - */ - protected int fTimestampCounter; - - /** - * Hash table for fast random access to cache entries - */ - protected Hashtable fEntryTable; - - /** - * Start of queue (most recently used entry) - */ - protected LRUCacheEntry fEntryQueue; - - /** - * End of queue (least recently used entry) - */ - protected LRUCacheEntry fEntryQueueTail; - - /** - * Default amount of space in the cache - */ - protected static final int DEFAULT_SPACELIMIT = 100; - /** - * Creates a new cache. Size of cache is defined by - * DEFAULT_SPACELIMIT. - */ - public LRUCache() { - - this(DEFAULT_SPACELIMIT); - } - /** - * Creates a new cache. - * @param size Size of Cache - */ - public LRUCache(int size) { - - fTimestampCounter = fCurrentSpace = 0; - fEntryQueue = fEntryQueueTail = null; - fEntryTable = new Hashtable(size); - fSpaceLimit = size; - } - /** - * Returns a new cache containing the same contents. - * - * @return New copy of object. - */ - public Object clone() { - - LRUCache newCache = newInstance(fSpaceLimit); - LRUCacheEntry qEntry; - - /* Preserve order of entries by copying from oldest to newest */ - qEntry = this.fEntryQueueTail; - while (qEntry != null) { - newCache.privateAdd (qEntry._fKey, qEntry._fValue, qEntry._fSpace); - qEntry = qEntry._fPrevious; - } - return newCache; - } - /** - * Flushes all entries from the cache. - */ - public void flush() { - - fCurrentSpace = 0; - LRUCacheEntry entry = fEntryQueueTail; // Remember last entry - fEntryTable = new Hashtable(); // Clear it out - fEntryQueue = fEntryQueueTail = null; - while (entry != null) { // send deletion notifications in LRU order - privateNotifyDeletionFromCache(entry); - entry = entry._fPrevious; - } - } - /** - * Flushes the given entry from the cache. Does nothing if entry does not - * exist in cache. - * - * @param key Key of object to flush - */ - public void flush (Object key) { - - LRUCacheEntry entry; - - entry = (LRUCacheEntry) fEntryTable.get(key); - - /* If entry does not exist, return */ - if (entry == null) return; - - this.privateRemoveEntry (entry, false); - } - /** - * Answers the value in the cache at the given key. - * If the value is not in the cache, returns null - * - * @param key Hash table key of object to retrieve - * @return Retreived object, or null if object does not exist - */ - public Object get(Object key) { - - LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key); - if (entry == null) { - return null; - } - - this.updateTimestamp (entry); - return entry._fValue; - } - /** - * Returns the amount of space that is current used in the cache. - */ - public int getCurrentSpace() { - return fCurrentSpace; - } - /** - * Returns the maximum amount of space available in the cache. - */ - public int getSpaceLimit() { - return fSpaceLimit; - } - /** - * Returns an Enumeration of the keys currently in the cache. - */ - public Enumeration keys() { - - return fEntryTable.keys(); - } - /** - * Returns an enumeration that iterates over all the keys and values - * currently in the cache. - */ - public ICacheEnumeration keysAndValues() { - return new ICacheEnumeration() { - - Enumeration fValues = fEntryTable.elements(); - LRUCacheEntry fEntry; - - public boolean hasMoreElements() { - return fValues.hasMoreElements(); - } - - public Object nextElement() { - fEntry = (LRUCacheEntry) fValues.nextElement(); - return fEntry._fKey; - } - - public Object getValue() { - if (fEntry == null) { - throw new java.util.NoSuchElementException(); - } - return fEntry._fValue; - } - }; - } - /** - * Ensures there is the specified amount of free space in the receiver, - * by removing old entries if necessary. Returns true if the requested space was - * made available, false otherwise. - * - * @param space Amount of space to free up - */ - protected boolean makeSpace (int space) { - - int limit; - - limit = this.getSpaceLimit(); - - /* if space is already available */ - if (fCurrentSpace + space <= limit) { - return true; - } - - /* if entry is too big for cache */ - if (space > limit) { - return false; - } - - /* Free up space by removing oldest entries */ - while (fCurrentSpace + space > limit && fEntryQueueTail != null) { - this.privateRemoveEntry (fEntryQueueTail, false); - } - return true; - } - /** - * Returns a new LRUCache instance - */ - protected LRUCache newInstance(int size) { - return new LRUCache(size); - } - /** - * Adds an entry for the given key/value/space. - */ - protected void privateAdd (Object key, Object value, int space) { - - LRUCacheEntry entry; - - entry = new LRUCacheEntry(key, value, space); - this.privateAddEntry (entry, false); - } - /** - * Adds the given entry from the receiver. - * @param shuffle Indicates whether we are just shuffling the queue - * (in which case, the entry table is not modified). - */ - protected void privateAddEntry (LRUCacheEntry entry, boolean shuffle) { - - if (!shuffle) { - fEntryTable.put (entry._fKey, entry); - fCurrentSpace += entry._fSpace; - } - - entry._fTimestamp = fTimestampCounter++; - entry._fNext = this.fEntryQueue; - entry._fPrevious = null; - - if (fEntryQueue == null) { - /* this is the first and last entry */ - fEntryQueueTail = entry; - } else { - fEntryQueue._fPrevious = entry; - } - - fEntryQueue = entry; - } - /** - * An entry has been removed from the cache, for example because it has - * fallen off the bottom of the LRU queue. - * Subclasses could over-ride this to implement a persistent cache below the LRU cache. - */ - protected void privateNotifyDeletionFromCache(LRUCacheEntry entry) { - // Default is NOP. - } - /** - * Removes the entry from the entry queue. - * @param shuffle indicates whether we are just shuffling the queue - * (in which case, the entry table is not modified). - */ - protected void privateRemoveEntry (LRUCacheEntry entry, boolean shuffle) { - - LRUCacheEntry previous, next; - - previous = entry._fPrevious; - next = entry._fNext; - - if (!shuffle) { - fEntryTable.remove(entry._fKey); - fCurrentSpace -= entry._fSpace; - privateNotifyDeletionFromCache(entry); - } - - /* if this was the first entry */ - if (previous == null) { - fEntryQueue = next; - } else { - previous._fNext = next; - } - - /* if this was the last entry */ - if (next == null) { - fEntryQueueTail = previous; - } else { - next._fPrevious = previous; - } - } - /** - * Sets the value in the cache at the given key. Returns the value. - * - * @param key Key of object to add. - * @param value Value of object to add. - * @return added value. - */ - public Object put(Object key, Object value) { - - int newSpace, oldSpace, newTotal; - LRUCacheEntry entry; - - /* Check whether there's an entry in the cache */ - newSpace = spaceFor (key, value); - entry = (LRUCacheEntry) fEntryTable.get (key); - - if (entry != null) { - - /** - * Replace the entry in the cache if it would not overflow - * the cache. Otherwise flush the entry and re-add it so as - * to keep cache within budget - */ - oldSpace = entry._fSpace; - newTotal = getCurrentSpace() - oldSpace + newSpace; - if (newTotal <= getSpaceLimit()) { - updateTimestamp (entry); - entry._fValue = value; - entry._fSpace = newSpace; - this.fCurrentSpace = newTotal; - return value; - } else { - privateRemoveEntry (entry, false); - } - } - if (makeSpace(newSpace)) { - privateAdd (key, value, newSpace); - } - return value; - } - /** - * Removes and returns the value in the cache for the given key. - * If the key is not in the cache, returns null. - * - * @param key Key of object to remove from cache. - * @return Value removed from cache. - */ - public Object removeKey (Object key) { - - LRUCacheEntry entry = (LRUCacheEntry) fEntryTable.get(key); - if (entry == null) { - return null; - } - Object value = entry._fValue; - this.privateRemoveEntry (entry, false); - return value; - } - /** - * Sets the maximum amount of space that the cache can store - * - * @param limit Number of units of cache space - */ - public void setSpaceLimit(int limit) { - if (limit < fSpaceLimit) { - makeSpace(fSpaceLimit - limit); - } - fSpaceLimit = limit; - } - /** - * Returns the space taken by the given key and value. - */ - protected int spaceFor (Object key, Object value) { - - if (value instanceof ILRUCacheable) { - return ((ILRUCacheable) value).getCacheFootprint(); - } else { - return 1; - } - } -/** - * Returns a String that represents the value of this object. This method - * is for debugging purposes only. - */ -public String toString() { - return - "LRUCache " + (fCurrentSpace * 100.0 / fSpaceLimit) + "% full\n" + //$NON-NLS-1$ //$NON-NLS-2$ - this.toStringContents(); -} -/** - * Returns a String that represents the contents of this object. This method - * is for debugging purposes only. - */ -protected String toStringContents() { - StringBuffer result = new StringBuffer(); - int length = fEntryTable.size(); - Object[] unsortedKeys = new Object[length]; - String[] unsortedToStrings = new String[length]; - Enumeration e = this.keys(); - for (int i = 0; i < length; i++) { - Object key = e.nextElement(); - unsortedKeys[i] = key; -// unsortedToStrings[i] = -// (key instanceof org.eclipse.jdt.internal.core.JavaElement) ? -// ((org.eclipse.jdt.internal.core.JavaElement)key).getElementName() : -// key.toString(); - unsortedToStrings[i] = key.toString(); - } - ToStringSorter sorter = new ToStringSorter(); - sorter.sort(unsortedKeys, unsortedToStrings); - for (int i = 0; i < length; i++) { - String toString = sorter.sortedStrings[i]; - Object value = this.get(sorter.sortedObjects[i]); - result.append(toString); - result.append(" -> "); //$NON-NLS-1$ - result.append(value); - result.append("\n"); //$NON-NLS-1$ - } - return result.toString(); -} - /** - * Updates the timestamp for the given entry, ensuring that the queue is - * kept in correct order. The entry must exist - */ - protected void updateTimestamp (LRUCacheEntry entry) { - - entry._fTimestamp = fTimestampCounter++; - if (fEntryQueue != entry) { - this.privateRemoveEntry (entry, true); - this.privateAddEntry (entry, true); - } - return; - } -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ToStringSorter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ToStringSorter.java deleted file mode 100644 index ce4ed4f..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/util/ToStringSorter.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpdt.core.util; - -/** - * The SortOperation takes a collection of objects and returns - * a sorted collection of these objects. The sorting of these - * objects is based on their toString(). They are sorted in - * alphabetical order. - */ -public class ToStringSorter { - Object[] sortedObjects; - String[] sortedStrings; -/** - * Returns true if stringTwo is 'greater than' stringOne - * This is the 'ordering' method of the sort operation. - */ -public boolean compare(String stringOne, String stringTwo) { - return stringOne.compareTo(stringTwo) < 0; -} -/** - * Sort the objects in sorted collection and return that collection. - */ -private void quickSort(int left, int right) { - int originalLeft = left; - int originalRight = right; - int midIndex = (left + right) / 2; - String midToString = this.sortedStrings[midIndex]; - - do { - while (compare(this.sortedStrings[left], midToString)) - left++; - while (compare(midToString, this.sortedStrings[right])) - right--; - if (left <= right) { - Object tmp = this.sortedObjects[left]; - this.sortedObjects[left] = this.sortedObjects[right]; - this.sortedObjects[right] = tmp; - String tmpToString = this.sortedStrings[left]; - this.sortedStrings[left] = this.sortedStrings[right]; - this.sortedStrings[right] = tmpToString; - left++; - right--; - } - } while (left <= right); - - if (originalLeft < right) - quickSort(originalLeft, right); - if (left < originalRight) - quickSort(left, originalRight); -} -/** - * Return a new sorted collection from this unsorted collection. - * Sort using quick sort. - */ -public void sort(Object[] unSortedObjects, String[] unsortedStrings) { - int size = unSortedObjects.length; - this.sortedObjects = new Object[size]; - this.sortedStrings = new String[size]; - - //copy the array so can return a new sorted collection - System.arraycopy(unSortedObjects, 0, this.sortedObjects, 0, size); - System.arraycopy(unsortedStrings, 0, this.sortedStrings, 0, size); - if (size > 1) - quickSort(0, size - 1); -} -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CommitWorkingCopyOperation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CommitWorkingCopyOperation.java index 3c1285c..839b8cd 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CommitWorkingCopyOperation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CommitWorkingCopyOperation.java @@ -27,189 +27,180 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.jobs.ISchedulingRule; - /** - * Commits the contents of a working copy compilation - * unit to its original element and resource, bringing - * the Java Model up-to-date with the current contents of the working - * copy. - * - *

It is possible that the contents of the - * original resource have changed since the working copy was created, - * in which case there is an update conflict. This operation allows - * for two settings to resolve conflict set by the fForce flag:

    - *
  • force flag is false - in this case an JavaModelException - * is thrown
  • - *
  • force flag is true - in this case the contents of - * the working copy are applied to the underlying resource even though - * the working copy was created before a subsequent change in the - * resource
  • + * Commits the contents of a working copy compilation unit to its original element and resource, bringing the Java Model up-to-date + * with the current contents of the working copy. + * + *

    + * It is possible that the contents of the original resource have changed since the working copy was created, in which case there is + * an update conflict. This operation allows for two settings to resolve conflict set by the fForce flag: + *

      + *
    • force flag is false- in this case an JavaModelException is thrown
    • + *
    • force flag is true- in this case the contents of the working copy are applied to the underlying resource + * even though the working copy was created before a subsequent change in the resource
    • *
    - * - *

    The default conflict resolution setting is the force flag is false - * - * A JavaModelOperation exception is thrown either if the commit could not - * be performed or if the new content of the compilation unit violates some Java Model - * constraint (e.g. if the new package declaration doesn't match the name of the folder - * containing the compilation unit). + * + *

    + * The default conflict resolution setting is the force flag is false + * + * A JavaModelOperation exception is thrown either if the commit could not be performed or if the new content of the compilation + * unit violates some Java Model constraint (e.g. if the new package declaration doesn't match the name of the folder containing the + * compilation unit). */ public class CommitWorkingCopyOperation extends JavaModelOperation { - /** - * Constructs an operation to commit the contents of a working copy - * to its original compilation unit. - */ - public CommitWorkingCopyOperation(ICompilationUnit element, boolean force) { - super(new IJavaElement[] {element}, force); - } - /** - * @exception JavaModelException if setting the source - * of the original compilation unit fails - */ - protected void executeOperation() throws JavaModelException { - try { - beginTask(Util.bind("workingCopy.commit"), 2); //$NON-NLS-1$ - CompilationUnit workingCopy = getCompilationUnit(); - IFile resource = (IFile)workingCopy.getResource(); - ICompilationUnit primary = workingCopy.getPrimary(); - boolean isPrimary = workingCopy.isPrimary(); - - JavaElementDeltaBuilder deltaBuilder = null; -// PackageFragmentRoot root = (PackageFragmentRoot)workingCopy.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); - boolean isIncluded = !Util.isExcluded(workingCopy); -// if (isPrimary || (root.isOnClasspath() && isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName()))) { - if (isPrimary || (isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName()))) { - - // force opening so that the delta builder can get the old info - if (!isPrimary && !primary.isOpen()) { - primary.open(null); - } - - // creates the delta builder (this remembers the content of the cu) if: - // - it is not excluded - // - and it is not a primary or it is a non-consistent primary - if (isIncluded && (!isPrimary || !workingCopy.isConsistent())) { - deltaBuilder = new JavaElementDeltaBuilder(primary); - } - - // save the cu - IBuffer primaryBuffer = primary.getBuffer(); - if (!isPrimary) { - if (primaryBuffer == null) return; - char[] primaryContents = primaryBuffer.getCharacters(); - boolean hasSaved = false; - try { - IBuffer workingCopyBuffer = workingCopy.getBuffer(); - if (workingCopyBuffer == null) return; - primaryBuffer.setContents(workingCopyBuffer.getCharacters()); - primaryBuffer.save(this.progressMonitor, this.force); - primary.makeConsistent(this); - hasSaved = true; - } finally { - if (!hasSaved){ - // restore original buffer contents since something went wrong - primaryBuffer.setContents(primaryContents); - } - } - } else { - // for a primary working copy no need to set the content of the buffer again - primaryBuffer.save(this.progressMonitor, this.force); - primary.makeConsistent(this); - } - } else { - // working copy on cu outside classpath OR resource doesn't exist yet - String encoding = null; - try { - encoding = resource.getCharset(); - } - catch (CoreException ce) { - // use no encoding - } - String contents = workingCopy.getSource(); - if (contents == null) return; - try { - byte[] bytes = encoding == null - ? contents.getBytes() - : contents.getBytes(encoding); - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - if (resource.exists()) { - resource.setContents( - stream, - this.force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, - null); - } else { - resource.create( - stream, - this.force, - this.progressMonitor); - } - } catch (CoreException e) { - throw new JavaModelException(e); - } catch (UnsupportedEncodingException e) { - throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); - } - - } - - setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); - - // make sure working copy is in sync - workingCopy.updateTimeStamp((CompilationUnit)primary); - workingCopy.makeConsistent(this); - worked(1); - - // build the deltas - if (deltaBuilder != null) { - deltaBuilder.buildDeltas(); - - // add the deltas to the list of deltas created during this operation - if (deltaBuilder.delta != null) { - addDelta(deltaBuilder.delta); - } - } - worked(1); - } finally { - done(); - } - } - - /** - * Returns the compilation unit this operation is working on. - */ - protected CompilationUnit getCompilationUnit() { - return (CompilationUnit)getElementToProcess(); - } - protected ISchedulingRule getSchedulingRule() { - IResource resource = getElementToProcess().getResource(); - IWorkspace workspace = resource.getWorkspace(); - if (resource.exists()) { - return workspace.getRuleFactory().modifyRule(resource); - } else { - return workspace.getRuleFactory().createRule(resource); - } - } - /** - * Possible failures:

      - *
    • INVALID_ELEMENT_TYPES - the compilation unit supplied to this - * operation is not a working copy - *
    • ELEMENT_NOT_PRESENT - the compilation unit the working copy is - * based on no longer exists. - *
    • UPDATE_CONFLICT - the original compilation unit has changed since - * the working copy was created and the operation specifies no force - *
    • READ_ONLY - the original compilation unit is in read-only mode - *
    - */ - public IJavaModelStatus verify() { - ICompilationUnit cu = getCompilationUnit(); - if (!cu.isWorkingCopy()) { - return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, cu); - } - ICompilationUnit original= (ICompilationUnit)cu.getOriginalElement(); - IResource resource = original.getResource(); - if (!cu.isBasedOn(resource) && !force) { - return new JavaModelStatus(IJavaModelStatusConstants.UPDATE_CONFLICT); - } - // no read-only check, since some repository adapters can change the flag on save - // operation. - return JavaModelStatus.VERIFIED_OK; - } -} + /** + * Constructs an operation to commit the contents of a working copy to its original compilation unit. + */ + public CommitWorkingCopyOperation(ICompilationUnit element, boolean force) { + super(new IJavaElement[] { element }, force); + } + + /** + * @exception JavaModelException + * if setting the source of the original compilation unit fails + */ + protected void executeOperation() throws JavaModelException { + try { + beginTask(Util.bind("workingCopy.commit"), 2); //$NON-NLS-1$ + CompilationUnit workingCopy = getCompilationUnit(); + IFile resource = (IFile) workingCopy.getResource(); + ICompilationUnit primary = workingCopy.getPrimary(); + boolean isPrimary = workingCopy.isPrimary(); + + JavaElementDeltaBuilder deltaBuilder = null; + // PackageFragmentRoot root = (PackageFragmentRoot)workingCopy.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); + boolean isIncluded = !Util.isExcluded(workingCopy); + // if (isPrimary || (root.isOnClasspath() && isIncluded && resource.isAccessible() && + // Util.isValidCompilationUnitName(workingCopy.getElementName()))) { + if (isPrimary || (isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName()))) { + + // force opening so that the delta builder can get the old info + if (!isPrimary && !primary.isOpen()) { + primary.open(null); + } + + // creates the delta builder (this remembers the content of the cu) if: + // - it is not excluded + // - and it is not a primary or it is a non-consistent primary + if (isIncluded && (!isPrimary || !workingCopy.isConsistent())) { + deltaBuilder = new JavaElementDeltaBuilder(primary); + } + + // save the cu + IBuffer primaryBuffer = primary.getBuffer(); + if (!isPrimary) { + if (primaryBuffer == null) + return; + char[] primaryContents = primaryBuffer.getCharacters(); + boolean hasSaved = false; + try { + IBuffer workingCopyBuffer = workingCopy.getBuffer(); + if (workingCopyBuffer == null) + return; + primaryBuffer.setContents(workingCopyBuffer.getCharacters()); + primaryBuffer.save(this.progressMonitor, this.force); + primary.makeConsistent(this); + hasSaved = true; + } finally { + if (!hasSaved) { + // restore original buffer contents since something went wrong + primaryBuffer.setContents(primaryContents); + } + } + } else { + // for a primary working copy no need to set the content of the buffer again + primaryBuffer.save(this.progressMonitor, this.force); + primary.makeConsistent(this); + } + } else { + // working copy on cu outside classpath OR resource doesn't exist yet + String encoding = null; + try { + encoding = resource.getCharset(); + } catch (CoreException ce) { + // use no encoding + } + String contents = workingCopy.getSource(); + if (contents == null) + return; + try { + byte[] bytes = encoding == null ? contents.getBytes() : contents.getBytes(encoding); + ByteArrayInputStream stream = new ByteArrayInputStream(bytes); + if (resource.exists()) { + resource.setContents(stream, this.force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, null); + } else { + resource.create(stream, this.force, this.progressMonitor); + } + } catch (CoreException e) { + throw new JavaModelException(e); + } catch (UnsupportedEncodingException e) { + throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); + } + + } + + setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); + + // make sure working copy is in sync + workingCopy.updateTimeStamp((CompilationUnit) primary); + workingCopy.makeConsistent(this); + worked(1); + + // build the deltas + if (deltaBuilder != null) { + deltaBuilder.buildDeltas(); + + // add the deltas to the list of deltas created during this operation + if (deltaBuilder.delta != null) { + addDelta(deltaBuilder.delta); + } + } + worked(1); + } finally { + done(); + } + } + + /** + * Returns the compilation unit this operation is working on. + */ + protected CompilationUnit getCompilationUnit() { + return (CompilationUnit) getElementToProcess(); + } + + protected ISchedulingRule getSchedulingRule() { + IResource resource = getElementToProcess().getResource(); + IWorkspace workspace = resource.getWorkspace(); + if (resource.exists()) { + return workspace.getRuleFactory().modifyRule(resource); + } else { + return workspace.getRuleFactory().createRule(resource); + } + } + + /** + * Possible failures: + *
      + *
    • INVALID_ELEMENT_TYPES - the compilation unit supplied to this operation is not a working copy + *
    • ELEMENT_NOT_PRESENT - the compilation unit the working copy is based on no longer exists. + *
    • UPDATE_CONFLICT - the original compilation unit has changed since the working copy was created and the operation specifies + * no force + *
    • READ_ONLY - the original compilation unit is in read-only mode + *
    + */ + public IJavaModelStatus verify() { + CompilationUnit cu = getCompilationUnit(); + if (!cu.isWorkingCopy()) { + return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, cu); + } + if (cu.hasResourceChanged() && !this.force) { + // axelcl deleted start - force it to VERIFIED_OK, need to be fixed + // return new JavaModelStatus(IJavaModelStatusConstants.UPDATE_CONFLICT); + // axelcl end + } + + // no read-only check, since some repository adapters can change the flag on save + // operation. + return JavaModelStatus.VERIFIED_OK; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnit.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnit.java index 95511d9..feeabcc 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnit.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnit.java @@ -219,7 +219,8 @@ protected boolean buildStructure(OpenableElementInfo info, final IProgressMonito * @see IWorkingCopy#commit(boolean, IProgressMonitor) */ public void commit(boolean force, IProgressMonitor monitor) throws JavaModelException { - throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this)); + commitWorkingCopy(force, monitor); +// throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this)); } /** * @see ICompilationUnit#commitWorkingCopy(boolean, IProgressMonitor) @@ -440,31 +441,31 @@ public ICompilationUnit findWorkingCopy(WorkingCopyOwner workingCopyOwner) { } } } -protected boolean generateInfos(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { - -// if (getParent() instanceof JarPackageFragment) { -// // ignore .java files in jar -// throw newNotPresentException(); -// } else { - // put the info now, because getting the contents requires it - JavaModelManager.getJavaModelManager().putInfo(this, info); - CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info; - - // generate structure - CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo, newElements); - IProblemFactory factory = new DefaultProblemFactory(); - SourceElementParser parser = new SourceElementParser(requestor, factory, new CompilerOptions(getJavaProject().getOptions(true))); -// SourceElementParser parser = new SourceElementParser(requestor, factory); - requestor.parser = parser; - parser.parseCompilationUnit(this, false); - if (isWorkingCopy()) { - CompilationUnit original = (CompilationUnit) getOriginalElement(); - // might be IResource.NULL_STAMP if original does not exist - unitInfo.timestamp = ((IFile) original.getResource()).getModificationStamp(); - } - return unitInfo.isStructureKnown(); -// } -} +//protected boolean generateInfos(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { +// +//// if (getParent() instanceof JarPackageFragment) { +//// // ignore .java files in jar +//// throw newNotPresentException(); +//// } else { +// // put the info now, because getting the contents requires it +// JavaModelManager.getJavaModelManager().putInfo(this, info); +// CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info; +// +// // generate structure +// CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo, newElements); +// IProblemFactory factory = new DefaultProblemFactory(); +// SourceElementParser parser = new SourceElementParser(requestor, factory, new CompilerOptions(getJavaProject().getOptions(true))); +//// SourceElementParser parser = new SourceElementParser(requestor, factory); +// requestor.parser = parser; +// parser.parseCompilationUnit(this, false); +// if (isWorkingCopy()) { +// CompilationUnit original = (CompilationUnit) getOriginalElement(); +// // might be IResource.NULL_STAMP if original does not exist +// unitInfo.timestamp = ((IFile) original.getResource()).getModificationStamp(); +// } +// return unitInfo.isStructureKnown(); +//// } +//} /** * @see ICompilationUnit#getAllTypes() */ @@ -1111,12 +1112,20 @@ public void rename(String name, boolean force, IProgressMonitor monitor) throws String[] renamings= new String[] {name}; getJavaModel().rename(elements, dests, renamings, force, monitor); } -/** - * Does nothing - this is not a working copy. - * - * @see IWorkingCopy#restore() + +/* + * @see ICompilationUnit */ public void restore () throws JavaModelException { + + if (!isWorkingCopy()) return; + + CompilationUnit original = (CompilationUnit) getOriginalElement(); + IBuffer buffer = this.getBuffer(); + if (buffer == null) return; + buffer.setContents(original.getContents()); + updateTimeStamp(original); + makeConsistent(null); } /** * @see ICodeAssist#codeComplete(int, ICodeCompletionRequestor) @@ -1196,6 +1205,7 @@ public void restore () throws JavaModelException { // (IPackageFragment)((JavaElement)parent).rootedAt(project), // name); //} + /* * Assume that this is a working copy */ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessor.java index a4b7bfe..c68939a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessor.java @@ -27,6 +27,7 @@ import net.sourceforge.phpdt.core.IJavaModel; import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.core.JavaModelException; +import net.sourceforge.phpdt.internal.core.builder.PHPBuilder; import net.sourceforge.phpdt.internal.core.util.Util; import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil; import net.sourceforge.phpeclipse.PHPeclipsePlugin; @@ -1287,120 +1288,6 @@ public class DeltaProcessor implements IResourceChangeListener { if (insertedTree) return rootDelta; return null; } - private void notifyListeners(IJavaElementDelta deltaToNotify, int eventType, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { - final ElementChangedEvent extraEvent = new ElementChangedEvent(deltaToNotify, eventType); - for (int i= 0; i < listenerCount; i++) { - if ((listenerMask[i] & eventType) != 0){ - final IElementChangedListener listener = listeners[i]; - long start = -1; - if (VERBOSE) { - System.out.print("Listener #" + (i+1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$ - start = System.currentTimeMillis(); - } - // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief - Platform.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - Util.log(exception, "Exception occurred in listener of Java element change notification"); //$NON-NLS-1$ - } - public void run() throws Exception { - listener.elementChanged(extraEvent); - } - }); - if (VERBOSE) { - System.out.println(" -> " + (System.currentTimeMillis()-start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - } - /** - * Generic processing for elements with changed contents:
      - *
    • The element is closed such that any subsequent accesses will re-open - * the element reflecting its new structure. - *
    • An entry is made in the delta reporting a content change (K_CHANGE with F_CONTENT flag set). - *
    - */ -// protected void nonJavaResourcesChanged(Openable element, IResourceDelta delta) -// throws JavaModelException { -// -// // reset non-java resources if element was open -// if (element.isOpen()) { -// JavaElementInfo info = (JavaElementInfo)element.getElementInfo(); -// switch (element.getElementType()) { -// case IJavaElement.JAVA_MODEL : -// ((JavaModelInfo) info).nonJavaResources = null; -// currentDelta().addResourceDelta(delta); -// return; -// case IJavaElement.JAVA_PROJECT : -// ((JavaProjectElementInfo) info).setNonJavaResources(null); -// -// // if a package fragment root is the project, clear it too -// JavaProject project = (JavaProject) element; -// PackageFragmentRoot projectRoot = -// (PackageFragmentRoot) project.getPackageFragmentRoot(project.getProject()); -// if (projectRoot.isOpen()) { -// ((PackageFragmentRootInfo) projectRoot.getElementInfo()).setNonJavaResources( -// null); -// } -// break; -// case IJavaElement.PACKAGE_FRAGMENT : -// ((PackageFragmentInfo) info).setNonJavaResources(null); -// break; -// case IJavaElement.PACKAGE_FRAGMENT_ROOT : -// ((PackageFragmentRootInfo) info).setNonJavaResources(null); -// } -// } -// -// JavaElementDelta elementDelta = currentDelta().find(element); -// if (elementDelta == null) { -// currentDelta().changed(element, IJavaElementDelta.F_CONTENT); -// elementDelta = currentDelta().find(element); -// } -// elementDelta.addResourceDelta(delta); -// } -// private OutputsInfo outputsInfo(RootInfo rootInfo, IResource res) { -// try { -// IJavaProject proj = -// rootInfo == null ? -// (IJavaProject)this.createElement(res.getProject(), IJavaElement.JAVA_PROJECT, null) : -// rootInfo.project; -// if (proj != null) { -// IPath projectOutput = proj.getOutputLocation(); -// int traverseMode = IGNORE; -// if (proj.getProject().getFullPath().equals(projectOutput)){ // case of proj==bin==src -// return new OutputsInfo(new IPath[] {projectOutput}, new int[] {SOURCE}, 1); -// } else { -// IClasspathEntry[] classpath = proj.getResolvedClasspath(true); -// IPath[] outputs = new IPath[classpath.length+1]; -// int[] traverseModes = new int[classpath.length+1]; -// int outputCount = 1; -// outputs[0] = projectOutput; -// traverseModes[0] = traverseMode; -// for (int i = 0, length = classpath.length; i < length; i++) { -// IClasspathEntry entry = classpath[i]; -// IPath entryPath = entry.getPath(); -// IPath output = entry.getOutputLocation(); -// if (output != null) { -// outputs[outputCount] = output; -// // check case of src==bin -// if (entryPath.equals(output)) { -// traverseModes[outputCount++] = (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) ? SOURCE : BINARY; -// } else { -// traverseModes[outputCount++] = IGNORE; -// } -// } -// -// // check case of src==bin -// if (entryPath.equals(projectOutput)) { -// traverseModes[0] = (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) ? SOURCE : BINARY; -// } -// } -// return new OutputsInfo(outputs, traverseModes, outputCount); -// } -// } -// } catch (JavaModelException e) { -// } -// return null; -// } /** * Check whether the updated file is affecting some of the properties of a given project (like @@ -1511,75 +1398,6 @@ public class DeltaProcessor implements IResourceChangeListener { * the corresponding set of IJavaElementDelta, rooted in the * relevant JavaModels. */ -// public IJavaElementDelta processResourceDelta(IResourceDelta changes) { -// -// try { -// IJavaModel model = this.manager.getJavaModel(); -// if (!model.isOpen()) { -// // force opening of java model so that java element delta are reported -// try { -// model.open(null); -// } catch (JavaModelException e) { -// if (VERBOSE) { -// e.printStackTrace(); -// } -// return null; -// } -// } -// this.initializeRoots(); -// this.currentElement = null; -// -// // get the workspace delta, and start processing there. -// IResourceDelta[] deltas = changes.getAffectedChildren(); -// for (int i = 0; i < deltas.length; i++) { -// IResourceDelta delta = deltas[i]; -// IResource res = delta.getResource(); -// -// // find out the element type -// RootInfo rootInfo = null; -// int elementType; -// IProject proj = (IProject)res; -// boolean wasJavaProject = this.manager.getJavaModel().findJavaProject(proj) != null; -// boolean isJavaProject = JavaProject.hasJavaNature(proj); -// if (!wasJavaProject && !isJavaProject) { -// elementType = NON_JAVA_RESOURCE; -// } else { -// rootInfo = this.enclosingRootInfo(res.getFullPath(), delta.getKind()); -// if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) { -// elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT; -// } else { -// elementType = IJavaElement.JAVA_PROJECT; -// } -// } -// -// // traverse delta -// if (!this.traverseDelta(delta, elementType, rootInfo, null) -// || (wasJavaProject != isJavaProject && (delta.getKind()) == IResourceDelta.CHANGED)) { // project has changed nature (description or open/closed) -// try { -// // add child as non java resource -// nonJavaResourcesChanged((JavaModel)model, delta); -// } catch (JavaModelException e) { -// } -// } -// -// } -// -// // update package fragment roots of projects that were affected -// Iterator iterator = this.projectsToUpdate.iterator(); -// while (iterator.hasNext()) { -// JavaProject project = (JavaProject)iterator.next(); -// project.updatePackageFragmentRoots(); -// } -// -// updateDependentNamelookups(); -// -// return this.currentDelta; -// } finally { -// this.currentDelta = null; -// this.projectsToUpdate.clear(); -// this.projectsForDependentNamelookupRefresh.clear(); -// } -// } /** * Update the JavaModel according to a .classpath file change. The file can have changed as a result of a previous @@ -1774,74 +1592,518 @@ public class DeltaProcessor implements IResourceChangeListener { * @see IResource */ public void resourceChanged(IResourceChangeEvent event) { - // jsurfer TODO compare 3.0 sources - if (event.getSource() instanceof IWorkspace) { - int eventType = this.overridenEventType == -1 ? event.getType() : this.overridenEventType; - IResource resource = event.getResource(); - IResourceDelta delta = event.getDelta(); - - switch(eventType){ - case IResourceChangeEvent.PRE_DELETE : + if (event.getSource() instanceof IWorkspace) { + int eventType = this.overridenEventType == -1 ? event.getType() : this.overridenEventType; + IResource resource = event.getResource(); + IResourceDelta delta = event.getDelta(); + + switch(eventType){ + case IResourceChangeEvent.PRE_DELETE : + try { + if(resource.getType() == IResource.PROJECT + && ((IProject) resource).hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) { + + deleting((IProject)resource); + } + } catch(CoreException e){ + // project doesn't exist or is not open: ignore + } + return; + + case IResourceChangeEvent.POST_CHANGE : + if (isAffectedBy(delta)) { // avoid populating for SYNC or MARKER deltas try { - if(resource.getType() == IResource.PROJECT - && ((IProject) resource).hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) { - // TODO jsurfer temp-del -// this.deleting((IProject)resource); + try { + stopDeltas(); +// checkProjectsBeingAddedOrRemoved(delta); +// if (this.refreshedElements != null) { +// createExternalArchiveDelta(null); +// } + IJavaElementDelta translatedDelta = processResourceDelta(delta); + if (translatedDelta != null) { + registerJavaModelDelta(translatedDelta); + } + } finally { + startDeltas(); } - } catch(CoreException e){ +// notifyTypeHierarchies(this.state.elementChangedListeners, this.state.elementChangedListenerCount); + fire(null, ElementChangedEvent.POST_CHANGE); + } finally { + // workaround for bug 15168 circular errors not reported + this.state.modelProjectsCache = null; + this.removedRoots = null; } - return; - - case IResourceChangeEvent.PRE_BUILD : -// TODO jsurfer temp-del -// if(isAffectedBy(delta)) { // avoid populating for SYNC or MARKER deltas -// this.checkProjectsBeingAddedOrRemoved(delta); -// -// // update the classpath related markers -// this.updateClasspathMarkers(); -// -// // the following will close project if affected by the property file change -// try { -// // don't fire classpath change deltas right away, but batch them -// this.manager.stopDeltas(); -// this.performPreBuildCheck(delta, null); -// } finally { -// this.manager.startDeltas(); + } + return; + + case IResourceChangeEvent.PRE_BUILD : + DeltaProcessingState.ProjectUpdateInfo[] updates = this.state.removeAllProjectUpdates(); + if (updates != null) { + for (int i = 0, length = updates.length; i < length; i++) { + try { + updates[i].updateProjectReferencesIfNecessary(); + } catch(JavaModelException e) { + // do nothing + } + } + } + // this.processPostChange = false; + if(isAffectedBy(delta)) { // avoid populating for SYNC or MARKER deltas +// updateClasspathMarkers(delta); + PHPBuilder.buildStarting(); + } + // does not fire any deltas + return; + + case IResourceChangeEvent.POST_BUILD : + PHPBuilder.buildFinished(); + return; + } + } +// // jsurfer TODO compare 3.0 sources +// if (event.getSource() instanceof IWorkspace) { +// int eventType = this.overridenEventType == -1 ? event.getType() : this.overridenEventType; +// IResource resource = event.getResource(); +// IResourceDelta delta = event.getDelta(); +// +// switch(eventType){ +// case IResourceChangeEvent.PRE_DELETE : +// try { +// if(resource.getType() == IResource.PROJECT +// && ((IProject) resource).hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) { +// // TODO jsurfer temp-del +//// this.deleting((IProject)resource); // } +// } catch(CoreException e){ // } - // only fire already computed deltas (resource ones will be processed in post change only) - this.manager.fire(null, ElementChangedEvent.PRE_AUTO_BUILD); - break; +// return; +// +// case IResourceChangeEvent.PRE_BUILD : +//// TODO jsurfer temp-del +//// if(isAffectedBy(delta)) { // avoid populating for SYNC or MARKER deltas +//// this.checkProjectsBeingAddedOrRemoved(delta); +//// +//// // update the classpath related markers +//// this.updateClasspathMarkers(); +//// +//// // the following will close project if affected by the property file change +//// try { +//// // don't fire classpath change deltas right away, but batch them +//// this.manager.stopDeltas(); +//// this.performPreBuildCheck(delta, null); +//// } finally { +//// this.manager.startDeltas(); +//// } +//// } +// // only fire already computed deltas (resource ones will be processed in post change only) +// this.manager.fire(null, ElementChangedEvent.PRE_AUTO_BUILD); +// break; +// +// case IResourceChangeEvent.POST_BUILD : +//// TODO jsurfer temp-del +//// JavaBuilder.finishedBuilding(event); +// break; +// +// case IResourceChangeEvent.POST_CHANGE : +//// TODO jsurfer temp-del +//// if (isAffectedBy(delta)) { +//// try { +//// if (this.refreshedElements != null) { +//// try { +//// createExternalArchiveDelta(null); +//// } catch (JavaModelException e) { +//// e.printStackTrace(); +//// } +//// } +//// IJavaElementDelta translatedDelta = this.processResourceDelta(delta); +//// if (translatedDelta != null) { +//// this.manager.registerJavaModelDelta(translatedDelta); +//// } +//// this.manager.fire(null, ElementChangedEvent.POST_CHANGE); +//// } finally { +//// // workaround for bug 15168 circular errors not reported +//// this.manager.javaProjectsCache = null; +//// this.removedRoots = null; +//// } +//// } +// } +// } + } + /* + * Turns the firing mode to on. That is, deltas that are/have been + * registered will be fired. + */ + private void startDeltas() { + this.isFiring= true; + } + /* + * Turns the firing mode to off. That is, deltas that are/have been + * registered will not be fired until deltas are started again. + */ + private void stopDeltas() { + this.isFiring= false; + } + /* + * Note that the project is about to be deleted. + */ + private void deleting(IProject project) { + + try { + // discard indexing jobs that belong to this project so that the project can be + // deleted without interferences from the index manager +// this.manager.indexManager.discardJobs(project.getName()); - case IResourceChangeEvent.POST_BUILD : -// TODO jsurfer temp-del -// JavaBuilder.finishedBuilding(event); - break; - - case IResourceChangeEvent.POST_CHANGE : -// TODO jsurfer temp-del -// if (isAffectedBy(delta)) { -// try { -// if (this.refreshedElements != null) { -// try { -// createExternalArchiveDelta(null); -// } catch (JavaModelException e) { -// e.printStackTrace(); + JavaProject javaProject = (JavaProject)JavaCore.create(project); + + // remember roots of this project + if (this.removedRoots == null) { + this.removedRoots = new HashMap(); + } + if (javaProject.isOpen()) { + this.removedRoots.put(javaProject, javaProject.getPackageFragmentRoots()); + } else { + // compute roots without opening project +// this.removedRoots.put( +// javaProject, +// javaProject.computePackageFragmentRoots( +// javaProject.getResolvedClasspath(true/*ignoreUnresolvedEntry*/, false/*don't generateMarkerOnError*/, false/*don't returnResolutionInProgress*/), +// false)); + } + + javaProject.close(); + + // workaround for bug 15168 circular errors not reported + if (this.state.modelProjectsCache == null) { + this.state.modelProjectsCache = this.manager.getJavaModel().getJavaProjects(); + } + this.removeFromParentInfo(javaProject); + + } catch (JavaModelException e) { + // java project doesn't exist: ignore + } + } + /* + * Converts a IResourceDelta rooted in a Workspace into + * the corresponding set of IJavaElementDelta, rooted in the + * relevant JavaModels. + */ + private IJavaElementDelta processResourceDelta(IResourceDelta changes) { + + try { + IJavaModel model = this.manager.getJavaModel(); + if (!model.isOpen()) { + // force opening of java model so that java element delta are reported + try { + model.open(null); + } catch (JavaModelException e) { + if (VERBOSE) { + e.printStackTrace(); + } + return null; + } + } + this.state.initializeRoots(); + this.currentElement = null; + + // get the workspace delta, and start processing there. + IResourceDelta[] deltas = changes.getAffectedChildren(); + for (int i = 0; i < deltas.length; i++) { + IResourceDelta delta = deltas[i]; + IResource res = delta.getResource(); + + // find out the element type + RootInfo rootInfo = null; + int elementType; + IProject proj = (IProject)res; + boolean wasJavaProject = this.manager.getJavaModel().findJavaProject(proj) != null; + boolean isJavaProject = JavaProject.hasJavaNature(proj); + if (!wasJavaProject && !isJavaProject) { + elementType = NON_JAVA_RESOURCE; + } else { + rootInfo = this.enclosingRootInfo(res.getFullPath(), delta.getKind()); + if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) { + elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT; + } else { + elementType = IJavaElement.JAVA_PROJECT; + } + } + + // traverse delta +// this.traverseDelta(delta, elementType, rootInfo, null); + + if (elementType == NON_JAVA_RESOURCE + || (wasJavaProject != isJavaProject && (delta.getKind()) == IResourceDelta.CHANGED)) { // project has changed nature (description or open/closed) + try { + // add child as non java resource + nonJavaResourcesChanged((JavaModel)model, delta); + } catch (JavaModelException e) { + // java model could not be opened + } + } + + } +// refreshPackageFragmentRoots(); +// resetProjectCaches(); + + return this.currentDelta; + } finally { + this.currentDelta = null; +// this.rootsToRefresh.clear(); +// this.projectCachesToReset.clear(); + } + } + + /* + * Converts an IResourceDelta and its children into + * the corresponding IJavaElementDeltas. + */ +// private void traverseDelta( +// IResourceDelta delta, +// int elementType, +// RootInfo rootInfo, +// OutputsInfo outputsInfo) { +// +// IResource res = delta.getResource(); +// +// // set stack of elements +// if (this.currentElement == null && rootInfo != null) { +//// this.currentElement = rootInfo.project; +// } +// +// // process current delta +// boolean processChildren = true; +// if (res instanceof IProject) { +// processChildren = +// this.updateCurrentDeltaAndIndex( +// delta, +// elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT ? +// IJavaElement.JAVA_PROJECT : // case of prj=src +// elementType, +// rootInfo); +// } else if (rootInfo != null) { +// processChildren = this.updateCurrentDeltaAndIndex(delta, elementType, rootInfo); +// } else { +// // not yet inside a package fragment root +// processChildren = true; +// } +// +// // get the project's output locations and traverse mode +// if (outputsInfo == null) outputsInfo = this.outputsInfo(rootInfo, res); +// +// // process children if needed +// if (processChildren) { +// IResourceDelta[] children = delta.getAffectedChildren(); +// boolean oneChildOnClasspath = false; +// int length = children.length; +// IResourceDelta[] orphanChildren = null; +// Openable parent = null; +// boolean isValidParent = true; +// for (int i = 0; i < length; i++) { +// IResourceDelta child = children[i]; +// IResource childRes = child.getResource(); +// +// // check source attachment change +// this.checkSourceAttachmentChange(child, childRes); +// +// // find out whether the child is a package fragment root of the current project +// IPath childPath = childRes.getFullPath(); +// int childKind = child.getKind(); +// RootInfo childRootInfo = this.rootInfo(childPath, childKind); +// if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) { +// // package fragment root of another project (dealt with later) +// childRootInfo = null; +// } +// +// // compute child type +// int childType = +// this.elementType( +// childRes, +// childKind, +// elementType, +// rootInfo == null ? childRootInfo : rootInfo +// ); +// +// // is childRes in the output folder and is it filtered out ? +// boolean isResFilteredFromOutput = this.isResFilteredFromOutput(outputsInfo, childRes, childType); +// +// boolean isNestedRoot = rootInfo != null && childRootInfo != null; +// if (!isResFilteredFromOutput +// && !isNestedRoot) { // do not treat as non-java rsc if nested root +// +// this.traverseDelta(child, childType, rootInfo == null ? childRootInfo : rootInfo, outputsInfo); // traverse delta for child in the same project +// +// if (childType == NON_JAVA_RESOURCE) { +// if (rootInfo != null) { // if inside a package fragment root +// if (!isValidParent) continue; +// if (parent == null) { +// // find the parent of the non-java resource to attach to +// if (this.currentElement == null +// || !rootInfo.project.equals(this.currentElement.getJavaProject())) { // note if currentElement is the IJavaModel, getJavaProject() is null +// // force the currentProject to be used +// this.currentElement = rootInfo.project; +// } +// if (elementType == IJavaElement.JAVA_PROJECT +// || (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT +// && res instanceof IProject)) { +// // NB: attach non-java resource to project (not to its package fragment root) +// parent = rootInfo.project; +// } else { +// parent = this.createElement(res, elementType, rootInfo); +// } +// if (parent == null) { +// isValidParent = false; +// continue; // } // } -// IJavaElementDelta translatedDelta = this.processResourceDelta(delta); -// if (translatedDelta != null) { -// this.manager.registerJavaModelDelta(translatedDelta); +// // add child as non java resource +// try { +// nonJavaResourcesChanged(parent, child); +// } catch (JavaModelException e) { +// // ignore // } -// this.manager.fire(null, ElementChangedEvent.POST_CHANGE); -// } finally { -// // workaround for bug 15168 circular errors not reported -// this.manager.javaProjectsCache = null; -// this.removedRoots = null; +// } else { +// // the non-java resource (or its parent folder) will be attached to the java project +// if (orphanChildren == null) orphanChildren = new IResourceDelta[length]; +// orphanChildren[i] = child; // } +// } else { +// oneChildOnClasspath = true; +// } +// } else { +// oneChildOnClasspath = true; // to avoid reporting child delta as non-java resource delta +// } +// +// // if child is a nested root +// // or if it is not a package fragment root of the current project +// // but it is a package fragment root of another project, traverse delta too +// if (isNestedRoot +// || (childRootInfo == null && (childRootInfo = this.rootInfo(childPath, childKind)) != null)) { +// this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, childRootInfo, null); // binary output of childRootInfo.project cannot be this root +// } +// +// // if the child is a package fragment root of one or several other projects +// ArrayList rootList; +// if ((rootList = this.otherRootsInfo(childPath, childKind)) != null) { +// Iterator iterator = rootList.iterator(); +// while (iterator.hasNext()) { +// childRootInfo = (RootInfo) iterator.next(); +// this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, childRootInfo, null); // binary output of childRootInfo.project cannot be this root +// } +// } +// } +// if (orphanChildren != null +// && (oneChildOnClasspath // orphan children are siblings of a package fragment root +// || res instanceof IProject)) { // non-java resource directly under a project +// +// // attach orphan children +// IProject rscProject = res.getProject(); +// JavaProject adoptiveProject = (JavaProject)JavaCore.create(rscProject); +// if (adoptiveProject != null +// && JavaProject.hasJavaNature(rscProject)) { // delta iff Java project (18698) +// for (int i = 0; i < length; i++) { +// if (orphanChildren[i] != null) { +// try { +// nonJavaResourcesChanged(adoptiveProject, orphanChildren[i]); +// } catch (JavaModelException e) { +// // ignore +// } +// } +// } +// } +// } // else resource delta will be added by parent +// } // else resource delta will be added by parent +// } + private void notifyListeners(IJavaElementDelta deltaToNotify, int eventType, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { + final ElementChangedEvent extraEvent = new ElementChangedEvent(deltaToNotify, eventType); + for (int i= 0; i < listenerCount; i++) { + if ((listenerMask[i] & eventType) != 0){ + final IElementChangedListener listener = listeners[i]; + long start = -1; + if (VERBOSE) { + System.out.print("Listener #" + (i+1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$ + start = System.currentTimeMillis(); + } + // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief + Platform.run(new ISafeRunnable() { + public void handleException(Throwable exception) { + Util.log(exception, "Exception occurred in listener of Java element change notification"); //$NON-NLS-1$ + } + public void run() throws Exception { + listener.elementChanged(extraEvent); + } + }); + if (VERBOSE) { + System.out.println(" -> " + (System.currentTimeMillis()-start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } + } +// private void notifyTypeHierarchies(IElementChangedListener[] listeners, int listenerCount) { +// for (int i= 0; i < listenerCount; i++) { +// final IElementChangedListener listener = listeners[i]; +// if (!(listener instanceof TypeHierarchy)) continue; +// +// // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief +// Platform.run(new ISafeRunnable() { +// public void handleException(Throwable exception) { +// Util.log(exception, "Exception occurred in listener of Java element change notification"); //$NON-NLS-1$ +// } +// public void run() throws Exception { +// TypeHierarchy typeHierarchy = (TypeHierarchy)listener; +// if (typeHierarchy.hasFineGrainChanges()) { +// // case of changes in primary working copies +// typeHierarchy.needsRefresh = true; +// typeHierarchy.fireChange(); // } +// } +// }); +// } +// } + /* + * Generic processing for elements with changed contents:
      + *
    • The element is closed such that any subsequent accesses will re-open + * the element reflecting its new structure. + *
    • An entry is made in the delta reporting a content change (K_CHANGE with F_CONTENT flag set). + *
    + */ + private void nonJavaResourcesChanged(Openable element, IResourceDelta delta) + throws JavaModelException { + + // reset non-java resources if element was open + if (element.isOpen()) { + JavaElementInfo info = (JavaElementInfo)element.getElementInfo(); + switch (element.getElementType()) { + case IJavaElement.JAVA_MODEL : + ((JavaModelInfo) info).nonJavaResources = null; + currentDelta().addResourceDelta(delta); + return; + case IJavaElement.JAVA_PROJECT : + ((JavaProjectElementInfo) info).setNonJavaResources(null); + + // if a package fragment root is the project, clear it too + JavaProject project = (JavaProject) element; + PackageFragmentRoot projectRoot = + (PackageFragmentRoot) project.getPackageFragmentRoot(project.getProject()); + if (projectRoot.isOpen()) { + ((PackageFragmentRootInfo) projectRoot.getElementInfo()).setNonJavaResources( + null); + } + break; + case IJavaElement.PACKAGE_FRAGMENT : + ((PackageFragmentInfo) info).setNonJavaResources(null); + break; + case IJavaElement.PACKAGE_FRAGMENT_ROOT : + ((PackageFragmentRootInfo) info).setNonJavaResources(null); } } + + JavaElementDelta current = currentDelta(); + JavaElementDelta elementDelta = current.find(element); + if (elementDelta == null) { + // don't use find after creating the delta as it can be null (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63434) + elementDelta = current.changed(element, IJavaElementDelta.F_CONTENT); + } + elementDelta.addResourceDelta(delta); } /* * Flushes all deltas without firing them. diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaElementDelta.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaElementDelta.java index 9cbedb3..1dfedd9 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaElementDelta.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaElementDelta.java @@ -238,17 +238,18 @@ protected void addResourceDelta(IResourceDelta child) { } resourceDeltas[resourceDeltasCounter++] = child; } + /** * Creates the nested deltas resulting from a change operation. * Convenience method for creating change deltas. * The constructor should be used to create the root delta * and then a change operation should call this method. */ -public void changed(IJavaElement element, int changeFlag) { +public JavaElementDelta changed(IJavaElement element, int changeFlag) { JavaElementDelta changedDelta = new JavaElementDelta(element); - changedDelta.fKind = CHANGED; - changedDelta.fChangeFlags |= changeFlag; + changedDelta.changed(changeFlag); insertDeltaTree(element, changedDelta); + return changedDelta; } /** * Mark this delta as a content changed delta. diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/PHPBuilder.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/PHPBuilder.java index 6cd1981..1bd843c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/PHPBuilder.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/PHPBuilder.java @@ -87,6 +87,22 @@ public class PHPBuilder extends IncrementalProjectBuilder { public static void finishedBuilding(IResourceChangeEvent event) { BuildNotifier.resetProblemCounters(); } + /** + * Hook allowing to initialize some static state before a complete build iteration. + * This hook is invoked during PRE_AUTO_BUILD notification + */ + public static void buildStarting() { + // do nothing + // TODO (philippe) is it still needed? + } + + /** + * Hook allowing to reset some static state after a complete build iteration. + * This hook is invoked during POST_AUTO_BUILD notification + */ + public static void buildFinished() { + BuildNotifier.resetProblemCounters(); + } public static void removeProblemsFor(IResource resource) { try { if (resource != null && resource.exists()) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/Resources.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/Resources.java new file mode 100644 index 0000000..d555c13 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/Resources.java @@ -0,0 +1,188 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.corext.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import net.sourceforge.phpdt.internal.corext.CorextMessages; +import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants; +import net.sourceforge.phpdt.internal.ui.PHPUIStatus; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceStatus; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; + +public class Resources { + + private Resources() { + } + + /** + * Checks if the given resource is in sync with the underlying file system. + * + * @param resource the resource to be checked + * @return IStatus status describing the check's result. If status. + * isOK() returns true then the resource is in sync + */ + public static IStatus checkInSync(IResource resource) { + return checkInSync(new IResource[] {resource}); + } + + /** + * Checks if the given resources are in sync with the underlying file + * system. + * + * @param resources the resources to be checked + * @return IStatus status describing the check's result. If status. + * isOK() returns true then the resources are in sync + */ + public static IStatus checkInSync(IResource[] resources) { + IStatus result= null; + for (int i= 0; i < resources.length; i++) { + IResource resource= resources[i]; + if (!resource.isSynchronized(IResource.DEPTH_INFINITE)) { + result= addOutOfSync(result, resource); + } + } + if (result != null) + return result; + return new Status(IStatus.OK, PHPeclipsePlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$ + } + + /** + * Makes the given resource committable. Committable means that it is + * writeable and that its content hasn't changed by calling + * validateEdit for the given resource on IWorkspace. + * + * @param resource the resource to be checked + * @param context the context passed to validateEdit + * @return status describing the method's result. If status.isOK() returns true then the resources are committable. + * + * @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object) + */ + public static IStatus makeCommittable(IResource resource, Object context) { + return makeCommittable(new IResource[] { resource }, context); + } + + /** + * Makes the given resources committable. Committable means that all + * resources are writeable and that the content of the resources hasn't + * changed by calling validateEdit for a given file on + * IWorkspace. + * + * @param resources the resources to be checked + * @param context the context passed to validateEdit + * @return IStatus status describing the method's result. If status. + * isOK() returns true then the add resources are + * committable + * + * @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object) + */ + public static IStatus makeCommittable(IResource[] resources, Object context) { + List readOnlyFiles= new ArrayList(); + for (int i= 0; i < resources.length; i++) { + IResource resource= resources[i]; + if (resource.getType() == IResource.FILE && resource.isReadOnly()) + readOnlyFiles.add(resource); + } + if (readOnlyFiles.size() == 0) + return new Status(IStatus.OK, PHPeclipsePlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$ + + Map oldTimeStamps= createModificationStampMap(readOnlyFiles); + IStatus status= ResourcesPlugin.getWorkspace().validateEdit( + (IFile[]) readOnlyFiles.toArray(new IFile[readOnlyFiles.size()]), context); + if (!status.isOK()) + return status; + + IStatus modified= null; + Map newTimeStamps= createModificationStampMap(readOnlyFiles); + for (Iterator iter= oldTimeStamps.keySet().iterator(); iter.hasNext();) { + IFile file= (IFile) iter.next(); + if (!oldTimeStamps.get(file).equals(newTimeStamps.get(file))) + modified= addModified(modified, file); + } + if (modified != null) + return modified; + return new Status(IStatus.OK, PHPeclipsePlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$ + } + + private static Map createModificationStampMap(List files){ + Map map= new HashMap(); + for (Iterator iter= files.iterator(); iter.hasNext(); ) { + IFile file= (IFile)iter.next(); + map.put(file, new Long(file.getModificationStamp())); + } + return map; + } + + private static IStatus addModified(IStatus status, IFile file) { + IStatus entry= PHPUIStatus.createError( + IJavaStatusConstants.VALIDATE_EDIT_CHANGED_CONTENT, + CorextMessages.getFormattedString("Resources.fileModified", file.getFullPath().toString()), //$NON-NLS-1$ + null); + if (status == null) { + return entry; + } else if (status.isMultiStatus()) { + ((MultiStatus)status).add(entry); + return status; + } else { + MultiStatus result= new MultiStatus(PHPeclipsePlugin.getPluginId(), + IJavaStatusConstants.VALIDATE_EDIT_CHANGED_CONTENT, + CorextMessages.getString("Resources.modifiedResources"), null); //$NON-NLS-1$ + result.add(status); + result.add(entry); + return result; + } + } + + private static IStatus addOutOfSync(IStatus status, IResource resource) { + IStatus entry= new Status( + IStatus.ERROR, + ResourcesPlugin.PI_RESOURCES, + IResourceStatus.OUT_OF_SYNC_LOCAL, + CorextMessages.getFormattedString("Resources.outOfSync", resource.getFullPath().toString()), //$NON-NLS-1$ + null); + if (status == null) { + return entry; + } else if (status.isMultiStatus()) { + ((MultiStatus)status).add(entry); + return status; + } else { + MultiStatus result= new MultiStatus( + ResourcesPlugin.PI_RESOURCES, + IResourceStatus.OUT_OF_SYNC_LOCAL, + CorextMessages.getString("Resources.outOfSyncResources"), null); //$NON-NLS-1$ + result.add(status); + result.add(entry); + return result; + } + } + + public static String[] getLocationOSStrings(IResource[] resources) { + List result= new ArrayList(resources.length); + for (int i= 0; i < resources.length; i++) { + IPath location= resources[i].getLocation(); + if (location != null) + result.add(location.toOSString()); + } + return (String[]) result.toArray(new String[result.size()]); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index 4b1d051..72d3508 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -55,6 +55,7 @@ import net.sourceforge.phpeclipse.builder.FileStorage; import net.sourceforge.phpeclipse.builder.IdentifierIndexManager; import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory; import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter; +import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider; import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider; import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr; import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager; @@ -107,7 +108,6 @@ import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; import org.eclipse.ui.editors.text.templates.ContributionTemplateStore; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; import org.eclipse.ui.texteditor.ChainedPreferenceStore; import org.eclipse.ui.texteditor.ConfigurationElementSorter; import org.eclipse.ui.texteditor.IDocumentProvider; @@ -247,7 +247,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon private IBufferFactory fBufferFactory; - private PHPDocumentProvider fCompilationUnitDocumentProvider; + private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider; private JavaTextTools fJavaTextTools; @@ -597,7 +597,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon } // TODO: refactor this into a better method name ! - public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() { + public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() { if (fCompilationUnitDocumentProvider == null) fCompilationUnitDocumentProvider = new PHPDocumentProvider(); return fCompilationUnitDocumentProvider; @@ -622,10 +622,10 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon public synchronized IWorkingCopyManager getWorkingCopyManager() { if (fWorkingCopyManager == null) { - PHPDocumentProvider provider = getCompilationUnitDocumentProvider(); - fWorkingCopyManager = new WorkingCopyManager(provider); - } - return fWorkingCopyManager; + ICompilationUnitDocumentProvider provider= getCompilationUnitDocumentProvider(); + fWorkingCopyManager= new WorkingCopyManager(provider); + } + return fWorkingCopyManager; } public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ICompilationUnitDocumentProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ICompilationUnitDocumentProvider.java new file mode 100644 index 0000000..ad7ff42 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ICompilationUnitDocumentProvider.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpeclipse.phpeditor; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ILineTracker; +import org.eclipse.jface.text.source.IAnnotationModelListener; + +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.IDocumentProviderExtension2; +import org.eclipse.ui.texteditor.IDocumentProviderExtension3; + +import net.sourceforge.phpdt.core.ICompilationUnit; + +/** + * @since 3.0 + */ +public interface ICompilationUnitDocumentProvider extends IDocumentProvider, IDocumentProviderExtension2, IDocumentProviderExtension3 { + + /** + * Shuts down this provider. + */ + void shutdown(); + + /** + * Returns the working copy for the given element. + * + * @param element the element + * @return the working copy for the given element + */ + ICompilationUnit getWorkingCopy(Object element); + + /** + * Saves the content of the given document to the given element. This method has + * only an effect if it is called when directly or indirectly inside saveDocument. + * + * @param monitor the progress monitor + * @param element the element to which to save + * @param document the document to save + * @param overwrite true if the save should be enforced + */ + void saveDocumentContent(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException; + + /** + * Creates a line tracker for the given element. It is of the same kind as the one that would be + * used for a newly created document for the given element. + * + * @param element the element + * @return a line tracker for the given element + */ + ILineTracker createLineTracker(Object element); + + /** + * Sets the document provider's save policy. + * + * @param savePolicy the save policy + */ + void setSavePolicy(ISavePolicy savePolicy); + + /** + * Adds a listener that reports changes from all compilation unit annotation models. + * + * @param listener the listener + */ + void addGlobalAnnotationModelListener(IAnnotationModelListener listener); + + /** + * Removes the listener. + * + * @param listener the listener + */ + void removeGlobalAnnotationModelListener(IAnnotationModelListener listener); +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java index 599cd4f..a707726 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java @@ -12,9 +12,6 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -24,6 +21,7 @@ import net.sourceforge.phpdt.core.IProblemRequestor; import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.core.compiler.IProblem; +import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; import net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension; import net.sourceforge.phpdt.internal.ui.text.spelling.SpellReconcileStrategy.SpellProblem; import net.sourceforge.phpdt.ui.PreferenceConstants; @@ -36,8 +34,6 @@ import org.eclipse.core.resources.IResourceRuleFactory; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.Assert; @@ -67,10 +63,12 @@ import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.editors.text.ForwardingDocumentProvider; import org.eclipse.ui.editors.text.TextFileDocumentProvider; import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel; import org.eclipse.ui.texteditor.AnnotationPreference; import org.eclipse.ui.texteditor.AnnotationPreferenceLookup; +import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.MarkerUtilities; import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; @@ -79,7 +77,7 @@ import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; * The PHPDocumentProvider provides the IDocuments used by java editors. */ -public class PHPDocumentProvider extends TextFileDocumentProvider { +public class PHPDocumentProvider extends TextFileDocumentProvider implements ICompilationUnitDocumentProvider { /** * Here for visibility issues only. */ @@ -836,15 +834,28 @@ public class PHPDocumentProvider extends TextFileDocumentProvider { private GlobalAnnotationModelListener fGlobalAnnotationModelListener; public PHPDocumentProvider() { - setParentDocumentProvider(new TextFileDocumentProvider(new JavaStorageDocumentProvider())); +// setParentDocumentProvider(new TextFileDocumentProvider(new JavaStorageDocumentProvider())); +// +// fPropertyListener= new IPropertyChangeListener() { +// public void propertyChange(PropertyChangeEvent event) { +// if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty())) +// enableHandlingTemporaryProblems(); +// } +// }; +// fGlobalAnnotationModelListener= new GlobalAnnotationModelListener(); +// PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener); + IDocumentProvider provider= new TextFileDocumentProvider(new JavaStorageDocumentProvider()); + provider= new ForwardingDocumentProvider(IPHPPartitions.PHP_PARTITIONING, new JavaDocumentSetupParticipant(), provider); + setParentDocumentProvider(provider); + + fGlobalAnnotationModelListener= new GlobalAnnotationModelListener(); fPropertyListener= new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty())) enableHandlingTemporaryProblems(); } }; - fGlobalAnnotationModelListener= new GlobalAnnotationModelListener(); PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener); } @@ -1093,8 +1104,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider { } protected void commitWorkingCopy(IProgressMonitor monitor, Object element, CompilationUnitInfo info, boolean overwrite) throws CoreException { - - synchronized (info.fCopy) { + synchronized (info.fCopy) { info.fCopy.reconcile(); } @@ -1147,12 +1157,39 @@ public class PHPDocumentProvider extends TextFileDocumentProvider { } } } + } /* * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object, org.eclipse.jface.text.IDocument, boolean) */ protected DocumentProviderOperation createSaveOperation(final Object element, final IDocument document, final boolean overwrite) throws CoreException { +// final FileInfo info= getFileInfo(element); +// if (info instanceof CompilationUnitInfo) { +// return new DocumentProviderOperation() { +// /* +// * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor) +// */ +// protected void execute(IProgressMonitor monitor) throws CoreException { +// commitWorkingCopy(monitor, element, (CompilationUnitInfo) info, overwrite); +// } +// /* +// * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule() +// */ +// public ISchedulingRule getSchedulingRule() { +// if (info.fElement instanceof IFileEditorInput) { +// IFile file= ((IFileEditorInput) info.fElement).getFile(); +// IResourceRuleFactory ruleFactory= ResourcesPlugin.getWorkspace().getRuleFactory(); +// if (file == null || !file.exists()) +// return ruleFactory.createRule(file); +// else +// return ruleFactory.modifyRule(file); +// } else +// return null; +// } +// }; +// } +// return null; final FileInfo info= getFileInfo(element); if (info instanceof CompilationUnitInfo) { return new DocumentProviderOperation() { @@ -1168,11 +1205,7 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi public ISchedulingRule getSchedulingRule() { if (info.fElement instanceof IFileEditorInput) { IFile file= ((IFileEditorInput) info.fElement).getFile(); - IResourceRuleFactory ruleFactory= ResourcesPlugin.getWorkspace().getRuleFactory(); - if (file == null || !file.exists()) - return ruleFactory.createRule(file); - else - return ruleFactory.modifyRule(file); + return computeSchedulingRule(file); } else return null; } @@ -1446,24 +1479,26 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi */ public void saveDocumentContent(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException { - - if (!fIsAboutToSave) - return; - - if (element instanceof IFileEditorInput) { - IFileEditorInput input = (IFileEditorInput) element; - try { - String encoding = getEncoding(element); - if (encoding == null) - encoding = ResourcesPlugin.getEncoding(); - InputStream stream = new ByteArrayInputStream(document.get().getBytes(encoding)); - IFile file = input.getFile(); - file.setContents(stream, overwrite, true, monitor); - } catch (IOException x) { - IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, x.getMessage(), x); - throw new CoreException(s); - } - } + if (!fIsAboutToSave) + return; + super.saveDocument(monitor, element, document, overwrite); +// if (!fIsAboutToSave) +// return; +// +// if (element instanceof IFileEditorInput) { +// IFileEditorInput input = (IFileEditorInput) element; +// try { +// String encoding = getEncoding(element); +// if (encoding == null) +// encoding = ResourcesPlugin.getEncoding(); +// InputStream stream = new ByteArrayInputStream(document.get().getBytes(encoding)); +// IFile file = input.getFile(); +// file.setContents(stream, overwrite, true, monitor); +// } catch (IOException x) { +// IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, x.getMessage(), x); +// throw new CoreException(s); +// } +// } } /** * Returns the underlying resource for the given element. @@ -1471,13 +1506,13 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi * @param the element * @return the underlying resource of the given element */ - public IResource getUnderlyingResource(Object element) { - if (element instanceof IFileEditorInput) { - IFileEditorInput input = (IFileEditorInput) element; - return input.getFile(); - } - return null; - } +// public IResource getUnderlyingResource(Object element) { +// if (element instanceof IFileEditorInput) { +// IFileEditorInput input = (IFileEditorInput) element; +// return input.getFile(); +// } +// return null; +// } /* * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object) @@ -1537,5 +1572,36 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi public void removeGlobalAnnotationModelListener(IAnnotationModelListener listener) { fGlobalAnnotationModelListener.removeListener(listener); } - + + /** + * Computes the scheduling rule needed to create or modify a resource. If + * the resource exists, its modify rule is returned. If it does not, the + * resource hierarchy is iterated towards the workspace root to find the + * first parent of toCreateOrModify that exists. Then the + * 'create' rule for the last non-existing resource is returned. + *

    + * XXX This is a workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601 + * IResourceRuleFactory.createRule should iterate the hierarchy itself. + *

    + *

    + * XXX to be replaced by call to TextFileDocumentProvider.computeSchedulingRule after 3.0 + *

    + * + * @param toCreateOrModify the resource to create or modify + * @return the minimal scheduling rule needed to modify or create a resource + */ + private ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) { + IResourceRuleFactory factory= ResourcesPlugin.getWorkspace().getRuleFactory(); + if (toCreateOrModify.exists()) { + return factory.modifyRule(toCreateOrModify); + } else { + IResource parent= toCreateOrModify; + do { + toCreateOrModify= parent; + parent= toCreateOrModify.getParent(); + } while (parent != null && !parent.exists()); + + return factory.createRule(toCreateOrModify); + } + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java index 182b550..a88f3d3 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java @@ -44,6 +44,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Preferences; +import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; @@ -2300,16 +2301,24 @@ public class PHPUnitEditor extends PHPEditor { //implements } } - private void configureTabConverter() { - if (fTabConverter != null) { - IDocumentProvider provider = getDocumentProvider(); - if (provider instanceof PHPDocumentProvider) { - PHPDocumentProvider cup = (PHPDocumentProvider) provider; - fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); - } - } - } - + // private void configureTabConverter() { + // if (fTabConverter != null) { + // IDocumentProvider provider = getDocumentProvider(); + // if (provider instanceof PHPDocumentProvider) { + // PHPDocumentProvider cup = (PHPDocumentProvider) provider; + // fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); + // } + // } + // } + private void configureTabConverter() { + if (fTabConverter != null) { + IDocumentProvider provider= getDocumentProvider(); + if (provider instanceof ICompilationUnitDocumentProvider) { + ICompilationUnitDocumentProvider cup= (ICompilationUnitDocumentProvider) provider; + fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); + } + } + } private void startTabConversion() { if (fTabConverter == null) { fTabConverter = new TabConverter(); @@ -2336,19 +2345,33 @@ public class PHPUnitEditor extends PHPEditor { //implements * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean, org.eclipse.core.runtime.IProgressMonitor) */ protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) { - IDocumentProvider p = getDocumentProvider(); - if (p instanceof PHPDocumentProvider) { - PHPDocumentProvider cp = (PHPDocumentProvider) p; - cp.setSavePolicy(fSavePolicy); - } - try { - super.performSave(overwrite, progressMonitor); - } finally { - if (p instanceof PHPDocumentProvider) { - PHPDocumentProvider cp = (PHPDocumentProvider) p; - cp.setSavePolicy(null); - } - } +// IDocumentProvider p = getDocumentProvider(); +// if (p instanceof PHPDocumentProvider) { +// PHPDocumentProvider cp = (PHPDocumentProvider) p; +// cp.setSavePolicy(fSavePolicy); +// } +// try { +// super.performSave(overwrite, progressMonitor); +// } finally { +// if (p instanceof PHPDocumentProvider) { +// PHPDocumentProvider cp = (PHPDocumentProvider) p; +// cp.setSavePolicy(null); +// } +// } + + IDocumentProvider p= getDocumentProvider(); + if (p instanceof ICompilationUnitDocumentProvider) { + ICompilationUnitDocumentProvider cp= (ICompilationUnitDocumentProvider) p; + cp.setSavePolicy(fSavePolicy); + } + try { + super.performSave(overwrite, progressMonitor); + } finally { + if (p instanceof ICompilationUnitDocumentProvider) { + ICompilationUnitDocumentProvider cp= (ICompilationUnitDocumentProvider) p; + cp.setSavePolicy(null); + } + } } /* diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/WorkingCopyManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/WorkingCopyManager.java index e0f9212..341108e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/WorkingCopyManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/WorkingCopyManager.java @@ -20,6 +20,7 @@ import net.sourceforge.phpdt.ui.IWorkingCopyManager; import net.sourceforge.phpdt.ui.IWorkingCopyManagerExtension; import org.eclipse.core.runtime.CoreException; +import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider; import org.eclipse.jface.text.Assert; import org.eclipse.ui.IEditorInput; @@ -30,7 +31,7 @@ import org.eclipse.ui.IEditorInput; */ public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyManagerExtension { - private PHPDocumentProvider fDocumentProvider; + private ICompilationUnitDocumentProvider fDocumentProvider; private Map fMap; private boolean fIsShuttingDown; @@ -40,7 +41,7 @@ public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyMana * * @param provider the provider */ - public WorkingCopyManager(PHPDocumentProvider provider) { + public WorkingCopyManager(ICompilationUnitDocumentProvider provider) { Assert.isNotNull(provider); fDocumentProvider= provider; } -- 1.7.1 From 63391a0f7bc3a8b472333ce550c700ae6311254b Mon Sep 17 00:00:00 2001 From: axelcl Date: Fri, 12 Nov 2004 20:17:10 +0000 Subject: [PATCH 15/16] misc --- .../ui/text/rules/MultiViewPartitioner.java | 3 +- .../ui/text/rules/OuterDocumentView.java | 10 +- .../phpdt/internal/core/DeltaProcessor.java | 12 +- .../phpeditor/php/PHPDocumentPartitioner.java | 123 ++++++++++---------- 4 files changed, 73 insertions(+), 75 deletions(-) diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java index d04d657..ea7cdda 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java @@ -8,7 +8,7 @@ * Contributors: * Igor Malinin - initial contribution * - * $Id: MultiViewPartitioner.java,v 1.5 2004-11-10 20:39:32 axelcl Exp $ + * $Id: MultiViewPartitioner.java,v 1.6 2004-11-12 20:15:58 axelcl Exp $ */ package net.sourceforge.phpeclipse.ui.text.rules; @@ -649,6 +649,7 @@ public abstract class MultiViewPartitioner extends AbstractPartitioner { return new TypedRegion(start, end - start, type); } catch (BadLocationException x) { + x.printStackTrace(); throw new IllegalArgumentException(); } } diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/OuterDocumentView.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/OuterDocumentView.java index 74abf96..d68b599 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/OuterDocumentView.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/OuterDocumentView.java @@ -8,7 +8,7 @@ * Contributors: * Igor Malinin - initial contribution * - * $Id: OuterDocumentView.java,v 1.3 2004-09-25 22:42:52 jsurfer Exp $ + * $Id: OuterDocumentView.java,v 1.4 2004-11-12 20:15:58 axelcl Exp $ */ package net.sourceforge.phpeclipse.ui.text.rules; @@ -269,9 +269,11 @@ public class OuterDocumentView extends AbstractDocument implements localOffset -= range.length; } // TODO jsurfer change start - check this -// if (localOffset<0) { -// return 0; -// } + if (localOffset<0) { + return 0; + } else if (localOffset>getLength()) { + return getLength(); + } // jsurfer change end return localOffset; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessor.java index c68939a..31261a9 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/DeltaProcessor.java @@ -1812,7 +1812,7 @@ public class DeltaProcessor implements IResourceChangeListener { IResource res = delta.getResource(); // find out the element type - RootInfo rootInfo = null; +// RootInfo rootInfo = null; int elementType; IProject proj = (IProject)res; boolean wasJavaProject = this.manager.getJavaModel().findJavaProject(proj) != null; @@ -1820,12 +1820,12 @@ public class DeltaProcessor implements IResourceChangeListener { if (!wasJavaProject && !isJavaProject) { elementType = NON_JAVA_RESOURCE; } else { - rootInfo = this.enclosingRootInfo(res.getFullPath(), delta.getKind()); - if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) { - elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT; - } else { +// rootInfo = this.enclosingRootInfo(res.getFullPath(), delta.getKind()); +// if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) { +// elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT; +// } else { elementType = IJavaElement.JAVA_PROJECT; - } +// } } // traverse delta diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDocumentPartitioner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDocumentPartitioner.java index c408f3b..107fa08 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDocumentPartitioner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDocumentPartitioner.java @@ -1,15 +1,15 @@ /********************************************************************** -Copyright (c) 2002 Widespace, OU and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://solareclipse.sourceforge.net/legal/cpl-v10.html + Copyright (c) 2002 Widespace, OU and others. + All rights reserved. This program and the accompanying materials + are made available under the terms of the Common Public License v1.0 + which accompanies this distribution, and is available at + http://solareclipse.sourceforge.net/legal/cpl-v10.html -Contributors: - Igor Malinin - initial contribution + Contributors: + Igor Malinin - initial contribution -$Id: PHPDocumentPartitioner.java,v 1.1 2004-09-02 18:32:34 jsurfer Exp $ -**********************************************************************/ + $Id: PHPDocumentPartitioner.java,v 1.2 2004-11-12 20:17:10 axelcl Exp $ + **********************************************************************/ package net.sourceforge.phpeclipse.phpeditor.php; import net.sourceforge.phpeclipse.PHPeclipsePlugin; @@ -22,72 +22,67 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.rules.IPartitionTokenScanner; - /** * * * @author Igor Malinin */ public class PHPDocumentPartitioner extends MultiViewPartitioner { - public static final String PHP_TEMPLATE_DATA = "__php_template_data"; - public static final String PHP_SCRIPT_CODE = "__php_script_code"; + public static final String PHP_TEMPLATE_DATA = "__php_template_data"; + + public static final String PHP_SCRIPT_CODE = "__php_script_code"; + + private IPartitionTokenScanner scriptScanner; - private IPartitionTokenScanner scriptScanner; + public PHPDocumentPartitioner(IPartitionTokenScanner scanner, IPartitionTokenScanner scriptScanner) { + super(scanner); - public PHPDocumentPartitioner( - IPartitionTokenScanner scanner, IPartitionTokenScanner scriptScanner - ) { - super(scanner); + this.scriptScanner = scriptScanner; + } - this.scriptScanner = scriptScanner; - } + protected FlatNode createNode(String type, int offset, int length) { + if (type.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA)) { + if (DEBUG) { + Assert.isTrue(offset >= 0); + } + ViewNode node = new ViewNode(type); + node.offset = offset; + node.length = length; + return node; + } - protected FlatNode createNode(String type, int offset, int length) { - if (type.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA) - ) { - if (DEBUG) { - Assert.isTrue(offset>=0); - } - ViewNode node = new ViewNode(type); - node.offset = offset; - node.length = length; - return node; - } + return super.createNode(type, offset, length); + } - return super.createNode(type, offset, length); - } + /* + * @see net.sf.solareclipse.text.rules.DocumentViewPartitioner#createPartitioner(String) + */ + protected IDocumentPartitioner createPartitioner(String contentType) { + if (contentType == null) { + // return JavaTextTools.createHTMLPartitioner(); + return PHPeclipsePlugin.getDefault().getJavaTextTools().getXMLTextTools().createXMLPartitioner(); + } - /* - * @see net.sf.solareclipse.text.rules.DocumentViewPartitioner#createPartitioner(String) - */ - protected IDocumentPartitioner createPartitioner(String contentType) { - if (contentType == null) { -// return JavaTextTools.createHTMLPartitioner(); - return PHPeclipsePlugin.getDefault().getJavaTextTools() - .getXMLTextTools().createXMLPartitioner(); - } - - if (contentType.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA) - ) { - return PHPeclipsePlugin.getDefault().getJavaTextTools().createPHPPartitioner(); - } - return null; - } + if (contentType.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA)) { + return PHPeclipsePlugin.getDefault().getJavaTextTools().createPHPPartitioner(); + } + return null; + } - /* - * @see net.sf.solareclipse.text.rules.DocumentViewPartitioner#getContentType(String, String) - */ - protected String getContentType(String parent, String view) { - if (parent == null) { - if (view == IDocument.DEFAULT_CONTENT_TYPE) { - return PHP_TEMPLATE_DATA; - } - } else { - if (view == IDocument.DEFAULT_CONTENT_TYPE) { - return PHP_SCRIPT_CODE; - } - } + /* + * @see net.sf.solareclipse.text.rules.DocumentViewPartitioner#getContentType(String, String) + */ + protected String getContentType(String parent, String view) { + if (parent == null) { + if (view == IDocument.DEFAULT_CONTENT_TYPE) { + return PHP_TEMPLATE_DATA; + } + } else { + if (view == IDocument.DEFAULT_CONTENT_TYPE) { + return PHP_SCRIPT_CODE; + } + } - return super.getContentType(parent, view); - } -} + return super.getContentType(parent, view); + } +} \ No newline at end of file -- 1.7.1 From 8c8f89b5be59299beddb6b0c24fbbef8a4be6f54 Mon Sep 17 00:00:00 2001 From: axelcl Date: Sat, 13 Nov 2004 12:36:32 +0000 Subject: [PATCH 16/16] inserted nodes.clear() for every Partitioner initializing --- .../ui/text/rules/AbstractPartitioner.java | 6 +- .../ui/text/rules/MultiViewPartitioner.java | 69 ++++++++++++++++++-- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/AbstractPartitioner.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/AbstractPartitioner.java index 981b803..d104237 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/AbstractPartitioner.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/AbstractPartitioner.java @@ -8,7 +8,7 @@ * Contributors: * Igor Malinin - initial contribution * - * $Id: AbstractPartitioner.java,v 1.1 2004-09-02 18:26:29 jsurfer Exp $ + * $Id: AbstractPartitioner.java,v 1.2 2004-11-13 12:36:32 axelcl Exp $ */ package net.sourceforge.phpeclipse.ui.text.rules; @@ -35,7 +35,7 @@ import org.eclipse.jface.text.rules.IToken; * @author Igor Malinin */ public abstract class AbstractPartitioner implements IDocumentPartitioner, IDocumentPartitionerExtension { - public final static boolean DEBUG = true; + public final static boolean DEBUG = false; /** Partition scanner */ protected IPartitionTokenScanner scanner; @@ -103,7 +103,7 @@ public abstract class AbstractPartitioner implements IDocumentPartitioner, IDocu */ protected void initialize() { scanner.setRange(document, 0, document.getLength()); - + nodes.clear(); IToken token = scanner.nextToken(); while (!token.isEOF()) { String contentType = getTokenContentType(token); diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java index ea7cdda..4bd1a6c 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/text/rules/MultiViewPartitioner.java @@ -8,7 +8,7 @@ * Contributors: * Igor Malinin - initial contribution * - * $Id: MultiViewPartitioner.java,v 1.6 2004-11-12 20:15:58 axelcl Exp $ + * $Id: MultiViewPartitioner.java,v 1.7 2004-11-13 12:36:32 axelcl Exp $ */ package net.sourceforge.phpeclipse.ui.text.rules; @@ -436,7 +436,13 @@ public abstract class MultiViewPartitioner extends AbstractPartitioner { */ public ITypedRegion[] computePartitioning(int offset, int length) { List list = new ArrayList(); - +// if (DEBUG) { +// System.out.print("MultiViewPartitioner::computePartitioning - Offset: "); +// System.out.print(offset); +// System.out.print(", Length: "); +// System.out.print(length); +// System.out.println(""); +// } int end = offset + length; int index = computeFlatNodeIndex(offset); @@ -465,10 +471,33 @@ public abstract class MultiViewPartitioner extends AbstractPartitioner { ++index; } - +// if (DEBUG) { +// showList(list); +// } + return (TypedRegion[]) list.toArray(new TypedRegion[list.size()]); } + private void showList(List list) { + try { + throw new NullPointerException(); + } catch (Exception e){ + e.printStackTrace(); + } + System.out.println(">>>>>List start"); + TypedRegion temp; + for (int i = 0; i < list.size(); i++) { + temp = (TypedRegion)list.get(i); + System.out.print("Offset: "); + System.out.print(temp.getOffset()); + System.out.print(", Length: "); + System.out.print(temp.getLength()); + System.out.print(", Type: "); + System.out.print(temp.getType()); + System.out.println(""); + } + System.out.println("<<<<