From 8dea0852fb960db1f239c6ea439b134addbb846c Mon Sep 17 00:00:00 2001 From: khartlage Date: Fri, 5 Mar 2004 21:11:46 +0000 Subject: [PATCH] misc parser changes --- .../sourceforge/phpdt/core/compiler/IProblem.java | 2 + .../phpdt/core/compiler/ITerminalSymbols.java | 14 +- .../phpdt/internal/compiler/parser/Parser.java | 355 +- .../phpdt/internal/compiler/parser/Scanner.java | 1425 +++--- .../internal/compiler/problem/ProblemHandler.java | 5 +- .../internal/compiler/problem/ProblemReporter.java | 5476 ++++++++++---------- .../internal/compiler/problem/messages.properties | 5 +- .../phpdt/internal/formatter/CodeFormatter.java | 2 +- 8 files changed, 3574 insertions(+), 3710 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IProblem.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IProblem.java index b6241ef..5674266 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IProblem.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IProblem.java @@ -365,6 +365,8 @@ public interface IProblem { int ParsingErrorOnKeyword = Syntax + Internal + 209; int ParsingErrorOnKeywordNoSuggestion = Syntax + Internal + 210; int PHPParsingError = Syntax + Internal + 211; + int PHPParsingWarning = Syntax + Internal + 212; + int PHPVarDeprecatedWarning = Syntax + Internal + 213; int UnmatchedBracket = Syntax + Internal + 220; int NoFieldOnBaseType = FieldRelated + 221; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java index d9e97af..cc27c47 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java @@ -77,7 +77,7 @@ public interface ITerminalSymbols { final static int TokenNameAND_EQUAL = 60; final static int TokenNameOR_EQUAL = 61; final static int TokenNameQUESTION = 62; - final static int TokenNameCOLON_COLON = 63; + final static int TokenNamePAAMAYIM_NEKUDOTAYIM = 63; final static int TokenNameAT = 64; final static int TokenNameDOLLAR_LBRACE = 127; @@ -155,9 +155,9 @@ public interface ITerminalSymbols { // public final static int TokenNameor = 1041; // public final static int TokenNamexor = 1042; public final static int TokenNamelist = 1043; - public final static int TokenNamenull = 1044; - public final static int TokenNamefalse = 1045; - public final static int TokenNametrue = 1046; +// public final static int TokenNamenull = 1044; +// public final static int TokenNamefalse = 1045; +// public final static int TokenNametrue = 1046; public final static int TokenNamethis = 1047; // public final static int TokenNameabstract = 1050; @@ -180,4 +180,10 @@ public interface ITerminalSymbols { public final static int TokenNameuse = 1066; public final static int TokenNameisset = 1066; public final static int TokenNamefinal = 1067; + + public final static int TokenNameLINE = 1070; + public final static int TokenNameFILE = 1071; + public final static int TokenNameCLASS_C = 1072; + public final static int TokenNameMETHOD_C = 1073; + public final static int TokenNameFUNC_C = 1074; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java index 7369a24..f389faa 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java @@ -165,6 +165,12 @@ public class Parser //extends PHPParserSuperclass problemEndPosition, referenceContext, compilationUnit.compilationResult); } + private void reportSyntaxWarning(String error, int problemStartPosition, + int problemEndPosition) { + problemReporter.phpParsingWarning(new String[]{error}, + problemStartPosition, problemEndPosition, referenceContext, + compilationUnit.compilationResult); + } /** * Method Declaration. * @@ -1222,38 +1228,38 @@ public class Parser //extends PHPParserSuperclass // getNextToken(); // } // return; -// } else if (token == TokenNamedefine) { -// getNextToken(); -// if (token == TokenNameLPAREN) { -// getNextToken(); -// } else { -// throwSyntaxError("'(' expected after 'define' keyword."); -// } -// expr(); -// if (token == TokenNameCOMMA) { -// getNextToken(); -// } else { -// throwSyntaxError("',' expected after first 'define' constant."); -// } -// expr(); -// if (token == TokenNameCOMMA) { -// getNextToken(); -// expr(); -// } -// if (token == TokenNameRPAREN) { -// getNextToken(); -// } else { -// throwSyntaxError("')' expected after 'define' statement."); -// } -// if (token == TokenNameSEMICOLON) { -// getNextToken(); -// } else { -// if (token != TokenNameStopPHP) { -// throwSyntaxError("';' expected after 'define' statement."); -// } -// getNextToken(); -// } -// return; + // } else if (token == TokenNamedefine) { + // getNextToken(); + // if (token == TokenNameLPAREN) { + // getNextToken(); + // } else { + // throwSyntaxError("'(' expected after 'define' keyword."); + // } + // expr(); + // if (token == TokenNameCOMMA) { + // getNextToken(); + // } else { + // throwSyntaxError("',' expected after first 'define' constant."); + // } + // expr(); + // if (token == TokenNameCOMMA) { + // getNextToken(); + // expr(); + // } + // if (token == TokenNameRPAREN) { + // getNextToken(); + // } else { + // throwSyntaxError("')' expected after 'define' statement."); + // } + // if (token == TokenNameSEMICOLON) { + // getNextToken(); + // } else { + // if (token != TokenNameStopPHP) { + // throwSyntaxError("';' expected after 'define' statement."); + // } + // getNextToken(); + // } + // return; } else if (token == TokenNamefunction) { MethodDeclaration methodDecl = new MethodDeclaration( this.compilationUnit.compilationResult); @@ -1437,7 +1443,7 @@ public class Parser //extends PHPParserSuperclass } getNextToken(); } else { - throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected"); + throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected"); } } private void interface_extends_list() { @@ -1492,14 +1498,10 @@ public class Parser //extends PHPParserSuperclass private void class_statement_list() { do { class_statement(); - } while (token == TokenNamepublic || - token == TokenNameprotected || - token == TokenNameprivate || - token == TokenNamestatic || - token == TokenNameabstract || - token == TokenNamefinal || - token == TokenNamefunction || - token == TokenNamevar); + } while (token == TokenNamepublic || token == TokenNameprotected + || token == TokenNameprivate || token == TokenNamestatic + || token == TokenNameabstract || token == TokenNamefinal + || token == TokenNamefunction || token == TokenNamevar); } private void class_statement() { // class_statement: @@ -1510,12 +1512,12 @@ public class Parser //extends PHPParserSuperclass initializeModifiers(); if (token == TokenNamevar) { checkAndSetModifiers(AccPublic); - reportSyntaxError( - "Keyword 'var' is deprecated. Please use 'public' 'private' or 'protected' modifier for field declarations.", - scanner.getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition()); + problemReporter.phpVarDeprecatedWarning(scanner + .getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition(), referenceContext, + compilationUnit.compilationResult); getNextToken(); - classProperty(); + class_variable_declaration(); } else { boolean hasModifiers = member_modifiers(); if (token == TokenNamefunction) { @@ -1533,7 +1535,7 @@ public class Parser //extends PHPParserSuperclass if (!hasModifiers) { throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations."); } - classProperty(); + class_variable_declaration(); } } // if (token == TokenNamefunction) { @@ -1618,32 +1620,34 @@ public class Parser //extends PHPParserSuperclass } return foundToken; } - private void classProperty() { - //'var' variable ';' - //'var' variable '=' constant ';' + private void class_variable_declaration() { + // class_variable_declaration: + // class_variable_declaration ',' T_VARIABLE + // | class_variable_declaration ',' T_VARIABLE '=' static_scalar + // | T_VARIABLE + // | T_VARIABLE '=' static_scalar do { if (token == TokenNameVariable) { getNextToken(); if (token == TokenNameEQUAL) { getNextToken(); - constant(); + static_scalar(); } } else { if (token == TokenNamethis) { - throwSyntaxError("Reserved word '$this' not allowed after keyword 'var'."); + throwSyntaxError("'$this' not allowed after keyword 'public' 'protected' 'private' 'var'."); } - throwSyntaxError("Variable expected after keyword 'var'."); + throwSyntaxError("Variable expected keyword 'public' 'protected' 'private' 'var'."); } if (token != TokenNameCOMMA) { break; } getNextToken(); } while (true); - if (token == TokenNameSEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after variable declaration."); + if (token != TokenNameSEMICOLON) { + throwSyntaxError("';' expected after field declaration."); } + getNextToken(); } private void functionDefinition(MethodDeclaration methodDecl) { if (astPtr == 0) { @@ -1730,7 +1734,7 @@ public class Parser //extends PHPParserSuperclass getNextToken(); if (token == TokenNameEQUAL) { getNextToken(); - constant(); + static_scalar(); } return; } @@ -2077,15 +2081,16 @@ public class Parser //extends PHPParserSuperclass getNextToken(); expr(); break; - case TokenNamenull : - getNextToken(); - break; - case TokenNamefalse : - getNextToken(); - break; - case TokenNametrue : - getNextToken(); - break; + // + // case TokenNamenull : + // getNextToken(); + // break; + // case TokenNamefalse : + // getNextToken(); + // break; + // case TokenNametrue : + // getNextToken(); + // break; case TokenNameStringConstant : getNextToken(); break; @@ -2193,7 +2198,7 @@ public class Parser //extends PHPParserSuperclass } break; case TokenNamearray : - // T_ARRAY '(' array_pair_list ')' + // T_ARRAY '(' array_pair_list ')' getNextToken(); if (token == TokenNameLPAREN) { getNextToken(); @@ -2299,7 +2304,7 @@ public class Parser //extends PHPParserSuperclass } getNextToken(); break; - case TokenNameCOLON_COLON : + case TokenNamePAAMAYIM_NEKUDOTAYIM : // :: case TokenNameMINUS_GREATER : // -> @@ -2386,28 +2391,48 @@ public class Parser //extends PHPParserSuperclass } while (while_flag); } private void array_pair_list() { -// array_pair_list: -// /* empty */ -//| non_empty_array_pair_list possible_comma + // array_pair_list: + // /* empty */ + //| non_empty_array_pair_list possible_comma non_empty_array_pair_list(); if (token == TokenNameCOMMA) { getNextToken(); } } - - private void non_empty_array_pair_list() { -//non_empty_array_pair_list: -// non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr -//| non_empty_array_pair_list ',' expr -//| expr T_DOUBLE_ARROW expr -//| expr -//| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable -//| non_empty_array_pair_list ',' '&' w_variable -//| expr T_DOUBLE_ARROW '&' w_variable -//| '&' w_variable - } - + //non_empty_array_pair_list: + // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr + //| non_empty_array_pair_list ',' expr + //| expr T_DOUBLE_ARROW expr + //| expr + //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable + //| non_empty_array_pair_list ',' '&' w_variable + //| expr T_DOUBLE_ARROW '&' w_variable + //| '&' w_variable + while (true) { + expr(); + if (token == TokenNameAND) { + getNextToken(); + variable(); + return; + } else if (token == TokenNameEQUAL_GREATER) { + getNextToken(); + if (token == TokenNameAND) { + getNextToken(); + variable(); + } else { + expr(); + } + } + if (token != TokenNameCOMMA) { + return; + } + getNextToken(); + if (token == TokenNameRPAREN) { + return; + } + } + } private void unaryExpression() { switch (token) { case TokenNamePLUS_PLUS : @@ -2706,7 +2731,7 @@ public class Parser //extends PHPParserSuperclass getNextToken(); } else if (token == TokenNameEQUAL) { getNextToken(); - constant(); + static_scalar(); } } else { throwSyntaxError("$-variable expected in variable-list."); @@ -2809,80 +2834,132 @@ public class Parser //extends PHPParserSuperclass } } } - /** - * It will look for a value (after a '=' for example) @ - */ - private void constant() { - // String ident; + private boolean common_scalar() { + // common_scalar: + // T_LNUMBER + // | T_DNUMBER + // | T_CONSTANT_ENCAPSED_STRING + // | T_LINE + // | T_FILE + // | T_CLASS_C + // | T_METHOD_C + // | T_FUNC_C switch (token) { - case TokenNamePLUS : + case TokenNameIntegerLiteral : getNextToken(); - switch (token) { - case TokenNameDoubleLiteral : - getNextToken(); - break; - case TokenNameIntegerLiteral : - getNextToken(); - break; - default : - throwSyntaxError("Constant expected after '+' presign."); - } - break; - case TokenNameMINUS : + return true; + case TokenNameDoubleLiteral : getNextToken(); - switch (token) { - case TokenNameDoubleLiteral : - getNextToken(); - break; - case TokenNameIntegerLiteral : - getNextToken(); - break; - default : - throwSyntaxError("Constant expected after '-' presign."); - } - break; - case TokenNamenull : + return true; + case TokenNameStringLiteral : getNextToken(); - break; - case TokenNamefalse : + return true; + case TokenNameStringConstant : getNextToken(); - break; - case TokenNametrue : + return true; + case TokenNameStringInterpolated : getNextToken(); - break; + return true; + case TokenNameFILE : + getNextToken(); + return true; + case TokenNameLINE : + getNextToken(); + return true; + case TokenNameCLASS_C : + getNextToken(); + return true; + case TokenNameMETHOD_C : + getNextToken(); + return true; + case TokenNameFUNC_C : + getNextToken(); + return true; + } + return false; + } + private void static_scalar() { + // static_scalar: /* compile-time evaluated scalars */ + // common_scalar + // | T_STRING + // | '+' static_scalar + // | '-' static_scalar + // | T_ARRAY '(' static_array_pair_list ')' + // | static_class_constant + if (common_scalar()) { + return; + } + switch (token) { case TokenNameIdentifier : - // ident = identifier; - char[] ident = scanner.getCurrentIdentifierSource(); getNextToken(); - if (token == TokenNameLPAREN) { + // static_class_constant: + // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING + if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) { getNextToken(); - if (token != TokenNameRPAREN) { - expressionList(); - if (token != TokenNameRPAREN) { - throwSyntaxError("')' expected after identifier '" - + new String(ident) + "' in postfix-expression."); - } + if (token == TokenNameIdentifier) { + getNextToken(); + } else { + throwSyntaxError("Identifier expected after '::' operator."); } - getNextToken(); } break; - case TokenNameStringLiteral : + case TokenNamePLUS : getNextToken(); + static_scalar(); break; - case TokenNameStringConstant : + case TokenNameMINUS : getNextToken(); + static_scalar(); break; - case TokenNameStringInterpolated : + case TokenNamearray : getNextToken(); - break; - case TokenNameDoubleLiteral : + if (token != TokenNameLPAREN) { + throwSyntaxError("'(' expected after keyword 'array'"); + } getNextToken(); - break; - case TokenNameIntegerLiteral : + if (token == TokenNameRPAREN) { + getNextToken(); + break; + } + non_empty_static_array_pair_list(); + if (token != TokenNameRPAREN) { + throwSyntaxError("')' expected after keyword 'array'"); + } getNextToken(); break; + // case TokenNamenull : + // getNextToken(); + // break; + // case TokenNamefalse : + // getNextToken(); + // break; + // case TokenNametrue : + // getNextToken(); + // break; default : - throwSyntaxError("Constant expected."); + throwSyntaxError("Static scalar/constant expected."); + } + } + private void non_empty_static_array_pair_list() { + // non_empty_static_array_pair_list: + // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW + // static_scalar + //| non_empty_static_array_pair_list ',' static_scalar + //| static_scalar T_DOUBLE_ARROW static_scalar + //| static_scalar + while (true) { + static_scalar(); + if (token == TokenNameEQUAL_GREATER) { + getNextToken(); + static_scalar(); + } + if (token != TokenNameCOMMA) { + break; + } + getNextToken(); + if (token != TokenNameRPAREN) { + break; + } } } public void reportSyntaxError() { //int act, int currentKind, int 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 a9520dd..bef873a 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 @@ -9,72 +9,59 @@ * 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; - import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.core.compiler.IScanner; import net.sourceforge.phpdt.core.compiler.ITerminalSymbols; import net.sourceforge.phpdt.core.compiler.InvalidInputException; import net.sourceforge.phpdt.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 phpMode = false; - 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 - + // after this position eof are generated instead of real token from the + // source public boolean tokenizeComments; public boolean tokenizeWhiteSpace; - //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 char[][] comments = new char[10][]; public int[] commentStops = new int[10]; public int[] commentStarts = new int[10]; public int commentPtr = -1; // no comment test with commentPtr value -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$ @@ -82,45 +69,31 @@ public class Scanner implements IScanner, ITerminalSymbols { 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 */ + public/* static */ final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][]; // support for detecting non-externalized string literals int currentLineNr = -1; @@ -134,8 +107,7 @@ public class Scanner implements IScanner, ITerminalSymbols { public StringLiteral[] nonNLSStrings = null; public boolean checkNonExternalizedStringLiterals = true; public boolean wasNonExternalizedStringLiteral = false; - - /* static */ { + /* static */{ for (int i = 0; i < 6; i++) { for (int j = 0; j < TableSize; j++) { for (int k = 0; k < InternalTableSize; k++) { @@ -144,13 +116,12 @@ 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; @@ -159,39 +130,35 @@ public class Scanner implements IScanner, ITerminalSymbols { public int foundTaskCount = 0; public char[][] taskTags = null; public char[][] taskPriorities = null; - - public static final boolean DEBUG = true; - + public static final boolean DEBUG = false; public Scanner() { this(false, false); } public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) { this(tokenizeComments, tokenizeWhiteSpace, 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; // if (withoutUnicodePtr != 0) // //0 is used as a fast test flag so the real first char is in position 1 @@ -218,17 +185,16 @@ public class Scanner implements IScanner, ITerminalSymbols { 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; // if (withoutUnicodePtr != 0) // // 0 is used as a fast test flag so the real first char is in position 1 @@ -240,14 +206,13 @@ 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; // if (withoutUnicodePtr != 0) // // 0 is used as a fast test flag so the real first char is in position 1 @@ -259,81 +224,79 @@ 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); + 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. */ public final int getLineEnd(int lineNumber) { - if (lineEnds == null) return -1; if (lineNumber >= lineEnds.length) return -1; if (lineNumber <= 0) return -1; - if (lineNumber == lineEnds.length - 1) return eofPosition; 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. * * In case the given line number is inconsistent, answers -1. */ public final int getLineStart(int lineNumber) { - if (lineEnds == null) return -1; if (lineNumber >= lineEnds.length) return -1; if (lineNumber <= 0) return -1; - if (lineNumber == 1) return initialPosition; return lineEnds[lineNumber - 2] + 1; @@ -342,14 +305,14 @@ public class Scanner implements IScanner, ITerminalSymbols { public final boolean getNextChar(char testedChar) { //BOOLEAN //handle the case of unicode. - //when a unicode appears then we must use a buffer that holds char internal values + //when a unicode appears then we must use a buffer that holds char + // internal values //At the end of this method currentCharacter holds the new visited char //and currentPosition points right next after it - //Both previous lines are true if the currentCharacter is == to the testedChar + //Both previous lines are true if the currentCharacter is == to the + // testedChar //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES - int temp = currentPosition; try { currentCharacter = source[currentPosition++]; @@ -419,14 +382,14 @@ public class Scanner implements IScanner, ITerminalSymbols { //INT 0 : testChar1 \\\\///\\\\ 1 : testedChar2 \\\\///\\\\ -1 : others //test can be done with (x==0) for the first and (x>0) for the second //handle the case of unicode. - //when a unicode appears then we must use a buffer that holds char internal values + //when a unicode appears then we must use a buffer that holds char + // internal values //At the end of this method currentCharacter holds the new visited char //and currentPosition points right next after it - //Both previous lines are true if the currentCharacter is == to the testedChar1/2 + //Both previous lines are true if the currentCharacter is == to the + // testedChar1/2 //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES - int temp = currentPosition; try { int result; @@ -488,7 +451,6 @@ public class Scanner implements IScanner, ITerminalSymbols { currentPosition = temp; return -1; } - // if (withoutUnicodePtr != 0) // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; return result; @@ -501,14 +463,13 @@ public class Scanner implements IScanner, ITerminalSymbols { public final boolean getNextCharAsDigit() { //BOOLEAN //handle the case of unicode. - //when a unicode appears then we must use a buffer that holds char internal values + //when a unicode appears then we must use a buffer that holds char + // internal values //At the end of this method currentCharacter holds the new visited char //and currentPosition points right next after it //Both previous lines are true if the currentCharacter is a digit //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES - int temp = currentPosition; try { currentCharacter = source[currentPosition++]; @@ -573,14 +534,14 @@ public class Scanner implements IScanner, ITerminalSymbols { public final boolean getNextCharAsDigit(int radix) { //BOOLEAN //handle the case of unicode. - //when a unicode appears then we must use a buffer that holds char internal values + //when a unicode appears then we must use a buffer that holds char + // internal values //At the end of this method currentCharacter holds the new visited char //and currentPosition points right next after it - //Both previous lines are true if the currentCharacter is a digit base on radix + //Both previous lines are true if the currentCharacter is a digit base on + // radix //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES - int temp = currentPosition; try { currentCharacter = source[currentPosition++]; @@ -645,14 +606,14 @@ public class Scanner implements IScanner, ITerminalSymbols { public boolean getNextCharAsJavaIdentifierPart() { //BOOLEAN //handle the case of unicode. - //when a unicode appears then we must use a buffer that holds char internal values + //when a unicode appears then we must use a buffer that holds char + // internal values //At the end of this method currentCharacter holds the new visited char //and currentPosition points right next after it - //Both previous lines are true if the currentCharacter is a JavaIdentifierPart + //Both previous lines are true if the currentCharacter is a + // JavaIdentifierPart //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES - int temp = currentPosition; try { currentCharacter = source[currentPosition++]; @@ -705,7 +666,6 @@ public class Scanner implements IScanner, ITerminalSymbols { currentPosition = temp; return false; } - // if (withoutUnicodePtr != 0) // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; return true; @@ -715,7 +675,6 @@ public class Scanner implements IScanner, ITerminalSymbols { return false; } } - public int getNextToken() throws InvalidInputException { int htmlPosition = currentPosition; try { @@ -724,18 +683,21 @@ public class Scanner implements IScanner, ITerminalSymbols { if (currentCharacter == '<') { if (getNextChar('?')) { currentCharacter = source[currentPosition++]; - if ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) { + if ((currentCharacter == ' ') + || Character.isWhitespace(currentCharacter)) { // = 0) { @@ -744,10 +706,10 @@ public class Scanner implements IScanner, ITerminalSymbols { // eofPosition) return TokenNameEOF; - // ---------Identify the next token------------- - switch (currentCharacter) { case '(' : return TokenNameLPAREN; @@ -838,7 +796,6 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameSEMICOLON; case ',' : return TokenNameCOMMA; - case '.' : if (getNextCharAsDigit()) return scanNumber(true); @@ -861,7 +818,6 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameMINUS_EQUAL; if (getNextChar('>')) return TokenNameMINUS_GREATER; - return TokenNameMINUS; } case '~' : @@ -904,9 +860,7 @@ public class Scanner implements IScanner, ITerminalSymbols { while (isPHPIdentifierPart(currentCharacter)) { currentCharacter = source[currentPosition++]; } - heredocLength = currentPosition - heredocStart - 1; - // heredoc end-tag determination boolean endTag = true; char ch; @@ -919,7 +873,8 @@ public class Scanner implements IScanner, ITerminalSymbols { currentLine = null; } for (int i = 0; i < heredocLength; i++) { - if (source[currentPosition + i] != source[heredocStart + i]) { + if (source[currentPosition + i] != source[heredocStart + + i]) { endTag = false; break; } @@ -932,9 +887,7 @@ public class Scanner implements IScanner, ITerminalSymbols { endTag = true; } } - } while (true); - return TokenNameHEREDOC; } return TokenNameLEFT_SHIFT; @@ -993,84 +946,87 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameQUESTION; case ':' : if (getNextChar(':')) - return TokenNameCOLON_COLON; + return TokenNamePAAMAYIM_NEKUDOTAYIM; return TokenNameCOLON; case '@' : return TokenNameAT; - // case '\'' : - // { - // int test; - // if ((test = getNextChar('\n', '\r')) == 0) { - // throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); - // } - // if (test > 0) { - // // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed - // for (int lookAhead = 0; - // lookAhead < 3; - // lookAhead++) { - // if (currentPosition + lookAhead - // == source.length) - // break; - // if (source[currentPosition + lookAhead] - // == '\n') - // break; - // if (source[currentPosition + lookAhead] - // == '\'') { - // currentPosition += lookAhead + 1; - // break; - // } - // } - // throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); - // } - // } - // if (getNextChar('\'')) { - // // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed - // for (int lookAhead = 0; - // lookAhead < 3; - // lookAhead++) { - // if (currentPosition + lookAhead - // == source.length) - // break; - // if (source[currentPosition + lookAhead] - // == '\n') - // break; - // if (source[currentPosition + lookAhead] - // == '\'') { - // currentPosition += lookAhead + 1; - // break; - // } - // } - // throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); - // } - // if (getNextChar('\\')) - // scanEscapeCharacter(); - // else { // consume next character - // unicodeAsBackSlash = false; - // if (((currentCharacter = source[currentPosition++]) - // == '\\') - // && (source[currentPosition] == 'u')) { - // getNextUnicodeChar(); - // } else { - // if (withoutUnicodePtr != 0) { - // withoutUnicodeBuffer[++withoutUnicodePtr] = - // currentCharacter; - // } - // } - // } - // // if (getNextChar('\'')) - // // return TokenNameCharacterLiteral; - // // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed - // for (int lookAhead = 0; lookAhead < 20; lookAhead++) { - // if (currentPosition + lookAhead == source.length) - // break; - // if (source[currentPosition + lookAhead] == '\n') - // break; - // if (source[currentPosition + lookAhead] == '\'') { - // currentPosition += lookAhead + 1; - // break; - // } - // } - // throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); + // case '\'' : + // { + // int test; + // if ((test = getNextChar('\n', '\r')) == 0) { + // throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); + // } + // if (test > 0) { + // // relocate if finding another quote fairly close: thus unicode + // '/u000D' will be fully consumed + // for (int lookAhead = 0; + // lookAhead < 3; + // lookAhead++) { + // if (currentPosition + lookAhead + // == source.length) + // break; + // if (source[currentPosition + lookAhead] + // == '\n') + // break; + // if (source[currentPosition + lookAhead] + // == '\'') { + // currentPosition += lookAhead + 1; + // break; + // } + // } + // throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); + // } + // } + // if (getNextChar('\'')) { + // // relocate if finding another quote fairly close: thus unicode + // '/u000D' will be fully consumed + // for (int lookAhead = 0; + // lookAhead < 3; + // lookAhead++) { + // if (currentPosition + lookAhead + // == source.length) + // break; + // if (source[currentPosition + lookAhead] + // == '\n') + // break; + // if (source[currentPosition + lookAhead] + // == '\'') { + // currentPosition += lookAhead + 1; + // break; + // } + // } + // throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); + // } + // if (getNextChar('\\')) + // scanEscapeCharacter(); + // else { // consume next character + // unicodeAsBackSlash = false; + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = + // currentCharacter; + // } + // } + // } + // // if (getNextChar('\'')) + // // return TokenNameCharacterLiteral; + // // relocate if finding another quote fairly close: thus unicode + // '/u000D' will be fully consumed + // for (int lookAhead = 0; lookAhead < 20; lookAhead++) { + // if (currentPosition + lookAhead == source.length) + // break; + // if (source[currentPosition + lookAhead] == '\n') + // break; + // if (source[currentPosition + lookAhead] == '\'') { + // currentPosition += lookAhead + 1; + // break; + // } + // } + // throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); case '\'' : try { // consume next character @@ -1085,13 +1041,12 @@ public class Scanner implements IScanner, ITerminalSymbols { // currentCharacter; // } // } - while (currentCharacter != '\'') { - /** ** in PHP \r and \n are valid in string literals *** */ // if ((currentCharacter == '\n') // || (currentCharacter == '\r')) { - // // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed + // // relocate if finding another quote fairly close: thus + // unicode '/u000D' will be fully consumed // for (int lookAhead = 0; lookAhead < 50; lookAhead++) { // if (currentPosition + lookAhead == source.length) // break; @@ -1107,17 +1062,22 @@ public class Scanner implements IScanner, ITerminalSymbols { if (currentCharacter == '\\') { 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 + //scanEscapeCharacter make a side effect on this value and + // we need the previous value few lines down this one scanSingleQuotedEscapeCharacter(); 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 + if (backSlashAsUnicodeInString) { //there are TWO \ in + // the stream where + // only one is correct withoutUnicodePtr--; } } @@ -1125,7 +1085,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') + // if (((currentCharacter = source[currentPosition++]) == + // '\\') // && (source[currentPosition] == 'u')) { // getNextUnicodeChar(); // } else { @@ -1133,13 +1094,13 @@ public class Scanner implements IScanner, ITerminalSymbols { withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } // } - } } catch (IndexOutOfBoundsException e) { throw new InvalidInputException(UNTERMINATED_STRING); } catch (InvalidInputException e) { if (e.getMessage().equals(INVALID_ESCAPE)) { - // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed + // relocate if finding another quote fairly close: thus + // unicode '/u000D' will be fully consumed for (int lookAhead = 0; lookAhead < 50; lookAhead++) { if (currentPosition + lookAhead == source.length) break; @@ -1150,16 +1111,20 @@ public class Scanner implements IScanner, ITerminalSymbols { break; } } - } throw e; // rethrow } - if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags //$NON-NLS-?$ where ? is an int. + if (checkNonExternalizedStringLiterals) { // check for presence + // of NLS tags + // //$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)); } return TokenNameStringConstant; case '"' : @@ -1176,13 +1141,12 @@ public class Scanner implements IScanner, ITerminalSymbols { // currentCharacter; // } // } - while (currentCharacter != '"') { - /** ** in PHP \r and \n are valid in string literals *** */ // if ((currentCharacter == '\n') // || (currentCharacter == '\r')) { - // // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed + // // relocate if finding another quote fairly close: thus + // unicode '/u000D' will be fully consumed // for (int lookAhead = 0; lookAhead < 50; lookAhead++) { // if (currentPosition + lookAhead == source.length) // break; @@ -1198,17 +1162,22 @@ public class Scanner implements IScanner, ITerminalSymbols { if (currentCharacter == '\\') { 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 + //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); + 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 + if (backSlashAsUnicodeInString) { //there are TWO \ in + // the stream where + // only one is correct withoutUnicodePtr--; } } @@ -1216,7 +1185,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') + // if (((currentCharacter = source[currentPosition++]) == + // '\\') // && (source[currentPosition] == 'u')) { // getNextUnicodeChar(); // } else { @@ -1224,13 +1194,13 @@ public class Scanner implements IScanner, ITerminalSymbols { withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } // } - } } catch (IndexOutOfBoundsException e) { throw new InvalidInputException(UNTERMINATED_STRING); } catch (InvalidInputException e) { if (e.getMessage().equals(INVALID_ESCAPE)) { - // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed + // relocate if finding another quote fairly close: thus + // unicode '/u000D' will be fully consumed for (int lookAhead = 0; lookAhead < 50; lookAhead++) { if (currentPosition + lookAhead == source.length) break; @@ -1241,16 +1211,20 @@ public class Scanner implements IScanner, ITerminalSymbols { break; } } - } throw e; // rethrow } - if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags //$NON-NLS-?$ where ? is an int. + if (checkNonExternalizedStringLiterals) { // check for presence + // of NLS tags + // //$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)); } return TokenNameStringLiteral; case '`' : @@ -1267,13 +1241,12 @@ public class Scanner implements IScanner, ITerminalSymbols { // currentCharacter; // } // } - while (currentCharacter != '`') { - /** ** in PHP \r and \n are valid in string literals *** */ // if ((currentCharacter == '\n') // || (currentCharacter == '\r')) { - // // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed + // // relocate if finding another quote fairly close: thus + // unicode '/u000D' will be fully consumed // for (int lookAhead = 0; lookAhead < 50; lookAhead++) { // if (currentPosition + lookAhead == source.length) // break; @@ -1289,17 +1262,22 @@ public class Scanner implements IScanner, ITerminalSymbols { if (currentCharacter == '\\') { 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 + //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); + 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 + if (backSlashAsUnicodeInString) { //there are TWO \ in + // the stream where + // only one is correct withoutUnicodePtr--; } } @@ -1307,7 +1285,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') + // if (((currentCharacter = source[currentPosition++]) == + // '\\') // && (source[currentPosition] == 'u')) { // getNextUnicodeChar(); // } else { @@ -1315,13 +1294,13 @@ public class Scanner implements IScanner, ITerminalSymbols { withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } // } - } } catch (IndexOutOfBoundsException e) { throw new InvalidInputException(UNTERMINATED_STRING); } catch (InvalidInputException e) { if (e.getMessage().equals(INVALID_ESCAPE)) { - // relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed + // relocate if finding another quote fairly close: thus + // unicode '/u000D' will be fully consumed for (int lookAhead = 0; lookAhead < 50; lookAhead++) { if (currentPosition + lookAhead == source.length) break; @@ -1332,23 +1311,28 @@ public class Scanner implements IScanner, ITerminalSymbols { break; } } - } throw e; // rethrow } - if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags //$NON-NLS-?$ where ? is an int. + if (checkNonExternalizedStringLiterals) { // check for presence + // of NLS tags + // //$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)); } return TokenNameStringInterpolated; case '#' : case '/' : { int test; - if ((currentCharacter == '#') || (test = getNextChar('/', '*')) == 0) { + if ((currentCharacter == '#') + || (test = getNextChar('/', '*')) == 0) { //line comment int endPositionForLineComment = 0; try { //get the next char @@ -1384,7 +1368,6 @@ public class Scanner implements IScanner, ITerminalSymbols { // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); // } // } - //handle the \\u case manually into comment // if (currentCharacter == '\\') { // if (source[currentPosition] == '\\') @@ -1399,7 +1382,6 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameStopPHP; } } - //get the next char isUnicode = false; currentCharacter = source[currentPosition++]; @@ -1432,7 +1414,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // source[currentPosition++])) // > 15 // || c4 < 0) { - // throw new InvalidInputException(INVALID_UNICODE_ESCAPE); + // throw new + // InvalidInputException(INVALID_UNICODE_ESCAPE); // } else { // currentCharacter = // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); @@ -1450,7 +1433,8 @@ public class Scanner implements IScanner, ITerminalSymbols { endPositionForLineComment = currentPosition - 1; } recordComment(false); - if ((currentCharacter == '\r') || (currentCharacter == '\n')) { + if ((currentCharacter == '\r') + || (currentCharacter == '\n')) { checkNonExternalizeString(); if (recordLineSeparator) { if (isUnicode) { @@ -1469,7 +1453,8 @@ public class Scanner implements IScanner, ITerminalSymbols { } return TokenNameCOMMENT_LINE; } - } catch (IndexOutOfBoundsException e) { //an eof will them be generated + } catch (IndexOutOfBoundsException e) { //an eof will them + // be generated if (tokenizeComments) { currentPosition--; // reset one character behind @@ -1484,7 +1469,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') + // if (((currentCharacter = source[currentPosition++]) == + // '\\') // && (source[currentPosition] == 'u')) { // getNextUnicodeChar(); // } else { @@ -1493,7 +1479,6 @@ public class Scanner implements IScanner, ITerminalSymbols { // currentCharacter; // } // } - if (currentCharacter == '*') { isJavadoc = true; star = true; @@ -1526,7 +1511,8 @@ public class Scanner implements IScanner, ITerminalSymbols { } //loop until end of comment */ while ((currentCharacter != '/') || (!star)) { - if ((currentCharacter == '\r') || (currentCharacter == '\n')) { + if ((currentCharacter == '\r') + || (currentCharacter == '\n')) { checkNonExternalizeString(); if (recordLineSeparator) { pushLineSeparator(); @@ -1567,9 +1553,9 @@ public class Scanner implements IScanner, ITerminalSymbols { case '\u001a' : if (atEnd()) return TokenNameEOF; - //the atEnd may not be if source is only some part of a real (external) stream + //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 == '$') { while ((currentCharacter = source[currentPosition++]) == '$') { @@ -1593,12 +1579,12 @@ public class Scanner implements IScanner, ITerminalSymbols { } return TokenNameEOF; } - // public final void getNextUnicodeChar() // throws IndexOutOfBoundsException, InvalidInputException { // //VOID // //handle the case of unicode. - // //when a unicode appears then we must use a buffer that holds char internal values + // //when a unicode appears then we must use a buffer that holds char + // internal values // //At the end of this method currentCharacter holds the new visited char // //and currentPosition points right next after it // @@ -1639,10 +1625,10 @@ 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; int found = 1; try { @@ -1656,12 +1642,12 @@ 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 '{' : @@ -1757,7 +1743,8 @@ public class Scanner implements IScanner, ITerminalSymbols { try { //get the next char currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') + // if (((currentCharacter = source[currentPosition++]) == + // '\\') // && (source[currentPosition] == 'u')) { // //-------------unicode traitement ------------ // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; @@ -1789,7 +1776,6 @@ public class Scanner implements IScanner, ITerminalSymbols { // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); // } // } - while (currentCharacter != '\r' && currentCharacter != '\n') { //get the next char currentCharacter = source[currentPosition++]; @@ -1827,7 +1813,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // } // } } - if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + if (recordLineSeparator + && ((currentCharacter == '\r') || (currentCharacter == '\n'))) pushLineSeparator(); } catch (IndexOutOfBoundsException e) { } //an eof will them be generated @@ -1852,11 +1839,13 @@ public class Scanner implements IScanner, ITerminalSymbols { if (currentCharacter == '*') { star = true; } - if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + if (recordLineSeparator + && ((currentCharacter == '\r') || (currentCharacter == '\n'))) pushLineSeparator(); try { //get the next char currentCharacter = source[currentPosition++]; - // if (((currentCharacter = source[currentPosition++]) == '\\') + // if (((currentCharacter = source[currentPosition++]) == + // '\\') // && (source[currentPosition] == 'u')) { // //-------------unicode traitement ------------ // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; @@ -1890,7 +1879,8 @@ public class Scanner implements IScanner, ITerminalSymbols { // } //loop until end of comment */ while ((currentCharacter != '/') || (!star)) { - if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + if (recordLineSeparator + && ((currentCharacter == '\r') || (currentCharacter == '\n'))) pushLineSeparator(); star = currentCharacter == '*'; //get next char @@ -1936,9 +1926,9 @@ public class Scanner implements IScanner, ITerminalSymbols { } break; } - default : - if (isPHPIdentifierStart(currentCharacter) || currentCharacter == '$') { + if (isPHPIdentifierStart(currentCharacter) + || currentCharacter == '$') { try { scanIdentifierOrKeyword((currentCharacter == '$')); } catch (InvalidInputException ex) { @@ -2006,18 +1996,15 @@ public class Scanner implements IScanner, ITerminalSymbols { // } public final int[] getLineEnds() { //return a bounded copy of this.lineEnds - int[] copy; System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1); return copy; } - public char[] getSource() { return this.source; } 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) { @@ -2074,15 +2061,14 @@ public class Scanner implements IScanner, ITerminalSymbols { case 'z' : return charArray_z; default : - return new char[] { charOne }; + 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) { @@ -2102,17 +2088,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; @@ -2133,26 +2117,23 @@ 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) + long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12) - + ((c2 = source[startPosition + 2]) << 6) - + (c3 = source[startPosition + 3])) + + ((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--------- @@ -2160,35 +2141,32 @@ 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 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])) + + ((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--------- @@ -2196,41 +2174,34 @@ 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 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])) + + ((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]) - && (c5 == charArray[5])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) + && (c3 == charArray[3]) && (c4 == charArray[4]) + && (c5 == charArray[5])) return charArray; } //---------other side--------- @@ -2238,33 +2209,27 @@ 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]) - && (c5 == charArray[5])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) + && (c3 == charArray[3]) && (c4 == charArray[4]) + && (c5 == charArray[5])) return charArray; } //--------add the entry------- 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; - if (this.checkNonExternalizedStringLiterals) { // reinitialize the current line for non externalize strings purpose currentLine = null; } //currentCharacter is at position currentPosition-1 - // cr 000D if (currentCharacter == '\r') { int separatorPos = currentPosition - 1; @@ -2323,17 +2288,13 @@ 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' - final int INCREMENT = 250; //currentCharacter is at position currentPosition-1 - if (this.checkNonExternalizedStringLiterals) { // reinitialize the current line for non externalize strings purpose currentLine = null; } - // cr 000D if (currentCharacter == '\r') { int separatorPos = currentPosition - 6; @@ -2387,10 +2348,11 @@ public class Scanner implements IScanner, ITerminalSymbols { } } public final void recordComment(boolean isJavadoc) { - // a new annotation comment is recorded try { - commentStops[++commentPtr] = isJavadoc ? currentPosition : -currentPosition; + commentStops[++commentPtr] = isJavadoc + ? currentPosition + : -currentPosition; } catch (IndexOutOfBoundsException e) { int oldStackLength = commentStops.length; int[] oldStack = commentStops; @@ -2402,23 +2364,20 @@ public class Scanner implements IScanner, ITerminalSymbols { 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; initialPosition = startPosition = currentPosition = begin; 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) { // // consume next character // unicodeAsBackSlash = false; @@ -2444,11 +2403,10 @@ public class Scanner implements IScanner, ITerminalSymbols { 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) { // // consume next character // unicodeAsBackSlash = false; @@ -2472,9 +2430,9 @@ public class Scanner implements IScanner, ITerminalSymbols { case 'n' : currentCharacter = '\n'; break; - // case 'f' : - // currentCharacter = '\f'; - // break; + // case 'f' : + // currentCharacter = '\f'; + // break; case 'r' : currentCharacter = '\r'; break; @@ -2495,7 +2453,6 @@ public class Scanner implements IScanner, ITerminalSymbols { // OctalDigit // OctalDigit OctalDigit // ZeroToThree OctalDigit OctalDigit - int number = Character.getNumericValue(currentCharacter); if (number >= 0 && number <= 7) { boolean zeroToThreeNot = number > 3; @@ -2503,22 +2460,27 @@ public class Scanner implements IScanner, ITerminalSymbols { 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 + 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 + } else { // has read \ZeroToThree OctalDigit NonOctalDigit + // --> ignore last character currentPosition--; } } - } else { // has read \OctalDigit NonDigit--> ignore last character + } else { // has read \OctalDigit NonDigit--> ignore last + // character currentPosition--; } - } else { // has read \OctalDigit NonOctalDigit--> ignore last character + } else { // has read \OctalDigit NonOctalDigit--> ignore last + // character currentPosition--; } } else { // has read \OctalDigit --> ignore last character @@ -2528,28 +2490,23 @@ public class Scanner implements IScanner, ITerminalSymbols { throw new InvalidInputException(INVALID_ESCAPE); currentCharacter = (char) number; } - //else - // throw new InvalidInputException(INVALID_ESCAPE); + //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 //keywors with the same length AND the same first char, then do another //disptach on the second char :-)...cool....but fast ! - useAssertAsAnIndentifier = false; - while (getNextCharAsJavaIdentifierPart()) { }; - if (isVariable) { if (new String(getCurrentTokenSource()).equals("$this")) { return TokenNamethis; @@ -2560,11 +2517,9 @@ public class Scanner implements IScanner, ITerminalSymbols { char[] data; char firstLetter; // if (withoutUnicodePtr == 0) - //quick test on length == 1 but not on length > 12 while most identifier //have a length which is <= 12...but there are lots of identifier with //only one char.... - // { if ((length = currentPosition - startPosition) == 1) return TokenNameIdentifier; @@ -2585,86 +2540,134 @@ public class Scanner implements IScanner, ITerminalSymbols { // } // index = 1; // } - firstLetter = data[index]; switch (firstLetter) { - - case 'a' : // as and array abstract + 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 + case 2 : + //as if ((data[++index] == 's')) { return TokenNameas; } else { return TokenNameIdentifier; } - case 3 : //and + 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')) + 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')) + 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 + case 'b' : + //break switch (length) { case 5 : - if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k')) + 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 const continue + case 'c' : + //case catch class const continue switch (length) { case 4 : - if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e')) + 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')) + if ((data[++index] == 'a') && (data[++index] == 't') + && (data[++index] == 'c') && (data[++index] == 'h')) return TokenNamecatch; - if ((data[index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's')) + if ((data[index] == 'l') && (data[++index] == 'a') + && (data[++index] == 's') && (data[++index] == 's')) return TokenNameclass; - if ((data[index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't')) + 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')) + 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 + case 'd' : + // declare default do die // TODO delete define ==> no keyword ! switch (length) { case 2 : @@ -2672,135 +2675,117 @@ public class Scanner implements IScanner, ITerminalSymbols { 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 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')) + 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')) + 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 + case 'e' : + //echo else exit elseif extends eval switch (length) { case 4 : - if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o')) + if ((data[++index] == 'c') && (data[++index] == 'h') + && (data[++index] == 'o')) return TokenNameecho; - else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e')) + else if ((data[index] == 'l') && (data[++index] == 's') + && (data[++index] == 'e')) return TokenNameelse; - else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't')) + else if ((data[index] == 'x') && (data[++index] == 'i') + && (data[++index] == 't')) return TokenNameexit; - else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l')) + 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')) + 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')) + 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')) + 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') + 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')) + 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')) + 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')) + 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')) + 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')) + && (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 + case 'f' : + //for false final function switch (length) { case 3 : if ((data[++index] == 'o') && (data[++index] == 'r')) @@ -2808,154 +2793,136 @@ public class Scanner implements IScanner, ITerminalSymbols { 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')) +// 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')) + 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')) + 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 + case 'g' : + //global if (length == 6) { - if ((data[++index] == 'l') - && (data[++index] == 'o') - && (data[++index] == 'b') - && (data[++index] == 'a') - && (data[++index] == 'l')) { + if ((data[++index] == 'l') && (data[++index] == 'o') + && (data[++index] == 'b') && (data[++index] == 'a') + && (data[++index] == 'l')) { return TokenNameglobal; } } return TokenNameIdentifier; - - case 'i' : //if int isset include include_once instanceof interface implements + 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 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')) + 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')) + 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')) + 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')) + 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')) + 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')) + 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 + case 'l' : + //list if (length == 4) { - if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) { + if ((data[++index] == 'i') && (data[++index] == 's') + && (data[++index] == 't')) { return TokenNamelist; } } return TokenNameIdentifier; - - case 'n' : // new null + 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; - +// 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 + case 'o' : + // or old_function if (length == 2) { if (data[++index] == 'r') { return TokenNameOR; @@ -2977,95 +2944,76 @@ public class Scanner implements IScanner, ITerminalSymbols { // } // } return TokenNameIdentifier; - - case 'p' : // print public private protected + case 'p' : + // print public private protected switch (length) { case 5 : - if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) { + 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')) { + 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')) { + 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')) { + 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 + 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')) { + 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')) { + 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')) { + 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; } } else return TokenNameIdentifier; - - case 's' : //static switch + 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')) { + 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') + else if ((data[index] == 'w') && (data[++index] == 'i') + && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h')) return TokenNameswitch; else @@ -3073,29 +3021,31 @@ public class Scanner implements IScanner, ITerminalSymbols { default : return TokenNameIdentifier; } - - case 't' : // try true throw + 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 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')) + 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 + case 'u' : + //use unset switch (length) { case 3 : if ((data[++index] == 's') && (data[++index] == 'e')) @@ -3103,49 +3053,51 @@ public class Scanner implements IScanner, ITerminalSymbols { else return TokenNameIdentifier; case 5 : - if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't')) + if ((data[++index] == 'n') && (data[++index] == 's') + && (data[++index] == 'e') && (data[++index] == 't')) return TokenNameunset; else return TokenNameIdentifier; default : return TokenNameIdentifier; } - case 'v' : //var + 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 + case 'w' : + //while switch (length) { case 5 : - if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e')) + 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; + //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 + case 'x' : + //xor switch (length) { case 3 : if ((data[++index] == 'o') && (data[++index] == 'r')) return TokenNameXOR; else return TokenNameIdentifier; - default : return TokenNameIdentifier; } @@ -3154,11 +3106,9 @@ public class Scanner implements IScanner, ITerminalSymbols { } } 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 //dotPrefix is true - boolean floating = dotPrefix; if ((!dotPrefix) && (currentCharacter == '0')) { if (getNextChar('x', 'X') >= 0) { //----------hexa----------------- @@ -3184,14 +3134,13 @@ public class Scanner implements IScanner, ITerminalSymbols { // else return TokenNameIntegerLiteral; } - //there is x or X in the number - //potential octal ! ... some one may write 000099.0 ! thus 00100 < 00078.0 is true !!!!! crazy language + //potential octal ! ... some one may write 000099.0 ! thus 00100 < + // 00078.0 is true !!!!! crazy language if (getNextCharAsDigit()) { //-------------potential octal----------------- while (getNextCharAsDigit()) { }; - // if (getNextChar('l', 'L') >= 0) { // return TokenNameLongLiteral; // } @@ -3199,7 +3148,6 @@ public class Scanner implements IScanner, ITerminalSymbols { // if (getNextChar('f', 'F') >= 0) { // return TokenNameFloatingPointLiteral; // } - if (getNextChar('d', 'D') >= 0) { return TokenNameDoubleLiteral; } else { //make the distinction between octal and float .... @@ -3218,7 +3166,6 @@ public class Scanner implements IScanner, ITerminalSymbols { // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; // } // } - if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume next character unicodeAsBackSlash = false; @@ -3250,21 +3197,16 @@ public class Scanner implements IScanner, ITerminalSymbols { /* carry on */ } } - 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 - if (getNextChar('e', 'E') >= 0) { floating = true; // consume next character @@ -3278,8 +3220,9 @@ public class Scanner implements IScanner, ITerminalSymbols { // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; // } // } - - if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume next character + if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume + // next + // character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; // if (((currentCharacter = source[currentPosition++]) == '\\') @@ -3296,14 +3239,11 @@ public class Scanner implements IScanner, ITerminalSymbols { while (getNextCharAsDigit()) { }; } - if (getNextChar('d', 'D') >= 0) return TokenNameDoubleLiteral; // if (getNextChar('f', 'F') >= 0) // return TokenNameFloatingPointLiteral; - //the long flag has been tested before - return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral; } /** @@ -3311,7 +3251,6 @@ public class Scanner implements IScanner, ITerminalSymbols { * */ public final int getLineNumber(int position) { - if (lineEnds == null) return 1; int length = linePtr + 1; @@ -3334,14 +3273,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) { this.source = new char[0]; } else { @@ -3351,18 +3287,14 @@ public class Scanner implements IScanner, ITerminalSymbols { initialPosition = currentPosition = 0; containsAssertKeyword = false; withoutUnicodeBuffer = new char[this.source.length]; - } - public String toString() { if (startPosition == source.length) return "EOF\n\n" + new String(source); //$NON-NLS-1$ if (currentPosition > source.length) return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$ - char front[] = new char[startPosition]; System.arraycopy(source, 0, front, 0, startPosition); - int middleLength = (currentPosition - 1) - startPosition + 1; char middle[]; if (middleLength > -1) { @@ -3371,19 +3303,20 @@ public class Scanner implements IScanner, ITerminalSymbols { } else { 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$ - + new String(end); + 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$ + return "ScannerError"; // + new String(getCurrentTokenSource()) + ")"; + // //$NON-NLS-1$ case TokenNameStopPHP : return "StopPHP(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ case TokenNameIdentifier : @@ -3406,8 +3339,8 @@ public class Scanner implements IScanner, ITerminalSymbols { return "continue"; //$NON-NLS-1$ case TokenNamedefault : return "default"; //$NON-NLS-1$ -// case TokenNamedefine : -// return "define"; //$NON-NLS-1$ + // case TokenNamedefine : + // return "define"; //$NON-NLS-1$ case TokenNamedo : return "do"; //$NON-NLS-1$ case TokenNameecho : @@ -3428,8 +3361,8 @@ public class Scanner implements IScanner, ITerminalSymbols { return "endwhile"; //$NON-NLS-1$ case TokenNameextends : return "extends"; //$NON-NLS-1$ - case TokenNamefalse : - return "false"; //$NON-NLS-1$ +// case TokenNamefalse : +// return "false"; //$NON-NLS-1$ case TokenNamefinal : return "final"; //$NON-NLS-1$ case TokenNamefor : @@ -3454,8 +3387,8 @@ public class Scanner implements IScanner, ITerminalSymbols { return "list"; //$NON-NLS-1$ case TokenNamenew : return "new"; //$NON-NLS-1$ - case TokenNamenull : - return "null"; //$NON-NLS-1$ +// case TokenNamenull : +// return "null"; //$NON-NLS-1$ case TokenNameprint : return "print"; //$NON-NLS-1$ case TokenNameprivate : @@ -3474,8 +3407,8 @@ public class Scanner implements IScanner, ITerminalSymbols { return "static"; //$NON-NLS-1$ case TokenNameswitch : return "switch"; //$NON-NLS-1$ - case TokenNametrue : - return "true"; //$NON-NLS-1$ +// case TokenNametrue : +// return "true"; //$NON-NLS-1$ case TokenNameunset : return "unset"; //$NON-NLS-1$ case TokenNamevar : @@ -3493,10 +3426,10 @@ public class Scanner implements IScanner, ITerminalSymbols { case TokenNameStringConstant : return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ case TokenNameStringInterpolated : - return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + return "StringInterpolated(" + 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 : @@ -3611,33 +3544,39 @@ public class Scanner implements IScanner, ITerminalSymbols { 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$ default : - return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$ + return "not-a-token(" + (new Integer(act)) + ") " + + new String(getCurrentTokenSource()); //$NON-NLS-1$ } } - - 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) { + public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, + boolean checkNonExternalizedStringLiterals, boolean assertMode) { this.eofPosition = Integer.MAX_VALUE; this.tokenizeComments = tokenizeComments; this.tokenizeWhiteSpace = tokenizeWhiteSpace; this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals; this.assertMode = assertMode; } - 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); @@ -3658,7 +3597,6 @@ public class Scanner implements IScanner, ITerminalSymbols { } pos = s.indexOf(TAG_PREFIX, start); } - this.nonNLSStrings = new StringLiteral[lineLength]; int nonNLSCounter = 0; for (Iterator iterator = line.iterator(); iterator.hasNext();) { @@ -3674,19 +3612,20 @@ 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). - if (unicodeAsBackSlash) { // consume next character unicodeAsBackSlash = false; - // if (((currentCharacter = source[currentPosition++]) == '\\') && (source[currentPosition] == 'u')) { + // if (((currentCharacter = source[currentPosition++]) == '\\') && + // (source[currentPosition] == 'u')) { // getNextUnicodeChar(); // } else { if (withoutUnicodePtr != 0) { @@ -3725,7 +3664,6 @@ public class Scanner implements IScanner, ITerminalSymbols { // OctalDigit // OctalDigit OctalDigit // ZeroToThree OctalDigit OctalDigit - int number = Character.getNumericValue(currentCharacter); if (number >= 0 && number <= 7) { boolean zeroToThreeNot = number > 3; @@ -3733,21 +3671,27 @@ public class Scanner implements IScanner, ITerminalSymbols { 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 + 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 + if (digit >= 0 && digit <= 7) { // has read \ZeroToThree + // OctalDigit OctalDigit number = (number * 8) + digit; - } else { // has read \ZeroToThree OctalDigit NonOctalDigit --> ignore last character + } else { // has read \ZeroToThree OctalDigit NonOctalDigit + // --> ignore last character currentPosition--; } } - } else { // has read \OctalDigit NonDigit--> ignore last character + } else { // has read \OctalDigit NonDigit--> ignore last + // character currentPosition--; } - } else { // has read \OctalDigit NonOctalDigit--> ignore last character + } else { // has read \OctalDigit NonOctalDigit--> ignore last + // character currentPosition--; } } else { // has read \OctalDigit --> ignore last character @@ -3760,83 +3704,76 @@ public class Scanner implements IScanner, ITerminalSymbols { 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++) { 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]) continue nextTag; } - if (this.foundTaskTags == null) { this.foundTaskTags = new char[5][]; this.foundTaskMessages = new char[5][]; 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, this.foundTaskCount); - System.arraycopy( - this.foundTaskMessages, - 0, - this.foundTaskMessages = 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, - this.foundTaskCount); + 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.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, + 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 } } - 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. int end = -1; char c; - for (int j = msgStart; j < max_value; j++) { if ((c = this.source[j]) == '\n' || c == '\r') { end = j - 1; break; } } - if (end == -1) { for (int j = max_value; j > msgStart; j--) { if ((c = this.source[j]) == '*') { @@ -3847,26 +3784,20 @@ public class Scanner implements IScanner, ITerminalSymbols { if (end == -1) end = max_value; } - if (msgStart == end) continue; // empty - // trim the message while (CharOperation.isWhitespace(source[end]) && msgStart <= end) end--; while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end) msgStart++; - // update the end position of the task this.foundTaskPositions[i][1] = end; - // get the message source final int messageLength = end - msgStart + 1; char[] message = new char[messageLength]; - System.arraycopy(source, msgStart, message, 0, messageLength); this.foundTaskMessages[i] = message; } } - } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemHandler.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemHandler.java index e96bead..6e52747 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemHandler.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemHandler.java @@ -51,7 +51,10 @@ public ProblemHandler(IErrorHandlingPolicy policy, IProblemFactory problemFactor * Error | Warning | Ignore */ public int computeSeverity(int problemId){ - + if (problemId==IProblem.PHPParsingWarning || + problemId==IProblem.PHPVarDeprecatedWarning) { + return Warning; + } return Error; // by default all problems are errors } public IProblem createProblem( diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java index 7e72de4..7e1acce 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java @@ -76,2821 +76,2663 @@ import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration; import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference; import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression; public class ProblemReporter extends ProblemHandler implements ProblemReasons { - public ReferenceContext referenceContext; - public ProblemReporter(IErrorHandlingPolicy policy, - IProblemFactory problemFactory) { - //CompilerOptions options, IProblemFactory problemFactory) { - super(policy, problemFactory);//options, problemFactory); - } - public void abortDueToInternalError(String errorMessage) { - String[] arguments = new String[]{errorMessage}; - this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, - 0, 0); - } - public void abortDueToInternalError(String errorMessage, AstNode location) { - String[] arguments = new String[]{errorMessage}; - this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, - location.sourceStart, location.sourceEnd); - } - public void abstractMethodCannotBeOverridden(SourceTypeBinding type, - MethodBinding concreteMethod) { - this.handle( - // %1 must be abstract since it cannot override the inherited - // package-private abstract method %2 - IProblem.AbstractMethodCannotBeOverridden, new String[]{ - new String(type.sourceName()), - new String(CharOperation.concat( - concreteMethod.declaringClass.readableName(), - concreteMethod.readableName(), '.'))}, - new String[]{ - new String(type.sourceName()), - new String(CharOperation.concat( - concreteMethod.declaringClass - .shortReadableName(), concreteMethod - .shortReadableName(), '.'))}, type - .sourceStart(), type.sourceEnd()); - } - public void abstractMethodInAbstractClass(SourceTypeBinding type, - AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(type.sourceName()), - new String(methodDecl.selector)}; - this.handle(IProblem.AbstractMethodInAbstractClass, arguments, - arguments, methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void abstractMethodMustBeImplemented(SourceTypeBinding type, - MethodBinding abstractMethod) { - this.handle( - // Must implement the inherited abstract method %1 - // 8.4.3 - Every non-abstract subclass of an abstract type, A, - // must provide a concrete implementation of all of A's - // methods. - IProblem.AbstractMethodMustBeImplemented, - new String[]{new String(CharOperation.concat( - abstractMethod.declaringClass.readableName(), - abstractMethod.readableName(), '.'))}, - new String[]{new String(CharOperation.concat( - abstractMethod.declaringClass.shortReadableName(), - abstractMethod.shortReadableName(), '.'))}, type - .sourceStart(), type.sourceEnd()); - } - public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) { - this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument, - method.sourceStart, method.sourceEnd, method, method - .compilationResult()); - } - public void alreadyDefinedLabel(char[] labelName, AstNode location) { - String[] arguments = new String[]{new String(labelName)}; - this.handle(IProblem.DuplicateLabel, arguments, arguments, - location.sourceStart, location.sourceEnd); - } - public void anonymousClassCannotExtendFinalClass(Expression expression, - TypeBinding type) { - this.handle(IProblem.AnonymousClassCannotExtendFinalClass, - new String[]{new String(type.readableName())}, - new String[]{new String(type.shortReadableName())}, - expression.sourceStart, expression.sourceEnd); - } - public void argumentTypeCannotBeVoid(SourceTypeBinding type, - AbstractMethodDeclaration methodDecl, Argument arg) { - String[] arguments = new String[]{new String(methodDecl.selector), - new String(arg.name)}; - this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, - AbstractMethodDeclaration methodDecl, Argument arg) { - String[] arguments = new String[]{new String(methodDecl.selector), - new String(arg.name)}; - this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, - arguments, methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void argumentTypeProblem(SourceTypeBinding type, - AbstractMethodDeclaration methodDecl, Argument arg, - TypeBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : - // 1 - id = IProblem.ArgumentTypeNotFound; - break; - case NotVisible : - // 2 - id = IProblem.ArgumentTypeNotVisible; - break; - case Ambiguous : - // 3 - id = IProblem.ArgumentTypeAmbiguous; - break; - case InternalNameProvided : - // 4 - id = IProblem.ArgumentTypeInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : - // 5 - id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - return; - } - this.handle(id, new String[]{new String(methodDecl.selector), - arg.name(), new String(expectedType.readableName())}, - new String[]{new String(methodDecl.selector), arg.name(), - new String(expectedType.shortReadableName())}, - arg.type.sourceStart, arg.type.sourceEnd); - } - public void arrayConstantsOnlyInArrayInitializers(int sourceStart, - int sourceEnd) { - this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument, - NoArgument, sourceStart, sourceEnd); - } - public void assignmentHasNoEffect(Assignment assignment, char[] name) { - String[] arguments = new String[]{new String(name)}; - this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments, - assignment.sourceStart, assignment.sourceEnd); - } - public void attemptToReturnNonVoidExpression( - ReturnStatement returnStatement, TypeBinding expectedType) { - this.handle(IProblem.VoidMethodReturnsValue, new String[]{new String( - expectedType.readableName())}, new String[]{new String( - expectedType.shortReadableName())}, - returnStatement.sourceStart, returnStatement.sourceEnd); - } - public void attemptToReturnVoidValue(ReturnStatement returnStatement) { - this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument, - returnStatement.sourceStart, returnStatement.sourceEnd); - } - //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location) - // { - // String[] arguments = new String[] {new String(location.selector), - // parametersAsString(location.binding)}; - // if (location.isConstructor()) { - // this.handle( - // IProblem.BytecodeExceeds64KLimitForConstructor, - // arguments, - // arguments, - // Error | Abort, - // location.sourceStart, - // location.sourceEnd); - // } else { - // this.handle( - // IProblem.BytecodeExceeds64KLimit, - // arguments, - // arguments, - // Error | Abort, - // location.sourceStart, - // location.sourceEnd); - // } - //} - public void bytecodeExceeds64KLimit(TypeDeclaration location) { - this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument, - NoArgument, Error | Abort, location.sourceStart, - location.sourceEnd); - } - public void cannotAllocateVoidArray(Expression expression) { - this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument, - expression.sourceStart, expression.sourceEnd); - } - public void cannotAssignToFinalField(FieldBinding field, AstNode location) { - this.handle(IProblem.FinalFieldAssignment, new String[]{ - (field.declaringClass == null ? "array" : new String( - field.declaringClass.readableName())), //$NON-NLS-1$ - new String(field.readableName())}, new String[]{ - (field.declaringClass == null ? "array" : new String( - field.declaringClass.shortReadableName())), //$NON-NLS-1$ - new String(field.shortReadableName())}, location.sourceStart, - location.sourceEnd); - } - public void cannotAssignToFinalLocal(LocalVariableBinding local, - AstNode location) { - String[] arguments = new String[]{new String(local.readableName())}; - this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, - arguments, location.sourceStart, location.sourceEnd); - } - public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, - AstNode location) { - String[] arguments = new String[]{new String(local.readableName())}; - this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments, - location.sourceStart, location.sourceEnd); - } - public void cannotDeclareLocalInterface(char[] interfaceName, - int sourceStart, int sourceEnd) { - String[] arguments = new String[]{new String(interfaceName)}; - this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, - arguments, sourceStart, sourceEnd); - } - public void cannotDefineDimensionsAndInitializer( - ArrayAllocationExpression expresssion) { - this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, - NoArgument, NoArgument, expresssion.sourceStart, - expresssion.sourceEnd); - } - public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, - MethodBinding method) { - this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[]{ - new String(method.declaringClass.readableName()), - new String(method.selector), parametersAsString(method)}, - new String[]{ - new String(method.declaringClass.shortReadableName()), - new String(method.selector), - parametersAsShortString(method)}, - messageSend.sourceStart, messageSend.sourceEnd); - } - public void cannotImportPackage(ImportReference importRef) { - String[] arguments = new String[]{CharOperation - .toString(importRef.tokens)}; - this.handle(IProblem.CannotImportPackage, arguments, arguments, - importRef.sourceStart, importRef.sourceEnd); - } - public void cannotInstantiate(TypeReference typeRef, TypeBinding type) { - this.handle(IProblem.InvalidClassInstantiation, - new String[]{new String(type.readableName())}, - new String[]{new String(type.shortReadableName())}, - typeRef.sourceStart, typeRef.sourceEnd); - } - public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, - AstNode location) { - String[] arguments = new String[]{new String(local.readableName())}; - this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments, - location.sourceStart, location.sourceEnd); - } - public void cannotReturnInInitializer(AstNode location) { - this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument, - location.sourceStart, location.sourceEnd); - } - public void cannotThrowNull(ThrowStatement statement) { - this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument, - statement.sourceStart, statement.sourceEnd); - } - public void cannotThrowType(SourceTypeBinding type, - AbstractMethodDeclaration methodDecl, TypeReference exceptionType, - TypeBinding expectedType) { - this.handle(IProblem.CannotThrowType, new String[]{new String( - expectedType.readableName())}, new String[]{new String( - expectedType.shortReadableName())}, exceptionType.sourceStart, - exceptionType.sourceEnd); - } - public void cannotUseSuperInJavaLangObject(AstNode reference) { - this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument, - reference.sourceStart, reference.sourceEnd); - } - public void cannotUseSuperInCodeSnippet(int start, int end) { - this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, - NoArgument, Error | Abort, start, end); - } - public void caseExpressionMustBeConstant(Expression expression) { - this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument, - expression.sourceStart, expression.sourceEnd); - } - public void classExtendFinalClass(SourceTypeBinding type, - TypeReference superclass, TypeBinding expectedType) { - String name = new String(type.sourceName()); - String expectedFullName = new String(expectedType.readableName()); - String expectedShortName = new String(expectedType.shortReadableName()); - if (expectedShortName.equals(name)) - expectedShortName = expectedFullName; - this.handle(IProblem.ClassExtendFinalClass, new String[]{ - expectedFullName, name}, new String[]{expectedShortName, name}, - superclass.sourceStart, superclass.sourceEnd); - } - public void codeSnippetMissingClass(String missing, int start, int end) { - String[] arguments = new String[]{missing}; - this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, - Error | Abort, start, end); - } - public void codeSnippetMissingMethod(String className, - String missingMethod, String argumentTypes, int start, int end) { - String[] arguments = new String[]{className, missingMethod, - argumentTypes}; - this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, - Error | Abort, start, end); - } - /* - * Given the current configuration, answers which category the problem - * falls into: Error | Warning | Ignore - */ - //public int computeSeverity(int problemId){ - // - // // severity can have been preset on the problem - //// if ((problem.severity & Fatal) != 0){ - //// return Error; - //// } - // - // // if not then check whether it is a configurable problem - // int errorThreshold = options.errorThreshold; - // int warningThreshold = options.warningThreshold; - // - // switch(problemId){ - // - // case IProblem.UnreachableCatch : - // case IProblem.CodeCannotBeReached : - // if ((errorThreshold & CompilerOptions.UnreachableCode) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.UnreachableCode) != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.MaskedCatch : - // if ((errorThreshold & CompilerOptions.MaskedCatchBlock) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.MaskedCatchBlock) != 0){ - // return Warning; - // } - // return Ignore; - // - ///* - // case Never Used : - // if ((errorThreshold & ParsingOptionalError) != 0){ - // return Error; - // } - // if ((warningThreshold & ParsingOptionalError) != 0){ - // return Warning; - // } - // return Ignore; - //*/ - // case IProblem.ImportNotFound : - // case IProblem.ImportNotVisible : - // case IProblem.ImportAmbiguous : - // case IProblem.ImportInternalNameProvided : - // case IProblem.ImportInheritedNameHidesEnclosingName : - // case IProblem.DuplicateImport : - // case IProblem.ConflictingImport : - // case IProblem.CannotImportPackage : - // if ((errorThreshold & CompilerOptions.ImportProblem) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.ImportProblem) != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.UnusedImport : - // // if import problem are disabled, then ignore - // if ((errorThreshold & CompilerOptions.ImportProblem) == 0 - // && (warningThreshold & CompilerOptions.ImportProblem) == 0){ - // return Ignore; - // } - // if ((errorThreshold & CompilerOptions.UnusedImport) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.UnusedImport) != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.MethodButWithConstructorName : - // if ((errorThreshold & CompilerOptions.MethodWithConstructorName) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.MethodWithConstructorName) != - // 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.OverridingNonVisibleMethod : - // if ((errorThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != - // 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.OverriddenPackageDefaultMethod) - // != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod : - // case - // IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod - // : - // if ((errorThreshold & - // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){ - // return Error; - // } - // if ((warningThreshold & - // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.OverridingDeprecatedMethod : - // case IProblem.UsingDeprecatedType : - // case IProblem.UsingDeprecatedMethod : - // case IProblem.UsingDeprecatedConstructor : - // case IProblem.UsingDeprecatedField : - // if ((errorThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.LocalVariableIsNeverUsed : - // if ((errorThreshold & CompilerOptions.UnusedLocalVariable) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.UnusedLocalVariable) != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.ArgumentIsNeverUsed : - // if ((errorThreshold & CompilerOptions.UnusedArgument) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.UnusedArgument) != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.NoImplicitStringConversionForCharArrayExpression : - // if ((errorThreshold & CompilerOptions.NoImplicitStringConversion) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.NoImplicitStringConversion) != - // 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.NeedToEmulateFieldReadAccess : - // case IProblem.NeedToEmulateFieldWriteAccess : - // case IProblem.NeedToEmulateMethodAccess : - // case IProblem.NeedToEmulateConstructorAccess : - // if ((errorThreshold & CompilerOptions.AccessEmulation) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.AccessEmulation) != 0){ - // return Warning; - // } - // return Ignore; - // case IProblem.NonExternalizedStringLiteral : - // if ((errorThreshold & CompilerOptions.NonExternalizedString) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.NonExternalizedString) != 0){ - // return Warning; - // } - // return Ignore; - // case IProblem.UseAssertAsAnIdentifier : - // if ((errorThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){ - // return Warning; - // } - // return Ignore; - // case IProblem.NonStaticAccessToStaticMethod : - // case IProblem.NonStaticAccessToStaticField : - // if ((errorThreshold & CompilerOptions.StaticAccessReceiver) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.StaticAccessReceiver) != 0){ - // return Warning; - // } - // return Ignore; - // case IProblem.AssignmentHasNoEffect: - // if ((errorThreshold & CompilerOptions.NoEffectAssignment) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.NoEffectAssignment) != 0){ - // return Warning; - // } - // return Ignore; - // case IProblem.UnusedPrivateConstructor: - // case IProblem.UnusedPrivateMethod: - // case IProblem.UnusedPrivateField: - // case IProblem.UnusedPrivateType: - // if ((errorThreshold & CompilerOptions.UnusedPrivateMember) != 0){ - // return Error; - // } - // if ((warningThreshold & CompilerOptions.UnusedPrivateMember) != 0){ - // return Warning; - // } - // return Ignore; - // - // case IProblem.Task : - // return Warning; - // default: - // return Error; - // } - //} - //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression - // expression, TypeBinding trueType, TypeBinding falseType) { - // this.handle( - // IProblem.IncompatibleTypesInConditionalOperator, - // new String[] {new String(trueType.readableName()), new - // String(falseType.readableName())}, - // new String[] {new String(trueType.sourceName()), new - // String(falseType.sourceName())}, - // expression.sourceStart, - // expression.sourceEnd); - //} - public void conflictingImport(ImportReference importRef) { - String[] arguments = new String[]{CharOperation - .toString(importRef.tokens)}; - this.handle(IProblem.ConflictingImport, arguments, arguments, - importRef.sourceStart, importRef.sourceEnd); - } - public void constantOutOfFormat(NumberLiteral lit) { - // the literal is not in a correct format - // this code is called on IntLiteral and LongLiteral - // example 000811 ...the 8 is uncorrect. - if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) { - char[] source = lit.source(); - try { - final String Radix; - final int radix; - if ((source[1] == 'x') || (source[1] == 'X')) { - radix = 16; - Radix = "Hexa"; //$NON-NLS-1$ - } else { - radix = 8; - Radix = "Octal"; //$NON-NLS-1$ - } - //look for the first digit that is incorrect - int place = -1; - label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) { - if (Character.digit(source[i], radix) == -1) { - place = i; - break label; - } - } - String[] arguments = new String[]{Radix + " " - + new String(source) + " (digit " - + new String(new char[]{source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - this.handle(IProblem.NumericValueOutOfRange, arguments, - arguments, lit.sourceStart, lit.sourceEnd); - return; - } catch (IndexOutOfBoundsException ex) { - } - // just in case .... use a predefined error.. - // we should never come here...(except if the code changes !) - this.constantOutOfRange(lit); - } - } - public void constantOutOfRange(Literal lit) { - // lit is some how out of range of it declared type - // example - // 9999999999999999999999999999999999999999999999999999999999999999999 - String[] arguments = new String[]{new String(lit.source())}; - this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, - lit.sourceStart, lit.sourceEnd); - } - public void deprecatedField(FieldBinding field, AstNode location) { - this.handle(IProblem.UsingDeprecatedField, new String[]{ - new String(field.declaringClass.readableName()), - new String(field.name)}, new String[]{ - new String(field.declaringClass.shortReadableName()), - new String(field.name)}, location.sourceStart, - location.sourceEnd); - } - public void deprecatedMethod(MethodBinding method, AstNode location) { - if (method.isConstructor()) - this.handle(IProblem.UsingDeprecatedConstructor, new String[]{ - new String(method.declaringClass.readableName()), - parametersAsString(method)}, new String[]{ - new String(method.declaringClass.shortReadableName()), - parametersAsShortString(method)}, location.sourceStart, - location.sourceEnd); - else - this.handle(IProblem.UsingDeprecatedMethod, new String[]{ - new String(method.declaringClass.readableName()), - new String(method.selector), parametersAsString(method)}, - new String[]{ - new String(method.declaringClass - .shortReadableName()), - new String(method.selector), - parametersAsShortString(method)}, - location.sourceStart, location.sourceEnd); - } - public void deprecatedType(TypeBinding type, AstNode location) { - if (location == null) - return; // 1G828DN - no type ref for synthetic arguments - this.handle(IProblem.UsingDeprecatedType, new String[]{new String(type - .readableName())}, new String[]{new String(type - .shortReadableName())}, location.sourceStart, - location.sourceEnd); - } - public void duplicateCase(Case statement, Constant constant) { - String[] arguments = new String[]{String.valueOf(constant.intValue())}; - this.handle(IProblem.DuplicateCase, arguments, arguments, - statement.sourceStart, statement.sourceEnd); - } - public void duplicateDefaultCase(DefaultCase statement) { - this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument, - statement.sourceStart, statement.sourceEnd); - } - public void duplicateFieldInType(SourceTypeBinding type, - FieldDeclaration fieldDecl) { - this.handle(IProblem.DuplicateField, new String[]{ - new String(type.sourceName()), fieldDecl.name()}, new String[]{ - new String(type.shortReadableName()), fieldDecl.name()}, - fieldDecl.sourceStart, fieldDecl.sourceEnd); - } - public void duplicateImport(ImportReference importRef) { - String[] arguments = new String[]{CharOperation - .toString(importRef.tokens)}; - this.handle(IProblem.DuplicateImport, arguments, arguments, - importRef.sourceStart, importRef.sourceEnd); - } - public void duplicateInitializationOfBlankFinalField(FieldBinding field, - Reference reference) { - String[] arguments = new String[]{new String(field.readableName())}; - this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments, - arguments, reference.sourceStart, reference.sourceEnd); - } - public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, - AstNode location) { - String[] arguments = new String[]{new String(local.readableName())}; - this.handle(IProblem.DuplicateFinalLocalInitialization, arguments, - arguments, location.sourceStart, location.sourceEnd); - } - public void duplicateMethodInType(SourceTypeBinding type, - AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(methodDecl.selector), - new String(type.sourceName())}; - this.handle(IProblem.DuplicateMethod, arguments, arguments, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void duplicateModifierForField(ReferenceBinding type, - FieldDeclaration fieldDecl) { - /* - * to highlight modifiers use: this.handle( new Problem( - * DuplicateModifierForField, new String[] {fieldDecl.name()}, - * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd)); - */ - String[] arguments = new String[]{fieldDecl.name()}; - this.handle(IProblem.DuplicateModifierForField, arguments, arguments, - fieldDecl.sourceStart, fieldDecl.sourceEnd); - } - public void duplicateModifierForMethod(ReferenceBinding type, - AbstractMethodDeclaration methodDecl) { - this.handle(IProblem.DuplicateModifierForMethod, - new String[]{new String(type.sourceName()), - new String(methodDecl.selector)}, new String[]{ - new String(type.shortReadableName()), - new String(methodDecl.selector)}, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void duplicateModifierForType(SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.DuplicateModifierForType, arguments, arguments, - type.sourceStart(), type.sourceEnd()); - } - public void duplicateModifierForVariable(LocalDeclaration localDecl, - boolean complainForArgument) { - String[] arguments = new String[]{localDecl.name()}; - this.handle(complainForArgument - ? IProblem.DuplicateModifierForArgument - : IProblem.DuplicateModifierForVariable, arguments, arguments, - localDecl.sourceStart, localDecl.sourceEnd); - } - public void duplicateNestedType(TypeDeclaration typeDecl) { - String[] arguments = new String[]{new String(typeDecl.name)}; - this.handle(IProblem.DuplicateNestedType, arguments, arguments, - typeDecl.sourceStart, typeDecl.sourceEnd); - } - public void duplicateSuperinterface(SourceTypeBinding type, - TypeDeclaration typeDecl, ReferenceBinding superType) { - this.handle(IProblem.DuplicateSuperInterface, new String[]{ - new String(superType.readableName()), - new String(type.sourceName())}, new String[]{ - new String(superType.shortReadableName()), - new String(type.sourceName())}, typeDecl.sourceStart, - typeDecl.sourceEnd); - } - public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, - TypeDeclaration typeDecl) { - String[] arguments = new String[]{ - new String(compUnitDecl.getFileName()), - new String(typeDecl.name)}; - this.referenceContext = typeDecl; // report the problem against the - // type not the entire compilation - // unit - this.handle(IProblem.DuplicateTypes, arguments, arguments, - typeDecl.sourceStart, typeDecl.sourceEnd, - compUnitDecl.compilationResult); - } - public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, - TypeBinding[] params) { - StringBuffer buffer = new StringBuffer(); - StringBuffer shortBuffer = new StringBuffer(); - for (int i = 0, length = params.length; i < length; i++) { - if (i != 0) { - buffer.append(", "); //$NON-NLS-1$ - shortBuffer.append(", "); //$NON-NLS-1$ - } - buffer.append(new String(params[i].readableName())); - shortBuffer.append(new String(params[i].shortReadableName())); - } - this.handle(recType.isArrayType() - ? IProblem.NoMessageSendOnArrayType - : IProblem.NoMessageSendOnBaseType, new String[]{ - new String(recType.readableName()), - new String(messageSend.selector), buffer.toString()}, - new String[]{new String(recType.shortReadableName()), - new String(messageSend.selector), - shortBuffer.toString()}, messageSend.sourceStart, - messageSend.sourceEnd); - } - public void errorThisSuperInStatic(AstNode reference) { - String[] arguments = new String[]{reference.isSuper() - ? "super" - : "this"}; //$NON-NLS-2$ //$NON-NLS-1$ - this.handle(IProblem.ThisInStaticContext, arguments, arguments, - reference.sourceStart, reference.sourceEnd); - } - public void exceptionTypeProblem(SourceTypeBinding type, - AbstractMethodDeclaration methodDecl, TypeReference exceptionType, - TypeBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : - // 1 - id = IProblem.ExceptionTypeNotFound; - break; - case NotVisible : - // 2 - id = IProblem.ExceptionTypeNotVisible; - break; - case Ambiguous : - // 3 - id = IProblem.ExceptionTypeAmbiguous; - break; - case InternalNameProvided : - // 4 - id = IProblem.ExceptionTypeInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : - // 5 - id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - return; - } - this.handle(id, new String[]{new String(methodDecl.selector), - new String(expectedType.readableName())}, new String[]{ - new String(methodDecl.selector), - new String(expectedType.shortReadableName())}, - exceptionType.sourceStart, exceptionType.sourceEnd); - } - public void expressionShouldBeAVariable(Expression expression) { - this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, - NoArgument, expression.sourceStart, expression.sourceEnd); - } - public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) { - this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument, - NoArgument, reference.sourceStart, reference.sourceEnd); - } - public void fieldTypeProblem(SourceTypeBinding type, - FieldDeclaration fieldDecl, TypeBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : - // 1 - id = IProblem.FieldTypeNotFound; - break; - case NotVisible : - // 2 - id = IProblem.FieldTypeNotVisible; - break; - case Ambiguous : - // 3 - id = IProblem.FieldTypeAmbiguous; - break; - case InternalNameProvided : - // 4 - id = IProblem.FieldTypeInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : - // 5 - id = IProblem.FieldTypeInheritedNameHidesEnclosingName; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - return; - } - this.handle(id, new String[]{fieldDecl.name(), - new String(type.sourceName()), - new String(expectedType.readableName())}, new String[]{ - fieldDecl.name(), new String(type.sourceName()), - new String(expectedType.shortReadableName())}, - fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd); - } - public void finalMethodCannotBeOverridden(MethodBinding currentMethod, - MethodBinding inheritedMethod) { - this.handle( - // Cannot override the final method from %1 - // 8.4.3.3 - Final methods cannot be overridden or hidden. - IProblem.FinalMethodCannotBeOverridden, - new String[]{new String(inheritedMethod.declaringClass - .readableName())}, new String[]{new String( - inheritedMethod.declaringClass.shortReadableName())}, - currentMethod.sourceStart(), currentMethod.sourceEnd()); - } - public void forwardReference(Reference reference, int indexInQualification, - TypeBinding type) { - this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument, - reference.sourceStart, reference.sourceEnd); - } - // use this private API when the compilation unit result can be found - // through the - // reference context. Otherwise, use the other API taking a problem and a - // compilation result - // as arguments - private void handle(int problemId, String[] problemArguments, - String[] messageArguments, int problemStartPosition, - int problemEndPosition) { - this.handle(problemId, problemArguments, messageArguments, - problemStartPosition, problemEndPosition, referenceContext, - referenceContext == null ? null : referenceContext - .compilationResult()); - referenceContext = null; - } - // use this private API when the compilation unit result can be found - // through the - // reference context. Otherwise, use the other API taking a problem and a - // compilation result - // as arguments - private void handle(int problemId, String[] problemArguments, - String[] messageArguments, int severity, int problemStartPosition, - int problemEndPosition) { - this.handle(problemId, problemArguments, messageArguments, severity, - problemStartPosition, problemEndPosition, referenceContext, - referenceContext == null ? null : referenceContext - .compilationResult()); - referenceContext = null; - } - // use this private API when the compilation unit result cannot be found - // through the - // reference context. - private void handle(int problemId, String[] problemArguments, - String[] messageArguments, int problemStartPosition, - int problemEndPosition, CompilationResult unitResult) { - this.handle(problemId, problemArguments, messageArguments, - problemStartPosition, problemEndPosition, referenceContext, - unitResult); - referenceContext = null; - } - public void hidingEnclosingType(TypeDeclaration typeDecl) { - String[] arguments = new String[]{new String(typeDecl.name)}; - this.handle(IProblem.HidingEnclosingType, arguments, arguments, - typeDecl.sourceStart, typeDecl.sourceEnd); - } - public void hierarchyCircularity(SourceTypeBinding sourceType, - ReferenceBinding superType, TypeReference reference) { - int start = 0; - int end = 0; - String typeName = ""; //$NON-NLS-1$ - String shortTypeName = ""; //$NON-NLS-1$ - if (reference == null) { // can only happen when java.lang.Object is - // busted - start = sourceType.sourceStart(); - end = sourceType.sourceEnd(); - typeName = new String(superType.readableName()); - shortTypeName = new String(superType.sourceName()); - } else { - start = reference.sourceStart; - end = reference.sourceEnd; - char[][] qName = reference.getTypeName(); - typeName = CharOperation.toString(qName); - shortTypeName = new String(qName[qName.length - 1]); - } - if (sourceType == superType) - this - .handle(IProblem.HierarchyCircularitySelfReference, - new String[]{new String(sourceType.sourceName()), - typeName}, new String[]{ - new String(sourceType.sourceName()), - shortTypeName}, start, end); - else - this.handle(IProblem.HierarchyCircularity, new String[]{ - new String(sourceType.sourceName()), typeName}, - new String[]{new String(sourceType.sourceName()), - shortTypeName}, start, end); - } - public void hierarchyHasProblems(SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type - .sourceStart(), type.sourceEnd()); - } - public void illegalAbstractModifierCombinationForMethod( - ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(type.sourceName()), - new String(methodDecl.selector)}; - this.handle(IProblem.IllegalAbstractModifierCombinationForMethod, - arguments, arguments, methodDecl.sourceStart, - methodDecl.sourceEnd); - } - public void illegalModifierCombinationFinalAbstractForClass( - SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass, - arguments, arguments, type.sourceStart(), type.sourceEnd()); - } - public void illegalModifierCombinationFinalVolatileForField( - ReferenceBinding type, FieldDeclaration fieldDecl) { - String[] arguments = new String[]{fieldDecl.name()}; - this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField, - arguments, arguments, fieldDecl.sourceStart, - fieldDecl.sourceEnd); - } - public void illegalModifierForClass(SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalModifierForClass, arguments, arguments, - type.sourceStart(), type.sourceEnd()); - } - public void illegalModifierForField(ReferenceBinding type, - FieldDeclaration fieldDecl) { - String[] arguments = new String[]{fieldDecl.name()}; - this.handle(IProblem.IllegalModifierForField, arguments, arguments, - fieldDecl.sourceStart, fieldDecl.sourceEnd); - } - public void illegalModifierForInterface(SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalModifierForInterface, arguments, arguments, - type.sourceStart(), type.sourceEnd()); - } - public void illegalModifierForInterfaceField(ReferenceBinding type, - FieldDeclaration fieldDecl) { - String[] arguments = new String[]{fieldDecl.name()}; - this.handle(IProblem.IllegalModifierForInterfaceField, arguments, - arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); - } - public void illegalModifierForInterfaceMethod(ReferenceBinding type, - AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(type.sourceName()), - new String(methodDecl.selector)}; - this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments, - arguments, methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void illegalModifierForLocalClass(SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalModifierForLocalClass, arguments, - arguments, type.sourceStart(), type.sourceEnd()); - } - public void illegalModifierForMemberClass(SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalModifierForMemberClass, arguments, - arguments, type.sourceStart(), type.sourceEnd()); - } - public void illegalModifierForMemberInterface(SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalModifierForMemberInterface, arguments, - arguments, type.sourceStart(), type.sourceEnd()); - } - public void illegalModifierForMethod(ReferenceBinding type, - AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(type.sourceName()), - new String(methodDecl.selector)}; - this.handle(IProblem.IllegalModifierForMethod, arguments, arguments, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void illegalModifierForVariable(LocalDeclaration localDecl, - boolean complainAsArgument) { - String[] arguments = new String[]{localDecl.name()}; - this.handle(complainAsArgument - ? IProblem.IllegalModifierForArgument - : IProblem.IllegalModifierForVariable, arguments, arguments, - localDecl.sourceStart, localDecl.sourceEnd); - } - public void illegalPrimitiveOrArrayTypeForEnclosingInstance( - TypeBinding enclosingType, AstNode location) { - this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance, - new String[]{new String(enclosingType.readableName())}, - new String[]{new String(enclosingType.shortReadableName())}, - location.sourceStart, location.sourceEnd); - } - public void illegalStaticModifierForMemberType(SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalStaticModifierForMemberType, arguments, - arguments, type.sourceStart(), type.sourceEnd()); - } - public void illegalVisibilityModifierCombinationForField( - ReferenceBinding type, FieldDeclaration fieldDecl) { - String[] arguments = new String[]{new String(fieldDecl.name())}; - this.handle(IProblem.IllegalVisibilityModifierCombinationForField, - arguments, arguments, fieldDecl.sourceStart, - fieldDecl.sourceEnd); - } - public void illegalVisibilityModifierCombinationForMemberType( - SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType, - arguments, arguments, type.sourceStart(), type.sourceEnd()); - } - public void illegalVisibilityModifierCombinationForMethod( - ReferenceBinding type, AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(type.sourceName()), - new String(methodDecl.selector)}; - this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod, - arguments, arguments, methodDecl.sourceStart, - methodDecl.sourceEnd); - } - public void illegalVisibilityModifierForInterfaceMemberType( - SourceTypeBinding type) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType, - arguments, arguments, type.sourceStart(), type.sourceEnd()); - } - public void illegalVoidExpression(AstNode location) { - this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument, - location.sourceStart, location.sourceEnd); - } - public void importProblem(ImportReference importRef, Binding expectedImport) { - int problemId = expectedImport.problemId(); - int id; - switch (problemId) { - case NotFound : - // 1 - id = IProblem.ImportNotFound; - break; - case NotVisible : - // 2 - id = IProblem.ImportNotVisible; - break; - case Ambiguous : - // 3 - id = IProblem.ImportAmbiguous; - break; - case InternalNameProvided : - // 4 - id = IProblem.ImportInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : - // 5 - id = IProblem.ImportInheritedNameHidesEnclosingName; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - return; - } - String argument; - if (expectedImport instanceof ProblemReferenceBinding) { - argument = CharOperation - .toString(((ProblemReferenceBinding) expectedImport).compoundName); - } else { - argument = CharOperation.toString(importRef.tokens); - } - String[] arguments = new String[]{argument}; - this.handle(id, arguments, arguments, importRef.sourceStart, - importRef.sourceEnd); - } - public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, - MethodBinding currentMethod, MethodBinding inheritedMethod, - ReferenceBinding exceptionType) { - if (type == currentMethod.declaringClass) { - int id; - if (currentMethod.declaringClass.isInterface() - && !inheritedMethod.isPublic()) { // interface inheriting - // Object protected - // method - id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod; - } else { - id = IProblem.IncompatibleExceptionInThrowsClause; - } - this - .handle( - // Exception %1 is not compatible with throws - // clause in %2 - // 9.4.4 - The type of exception in the throws - // clause is incompatible. - id, - new String[]{ - new String(exceptionType.sourceName()), - new String( - CharOperation - .concat( - inheritedMethod.declaringClass - .readableName(), - inheritedMethod - .readableName(), - '.'))}, - new String[]{ - new String(exceptionType.sourceName()), - new String( - CharOperation - .concat( - inheritedMethod.declaringClass - .shortReadableName(), - inheritedMethod - .shortReadableName(), - '.'))}, - currentMethod.sourceStart(), currentMethod - .sourceEnd()); - } else - this - .handle( - // Exception %1 in throws clause of %2 is not - // compatible with %3 - // 9.4.4 - The type of exception in the throws - // clause is incompatible. - IProblem.IncompatibleExceptionInInheritedMethodThrowsClause, - new String[]{ - new String(exceptionType.sourceName()), - new String(CharOperation.concat( - currentMethod.declaringClass - .sourceName(), - currentMethod.readableName(), '.')), - new String( - CharOperation - .concat( - inheritedMethod.declaringClass - .readableName(), - inheritedMethod - .readableName(), - '.'))}, - new String[]{ - new String(exceptionType.sourceName()), - new String(CharOperation.concat( - currentMethod.declaringClass - .sourceName(), - currentMethod.shortReadableName(), - '.')), - new String( - CharOperation - .concat( - inheritedMethod.declaringClass - .shortReadableName(), - inheritedMethod - .shortReadableName(), - '.'))}, type - .sourceStart(), type.sourceEnd()); - } - public void incompatibleReturnType(MethodBinding currentMethod, - MethodBinding inheritedMethod) { - StringBuffer methodSignature = new StringBuffer(); - methodSignature.append(inheritedMethod.declaringClass.readableName()) - .append('.').append(inheritedMethod.readableName()); - StringBuffer shortSignature = new StringBuffer(); - shortSignature.append( - inheritedMethod.declaringClass.shortReadableName()).append('.') - .append(inheritedMethod.shortReadableName()); - int id; - if (currentMethod.declaringClass.isInterface() - && !inheritedMethod.isPublic()) { // interface inheriting - // Object protected method - id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod; - } else { - id = IProblem.IncompatibleReturnType; - } - this.handle(id, new String[]{methodSignature.toString()}, - new String[]{shortSignature.toString()}, currentMethod - .sourceStart(), currentMethod.sourceEnd()); - } - public void incorrectLocationForEmptyDimension( - ArrayAllocationExpression expression, int index) { - this.handle(IProblem.IllegalDimension, NoArgument, NoArgument, - expression.dimensions[index + 1].sourceStart, - expression.dimensions[index + 1].sourceEnd); - } - public void incorrectSwitchType(Expression expression, TypeBinding testType) { - this.handle(IProblem.IncorrectSwitchType, new String[]{new String( - testType.readableName())}, new String[]{new String(testType - .shortReadableName())}, expression.sourceStart, - expression.sourceEnd); - } - public void inheritedMethodReducesVisibility(SourceTypeBinding type, - MethodBinding concreteMethod, MethodBinding[] abstractMethods) { - StringBuffer concreteSignature = new StringBuffer(); - concreteSignature.append(concreteMethod.declaringClass.readableName()) - .append('.').append(concreteMethod.readableName()); - StringBuffer shortSignature = new StringBuffer(); - shortSignature - .append(concreteMethod.declaringClass.shortReadableName()) - .append('.').append(concreteMethod.shortReadableName()); - this.handle( - // The inherited method %1 cannot hide the public abstract method in %2 - IProblem.InheritedMethodReducesVisibility, new String[]{ - new String(concreteSignature.toString()), - new String(abstractMethods[0].declaringClass - .readableName())}, new String[]{ - new String(shortSignature.toString()), - new String(abstractMethods[0].declaringClass - .shortReadableName())}, type.sourceStart(), - type.sourceEnd()); - } - public void inheritedMethodsHaveIncompatibleReturnTypes( - SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) { - StringBuffer methodSignatures = new StringBuffer(); - StringBuffer shortSignatures = new StringBuffer(); - for (int i = length; --i >= 0;) { - methodSignatures.append( - inheritedMethods[i].declaringClass.readableName()).append( - '.').append(inheritedMethods[i].readableName()); - shortSignatures.append( - inheritedMethods[i].declaringClass.shortReadableName()) - .append('.') - .append(inheritedMethods[i].shortReadableName()); - if (i != 0) { - methodSignatures.append(", "); //$NON-NLS-1$ - shortSignatures.append(", "); //$NON-NLS-1$ - } - } - this.handle( - // Return type is incompatible with %1 - // 9.4.2 - The return type from the method is incompatible with - // the declaration. - IProblem.IncompatibleReturnType, new String[]{methodSignatures - .toString()}, new String[]{shortSignatures.toString()}, - type.sourceStart(), type.sourceEnd()); - } - public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) { - this.handle(IProblem.InitializerMustCompleteNormally, NoArgument, - NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd); - } - public void innerTypesCannotDeclareStaticInitializers( - ReferenceBinding innerType, AstNode location) { - this.handle(IProblem.CannotDefineStaticInitializerInLocalType, - new String[]{new String(innerType.readableName())}, - new String[]{new String(innerType.shortReadableName())}, - location.sourceStart, location.sourceEnd); - } - public void interfaceCannotHaveConstructors( - ConstructorDeclaration constructor) { - this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument, - NoArgument, constructor.sourceStart, constructor.sourceEnd, - constructor, constructor.compilationResult()); - } - public void interfaceCannotHaveInitializers(SourceTypeBinding type, - FieldDeclaration fieldDecl) { - String[] arguments = new String[]{new String(type.sourceName())}; - this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, - arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); - } - public void invalidBreak(AstNode location) { - this.handle(IProblem.InvalidBreak, NoArgument, NoArgument, - location.sourceStart, location.sourceEnd); - } - public void invalidConstructor(Statement statement, - MethodBinding targetConstructor) { - boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration) - && ((ConstructorDeclaration) referenceContext) - .isDefaultConstructor(); - boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall) - && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper); - int flag = IProblem.UndefinedConstructor; //default... - switch (targetConstructor.problemId()) { - case NotFound : - if (insideDefaultConstructor) { - flag = IProblem.UndefinedConstructorInDefaultConstructor; - } else if (insideImplicitConstructorCall) { - flag = IProblem.UndefinedConstructorInImplicitConstructorCall; - } else { - flag = IProblem.UndefinedConstructor; - } - break; - case NotVisible : - if (insideDefaultConstructor) { - flag = IProblem.NotVisibleConstructorInDefaultConstructor; - } else if (insideImplicitConstructorCall) { - flag = IProblem.NotVisibleConstructorInImplicitConstructorCall; - } else { - flag = IProblem.NotVisibleConstructor; - } - break; - case Ambiguous : - if (insideDefaultConstructor) { - flag = IProblem.AmbiguousConstructorInDefaultConstructor; - } else if (insideImplicitConstructorCall) { - flag = IProblem.AmbiguousConstructorInImplicitConstructorCall; - } else { - flag = IProblem.AmbiguousConstructor; - } - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - break; - } - this.handle(flag, new String[]{ - new String(targetConstructor.declaringClass.readableName()), - parametersAsString(targetConstructor)}, - new String[]{ - new String(targetConstructor.declaringClass - .shortReadableName()), - parametersAsShortString(targetConstructor)}, - statement.sourceStart, statement.sourceEnd); - } - public void invalidContinue(AstNode location) { - this.handle(IProblem.InvalidContinue, NoArgument, NoArgument, - location.sourceStart, location.sourceEnd); - } - public void invalidEnclosingType(Expression expression, TypeBinding type, - ReferenceBinding enclosingType) { - if (enclosingType.isAnonymousType()) - enclosingType = enclosingType.superclass(); - int flag = IProblem.UndefinedType; // default - switch (type.problemId()) { - case NotFound : - // 1 - flag = IProblem.UndefinedType; - break; - case NotVisible : - // 2 - flag = IProblem.NotVisibleType; - break; - case Ambiguous : - // 3 - flag = IProblem.AmbiguousType; - break; - case InternalNameProvided : - flag = IProblem.InternalTypeNameProvided; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - break; - } - this.handle(flag, new String[]{new String(enclosingType.readableName()) - + "." + new String(type.readableName())}, //$NON-NLS-1$ - new String[]{new String(enclosingType.shortReadableName()) - + "." + new String(type.shortReadableName())}, //$NON-NLS-1$ - expression.sourceStart, expression.sourceEnd); - } - public void invalidExpressionAsStatement(Expression expression) { - this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, - NoArgument, expression.sourceStart, expression.sourceEnd); - } - public void invalidField(FieldReference fieldRef, TypeBinding searchedType) { - int severity = Error; - int flag = IProblem.UndefinedField; - FieldBinding field = fieldRef.binding; - switch (field.problemId()) { - case NotFound : - flag = IProblem.UndefinedField; - /* - * also need to check that the searchedType is the receiver - * type if (searchedType.isHierarchyInconsistent()) severity = - * SecondaryError; - */ - break; - case NotVisible : - flag = IProblem.NotVisibleField; - break; - case Ambiguous : - flag = IProblem.AmbiguousField; - break; - case NonStaticReferenceInStaticContext : - flag = IProblem.NonStaticFieldFromStaticInvocation; - break; - case NonStaticReferenceInConstructorInvocation : - flag = IProblem.InstanceFieldDuringConstructorInvocation; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedFieldHidesEnclosingName; - break; - case ReceiverTypeNotVisible : - this.handle(IProblem.NotVisibleType, new String[]{new String( - searchedType.leafComponentType().readableName())}, - new String[]{new String(searchedType - .leafComponentType().shortReadableName())}, - fieldRef.receiver.sourceStart, - fieldRef.receiver.sourceEnd); - return; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - break; - } - String[] arguments = new String[]{new String(field.readableName())}; - this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart, - fieldRef.sourceEnd); - } - public void invalidField(NameReference nameRef, FieldBinding field) { - int flag = IProblem.UndefinedField; - switch (field.problemId()) { - case NotFound : - flag = IProblem.UndefinedField; - break; - case NotVisible : - flag = IProblem.NotVisibleField; - break; - case Ambiguous : - flag = IProblem.AmbiguousField; - break; - case NonStaticReferenceInStaticContext : - flag = IProblem.NonStaticFieldFromStaticInvocation; - break; - case NonStaticReferenceInConstructorInvocation : - flag = IProblem.InstanceFieldDuringConstructorInvocation; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedFieldHidesEnclosingName; - break; - case ReceiverTypeNotVisible : - this.handle(IProblem.NotVisibleType, - new String[]{new String(field.declaringClass - .leafComponentType().readableName())}, - new String[]{new String(field.declaringClass - .leafComponentType().shortReadableName())}, - nameRef.sourceStart, nameRef.sourceEnd); - return; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - break; - } - String[] arguments = new String[]{new String(field.readableName())}; - this.handle(flag, arguments, arguments, nameRef.sourceStart, - nameRef.sourceEnd); - } - public void invalidField(QualifiedNameReference nameRef, - FieldBinding field, int index, TypeBinding searchedType) { - //the resolution of the index-th field of qname failed - //qname.otherBindings[index] is the binding that has produced the - // error - //The different targetted errors should be : - //UndefinedField - //NotVisibleField - //AmbiguousField - if (searchedType.isBaseType()) { - this.handle(IProblem.NoFieldOnBaseType, new String[]{ - new String(searchedType.readableName()), - CharOperation.toString(CharOperation.subarray( - nameRef.tokens, 0, index)), - new String(nameRef.tokens[index])}, new String[]{ - new String(searchedType.sourceName()), - CharOperation.toString(CharOperation.subarray( - nameRef.tokens, 0, index)), - new String(nameRef.tokens[index])}, nameRef.sourceStart, - nameRef.sourceEnd); - return; - } - int flag = IProblem.UndefinedField; - switch (field.problemId()) { - case NotFound : - flag = IProblem.UndefinedField; - /* - * also need to check that the searchedType is the receiver - * type if (searchedType.isHierarchyInconsistent()) severity = - * SecondaryError; - */ - break; - case NotVisible : - flag = IProblem.NotVisibleField; - break; - case Ambiguous : - flag = IProblem.AmbiguousField; - break; - case NonStaticReferenceInStaticContext : - flag = IProblem.NonStaticFieldFromStaticInvocation; - break; - case NonStaticReferenceInConstructorInvocation : - flag = IProblem.InstanceFieldDuringConstructorInvocation; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedFieldHidesEnclosingName; - break; - case ReceiverTypeNotVisible : - this.handle(IProblem.NotVisibleType, new String[]{new String( - searchedType.leafComponentType().readableName())}, - new String[]{new String(searchedType - .leafComponentType().shortReadableName())}, - nameRef.sourceStart, nameRef.sourceEnd); - return; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - break; - } - String[] arguments = new String[]{CharOperation.toString(CharOperation - .subarray(nameRef.tokens, 0, index + 1))}; - this.handle(flag, arguments, arguments, nameRef.sourceStart, - nameRef.sourceEnd); - } - public void invalidMethod(MessageSend messageSend, MethodBinding method) { - // CODE should be UPDATED according to error coding in the different - // method binding errors - // The different targetted errors should be : - // UndefinedMethod - // NotVisibleMethod - // AmbiguousMethod - // InheritedNameHidesEnclosingName - // InstanceMethodDuringConstructorInvocation - // StaticMethodRequested - int flag = IProblem.UndefinedMethod; //default... - switch (method.problemId()) { - case NotFound : - flag = IProblem.UndefinedMethod; - break; - case NotVisible : - flag = IProblem.NotVisibleMethod; - break; - case Ambiguous : - flag = IProblem.AmbiguousMethod; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedMethodHidesEnclosingName; - break; - case NonStaticReferenceInConstructorInvocation : - flag = IProblem.InstanceMethodDuringConstructorInvocation; - break; - case NonStaticReferenceInStaticContext : - flag = IProblem.StaticMethodRequested; - break; - case ReceiverTypeNotVisible : - this.handle(IProblem.NotVisibleType, new String[]{new String( - method.declaringClass.leafComponentType() - .readableName())}, new String[]{new String( - method.declaringClass.leafComponentType() - .shortReadableName())}, - messageSend.receiver.sourceStart, - messageSend.receiver.sourceEnd); - return; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - break; - } - if (flag == IProblem.UndefinedMethod) { - ProblemMethodBinding problemMethod = (ProblemMethodBinding) method; - if (problemMethod.closestMatch != null) { - String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch); - String parameterTypeNames = parametersAsString(method); - String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch); - String parameterTypeShortNames = parametersAsShortString(method); - if (closestParameterTypeShortNames - .equals(parameterTypeShortNames)) { - closestParameterTypeShortNames = closestParameterTypeNames; - parameterTypeShortNames = parameterTypeNames; - } - this - .handle( - IProblem.ParameterMismatch, - new String[]{ - new String( - problemMethod.closestMatch.declaringClass - .readableName()), - new String( - problemMethod.closestMatch.selector), - closestParameterTypeNames, - parameterTypeNames}, - new String[]{ - new String( - problemMethod.closestMatch.declaringClass - .shortReadableName()), - new String( - problemMethod.closestMatch.selector), - closestParameterTypeShortNames, - parameterTypeShortNames}, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); - return; - } - } - this.handle(flag, new String[]{ - new String(method.declaringClass.readableName()), - new String(method.selector), parametersAsString(method)}, - new String[]{ - new String(method.declaringClass.shortReadableName()), - new String(method.selector), - parametersAsShortString(method)}, - (int) (messageSend.nameSourcePosition >>> 32), - (int) messageSend.nameSourcePosition); - } - public void invalidNullToSynchronize(Expression expression) { - this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument, - expression.sourceStart, expression.sourceEnd); - } - public void invalidOperator(BinaryExpression expression, - TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)) { - leftShortName = leftName; - rightShortName = rightName; - } - this.handle(IProblem.InvalidOperator, new String[]{ - expression.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$ - new String[]{expression.operatorToString(), - leftShortName + ", " + rightShortName}, //$NON-NLS-1$ - expression.sourceStart, expression.sourceEnd); - } - public void invalidOperator(CompoundAssignment assign, - TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)) { - leftShortName = leftName; - rightShortName = rightName; - } - this.handle(IProblem.InvalidOperator, new String[]{ - assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$ - new String[]{assign.operatorToString(), - leftShortName + ", " + rightShortName}, //$NON-NLS-1$ - assign.sourceStart, assign.sourceEnd); - } - public void invalidOperator(UnaryExpression expression, TypeBinding type) { - this.handle(IProblem.InvalidOperator, - new String[]{expression.operatorToString(), - new String(type.readableName())}, new String[]{ - expression.operatorToString(), - new String(type.shortReadableName())}, - expression.sourceStart, expression.sourceEnd); - } - public void invalidParenthesizedExpression(AstNode reference) { - this.handle(IProblem.InvalidParenthesizedExpression, NoArgument, - NoArgument, reference.sourceStart, reference.sourceEnd); - } - public void invalidSuperclass(SourceTypeBinding type, - TypeReference superclassRef, ReferenceBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : - // 1 - id = IProblem.SuperclassNotFound; - break; - case NotVisible : - // 2 - id = IProblem.SuperclassNotVisible; - break; - case Ambiguous : - // 3 - id = IProblem.SuperclassAmbiguous; - break; - case InternalNameProvided : - // 4 - id = IProblem.SuperclassInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : - // 5 - id = IProblem.SuperclassInheritedNameHidesEnclosingName; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - return; - } - this.handle(id, new String[]{new String(expectedType.readableName()), - new String(type.sourceName())}, new String[]{ - new String(expectedType.shortReadableName()), - new String(type.sourceName())}, superclassRef.sourceStart, - superclassRef.sourceEnd); - } - public void invalidSuperinterface(SourceTypeBinding type, - TypeReference superinterfaceRef, ReferenceBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : - // 1 - id = IProblem.InterfaceNotFound; - break; - case NotVisible : - // 2 - id = IProblem.InterfaceNotVisible; - break; - case Ambiguous : - // 3 - id = IProblem.InterfaceAmbiguous; - break; - case InternalNameProvided : - // 4 - id = IProblem.InterfaceInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : - // 5 - id = IProblem.InterfaceInheritedNameHidesEnclosingName; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - return; - } - this.handle(id, new String[]{new String(expectedType.readableName()), - new String(type.sourceName())}, new String[]{ - new String(expectedType.shortReadableName()), - new String(type.sourceName())}, superinterfaceRef.sourceStart, - superinterfaceRef.sourceEnd); - } - public void invalidType(AstNode location, TypeBinding type) { - int flag = IProblem.UndefinedType; // default - switch (type.problemId()) { - case NotFound : - flag = IProblem.UndefinedType; - break; - case NotVisible : - flag = IProblem.NotVisibleType; - break; - case Ambiguous : - flag = IProblem.AmbiguousType; - break; - case InternalNameProvided : - flag = IProblem.InternalTypeNameProvided; - break; - case InheritedNameHidesEnclosingName : - flag = IProblem.InheritedTypeHidesEnclosingName; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - break; - } - this.handle(flag, new String[]{new String(type.readableName())}, - new String[]{new String(type.shortReadableName())}, - location.sourceStart, location.sourceEnd); - } - public void invalidTypeReference(Expression expression) { - this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument, - expression.sourceStart, expression.sourceEnd); - } - public void invalidTypeToSynchronize(Expression expression, TypeBinding type) { - this.handle(IProblem.InvalidTypeToSynchronized, - new String[]{new String(type.readableName())}, - new String[]{new String(type.shortReadableName())}, - expression.sourceStart, expression.sourceEnd); - } - public void invalidUnaryExpression(Expression expression) { - this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument, - expression.sourceStart, expression.sourceEnd); - } - public void isClassPathCorrect(char[][] wellKnownTypeName, - CompilationUnitDeclaration compUnitDecl) { - referenceContext = compUnitDecl; - String[] arguments = new String[]{CharOperation - .toString(wellKnownTypeName)}; - this.handle(IProblem.IsClassPathCorrect, arguments, arguments, - AbortCompilation | Error, compUnitDecl == null - ? 0 - : compUnitDecl.sourceStart, compUnitDecl == null - ? 1 - : compUnitDecl.sourceEnd); - } - public void maskedExceptionHandler(ReferenceBinding exceptionType, - AstNode location) { - this.handle(IProblem.MaskedCatch, NoArgument, NoArgument, - location.sourceStart, location.sourceEnd); - } - public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) { - this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void methodNeedingNoBody(MethodDeclaration methodDecl) { - this.handle( - // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ? - // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod, - IProblem.BodyForAbstractMethod, NoArgument, NoArgument, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void methodWithConstructorName(MethodDeclaration methodDecl) { - this.handle(IProblem.MethodButWithConstructorName, NoArgument, - NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd); - } - //public void missingEnclosingInstanceSpecification(ReferenceBinding - // enclosingType, AstNode location) { - // boolean insideConstructorCall = - // (location instanceof ExplicitConstructorCall) - // && (((ExplicitConstructorCall) location).accessMode == - // ExplicitConstructorCall.ImplicitSuper); - // - // this.handle( - // insideConstructorCall - // ? IProblem.MissingEnclosingInstanceForConstructorCall - // : IProblem.MissingEnclosingInstance, - // new String[] {new String(enclosingType.readableName())}, - // new String[] {new String(enclosingType.shortReadableName())}, - // location.sourceStart, - // location.sourceEnd); - //} - public void missingReturnType(AbstractMethodDeclaration methodDecl) { - this.handle(IProblem.MissingReturnType, NoArgument, NoArgument, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void missingSemiColon(Expression expression) { - this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument, - expression.sourceStart, expression.sourceEnd); - } - public void mustDefineDimensionsOrInitializer( - ArrayAllocationExpression expression) { - this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer, - NoArgument, NoArgument, expression.sourceStart, - expression.sourceEnd); - } - public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) { - String[] arguments = new String[]{new String(compUnitDecl.getFileName())}; - this.handle(IProblem.MustSpecifyPackage, arguments, arguments, - compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1); - } - public void mustUseAStaticMethod(MessageSend messageSend, - MethodBinding method) { - this.handle(IProblem.StaticMethodRequested, new String[]{ - new String(method.declaringClass.readableName()), - new String(method.selector), parametersAsString(method)}, - new String[]{ - new String(method.declaringClass.shortReadableName()), - new String(method.selector), - parametersAsShortString(method)}, - messageSend.sourceStart, messageSend.sourceEnd); - } - public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, - AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(type.sourceName()), - new String(methodDecl.selector)}; - this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, - arguments, methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void needImplementation() { - this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$ - } - public void needToEmulateFieldReadAccess(FieldBinding field, - AstNode location) { - this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[]{ - new String(field.declaringClass.readableName()), - new String(field.name)}, new String[]{ - new String(field.declaringClass.shortReadableName()), - new String(field.name)}, location.sourceStart, - location.sourceEnd); - } - public void needToEmulateFieldWriteAccess(FieldBinding field, - AstNode location) { - this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[]{ - new String(field.declaringClass.readableName()), - new String(field.name)}, new String[]{ - new String(field.declaringClass.shortReadableName()), - new String(field.name)}, location.sourceStart, - location.sourceEnd); - } - public void needToEmulateMethodAccess(MethodBinding method, AstNode location) { - if (method.isConstructor()) - this.handle(IProblem.NeedToEmulateConstructorAccess, new String[]{ - new String(method.declaringClass.readableName()), - parametersAsString(method)}, new String[]{ - new String(method.declaringClass.shortReadableName()), - parametersAsShortString(method)}, location.sourceStart, - location.sourceEnd); - else - this.handle(IProblem.NeedToEmulateMethodAccess, new String[]{ - new String(method.declaringClass.readableName()), - new String(method.selector), parametersAsString(method)}, - new String[]{ - new String(method.declaringClass - .shortReadableName()), - new String(method.selector), - parametersAsShortString(method)}, - location.sourceStart, location.sourceEnd); - } - public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) { - String[] arguments = new String[]{new String(typeDecl.name)}; - this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, - arguments, typeDecl.sourceStart, typeDecl.sourceEnd); - } - public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, - AstNode location) { - String[] arguments = new String[]{new String(local.name)}; - this.handle(local instanceof SyntheticArgumentBinding - ? IProblem.TooManySyntheticArgumentSlots - : IProblem.TooManyArgumentSlots, arguments, arguments, Abort - | Error, location.sourceStart, location.sourceEnd); - } - public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, - AstNode location) { - String[] arguments = new String[]{new String(local.name)}; - this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, - Abort | Error, location.sourceStart, location.sourceEnd); - } - public void noSuchEnclosingInstance(TypeBinding targetType, - AstNode location, boolean isConstructorCall) { - int id; - if (isConstructorCall) { - //28 = No enclosing instance of type {0} is available due to some - // intermediate constructor invocation - id = IProblem.EnclosingInstanceInConstructorCall; - } else if ((location instanceof ExplicitConstructorCall) - && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) { - //20 = No enclosing instance of type {0} is accessible to invoke - // the super constructor. Must define a constructor and explicitly - // qualify its super constructor invocation with an instance of {0} - // (e.g. x.super() where x is an instance of {0}). - id = IProblem.MissingEnclosingInstanceForConstructorCall; - } else if (location instanceof AllocationExpression - && (((AllocationExpression) location).binding.declaringClass - .isMemberType() || (((AllocationExpression) location).binding.declaringClass - .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass - .superclass().isMemberType()))) { - //21 = No enclosing instance of type {0} is accessible. Must - // qualify the allocation with an enclosing instance of type {0} - // (e.g. x.new A() where x is an instance of {0}). - id = IProblem.MissingEnclosingInstance; - } else { // default - //22 = No enclosing instance of the type {0} is accessible in - // scope - id = IProblem.IncorrectEnclosingInstanceReference; - } - this.handle(id, new String[]{new String(targetType.readableName())}, - new String[]{new String(targetType.shortReadableName())}, - location.sourceStart, location.sourceEnd); - } - public void notCompatibleTypesError(EqualExpression expression, - TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)) { - leftShortName = leftName; - rightShortName = rightName; - } - this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[]{ - leftName, rightName}, new String[]{leftShortName, - rightShortName}, expression.sourceStart, expression.sourceEnd); - } - public void notCompatibleTypesError(InstanceOfExpression expression, - TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)) { - leftShortName = leftName; - rightShortName = rightName; - } - this.handle(IProblem.IncompatibleTypesInConditionalOperator, - new String[]{leftName, rightName}, new String[]{leftShortName, - rightShortName}, expression.sourceStart, - expression.sourceEnd); - } - public void objectCannotHaveSuperTypes(SourceTypeBinding type) { - this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, - NoArgument, type.sourceStart(), type.sourceEnd()); - } - public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, - TypeBinding leftType, TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)) { - leftShortName = leftName; - rightShortName = rightName; - } - this.handle(IProblem.TypeMismatch, new String[]{leftName, rightName}, - new String[]{leftShortName, rightShortName}, - assignment.sourceStart, assignment.sourceEnd); - } - public void overridesDeprecatedMethod(MethodBinding localMethod, - MethodBinding inheritedMethod) { - this.handle(IProblem.OverridingDeprecatedMethod, new String[]{ - new String(CharOperation.concat(localMethod.declaringClass - .readableName(), localMethod.readableName(), '.')), - new String(inheritedMethod.declaringClass.readableName())}, - new String[]{ - new String(CharOperation.concat( - localMethod.declaringClass.shortReadableName(), - localMethod.shortReadableName(), '.')), - new String(inheritedMethod.declaringClass - .shortReadableName())}, localMethod - .sourceStart(), localMethod.sourceEnd()); - } - public void overridesPackageDefaultMethod(MethodBinding localMethod, - MethodBinding inheritedMethod) { - this.handle(IProblem.OverridingNonVisibleMethod, new String[]{ - new String(CharOperation.concat(localMethod.declaringClass - .readableName(), localMethod.readableName(), '.')), - new String(inheritedMethod.declaringClass.readableName())}, - new String[]{ - new String(CharOperation.concat( - localMethod.declaringClass.shortReadableName(), - localMethod.shortReadableName(), '.')), - new String(inheritedMethod.declaringClass - .shortReadableName())}, localMethod - .sourceStart(), localMethod.sourceEnd()); - } - public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) { - String[] arguments = new String[]{CharOperation - .toString(compUnitDecl.currentPackage.tokens)}; - this.handle(IProblem.PackageCollidesWithType, arguments, arguments, - compUnitDecl.currentPackage.sourceStart, - compUnitDecl.currentPackage.sourceEnd); - } - public void packageIsNotExpectedPackage( - CompilationUnitDeclaration compUnitDecl) { - String[] arguments = new String[]{CharOperation - .toString(compUnitDecl.compilationResult.compilationUnit - .getPackageName())}; - this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments, - compUnitDecl.currentPackage == null - ? 0 - : compUnitDecl.currentPackage.sourceStart, - compUnitDecl.currentPackage == null - ? 0 - : compUnitDecl.currentPackage.sourceEnd); - } - private String parametersAsString(MethodBinding method) { - TypeBinding[] params = method.parameters; - StringBuffer buffer = new StringBuffer(); - for (int i = 0, length = params.length; i < length; i++) { - if (i != 0) - buffer.append(", "); //$NON-NLS-1$ - buffer.append(new String(params[i].readableName())); - } - return buffer.toString(); - } - private String parametersAsShortString(MethodBinding method) { - TypeBinding[] params = method.parameters; - StringBuffer buffer = new StringBuffer(); - for (int i = 0, length = params.length; i < length; i++) { - if (i != 0) - buffer.append(", "); //$NON-NLS-1$ - buffer.append(new String(params[i].shortReadableName())); - } - return buffer.toString(); - } - public void parseError(int startPosition, int endPosition, - char[] currentTokenSource, String errorTokenName, - String[] possibleTokens) { - if (possibleTokens.length == 0) { //no suggestion available - if (isKeyword(currentTokenSource)) { - String[] arguments = new String[]{new String(currentTokenSource)}; - this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, - arguments, arguments, - // this is the current -invalid- token position - startPosition, endPosition); - return; - } else { - String[] arguments = new String[]{errorTokenName}; - this.handle(IProblem.ParsingErrorNoSuggestion, arguments, - arguments, - // this is the current -invalid- token position - startPosition, endPosition); - return; - } - } - //build a list of probable right tokens - StringBuffer list = new StringBuffer(20); - for (int i = 0, max = possibleTokens.length; i < max; i++) { - if (i > 0) - list.append(", "); //$NON-NLS-1$ - list.append('"'); - list.append(possibleTokens[i]); - list.append('"'); - } - if (isKeyword(currentTokenSource)) { - String[] arguments = new String[]{new String(currentTokenSource), - list.toString()}; - this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments, - // this is the current -invalid- token position - startPosition, endPosition); - return; - } - //extract the literal when it's a literal - if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$ - (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$ - errorTokenName = new String(currentTokenSource); - } - String[] arguments = new String[]{errorTokenName, list.toString()}; - this.handle(IProblem.ParsingError, arguments, arguments, - // this is the current -invalid- token position - startPosition, endPosition); - } - public void publicClassMustMatchFileName( - CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) { - this.referenceContext = typeDecl; // report the problem against the - // type not the entire compilation - // unit - String[] arguments = new String[]{ - new String(compUnitDecl.getFileName()), - new String(typeDecl.name)}; - this.handle(IProblem.PublicClassMustMatchFileName, arguments, - arguments, typeDecl.sourceStart, typeDecl.sourceEnd, - compUnitDecl.compilationResult); - } - public void recursiveConstructorInvocation( - ExplicitConstructorCall constructorCall) { - this.handle(IProblem.RecursiveConstructorInvocation, new String[]{ - new String(constructorCall.binding.declaringClass - .readableName()), - parametersAsString(constructorCall.binding)}, new String[]{ - new String(constructorCall.binding.declaringClass - .shortReadableName()), - parametersAsShortString(constructorCall.binding)}, - constructorCall.sourceStart, constructorCall.sourceEnd); - } - public void redefineArgument(Argument arg) { - String[] arguments = new String[]{new String(arg.name)}; - this.handle(IProblem.RedefinedArgument, arguments, arguments, - arg.sourceStart, arg.sourceEnd); - } - public void redefineLocal(LocalDeclaration localDecl) { - String[] arguments = new String[]{new String(localDecl.name)}; - this.handle(IProblem.RedefinedLocal, arguments, arguments, - localDecl.sourceStart, localDecl.sourceEnd); - } - public void referenceMustBeArrayTypeAt(TypeBinding arrayType, - ArrayReference arrayRef) { - this.handle(IProblem.ArrayReferenceRequired, new String[]{new String( - arrayType.readableName())}, new String[]{new String(arrayType - .shortReadableName())}, arrayRef.sourceStart, - arrayRef.sourceEnd); - } - public void returnTypeCannotBeVoidArray(SourceTypeBinding type, - MethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(methodDecl.selector)}; - this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void returnTypeProblem(SourceTypeBinding type, - MethodDeclaration methodDecl, TypeBinding expectedType) { - int problemId = expectedType.problemId(); - int id; - switch (problemId) { - case NotFound : - // 1 - id = IProblem.ReturnTypeNotFound; - break; - case NotVisible : - // 2 - id = IProblem.ReturnTypeNotVisible; - break; - case Ambiguous : - // 3 - id = IProblem.ReturnTypeAmbiguous; - break; - case InternalNameProvided : - // 4 - id = IProblem.ReturnTypeInternalNameProvided; - break; - case InheritedNameHidesEnclosingName : - // 5 - id = IProblem.ReturnTypeInheritedNameHidesEnclosingName; - break; - case NoError : - // 0 - default : - needImplementation(); // want to fail to see why we were - // here... - return; - } - this.handle(id, new String[]{new String(methodDecl.selector), - new String(expectedType.readableName())}, new String[]{ - new String(methodDecl.selector), - new String(expectedType.shortReadableName())}, - methodDecl.returnType.sourceStart, - methodDecl.returnType.sourceEnd); - } - public void scannerError(Parser parser, String errorTokenName) { - Scanner scanner = parser.scanner; - int flag = IProblem.ParsingErrorNoSuggestion; - int startPos = scanner.startPosition; - //special treatment for recognized errors.... - if (errorTokenName.equals(Scanner.END_OF_SOURCE)) - flag = IProblem.EndOfSource; - else if (errorTokenName.equals(Scanner.INVALID_HEXA)) - flag = IProblem.InvalidHexa; - else if (errorTokenName.equals(Scanner.INVALID_OCTAL)) - flag = IProblem.InvalidOctal; - else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT)) - flag = IProblem.InvalidCharacterConstant; - else if (errorTokenName.equals(Scanner.INVALID_ESCAPE)) - flag = IProblem.InvalidEscape; - else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) { - flag = IProblem.InvalidUnicodeEscape; - // better locate the error message - char[] source = scanner.source; - int checkPos = scanner.currentPosition - 1; - if (checkPos >= source.length) - checkPos = source.length - 1; - while (checkPos >= startPos) { - if (source[checkPos] == '\\') - break; - checkPos--; - } - startPos = checkPos; - } else if (errorTokenName.equals(Scanner.INVALID_FLOAT)) - flag = IProblem.InvalidFloat; - else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING)) - flag = IProblem.UnterminatedString; - else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT)) - flag = IProblem.UnterminatedComment; - else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING)) - flag = IProblem.UnterminatedString; - String[] arguments = flag == IProblem.ParsingErrorNoSuggestion - ? new String[]{errorTokenName} - : NoArgument; - this.handle(flag, arguments, arguments, - // this is the current -invalid- token position - startPos, scanner.currentPosition - 1, - parser.compilationUnit.compilationResult); - } - public void shouldReturn(TypeBinding returnType, AstNode location) { - this.handle(IProblem.ShouldReturnValue, new String[]{new String( - returnType.readableName())}, new String[]{new String(returnType - .shortReadableName())}, location.sourceStart, - location.sourceEnd); - } - public void signalNoImplicitStringConversionForCharArrayExpression( - Expression expression) { - this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression, - NoArgument, NoArgument, expression.sourceStart, - expression.sourceEnd); - } - public void staticAndInstanceConflict(MethodBinding currentMethod, - MethodBinding inheritedMethod) { - if (currentMethod.isStatic()) - this.handle( - // This static method cannot hide the instance method from %1 - // 8.4.6.4 - If a class inherits more than one method with - // the same signature a static (non-abstract) method cannot - // hide an instance method. - IProblem.CannotHideAnInstanceMethodWithAStaticMethod, - new String[]{new String(inheritedMethod.declaringClass - .readableName())}, - new String[]{new String(inheritedMethod.declaringClass - .shortReadableName())}, - currentMethod.sourceStart(), currentMethod.sourceEnd()); - else - this.handle( - // This instance method cannot override the static method from %1 - // 8.4.6.4 - If a class inherits more than one method with - // the same signature an instance (non-abstract) method - // cannot override a static method. - IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod, - new String[]{new String(inheritedMethod.declaringClass - .readableName())}, - new String[]{new String(inheritedMethod.declaringClass - .shortReadableName())}, - currentMethod.sourceStart(), currentMethod.sourceEnd()); - } - public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, - FieldBinding field) { - String[] arguments = new String[]{new String(field.readableName())}; - this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, - arguments, fieldRef.sourceStart, fieldRef.sourceEnd); - } - public void staticFieldAccessToNonStaticVariable( - QualifiedNameReference nameRef, FieldBinding field) { - String[] arguments = new String[]{new String(field.readableName())}; - this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, - arguments, nameRef.sourceStart, nameRef.sourceEnd); - } - public void staticFieldAccessToNonStaticVariable( - SingleNameReference nameRef, FieldBinding field) { - String[] arguments = new String[]{new String(field.readableName())}; - this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, - arguments, nameRef.sourceStart, nameRef.sourceEnd); - } - public void staticInheritedMethodConflicts(SourceTypeBinding type, - MethodBinding concreteMethod, MethodBinding[] abstractMethods) { - this.handle( - // The static method %1 conflicts with the abstract method in %2 - // 8.4.6.4 - If a class inherits more than one method with the - // same signature it is an error for one to be static - // (non-abstract) and the other abstract. - IProblem.StaticInheritedMethodConflicts, new String[]{ - new String(concreteMethod.readableName()), - new String(abstractMethods[0].declaringClass - .readableName())}, new String[]{ - new String(concreteMethod.readableName()), - new String(abstractMethods[0].declaringClass - .shortReadableName())}, type.sourceStart(), - type.sourceEnd()); - } - public void stringConstantIsExceedingUtf8Limit(AstNode location) { - this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument, - NoArgument, location.sourceStart, location.sourceEnd); - } - public void superclassMustBeAClass(SourceTypeBinding type, - TypeReference superclassRef, ReferenceBinding superType) { - this.handle(IProblem.SuperclassMustBeAClass, new String[]{ - new String(superType.readableName()), - new String(type.sourceName())}, new String[]{ - new String(superType.shortReadableName()), - new String(type.sourceName())}, superclassRef.sourceStart, - superclassRef.sourceEnd); - } - public void superinterfaceMustBeAnInterface(SourceTypeBinding type, - TypeDeclaration typeDecl, ReferenceBinding superType) { - this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[]{ - new String(superType.readableName()), - new String(type.sourceName())}, new String[]{ - new String(superType.shortReadableName()), - new String(type.sourceName())}, typeDecl.sourceStart, - typeDecl.sourceEnd); - } - public void task(String tag, String message, String priority, int start, - int end) { - this - .handle( - IProblem.Task, - new String[]{tag, message, priority/* - * secret argument - * that is not - * surfaced in - * getMessage() - */}, - new String[]{tag, message, priority/* - * secret argument - * that is not - * surfaced in - * getMessage() - */}, - start, end); - } - public void tooManyDimensions(AstNode expression) { - this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument, - expression.sourceStart, expression.sourceEnd); - } - public void tooManyFields(TypeDeclaration typeDeclaration) { - this.handle(IProblem.TooManyFields, new String[]{new String( - typeDeclaration.binding.readableName())}, - new String[]{new String(typeDeclaration.binding - .shortReadableName())}, Abort | Error, - typeDeclaration.sourceStart, typeDeclaration.sourceEnd); - } - public void tooManyMethods(TypeDeclaration typeDeclaration) { - this.handle(IProblem.TooManyMethods, new String[]{new String( - typeDeclaration.binding.readableName())}, - new String[]{new String(typeDeclaration.binding - .shortReadableName())}, Abort | Error, - typeDeclaration.sourceStart, typeDeclaration.sourceEnd); - } - public void typeCastError(CastExpression expression, TypeBinding leftType, - TypeBinding rightType) { - String leftName = new String(leftType.readableName()); - String rightName = new String(rightType.readableName()); - String leftShortName = new String(leftType.shortReadableName()); - String rightShortName = new String(rightType.shortReadableName()); - if (leftShortName.equals(rightShortName)) { - leftShortName = leftName; - rightShortName = rightName; - } - this.handle(IProblem.IllegalCast, new String[]{rightName, leftName}, - new String[]{rightShortName, leftShortName}, - expression.sourceStart, expression.sourceEnd); - } - public void typeCollidesWithPackage( - CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) { - this.referenceContext = typeDecl; // report the problem against the - // type not the entire compilation - // unit - String[] arguments = new String[]{ - new String(compUnitDecl.getFileName()), - new String(typeDecl.name)}; - this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments, - typeDecl.sourceStart, typeDecl.sourceEnd, - compUnitDecl.compilationResult); - } - public void typeMismatchError(TypeBinding resultType, - TypeBinding expectedType, AstNode location) { - String resultTypeName = new String(resultType.readableName()); - String expectedTypeName = new String(expectedType.readableName()); - String resultTypeShortName = new String(resultType.shortReadableName()); - String expectedTypeShortName = new String(expectedType - .shortReadableName()); - if (resultTypeShortName.equals(expectedTypeShortName)) { - resultTypeShortName = resultTypeName; - expectedTypeShortName = expectedTypeName; - } - this.handle(IProblem.TypeMismatch, new String[]{resultTypeName, - expectedTypeName}, new String[]{resultTypeShortName, - expectedTypeShortName}, location.sourceStart, - location.sourceEnd); - } - public void typeMismatchErrorActualTypeExpectedType(Expression expression, - TypeBinding constantType, TypeBinding expectedType) { - String constantTypeName = new String(constantType.readableName()); - String expectedTypeName = new String(expectedType.readableName()); - String constantTypeShortName = new String(constantType - .shortReadableName()); - String expectedTypeShortName = new String(expectedType - .shortReadableName()); - if (constantTypeShortName.equals(expectedTypeShortName)) { - constantTypeShortName = constantTypeName; - expectedTypeShortName = expectedTypeName; - } - this.handle(IProblem.TypeMismatch, new String[]{constantTypeName, - expectedTypeName}, new String[]{constantTypeShortName, - expectedTypeShortName}, expression.sourceStart, - expression.sourceEnd); - } - public void undefinedLabel(BranchStatement statement) { - String[] arguments = new String[]{new String(statement.label)}; - this.handle(IProblem.UndefinedLabel, arguments, arguments, - statement.sourceStart, statement.sourceEnd); - } - public void unexpectedStaticModifierForField(SourceTypeBinding type, - FieldDeclaration fieldDecl) { - String[] arguments = new String[]{fieldDecl.name()}; - this.handle(IProblem.UnexpectedStaticModifierForField, arguments, - arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); - } - public void unexpectedStaticModifierForMethod(ReferenceBinding type, - AbstractMethodDeclaration methodDecl) { - String[] arguments = new String[]{new String(type.sourceName()), - new String(methodDecl.selector)}; - this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments, - arguments, methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void unhandledException(TypeBinding exceptionType, AstNode location) { - boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration) - && ((ConstructorDeclaration) referenceContext) - .isDefaultConstructor(); - boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall) - && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper); - this - .handle( - insideDefaultConstructor - ? IProblem.UnhandledExceptionInDefaultConstructor - : (insideImplicitConstructorCall - ? IProblem.UndefinedConstructorInImplicitConstructorCall - : IProblem.UnhandledException), - new String[]{new String(exceptionType.readableName())}, - new String[]{new String(exceptionType - .shortReadableName())}, location.sourceStart, - location.sourceEnd); - } - public void uninitializedBlankFinalField(FieldBinding binding, - AstNode location) { - String[] arguments = new String[]{new String(binding.readableName())}; - this.handle(IProblem.UninitializedBlankFinalField, arguments, - arguments, location.sourceStart, location.sourceEnd); - } - public void uninitializedLocalVariable(LocalVariableBinding binding, - AstNode location) { - String[] arguments = new String[]{new String(binding.readableName())}; - this.handle(IProblem.UninitializedLocalVariable, arguments, arguments, - location.sourceStart, location.sourceEnd); - } - public void unmatchedBracket(int position, ReferenceContext context, - CompilationResult compilationResult) { - this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, - position, position, context, compilationResult); - } - public void unnecessaryEnclosingInstanceSpecification( - Expression expression, ReferenceBinding targetType) { - this.handle(IProblem.IllegalEnclosingInstanceSpecification, - new String[]{new String(targetType.readableName())}, - new String[]{new String(targetType.shortReadableName())}, - expression.sourceStart, expression.sourceEnd); - } - public void unnecessaryReceiverForStaticMethod(AstNode location, - MethodBinding method) { - this.handle(IProblem.NonStaticAccessToStaticMethod, new String[]{ - new String(method.declaringClass.readableName()), - new String(method.selector), parametersAsString(method)}, - new String[]{ - new String(method.declaringClass.shortReadableName()), - new String(method.selector), - parametersAsShortString(method)}, location.sourceStart, - location.sourceEnd); - } - public void unnecessaryReceiverForStaticField(AstNode location, - FieldBinding field) { - this.handle(IProblem.NonStaticAccessToStaticField, new String[]{ - new String(field.declaringClass.readableName()), - new String(field.name)}, new String[]{ - new String(field.declaringClass.shortReadableName()), - new String(field.name)}, location.sourceStart, - location.sourceEnd); - } - public void unreachableCode(Statement statement) { - this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument, - statement.sourceStart, statement.sourceEnd); - } - public void unreachableExceptionHandler(ReferenceBinding exceptionType, - AstNode location) { - this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, - location.sourceStart, location.sourceEnd); - } - public void unresolvableReference(NameReference nameRef, Binding binding) { - int severity = Error; - /* - * also need to check that the searchedType is the receiver type if - * (binding instanceof ProblemBinding) { ProblemBinding problem = - * (ProblemBinding) binding; if (problem.searchType != null && - * problem.searchType.isHierarchyInconsistent()) severity = - * SecondaryError; } - */ - String[] arguments = new String[]{new String(binding.readableName())}; - this.handle(IProblem.UndefinedName, arguments, arguments, severity, - nameRef.sourceStart, nameRef.sourceEnd); - } - public void unusedArgument(LocalDeclaration localDecl) { - String[] arguments = new String[]{localDecl.name()}; - this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments, - localDecl.sourceStart, localDecl.sourceEnd); - } - public void unusedImport(ImportReference importRef) { - String[] arguments = new String[]{CharOperation - .toString(importRef.tokens)}; - this.handle(IProblem.UnusedImport, arguments, arguments, - importRef.sourceStart, importRef.sourceEnd); - } - public void unusedLocalVariable(LocalDeclaration localDecl) { - String[] arguments = new String[]{localDecl.name()}; - this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments, - localDecl.sourceStart, localDecl.sourceEnd); - } - public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) { - if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore) - return; - // no complaint for no-arg constructors (or default ones) - known - // pattern to block instantiation - if (constructorDecl.arguments == null - || constructorDecl.arguments.length == 0) - return; - MethodBinding constructor = constructorDecl.binding; - this.handle(IProblem.UnusedPrivateConstructor, new String[]{ - new String(constructor.declaringClass.readableName()), - parametersAsString(constructor)}, new String[]{ - new String(constructor.declaringClass.shortReadableName()), - parametersAsShortString(constructor)}, - constructorDecl.sourceStart, constructorDecl.sourceEnd); - } - public void unusedPrivateField(FieldDeclaration fieldDecl) { - if (computeSeverity(IProblem.UnusedPrivateField) == Ignore) - return; - FieldBinding field = fieldDecl.binding; - if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) - && field.isStatic() && field.isFinal() - && TypeBinding.LongBinding == field.type) { - return; // do not report unused serialVersionUID field - } - this.handle(IProblem.UnusedPrivateField, new String[]{ - new String(field.declaringClass.readableName()), - new String(field.name),}, new String[]{ - new String(field.declaringClass.shortReadableName()), - new String(field.name),}, fieldDecl.sourceStart, - fieldDecl.sourceEnd); - } - public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) { - if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore) - return; - MethodBinding method = methodDecl.binding; - // no report for serialization support 'void - // readObject(ObjectInputStream)' - if (!method.isStatic() - && TypeBinding.VoidBinding == method.returnType - && method.parameters.length == 1 - && method.parameters[0].dimensions() == 0 - && CharOperation.equals(method.selector, - TypeConstants.READOBJECT) - && CharOperation.equals( - TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, - method.parameters[0].readableName())) { - return; - } - // no report for serialization support 'void - // writeObject(ObjectOutputStream)' - if (!method.isStatic() - && TypeBinding.VoidBinding == method.returnType - && method.parameters.length == 1 - && method.parameters[0].dimensions() == 0 - && CharOperation.equals(method.selector, - TypeConstants.WRITEOBJECT) - && CharOperation.equals( - TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, - method.parameters[0].readableName())) { - return; - } - // no report for serialization support 'Object readResolve()' - if (!method.isStatic() - && TypeBinding.T_Object == method.returnType.id - && method.parameters.length == 0 - && CharOperation.equals(method.selector, - TypeConstants.READRESOLVE)) { - return; - } - // no report for serialization support 'Object writeReplace()' - if (!method.isStatic() - && TypeBinding.T_Object == method.returnType.id - && method.parameters.length == 0 - && CharOperation.equals(method.selector, - TypeConstants.WRITEREPLACE)) { - return; - } - this.handle(IProblem.UnusedPrivateMethod, new String[]{ - new String(method.declaringClass.readableName()), - new String(method.selector), parametersAsString(method)}, - new String[]{ - new String(method.declaringClass.shortReadableName()), - new String(method.selector), - parametersAsShortString(method)}, - methodDecl.sourceStart, methodDecl.sourceEnd); - } - public void unusedPrivateType(TypeDeclaration typeDecl) { - if (computeSeverity(IProblem.UnusedPrivateType) == Ignore) - return; - ReferenceBinding type = typeDecl.binding; - this.handle(IProblem.UnusedPrivateType, new String[]{new String(type - .readableName()),}, new String[]{new String(type - .shortReadableName()),}, typeDecl.sourceStart, - typeDecl.sourceEnd); - } - public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) { - this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument, - sourceStart, sourceEnd); - } - public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) { - String[] arguments = new String[]{new String(varDecl.name)}; - this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments, - varDecl.sourceStart, varDecl.sourceEnd); - } - public void variableTypeCannotBeVoidArray( - AbstractVariableDeclaration varDecl) { - String[] arguments = new String[]{new String(varDecl.name)}; - this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, - arguments, varDecl.sourceStart, varDecl.sourceEnd); - } - public void visibilityConflict(MethodBinding currentMethod, - MethodBinding inheritedMethod) { - this.handle( - // Cannot reduce the visibility of the inherited method from %1 - // 8.4.6.3 - The access modifier of an hiding method must - // provide at least as much access as the hidden method. - // 8.4.6.3 - The access modifier of an overiding method must - // provide at least as much access as the overriden method. - IProblem.MethodReducesVisibility, new String[]{new String( - inheritedMethod.declaringClass.readableName())}, - new String[]{new String(inheritedMethod.declaringClass - .shortReadableName())}, currentMethod.sourceStart(), - currentMethod.sourceEnd()); - } - public void wrongSequenceOfExceptionTypesError(TryStatement statement, - int under, int upper) { - //the two catch block under and upper are in an incorrect order. - //under should be define BEFORE upper in the source - TypeReference typeRef = statement.catchArguments[under].type; - this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, - typeRef.sourceStart, typeRef.sourceEnd); - } - public void nonExternalizedStringLiteral(AstNode location) { - this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, - NoArgument, location.sourceStart, location.sourceEnd); - } - public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) { - this - .handle(IProblem.TooManyBytesForStringConstant, - new String[]{new String(typeDeclaration.binding - .readableName())}, new String[]{new String( - typeDeclaration.binding.shortReadableName())}, - Abort | Error, typeDeclaration.sourceStart, - typeDeclaration.sourceEnd); - } - public void noMoreAvailableSpaceInConstantPool( - TypeDeclaration typeDeclaration) { - this - .handle(IProblem.TooManyConstantsInConstantPool, - new String[]{new String(typeDeclaration.binding - .readableName())}, new String[]{new String( - typeDeclaration.binding.shortReadableName())}, - Abort | Error, typeDeclaration.sourceStart, - typeDeclaration.sourceEnd); - } - private boolean isKeyword(char[] tokenSource) { - /* - * This code is heavily grammar dependant - */ - if (tokenSource == null) { - return false; - } - try { - Scanner scanner = new Scanner(); - scanner.setSource(tokenSource); - int token = scanner.getNextToken(); - char[] currentKeyword; - try { - currentKeyword = scanner.getCurrentIdentifierSource(); - } catch (ArrayIndexOutOfBoundsException e) { - return false; - } - int nextToken = scanner.getNextToken(); - if (nextToken == Scanner.TokenNameEOF - && scanner.startPosition == scanner.source.length) { // to - // handle - // case - // where - // we - // had - // an - // ArrayIndexOutOfBoundsException - // while reading the last token - switch (token) { - case Scanner.TokenNameERROR : - if (CharOperation.equals("goto".toCharArray(), - currentKeyword) - || CharOperation.equals("const".toCharArray(), - currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$ - return true; - } else { - return false; - } - case Scanner.TokenNameabstract : - // case Scanner.TokenNameassert: - // case Scanner.TokenNamebyte: - case Scanner.TokenNamebreak : - // case Scanner.TokenNameboolean: - case Scanner.TokenNamecase : - // case Scanner.TokenNamechar: - case Scanner.TokenNamecatch : - case Scanner.TokenNameclass : - case Scanner.TokenNamecontinue : - case Scanner.TokenNamedo : - // case Scanner.TokenNamedouble: - case Scanner.TokenNamedefault : - case Scanner.TokenNameelse : - case Scanner.TokenNameextends : - case Scanner.TokenNamefor : - // case Scanner.TokenNamefinal: - // case Scanner.TokenNamefloat: - case Scanner.TokenNamefalse : - case Scanner.TokenNamefinally : - case Scanner.TokenNameif : - // case Scanner.TokenNameint: - // case Scanner.TokenNameimport: - case Scanner.TokenNameinterface : - case Scanner.TokenNameimplements : - case Scanner.TokenNameinstanceof : - // case Scanner.TokenNamelong: - case Scanner.TokenNamenew : - case Scanner.TokenNamenull : - // case Scanner.TokenNamenative: - case Scanner.TokenNamepublic : - // case Scanner.TokenNamepackage: - case Scanner.TokenNameprivate : - case Scanner.TokenNameprotected : - case Scanner.TokenNamereturn : - // case Scanner.TokenNameshort: - case Scanner.TokenNamesuper : - case Scanner.TokenNamestatic : - case Scanner.TokenNameswitch : - // case Scanner.TokenNamestrictfp: - // case Scanner.TokenNamesynchronized: - case Scanner.TokenNametry : - case Scanner.TokenNamethis : - case Scanner.TokenNametrue : - case Scanner.TokenNamethrow : - // case Scanner.TokenNamethrows: - // case Scanner.TokenNametransient: - // case Scanner.TokenNamevoid: - // case Scanner.TokenNamevolatile: - case Scanner.TokenNamewhile : - return true; - default : - return false; - } - } else { - return false; - } - } catch (InvalidInputException e) { - return false; - } - } - // jsurfer start - public void phpParsingError(String[] messageArguments, - int problemStartPosition, int problemEndPosition, - ReferenceContext context, CompilationResult compilationResult) { - this.handle(IProblem.PHPParsingError, NoArgument, messageArguments, - problemStartPosition, problemEndPosition, context, - compilationResult); - } + public ReferenceContext referenceContext; + public ProblemReporter(IErrorHandlingPolicy policy, + IProblemFactory problemFactory) { + //CompilerOptions options, IProblemFactory problemFactory) { + super(policy, problemFactory);//options, problemFactory); + } + public void abortDueToInternalError(String errorMessage) { + String[] arguments = new String[]{errorMessage}; + this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, 0, + 0); + } + public void abortDueToInternalError(String errorMessage, AstNode location) { + String[] arguments = new String[]{errorMessage}; + this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, + location.sourceStart, location.sourceEnd); + } + public void abstractMethodCannotBeOverridden(SourceTypeBinding type, + MethodBinding concreteMethod) { + this + .handle( + // %1 must be abstract since it cannot override the inherited + // package-private abstract method %2 + IProblem.AbstractMethodCannotBeOverridden, new String[]{ + new String(type.sourceName()), + new String(CharOperation.concat(concreteMethod.declaringClass + .readableName(), concreteMethod.readableName(), '.'))}, + new String[]{ + new String(type.sourceName()), + new String(CharOperation.concat(concreteMethod.declaringClass + .shortReadableName(), concreteMethod.shortReadableName(), + '.'))}, type.sourceStart(), type.sourceEnd()); + } + public void abstractMethodInAbstractClass(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void abstractMethodMustBeImplemented(SourceTypeBinding type, + MethodBinding abstractMethod) { + this.handle( + // Must implement the inherited abstract method %1 + // 8.4.3 - Every non-abstract subclass of an abstract type, A, + // must provide a concrete implementation of all of A's + // methods. + IProblem.AbstractMethodMustBeImplemented, new String[]{new String( + CharOperation.concat(abstractMethod.declaringClass.readableName(), + abstractMethod.readableName(), '.'))}, + new String[]{new String(CharOperation.concat( + abstractMethod.declaringClass.shortReadableName(), abstractMethod + .shortReadableName(), '.'))}, type.sourceStart(), type + .sourceEnd()); + } + public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) { + this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument, + method.sourceStart, method.sourceEnd, method, method + .compilationResult()); + } + public void alreadyDefinedLabel(char[] labelName, AstNode location) { + String[] arguments = new String[]{new String(labelName)}; + this.handle(IProblem.DuplicateLabel, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void anonymousClassCannotExtendFinalClass(Expression expression, + TypeBinding type) { + this.handle(IProblem.AnonymousClassCannotExtendFinalClass, + new String[]{new String(type.readableName())}, new String[]{new String( + type.shortReadableName())}, expression.sourceStart, + expression.sourceEnd); + } + public void argumentTypeCannotBeVoid(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, Argument arg) { + String[] arguments = new String[]{new String(methodDecl.selector), + new String(arg.name)}; + this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, Argument arg) { + String[] arguments = new String[]{new String(methodDecl.selector), + new String(arg.name)}; + this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void argumentTypeProblem(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, Argument arg, + TypeBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.ArgumentTypeNotFound; + break; + case NotVisible : + // 2 + id = IProblem.ArgumentTypeNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.ArgumentTypeAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.ArgumentTypeInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(methodDecl.selector), arg.name(), + new String(expectedType.readableName())}, new String[]{ + new String(methodDecl.selector), arg.name(), + new String(expectedType.shortReadableName())}, arg.type.sourceStart, + arg.type.sourceEnd); + } + public void arrayConstantsOnlyInArrayInitializers(int sourceStart, + int sourceEnd) { + this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument, + NoArgument, sourceStart, sourceEnd); + } + public void assignmentHasNoEffect(Assignment assignment, char[] name) { + String[] arguments = new String[]{new String(name)}; + this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments, + assignment.sourceStart, assignment.sourceEnd); + } + public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, + TypeBinding expectedType) { + this.handle(IProblem.VoidMethodReturnsValue, new String[]{new String( + expectedType.readableName())}, new String[]{new String(expectedType + .shortReadableName())}, returnStatement.sourceStart, + returnStatement.sourceEnd); + } + public void attemptToReturnVoidValue(ReturnStatement returnStatement) { + this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument, + returnStatement.sourceStart, returnStatement.sourceEnd); + } + //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location) + // { + // String[] arguments = new String[] {new String(location.selector), + // parametersAsString(location.binding)}; + // if (location.isConstructor()) { + // this.handle( + // IProblem.BytecodeExceeds64KLimitForConstructor, + // arguments, + // arguments, + // Error | Abort, + // location.sourceStart, + // location.sourceEnd); + // } else { + // this.handle( + // IProblem.BytecodeExceeds64KLimit, + // arguments, + // arguments, + // Error | Abort, + // location.sourceStart, + // location.sourceEnd); + // } + //} + public void bytecodeExceeds64KLimit(TypeDeclaration location) { + this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument, + NoArgument, Error | Abort, location.sourceStart, location.sourceEnd); + } + public void cannotAllocateVoidArray(Expression expression) { + this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void cannotAssignToFinalField(FieldBinding field, AstNode location) { + this.handle(IProblem.FinalFieldAssignment, new String[]{ + (field.declaringClass == null ? "array" : new String( + field.declaringClass.readableName())), //$NON-NLS-1$ + new String(field.readableName())}, new String[]{ + (field.declaringClass == null ? "array" : new String( + field.declaringClass.shortReadableName())), //$NON-NLS-1$ + new String(field.shortReadableName())}, location.sourceStart, + location.sourceEnd); + } + public void cannotAssignToFinalLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.readableName())}; + this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.readableName())}; + this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void cannotDeclareLocalInterface(char[] interfaceName, + int sourceStart, int sourceEnd) { + String[] arguments = new String[]{new String(interfaceName)}; + this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, + arguments, sourceStart, sourceEnd); + } + public void cannotDefineDimensionsAndInitializer( + ArrayAllocationExpression expresssion) { + this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument, + NoArgument, expresssion.sourceStart, expresssion.sourceEnd); + } + public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, + MethodBinding method) { + this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), parametersAsShortString(method)}, + messageSend.sourceStart, messageSend.sourceEnd); + } + public void cannotImportPackage(ImportReference importRef) { + String[] arguments = new String[]{CharOperation.toString(importRef.tokens)}; + this.handle(IProblem.CannotImportPackage, arguments, arguments, + importRef.sourceStart, importRef.sourceEnd); + } + public void cannotInstantiate(TypeReference typeRef, TypeBinding type) { + this.handle(IProblem.InvalidClassInstantiation, new String[]{new String( + type.readableName())}, + new String[]{new String(type.shortReadableName())}, + typeRef.sourceStart, typeRef.sourceEnd); + } + public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.readableName())}; + this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void cannotReturnInInitializer(AstNode location) { + this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void cannotThrowNull(ThrowStatement statement) { + this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument, + statement.sourceStart, statement.sourceEnd); + } + public void cannotThrowType(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, TypeReference exceptionType, + TypeBinding expectedType) { + this.handle(IProblem.CannotThrowType, new String[]{new String(expectedType + .readableName())}, new String[]{new String(expectedType + .shortReadableName())}, exceptionType.sourceStart, + exceptionType.sourceEnd); + } + public void cannotUseSuperInJavaLangObject(AstNode reference) { + this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument, + reference.sourceStart, reference.sourceEnd); + } + public void cannotUseSuperInCodeSnippet(int start, int end) { + this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument, + Error | Abort, start, end); + } + public void caseExpressionMustBeConstant(Expression expression) { + this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void classExtendFinalClass(SourceTypeBinding type, + TypeReference superclass, TypeBinding expectedType) { + String name = new String(type.sourceName()); + String expectedFullName = new String(expectedType.readableName()); + String expectedShortName = new String(expectedType.shortReadableName()); + if (expectedShortName.equals(name)) + expectedShortName = expectedFullName; + this.handle(IProblem.ClassExtendFinalClass, new String[]{expectedFullName, + name}, new String[]{expectedShortName, name}, superclass.sourceStart, + superclass.sourceEnd); + } + public void codeSnippetMissingClass(String missing, int start, int end) { + String[] arguments = new String[]{missing}; + this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error + | Abort, start, end); + } + public void codeSnippetMissingMethod(String className, String missingMethod, + String argumentTypes, int start, int end) { + String[] arguments = new String[]{className, missingMethod, argumentTypes}; + this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error + | Abort, start, end); + } + /* + * Given the current configuration, answers which category the problem falls + * into: Error | Warning | Ignore + */ + //public int computeSeverity(int problemId){ + // + // // severity can have been preset on the problem + //// if ((problem.severity & Fatal) != 0){ + //// return Error; + //// } + // + // // if not then check whether it is a configurable problem + // int errorThreshold = options.errorThreshold; + // int warningThreshold = options.warningThreshold; + // + // switch(problemId){ + // + // case IProblem.UnreachableCatch : + // case IProblem.CodeCannotBeReached : + // if ((errorThreshold & CompilerOptions.UnreachableCode) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnreachableCode) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.MaskedCatch : + // if ((errorThreshold & CompilerOptions.MaskedCatchBlock) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.MaskedCatchBlock) != 0){ + // return Warning; + // } + // return Ignore; + // + ///* + // case Never Used : + // if ((errorThreshold & ParsingOptionalError) != 0){ + // return Error; + // } + // if ((warningThreshold & ParsingOptionalError) != 0){ + // return Warning; + // } + // return Ignore; + //*/ + // case IProblem.ImportNotFound : + // case IProblem.ImportNotVisible : + // case IProblem.ImportAmbiguous : + // case IProblem.ImportInternalNameProvided : + // case IProblem.ImportInheritedNameHidesEnclosingName : + // case IProblem.DuplicateImport : + // case IProblem.ConflictingImport : + // case IProblem.CannotImportPackage : + // if ((errorThreshold & CompilerOptions.ImportProblem) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.ImportProblem) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.UnusedImport : + // // if import problem are disabled, then ignore + // if ((errorThreshold & CompilerOptions.ImportProblem) == 0 + // && (warningThreshold & CompilerOptions.ImportProblem) == 0){ + // return Ignore; + // } + // if ((errorThreshold & CompilerOptions.UnusedImport) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnusedImport) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.MethodButWithConstructorName : + // if ((errorThreshold & CompilerOptions.MethodWithConstructorName) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.MethodWithConstructorName) != + // 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.OverridingNonVisibleMethod : + // if ((errorThreshold & CompilerOptions.OverriddenPackageDefaultMethod) != + // 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.OverriddenPackageDefaultMethod) + // != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod : + // case + // IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod + // : + // if ((errorThreshold & + // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){ + // return Error; + // } + // if ((warningThreshold & + // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.OverridingDeprecatedMethod : + // case IProblem.UsingDeprecatedType : + // case IProblem.UsingDeprecatedMethod : + // case IProblem.UsingDeprecatedConstructor : + // case IProblem.UsingDeprecatedField : + // if ((errorThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.LocalVariableIsNeverUsed : + // if ((errorThreshold & CompilerOptions.UnusedLocalVariable) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnusedLocalVariable) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.ArgumentIsNeverUsed : + // if ((errorThreshold & CompilerOptions.UnusedArgument) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnusedArgument) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.NoImplicitStringConversionForCharArrayExpression : + // if ((errorThreshold & CompilerOptions.NoImplicitStringConversion) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.NoImplicitStringConversion) != + // 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.NeedToEmulateFieldReadAccess : + // case IProblem.NeedToEmulateFieldWriteAccess : + // case IProblem.NeedToEmulateMethodAccess : + // case IProblem.NeedToEmulateConstructorAccess : + // if ((errorThreshold & CompilerOptions.AccessEmulation) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.AccessEmulation) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.NonExternalizedStringLiteral : + // if ((errorThreshold & CompilerOptions.NonExternalizedString) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.NonExternalizedString) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.UseAssertAsAnIdentifier : + // if ((errorThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.NonStaticAccessToStaticMethod : + // case IProblem.NonStaticAccessToStaticField : + // if ((errorThreshold & CompilerOptions.StaticAccessReceiver) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.StaticAccessReceiver) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.AssignmentHasNoEffect: + // if ((errorThreshold & CompilerOptions.NoEffectAssignment) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.NoEffectAssignment) != 0){ + // return Warning; + // } + // return Ignore; + // case IProblem.UnusedPrivateConstructor: + // case IProblem.UnusedPrivateMethod: + // case IProblem.UnusedPrivateField: + // case IProblem.UnusedPrivateType: + // if ((errorThreshold & CompilerOptions.UnusedPrivateMember) != 0){ + // return Error; + // } + // if ((warningThreshold & CompilerOptions.UnusedPrivateMember) != 0){ + // return Warning; + // } + // return Ignore; + // + // case IProblem.Task : + // return Warning; + // default: + // return Error; + // } + //} + //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression + // expression, TypeBinding trueType, TypeBinding falseType) { + // this.handle( + // IProblem.IncompatibleTypesInConditionalOperator, + // new String[] {new String(trueType.readableName()), new + // String(falseType.readableName())}, + // new String[] {new String(trueType.sourceName()), new + // String(falseType.sourceName())}, + // expression.sourceStart, + // expression.sourceEnd); + //} + public void conflictingImport(ImportReference importRef) { + String[] arguments = new String[]{CharOperation.toString(importRef.tokens)}; + this.handle(IProblem.ConflictingImport, arguments, arguments, + importRef.sourceStart, importRef.sourceEnd); + } + public void constantOutOfFormat(NumberLiteral lit) { + // the literal is not in a correct format + // this code is called on IntLiteral and LongLiteral + // example 000811 ...the 8 is uncorrect. + if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) { + char[] source = lit.source(); + try { + final String Radix; + final int radix; + if ((source[1] == 'x') || (source[1] == 'X')) { + radix = 16; + Radix = "Hexa"; //$NON-NLS-1$ + } else { + radix = 8; + Radix = "Octal"; //$NON-NLS-1$ + } + //look for the first digit that is incorrect + int place = -1; + label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) { + if (Character.digit(source[i], radix) == -1) { + place = i; + break label; + } + } + String[] arguments = new String[]{Radix + " " + new String(source) + + " (digit " + new String(new char[]{source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, + lit.sourceStart, lit.sourceEnd); + return; + } catch (IndexOutOfBoundsException ex) { + } + // just in case .... use a predefined error.. + // we should never come here...(except if the code changes !) + this.constantOutOfRange(lit); + } + } + public void constantOutOfRange(Literal lit) { + // lit is some how out of range of it declared type + // example + // 9999999999999999999999999999999999999999999999999999999999999999999 + String[] arguments = new String[]{new String(lit.source())}; + this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, + lit.sourceStart, lit.sourceEnd); + } + public void deprecatedField(FieldBinding field, AstNode location) { + this.handle(IProblem.UsingDeprecatedField, + new String[]{new String(field.declaringClass.readableName()), + new String(field.name)}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name)}, location.sourceStart, location.sourceEnd); + } + public void deprecatedMethod(MethodBinding method, AstNode location) { + if (method.isConstructor()) + this.handle(IProblem.UsingDeprecatedConstructor, new String[]{ + new String(method.declaringClass.readableName()), + parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + parametersAsShortString(method)}, location.sourceStart, + location.sourceEnd); + else + this.handle(IProblem.UsingDeprecatedMethod, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{new String(method.declaringClass.shortReadableName()), + new String(method.selector), parametersAsShortString(method)}, + location.sourceStart, location.sourceEnd); + } + public void deprecatedType(TypeBinding type, AstNode location) { + if (location == null) + return; // 1G828DN - no type ref for synthetic arguments + this.handle(IProblem.UsingDeprecatedType, new String[]{new String(type + .readableName())}, new String[]{new String(type.shortReadableName())}, + location.sourceStart, location.sourceEnd); + } + public void duplicateCase(Case statement, Constant constant) { + String[] arguments = new String[]{String.valueOf(constant.intValue())}; + this.handle(IProblem.DuplicateCase, arguments, arguments, + statement.sourceStart, statement.sourceEnd); + } + public void duplicateDefaultCase(DefaultCase statement) { + this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument, + statement.sourceStart, statement.sourceEnd); + } + public void duplicateFieldInType(SourceTypeBinding type, + FieldDeclaration fieldDecl) { + this.handle(IProblem.DuplicateField, new String[]{ + new String(type.sourceName()), fieldDecl.name()}, new String[]{ + new String(type.shortReadableName()), fieldDecl.name()}, + fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void duplicateImport(ImportReference importRef) { + String[] arguments = new String[]{CharOperation.toString(importRef.tokens)}; + this.handle(IProblem.DuplicateImport, arguments, arguments, + importRef.sourceStart, importRef.sourceEnd); + } + public void duplicateInitializationOfBlankFinalField(FieldBinding field, + Reference reference) { + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments, + arguments, reference.sourceStart, reference.sourceEnd); + } + public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.readableName())}; + this.handle(IProblem.DuplicateFinalLocalInitialization, arguments, + arguments, location.sourceStart, location.sourceEnd); + } + public void duplicateMethodInType(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(methodDecl.selector), + new String(type.sourceName())}; + this.handle(IProblem.DuplicateMethod, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void duplicateModifierForField(ReferenceBinding type, + FieldDeclaration fieldDecl) { + /* + * to highlight modifiers use: this.handle( new Problem( + * DuplicateModifierForField, new String[] {fieldDecl.name()}, + * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd)); + */ + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.DuplicateModifierForField, arguments, arguments, + fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void duplicateModifierForMethod(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + this.handle(IProblem.DuplicateModifierForMethod, new String[]{ + new String(type.sourceName()), new String(methodDecl.selector)}, + new String[]{new String(type.shortReadableName()), + new String(methodDecl.selector)}, methodDecl.sourceStart, + methodDecl.sourceEnd); + } + public void duplicateModifierForType(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type + .sourceStart(), type.sourceEnd()); + } + public void duplicateModifierForVariable(LocalDeclaration localDecl, + boolean complainForArgument) { + String[] arguments = new String[]{localDecl.name()}; + this.handle(complainForArgument + ? IProblem.DuplicateModifierForArgument + : IProblem.DuplicateModifierForVariable, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void duplicateNestedType(TypeDeclaration typeDecl) { + String[] arguments = new String[]{new String(typeDecl.name)}; + this.handle(IProblem.DuplicateNestedType, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd); + } + public void duplicateSuperinterface(SourceTypeBinding type, + TypeDeclaration typeDecl, ReferenceBinding superType) { + this.handle(IProblem.DuplicateSuperInterface, new String[]{ + new String(superType.readableName()), new String(type.sourceName())}, + new String[]{new String(superType.shortReadableName()), + new String(type.sourceName())}, typeDecl.sourceStart, + typeDecl.sourceEnd); + } + public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, + TypeDeclaration typeDecl) { + String[] arguments = new String[]{new String(compUnitDecl.getFileName()), + new String(typeDecl.name)}; + this.referenceContext = typeDecl; // report the problem against the + // type not the entire compilation + // unit + this.handle(IProblem.DuplicateTypes, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd, + compUnitDecl.compilationResult); + } + public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, + TypeBinding[] params) { + StringBuffer buffer = new StringBuffer(); + StringBuffer shortBuffer = new StringBuffer(); + for (int i = 0, length = params.length; i < length; i++) { + if (i != 0) { + buffer.append(", "); //$NON-NLS-1$ + shortBuffer.append(", "); //$NON-NLS-1$ + } + buffer.append(new String(params[i].readableName())); + shortBuffer.append(new String(params[i].shortReadableName())); + } + this.handle(recType.isArrayType() + ? IProblem.NoMessageSendOnArrayType + : IProblem.NoMessageSendOnBaseType, new String[]{ + new String(recType.readableName()), new String(messageSend.selector), + buffer.toString()}, new String[]{ + new String(recType.shortReadableName()), + new String(messageSend.selector), shortBuffer.toString()}, + messageSend.sourceStart, messageSend.sourceEnd); + } + public void errorThisSuperInStatic(AstNode reference) { + String[] arguments = new String[]{reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$ + this.handle(IProblem.ThisInStaticContext, arguments, arguments, + reference.sourceStart, reference.sourceEnd); + } + public void exceptionTypeProblem(SourceTypeBinding type, + AbstractMethodDeclaration methodDecl, TypeReference exceptionType, + TypeBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.ExceptionTypeNotFound; + break; + case NotVisible : + // 2 + id = IProblem.ExceptionTypeNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.ExceptionTypeAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.ExceptionTypeInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(methodDecl.selector), + new String(expectedType.readableName())}, new String[]{ + new String(methodDecl.selector), + new String(expectedType.shortReadableName())}, + exceptionType.sourceStart, exceptionType.sourceEnd); + } + public void expressionShouldBeAVariable(Expression expression) { + this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) { + this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument, + NoArgument, reference.sourceStart, reference.sourceEnd); + } + public void fieldTypeProblem(SourceTypeBinding type, + FieldDeclaration fieldDecl, TypeBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.FieldTypeNotFound; + break; + case NotVisible : + // 2 + id = IProblem.FieldTypeNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.FieldTypeAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.FieldTypeInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.FieldTypeInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, + new String[]{fieldDecl.name(), new String(type.sourceName()), + new String(expectedType.readableName())}, new String[]{ + fieldDecl.name(), new String(type.sourceName()), + new String(expectedType.shortReadableName())}, + fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd); + } + public void finalMethodCannotBeOverridden(MethodBinding currentMethod, + MethodBinding inheritedMethod) { + this.handle( + // Cannot override the final method from %1 + // 8.4.3.3 - Final methods cannot be overridden or hidden. + IProblem.FinalMethodCannotBeOverridden, new String[]{new String( + inheritedMethod.declaringClass.readableName())}, + new String[]{new String(inheritedMethod.declaringClass + .shortReadableName())}, currentMethod.sourceStart(), currentMethod + .sourceEnd()); + } + public void forwardReference(Reference reference, int indexInQualification, + TypeBinding type) { + this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument, + reference.sourceStart, reference.sourceEnd); + } + // use this private API when the compilation unit result can be found + // through the + // reference context. Otherwise, use the other API taking a problem and a + // compilation result + // as arguments + private void handle(int problemId, String[] problemArguments, + String[] messageArguments, int problemStartPosition, + int problemEndPosition) { + this.handle(problemId, problemArguments, messageArguments, + problemStartPosition, problemEndPosition, referenceContext, + referenceContext == null ? null : referenceContext.compilationResult()); + referenceContext = null; + } + // use this private API when the compilation unit result can be found + // through the + // reference context. Otherwise, use the other API taking a problem and a + // compilation result + // as arguments + private void handle(int problemId, String[] problemArguments, + String[] messageArguments, int severity, int problemStartPosition, + int problemEndPosition) { + this.handle(problemId, problemArguments, messageArguments, severity, + problemStartPosition, problemEndPosition, referenceContext, + referenceContext == null ? null : referenceContext.compilationResult()); + referenceContext = null; + } + // use this private API when the compilation unit result cannot be found + // through the + // reference context. + private void handle(int problemId, String[] problemArguments, + String[] messageArguments, int problemStartPosition, + int problemEndPosition, CompilationResult unitResult) { + this.handle(problemId, problemArguments, messageArguments, + problemStartPosition, problemEndPosition, referenceContext, unitResult); + referenceContext = null; + } + public void hidingEnclosingType(TypeDeclaration typeDecl) { + String[] arguments = new String[]{new String(typeDecl.name)}; + this.handle(IProblem.HidingEnclosingType, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd); + } + public void hierarchyCircularity(SourceTypeBinding sourceType, + ReferenceBinding superType, TypeReference reference) { + int start = 0; + int end = 0; + String typeName = ""; //$NON-NLS-1$ + String shortTypeName = ""; //$NON-NLS-1$ + if (reference == null) { // can only happen when java.lang.Object is + // busted + start = sourceType.sourceStart(); + end = sourceType.sourceEnd(); + typeName = new String(superType.readableName()); + shortTypeName = new String(superType.sourceName()); + } else { + start = reference.sourceStart; + end = reference.sourceEnd; + char[][] qName = reference.getTypeName(); + typeName = CharOperation.toString(qName); + shortTypeName = new String(qName[qName.length - 1]); + } + if (sourceType == superType) + this.handle(IProblem.HierarchyCircularitySelfReference, new String[]{ + new String(sourceType.sourceName()), typeName}, new String[]{ + new String(sourceType.sourceName()), shortTypeName}, start, end); + else + this.handle(IProblem.HierarchyCircularity, new String[]{ + new String(sourceType.sourceName()), typeName}, new String[]{ + new String(sourceType.sourceName()), shortTypeName}, start, end); + } + public void hierarchyHasProblems(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type + .sourceStart(), type.sourceEnd()); + } + public void illegalAbstractModifierCombinationForMethod( + ReferenceBinding type, AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.IllegalAbstractModifierCombinationForMethod, + arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void illegalModifierCombinationFinalAbstractForClass( + SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass, + arguments, arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierCombinationFinalVolatileForField( + ReferenceBinding type, FieldDeclaration fieldDecl) { + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField, + arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void illegalModifierForClass(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type + .sourceStart(), type.sourceEnd()); + } + public void illegalModifierForField(ReferenceBinding type, + FieldDeclaration fieldDecl) { + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.IllegalModifierForField, arguments, arguments, + fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void illegalModifierForInterface(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForInterface, arguments, arguments, + type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForInterfaceField(ReferenceBinding type, + FieldDeclaration fieldDecl) { + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.IllegalModifierForInterfaceField, arguments, + arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void illegalModifierForInterfaceMethod(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments, + arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void illegalModifierForLocalClass(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments, + type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForMemberClass(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments, + type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForMemberInterface(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalModifierForMemberInterface, arguments, + arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalModifierForMethod(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.IllegalModifierForMethod, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void illegalModifierForVariable(LocalDeclaration localDecl, + boolean complainAsArgument) { + String[] arguments = new String[]{localDecl.name()}; + this.handle(complainAsArgument + ? IProblem.IllegalModifierForArgument + : IProblem.IllegalModifierForVariable, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void illegalPrimitiveOrArrayTypeForEnclosingInstance( + TypeBinding enclosingType, AstNode location) { + this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance, + new String[]{new String(enclosingType.readableName())}, + new String[]{new String(enclosingType.shortReadableName())}, + location.sourceStart, location.sourceEnd); + } + public void illegalStaticModifierForMemberType(SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalStaticModifierForMemberType, arguments, + arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalVisibilityModifierCombinationForField( + ReferenceBinding type, FieldDeclaration fieldDecl) { + String[] arguments = new String[]{new String(fieldDecl.name())}; + this.handle(IProblem.IllegalVisibilityModifierCombinationForField, + arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void illegalVisibilityModifierCombinationForMemberType( + SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType, + arguments, arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalVisibilityModifierCombinationForMethod( + ReferenceBinding type, AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod, + arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void illegalVisibilityModifierForInterfaceMemberType( + SourceTypeBinding type) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType, + arguments, arguments, type.sourceStart(), type.sourceEnd()); + } + public void illegalVoidExpression(AstNode location) { + this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void importProblem(ImportReference importRef, Binding expectedImport) { + int problemId = expectedImport.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.ImportNotFound; + break; + case NotVisible : + // 2 + id = IProblem.ImportNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.ImportAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.ImportInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.ImportInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + String argument; + if (expectedImport instanceof ProblemReferenceBinding) { + argument = CharOperation + .toString(((ProblemReferenceBinding) expectedImport).compoundName); + } else { + argument = CharOperation.toString(importRef.tokens); + } + String[] arguments = new String[]{argument}; + this.handle(id, arguments, arguments, importRef.sourceStart, + importRef.sourceEnd); + } + public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, + MethodBinding currentMethod, MethodBinding inheritedMethod, + ReferenceBinding exceptionType) { + if (type == currentMethod.declaringClass) { + int id; + if (currentMethod.declaringClass.isInterface() + && !inheritedMethod.isPublic()) { // interface inheriting + // Object protected + // method + id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod; + } else { + id = IProblem.IncompatibleExceptionInThrowsClause; + } + this.handle( + // Exception %1 is not compatible with throws + // clause in %2 + // 9.4.4 - The type of exception in the throws + // clause is incompatible. + id, new String[]{ + new String(exceptionType.sourceName()), + new String(CharOperation.concat(inheritedMethod.declaringClass + .readableName(), inheritedMethod.readableName(), '.'))}, + new String[]{ + new String(exceptionType.sourceName()), + new String(CharOperation.concat(inheritedMethod.declaringClass + .shortReadableName(), inheritedMethod.shortReadableName(), + '.'))}, currentMethod.sourceStart(), currentMethod + .sourceEnd()); + } else + this.handle( + // Exception %1 in throws clause of %2 is not + // compatible with %3 + // 9.4.4 - The type of exception in the throws + // clause is incompatible. + IProblem.IncompatibleExceptionInInheritedMethodThrowsClause, + new String[]{ + new String(exceptionType.sourceName()), + new String(CharOperation.concat(currentMethod.declaringClass + .sourceName(), currentMethod.readableName(), '.')), + new String(CharOperation.concat(inheritedMethod.declaringClass + .readableName(), inheritedMethod.readableName(), '.'))}, + new String[]{ + new String(exceptionType.sourceName()), + new String(CharOperation.concat(currentMethod.declaringClass + .sourceName(), currentMethod.shortReadableName(), '.')), + new String(CharOperation.concat(inheritedMethod.declaringClass + .shortReadableName(), inheritedMethod.shortReadableName(), + '.'))}, type.sourceStart(), type.sourceEnd()); + } + public void incompatibleReturnType(MethodBinding currentMethod, + MethodBinding inheritedMethod) { + StringBuffer methodSignature = new StringBuffer(); + methodSignature.append(inheritedMethod.declaringClass.readableName()) + .append('.').append(inheritedMethod.readableName()); + StringBuffer shortSignature = new StringBuffer(); + shortSignature.append(inheritedMethod.declaringClass.shortReadableName()) + .append('.').append(inheritedMethod.shortReadableName()); + int id; + if (currentMethod.declaringClass.isInterface() + && !inheritedMethod.isPublic()) { // interface inheriting + // Object protected method + id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod; + } else { + id = IProblem.IncompatibleReturnType; + } + this.handle(id, new String[]{methodSignature.toString()}, + new String[]{shortSignature.toString()}, currentMethod.sourceStart(), + currentMethod.sourceEnd()); + } + public void incorrectLocationForEmptyDimension( + ArrayAllocationExpression expression, int index) { + this.handle(IProblem.IllegalDimension, NoArgument, NoArgument, + expression.dimensions[index + 1].sourceStart, + expression.dimensions[index + 1].sourceEnd); + } + public void incorrectSwitchType(Expression expression, TypeBinding testType) { + this.handle(IProblem.IncorrectSwitchType, new String[]{new String(testType + .readableName())}, + new String[]{new String(testType.shortReadableName())}, + expression.sourceStart, expression.sourceEnd); + } + public void inheritedMethodReducesVisibility(SourceTypeBinding type, + MethodBinding concreteMethod, MethodBinding[] abstractMethods) { + StringBuffer concreteSignature = new StringBuffer(); + concreteSignature.append(concreteMethod.declaringClass.readableName()) + .append('.').append(concreteMethod.readableName()); + StringBuffer shortSignature = new StringBuffer(); + shortSignature.append(concreteMethod.declaringClass.shortReadableName()) + .append('.').append(concreteMethod.shortReadableName()); + this.handle( + // The inherited method %1 cannot hide the public abstract method in %2 + IProblem.InheritedMethodReducesVisibility, new String[]{ + new String(concreteSignature.toString()), + new String(abstractMethods[0].declaringClass.readableName())}, + new String[]{new String(shortSignature.toString()), + new String(abstractMethods[0].declaringClass.shortReadableName())}, + type.sourceStart(), type.sourceEnd()); + } + public void inheritedMethodsHaveIncompatibleReturnTypes( + SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) { + StringBuffer methodSignatures = new StringBuffer(); + StringBuffer shortSignatures = new StringBuffer(); + for (int i = length; --i >= 0;) { + methodSignatures + .append(inheritedMethods[i].declaringClass.readableName()) + .append('.').append(inheritedMethods[i].readableName()); + shortSignatures.append( + inheritedMethods[i].declaringClass.shortReadableName()).append('.') + .append(inheritedMethods[i].shortReadableName()); + if (i != 0) { + methodSignatures.append(", "); //$NON-NLS-1$ + shortSignatures.append(", "); //$NON-NLS-1$ + } + } + this.handle( + // Return type is incompatible with %1 + // 9.4.2 - The return type from the method is incompatible with + // the declaration. + IProblem.IncompatibleReturnType, new String[]{methodSignatures + .toString()}, new String[]{shortSignatures.toString()}, type + .sourceStart(), type.sourceEnd()); + } + public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) { + this.handle(IProblem.InitializerMustCompleteNormally, NoArgument, + NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void innerTypesCannotDeclareStaticInitializers( + ReferenceBinding innerType, AstNode location) { + this.handle(IProblem.CannotDefineStaticInitializerInLocalType, + new String[]{new String(innerType.readableName())}, + new String[]{new String(innerType.shortReadableName())}, + location.sourceStart, location.sourceEnd); + } + public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) { + this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument, + NoArgument, constructor.sourceStart, constructor.sourceEnd, + constructor, constructor.compilationResult()); + } + public void interfaceCannotHaveInitializers(SourceTypeBinding type, + FieldDeclaration fieldDecl) { + String[] arguments = new String[]{new String(type.sourceName())}; + this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments, + fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void invalidBreak(AstNode location) { + this.handle(IProblem.InvalidBreak, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void invalidConstructor(Statement statement, + MethodBinding targetConstructor) { + boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration) + && ((ConstructorDeclaration) referenceContext).isDefaultConstructor(); + boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall) + && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper); + int flag = IProblem.UndefinedConstructor; //default... + switch (targetConstructor.problemId()) { + case NotFound : + if (insideDefaultConstructor) { + flag = IProblem.UndefinedConstructorInDefaultConstructor; + } else if (insideImplicitConstructorCall) { + flag = IProblem.UndefinedConstructorInImplicitConstructorCall; + } else { + flag = IProblem.UndefinedConstructor; + } + break; + case NotVisible : + if (insideDefaultConstructor) { + flag = IProblem.NotVisibleConstructorInDefaultConstructor; + } else if (insideImplicitConstructorCall) { + flag = IProblem.NotVisibleConstructorInImplicitConstructorCall; + } else { + flag = IProblem.NotVisibleConstructor; + } + break; + case Ambiguous : + if (insideDefaultConstructor) { + flag = IProblem.AmbiguousConstructorInDefaultConstructor; + } else if (insideImplicitConstructorCall) { + flag = IProblem.AmbiguousConstructorInImplicitConstructorCall; + } else { + flag = IProblem.AmbiguousConstructor; + } + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + this.handle(flag, new String[]{ + new String(targetConstructor.declaringClass.readableName()), + parametersAsString(targetConstructor)}, new String[]{ + new String(targetConstructor.declaringClass.shortReadableName()), + parametersAsShortString(targetConstructor)}, statement.sourceStart, + statement.sourceEnd); + } + public void invalidContinue(AstNode location) { + this.handle(IProblem.InvalidContinue, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void invalidEnclosingType(Expression expression, TypeBinding type, + ReferenceBinding enclosingType) { + if (enclosingType.isAnonymousType()) + enclosingType = enclosingType.superclass(); + int flag = IProblem.UndefinedType; // default + switch (type.problemId()) { + case NotFound : + // 1 + flag = IProblem.UndefinedType; + break; + case NotVisible : + // 2 + flag = IProblem.NotVisibleType; + break; + case Ambiguous : + // 3 + flag = IProblem.AmbiguousType; + break; + case InternalNameProvided : + flag = IProblem.InternalTypeNameProvided; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + this.handle(flag, new String[]{new String(enclosingType.readableName()) + + "." + new String(type.readableName())}, //$NON-NLS-1$ + new String[]{new String(enclosingType.shortReadableName()) + "." + + new String(type.shortReadableName())}, //$NON-NLS-1$ + expression.sourceStart, expression.sourceEnd); + } + public void invalidExpressionAsStatement(Expression expression) { + this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void invalidField(FieldReference fieldRef, TypeBinding searchedType) { + int severity = Error; + int flag = IProblem.UndefinedField; + FieldBinding field = fieldRef.binding; + switch (field.problemId()) { + case NotFound : + flag = IProblem.UndefinedField; + /* + * also need to check that the searchedType is the receiver type if + * (searchedType.isHierarchyInconsistent()) severity = SecondaryError; + */ + break; + case NotVisible : + flag = IProblem.NotVisibleField; + break; + case Ambiguous : + flag = IProblem.AmbiguousField; + break; + case NonStaticReferenceInStaticContext : + flag = IProblem.NonStaticFieldFromStaticInvocation; + break; + case NonStaticReferenceInConstructorInvocation : + flag = IProblem.InstanceFieldDuringConstructorInvocation; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedFieldHidesEnclosingName; + break; + case ReceiverTypeNotVisible : + this.handle(IProblem.NotVisibleType, new String[]{new String( + searchedType.leafComponentType().readableName())}, + new String[]{new String(searchedType.leafComponentType() + .shortReadableName())}, fieldRef.receiver.sourceStart, + fieldRef.receiver.sourceEnd); + return; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart, + fieldRef.sourceEnd); + } + public void invalidField(NameReference nameRef, FieldBinding field) { + int flag = IProblem.UndefinedField; + switch (field.problemId()) { + case NotFound : + flag = IProblem.UndefinedField; + break; + case NotVisible : + flag = IProblem.NotVisibleField; + break; + case Ambiguous : + flag = IProblem.AmbiguousField; + break; + case NonStaticReferenceInStaticContext : + flag = IProblem.NonStaticFieldFromStaticInvocation; + break; + case NonStaticReferenceInConstructorInvocation : + flag = IProblem.InstanceFieldDuringConstructorInvocation; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedFieldHidesEnclosingName; + break; + case ReceiverTypeNotVisible : + this.handle(IProblem.NotVisibleType, new String[]{new String( + field.declaringClass.leafComponentType().readableName())}, + new String[]{new String(field.declaringClass.leafComponentType() + .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd); + return; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(flag, arguments, arguments, nameRef.sourceStart, + nameRef.sourceEnd); + } + public void invalidField(QualifiedNameReference nameRef, FieldBinding field, + int index, TypeBinding searchedType) { + //the resolution of the index-th field of qname failed + //qname.otherBindings[index] is the binding that has produced the + // error + //The different targetted errors should be : + //UndefinedField + //NotVisibleField + //AmbiguousField + if (searchedType.isBaseType()) { + this.handle(IProblem.NoFieldOnBaseType, new String[]{ + new String(searchedType.readableName()), + CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, + index)), new String(nameRef.tokens[index])}, new String[]{ + new String(searchedType.sourceName()), + CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, + index)), new String(nameRef.tokens[index])}, nameRef.sourceStart, + nameRef.sourceEnd); + return; + } + int flag = IProblem.UndefinedField; + switch (field.problemId()) { + case NotFound : + flag = IProblem.UndefinedField; + /* + * also need to check that the searchedType is the receiver type if + * (searchedType.isHierarchyInconsistent()) severity = SecondaryError; + */ + break; + case NotVisible : + flag = IProblem.NotVisibleField; + break; + case Ambiguous : + flag = IProblem.AmbiguousField; + break; + case NonStaticReferenceInStaticContext : + flag = IProblem.NonStaticFieldFromStaticInvocation; + break; + case NonStaticReferenceInConstructorInvocation : + flag = IProblem.InstanceFieldDuringConstructorInvocation; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedFieldHidesEnclosingName; + break; + case ReceiverTypeNotVisible : + this.handle(IProblem.NotVisibleType, new String[]{new String( + searchedType.leafComponentType().readableName())}, + new String[]{new String(searchedType.leafComponentType() + .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd); + return; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + String[] arguments = new String[]{CharOperation.toString(CharOperation + .subarray(nameRef.tokens, 0, index + 1))}; + this.handle(flag, arguments, arguments, nameRef.sourceStart, + nameRef.sourceEnd); + } + public void invalidMethod(MessageSend messageSend, MethodBinding method) { + // CODE should be UPDATED according to error coding in the different + // method binding errors + // The different targetted errors should be : + // UndefinedMethod + // NotVisibleMethod + // AmbiguousMethod + // InheritedNameHidesEnclosingName + // InstanceMethodDuringConstructorInvocation + // StaticMethodRequested + int flag = IProblem.UndefinedMethod; //default... + switch (method.problemId()) { + case NotFound : + flag = IProblem.UndefinedMethod; + break; + case NotVisible : + flag = IProblem.NotVisibleMethod; + break; + case Ambiguous : + flag = IProblem.AmbiguousMethod; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedMethodHidesEnclosingName; + break; + case NonStaticReferenceInConstructorInvocation : + flag = IProblem.InstanceMethodDuringConstructorInvocation; + break; + case NonStaticReferenceInStaticContext : + flag = IProblem.StaticMethodRequested; + break; + case ReceiverTypeNotVisible : + this.handle(IProblem.NotVisibleType, new String[]{new String( + method.declaringClass.leafComponentType().readableName())}, + new String[]{new String(method.declaringClass.leafComponentType() + .shortReadableName())}, messageSend.receiver.sourceStart, + messageSend.receiver.sourceEnd); + return; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + if (flag == IProblem.UndefinedMethod) { + ProblemMethodBinding problemMethod = (ProblemMethodBinding) method; + if (problemMethod.closestMatch != null) { + String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch); + String parameterTypeNames = parametersAsString(method); + String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch); + String parameterTypeShortNames = parametersAsShortString(method); + if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) { + closestParameterTypeShortNames = closestParameterTypeNames; + parameterTypeShortNames = parameterTypeNames; + } + this.handle(IProblem.ParameterMismatch, + new String[]{ + new String(problemMethod.closestMatch.declaringClass + .readableName()), + new String(problemMethod.closestMatch.selector), + closestParameterTypeNames, parameterTypeNames}, new String[]{ + new String(problemMethod.closestMatch.declaringClass + .shortReadableName()), + new String(problemMethod.closestMatch.selector), + closestParameterTypeShortNames, parameterTypeShortNames}, + (int) (messageSend.nameSourcePosition >>> 32), + (int) messageSend.nameSourcePosition); + return; + } + } + this.handle(flag, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), parametersAsShortString(method)}, + (int) (messageSend.nameSourcePosition >>> 32), + (int) messageSend.nameSourcePosition); + } + public void invalidNullToSynchronize(Expression expression) { + this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void invalidOperator(BinaryExpression expression, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.InvalidOperator, new String[]{ + expression.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$ + new String[]{expression.operatorToString(), + leftShortName + ", " + rightShortName}, //$NON-NLS-1$ + expression.sourceStart, expression.sourceEnd); + } + public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, + TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.InvalidOperator, new String[]{ + assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$ + new String[]{assign.operatorToString(), + leftShortName + ", " + rightShortName}, //$NON-NLS-1$ + assign.sourceStart, assign.sourceEnd); + } + public void invalidOperator(UnaryExpression expression, TypeBinding type) { + this.handle(IProblem.InvalidOperator, new String[]{ + expression.operatorToString(), new String(type.readableName())}, + new String[]{expression.operatorToString(), + new String(type.shortReadableName())}, expression.sourceStart, + expression.sourceEnd); + } + public void invalidParenthesizedExpression(AstNode reference) { + this.handle(IProblem.InvalidParenthesizedExpression, NoArgument, + NoArgument, reference.sourceStart, reference.sourceEnd); + } + public void invalidSuperclass(SourceTypeBinding type, + TypeReference superclassRef, ReferenceBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.SuperclassNotFound; + break; + case NotVisible : + // 2 + id = IProblem.SuperclassNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.SuperclassAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.SuperclassInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.SuperclassInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(expectedType.readableName()), + new String(type.sourceName())}, new String[]{ + new String(expectedType.shortReadableName()), + new String(type.sourceName())}, superclassRef.sourceStart, + superclassRef.sourceEnd); + } + public void invalidSuperinterface(SourceTypeBinding type, + TypeReference superinterfaceRef, ReferenceBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.InterfaceNotFound; + break; + case NotVisible : + // 2 + id = IProblem.InterfaceNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.InterfaceAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.InterfaceInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.InterfaceInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(expectedType.readableName()), + new String(type.sourceName())}, new String[]{ + new String(expectedType.shortReadableName()), + new String(type.sourceName())}, superinterfaceRef.sourceStart, + superinterfaceRef.sourceEnd); + } + public void invalidType(AstNode location, TypeBinding type) { + int flag = IProblem.UndefinedType; // default + switch (type.problemId()) { + case NotFound : + flag = IProblem.UndefinedType; + break; + case NotVisible : + flag = IProblem.NotVisibleType; + break; + case Ambiguous : + flag = IProblem.AmbiguousType; + break; + case InternalNameProvided : + flag = IProblem.InternalTypeNameProvided; + break; + case InheritedNameHidesEnclosingName : + flag = IProblem.InheritedTypeHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + break; + } + this.handle(flag, new String[]{new String(type.readableName())}, + new String[]{new String(type.shortReadableName())}, + location.sourceStart, location.sourceEnd); + } + public void invalidTypeReference(Expression expression) { + this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void invalidTypeToSynchronize(Expression expression, TypeBinding type) { + this.handle(IProblem.InvalidTypeToSynchronized, new String[]{new String( + type.readableName())}, + new String[]{new String(type.shortReadableName())}, + expression.sourceStart, expression.sourceEnd); + } + public void invalidUnaryExpression(Expression expression) { + this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void isClassPathCorrect(char[][] wellKnownTypeName, + CompilationUnitDeclaration compUnitDecl) { + referenceContext = compUnitDecl; + String[] arguments = new String[]{CharOperation.toString(wellKnownTypeName)}; + this.handle(IProblem.IsClassPathCorrect, arguments, arguments, + AbortCompilation | Error, compUnitDecl == null + ? 0 + : compUnitDecl.sourceStart, compUnitDecl == null + ? 1 + : compUnitDecl.sourceEnd); + } + public void maskedExceptionHandler(ReferenceBinding exceptionType, + AstNode location) { + this.handle(IProblem.MaskedCatch, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) { + this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void methodNeedingNoBody(MethodDeclaration methodDecl) { + this.handle( + // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ? + // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod, + IProblem.BodyForAbstractMethod, NoArgument, NoArgument, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void methodWithConstructorName(MethodDeclaration methodDecl) { + this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + //public void missingEnclosingInstanceSpecification(ReferenceBinding + // enclosingType, AstNode location) { + // boolean insideConstructorCall = + // (location instanceof ExplicitConstructorCall) + // && (((ExplicitConstructorCall) location).accessMode == + // ExplicitConstructorCall.ImplicitSuper); + // + // this.handle( + // insideConstructorCall + // ? IProblem.MissingEnclosingInstanceForConstructorCall + // : IProblem.MissingEnclosingInstance, + // new String[] {new String(enclosingType.readableName())}, + // new String[] {new String(enclosingType.shortReadableName())}, + // location.sourceStart, + // location.sourceEnd); + //} + public void missingReturnType(AbstractMethodDeclaration methodDecl) { + this.handle(IProblem.MissingReturnType, NoArgument, NoArgument, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void missingSemiColon(Expression expression) { + this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void mustDefineDimensionsOrInitializer( + ArrayAllocationExpression expression) { + this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer, + NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd); + } + public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) { + String[] arguments = new String[]{new String(compUnitDecl.getFileName())}; + this.handle(IProblem.MustSpecifyPackage, arguments, arguments, + compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1); + } + public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) { + this.handle(IProblem.StaticMethodRequested, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), parametersAsShortString(method)}, + messageSend.sourceStart, messageSend.sourceEnd); + } + public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void needImplementation() { + this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$ + } + public void needToEmulateFieldReadAccess(FieldBinding field, AstNode location) { + this.handle(IProblem.NeedToEmulateFieldReadAccess, + new String[]{new String(field.declaringClass.readableName()), + new String(field.name)}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name)}, location.sourceStart, location.sourceEnd); + } + public void needToEmulateFieldWriteAccess(FieldBinding field, AstNode location) { + this.handle(IProblem.NeedToEmulateFieldWriteAccess, + new String[]{new String(field.declaringClass.readableName()), + new String(field.name)}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name)}, location.sourceStart, location.sourceEnd); + } + public void needToEmulateMethodAccess(MethodBinding method, AstNode location) { + if (method.isConstructor()) + this.handle(IProblem.NeedToEmulateConstructorAccess, new String[]{ + new String(method.declaringClass.readableName()), + parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + parametersAsShortString(method)}, location.sourceStart, + location.sourceEnd); + else + this.handle(IProblem.NeedToEmulateMethodAccess, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, + new String[]{new String(method.declaringClass.shortReadableName()), + new String(method.selector), parametersAsShortString(method)}, + location.sourceStart, location.sourceEnd); + } + public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) { + String[] arguments = new String[]{new String(typeDecl.name)}; + this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, + arguments, typeDecl.sourceStart, typeDecl.sourceEnd); + } + public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.name)}; + this.handle(local instanceof SyntheticArgumentBinding + ? IProblem.TooManySyntheticArgumentSlots + : IProblem.TooManyArgumentSlots, arguments, arguments, Abort | Error, + location.sourceStart, location.sourceEnd); + } + public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, + AstNode location) { + String[] arguments = new String[]{new String(local.name)}; + this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort + | Error, location.sourceStart, location.sourceEnd); + } + public void noSuchEnclosingInstance(TypeBinding targetType, AstNode location, + boolean isConstructorCall) { + int id; + if (isConstructorCall) { + //28 = No enclosing instance of type {0} is available due to some + // intermediate constructor invocation + id = IProblem.EnclosingInstanceInConstructorCall; + } else if ((location instanceof ExplicitConstructorCall) + && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) { + //20 = No enclosing instance of type {0} is accessible to invoke + // the super constructor. Must define a constructor and explicitly + // qualify its super constructor invocation with an instance of {0} + // (e.g. x.super() where x is an instance of {0}). + id = IProblem.MissingEnclosingInstanceForConstructorCall; + } else if (location instanceof AllocationExpression + && (((AllocationExpression) location).binding.declaringClass + .isMemberType() || (((AllocationExpression) location).binding.declaringClass + .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass + .superclass().isMemberType()))) { + //21 = No enclosing instance of type {0} is accessible. Must + // qualify the allocation with an enclosing instance of type {0} + // (e.g. x.new A() where x is an instance of {0}). + id = IProblem.MissingEnclosingInstance; + } else { // default + //22 = No enclosing instance of the type {0} is accessible in + // scope + id = IProblem.IncorrectEnclosingInstanceReference; + } + this.handle(id, new String[]{new String(targetType.readableName())}, + new String[]{new String(targetType.shortReadableName())}, + location.sourceStart, location.sourceEnd); + } + public void notCompatibleTypesError(EqualExpression expression, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[]{ + leftName, rightName}, new String[]{leftShortName, rightShortName}, + expression.sourceStart, expression.sourceEnd); + } + public void notCompatibleTypesError(InstanceOfExpression expression, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[]{ + leftName, rightName}, new String[]{leftShortName, rightShortName}, + expression.sourceStart, expression.sourceEnd); + } + public void objectCannotHaveSuperTypes(SourceTypeBinding type) { + this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument, + type.sourceStart(), type.sourceEnd()); + } + public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, + TypeBinding leftType, TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.TypeMismatch, new String[]{leftName, rightName}, + new String[]{leftShortName, rightShortName}, assignment.sourceStart, + assignment.sourceEnd); + } + public void overridesDeprecatedMethod(MethodBinding localMethod, + MethodBinding inheritedMethod) { + this.handle(IProblem.OverridingDeprecatedMethod, new String[]{ + new String(CharOperation.concat(localMethod.declaringClass + .readableName(), localMethod.readableName(), '.')), + new String(inheritedMethod.declaringClass.readableName())}, + new String[]{ + new String(CharOperation.concat(localMethod.declaringClass + .shortReadableName(), localMethod.shortReadableName(), '.')), + new String(inheritedMethod.declaringClass.shortReadableName())}, + localMethod.sourceStart(), localMethod.sourceEnd()); + } + public void overridesPackageDefaultMethod(MethodBinding localMethod, + MethodBinding inheritedMethod) { + this.handle(IProblem.OverridingNonVisibleMethod, new String[]{ + new String(CharOperation.concat(localMethod.declaringClass + .readableName(), localMethod.readableName(), '.')), + new String(inheritedMethod.declaringClass.readableName())}, + new String[]{ + new String(CharOperation.concat(localMethod.declaringClass + .shortReadableName(), localMethod.shortReadableName(), '.')), + new String(inheritedMethod.declaringClass.shortReadableName())}, + localMethod.sourceStart(), localMethod.sourceEnd()); + } + public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) { + String[] arguments = new String[]{CharOperation + .toString(compUnitDecl.currentPackage.tokens)}; + this.handle(IProblem.PackageCollidesWithType, arguments, arguments, + compUnitDecl.currentPackage.sourceStart, + compUnitDecl.currentPackage.sourceEnd); + } + public void packageIsNotExpectedPackage( + CompilationUnitDeclaration compUnitDecl) { + String[] arguments = new String[]{CharOperation + .toString(compUnitDecl.compilationResult.compilationUnit + .getPackageName())}; + this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments, + compUnitDecl.currentPackage == null + ? 0 + : compUnitDecl.currentPackage.sourceStart, + compUnitDecl.currentPackage == null + ? 0 + : compUnitDecl.currentPackage.sourceEnd); + } + private String parametersAsString(MethodBinding method) { + TypeBinding[] params = method.parameters; + StringBuffer buffer = new StringBuffer(); + for (int i = 0, length = params.length; i < length; i++) { + if (i != 0) + buffer.append(", "); //$NON-NLS-1$ + buffer.append(new String(params[i].readableName())); + } + return buffer.toString(); + } + private String parametersAsShortString(MethodBinding method) { + TypeBinding[] params = method.parameters; + StringBuffer buffer = new StringBuffer(); + for (int i = 0, length = params.length; i < length; i++) { + if (i != 0) + buffer.append(", "); //$NON-NLS-1$ + buffer.append(new String(params[i].shortReadableName())); + } + return buffer.toString(); + } + public void parseError(int startPosition, int endPosition, + char[] currentTokenSource, String errorTokenName, String[] possibleTokens) { + if (possibleTokens.length == 0) { //no suggestion available + if (isKeyword(currentTokenSource)) { + String[] arguments = new String[]{new String(currentTokenSource)}; + this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments, + arguments, + // this is the current -invalid- token position + startPosition, endPosition); + return; + } else { + String[] arguments = new String[]{errorTokenName}; + this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments, + // this is the current -invalid- token position + startPosition, endPosition); + return; + } + } + //build a list of probable right tokens + StringBuffer list = new StringBuffer(20); + for (int i = 0, max = possibleTokens.length; i < max; i++) { + if (i > 0) + list.append(", "); //$NON-NLS-1$ + list.append('"'); + list.append(possibleTokens[i]); + list.append('"'); + } + if (isKeyword(currentTokenSource)) { + String[] arguments = new String[]{new String(currentTokenSource), + list.toString()}; + this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments, + // this is the current -invalid- token position + startPosition, endPosition); + return; + } + //extract the literal when it's a literal + if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$ + (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$ + errorTokenName = new String(currentTokenSource); + } + String[] arguments = new String[]{errorTokenName, list.toString()}; + this.handle(IProblem.ParsingError, arguments, arguments, + // this is the current -invalid- token position + startPosition, endPosition); + } + public void publicClassMustMatchFileName( + CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) { + this.referenceContext = typeDecl; // report the problem against the + // type not the entire compilation + // unit + String[] arguments = new String[]{new String(compUnitDecl.getFileName()), + new String(typeDecl.name)}; + this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd, + compUnitDecl.compilationResult); + } + public void recursiveConstructorInvocation( + ExplicitConstructorCall constructorCall) { + this.handle(IProblem.RecursiveConstructorInvocation, new String[]{ + new String(constructorCall.binding.declaringClass.readableName()), + parametersAsString(constructorCall.binding)}, new String[]{ + new String(constructorCall.binding.declaringClass.shortReadableName()), + parametersAsShortString(constructorCall.binding)}, + constructorCall.sourceStart, constructorCall.sourceEnd); + } + public void redefineArgument(Argument arg) { + String[] arguments = new String[]{new String(arg.name)}; + this.handle(IProblem.RedefinedArgument, arguments, arguments, + arg.sourceStart, arg.sourceEnd); + } + public void redefineLocal(LocalDeclaration localDecl) { + String[] arguments = new String[]{new String(localDecl.name)}; + this.handle(IProblem.RedefinedLocal, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void referenceMustBeArrayTypeAt(TypeBinding arrayType, + ArrayReference arrayRef) { + this.handle(IProblem.ArrayReferenceRequired, new String[]{new String( + arrayType.readableName())}, new String[]{new String(arrayType + .shortReadableName())}, arrayRef.sourceStart, arrayRef.sourceEnd); + } + public void returnTypeCannotBeVoidArray(SourceTypeBinding type, + MethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(methodDecl.selector)}; + this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void returnTypeProblem(SourceTypeBinding type, + MethodDeclaration methodDecl, TypeBinding expectedType) { + int problemId = expectedType.problemId(); + int id; + switch (problemId) { + case NotFound : + // 1 + id = IProblem.ReturnTypeNotFound; + break; + case NotVisible : + // 2 + id = IProblem.ReturnTypeNotVisible; + break; + case Ambiguous : + // 3 + id = IProblem.ReturnTypeAmbiguous; + break; + case InternalNameProvided : + // 4 + id = IProblem.ReturnTypeInternalNameProvided; + break; + case InheritedNameHidesEnclosingName : + // 5 + id = IProblem.ReturnTypeInheritedNameHidesEnclosingName; + break; + case NoError : + // 0 + default : + needImplementation(); // want to fail to see why we were + // here... + return; + } + this.handle(id, new String[]{new String(methodDecl.selector), + new String(expectedType.readableName())}, new String[]{ + new String(methodDecl.selector), + new String(expectedType.shortReadableName())}, + methodDecl.returnType.sourceStart, methodDecl.returnType.sourceEnd); + } + public void scannerError(Parser parser, String errorTokenName) { + Scanner scanner = parser.scanner; + int flag = IProblem.ParsingErrorNoSuggestion; + int startPos = scanner.startPosition; + //special treatment for recognized errors.... + if (errorTokenName.equals(Scanner.END_OF_SOURCE)) + flag = IProblem.EndOfSource; + else if (errorTokenName.equals(Scanner.INVALID_HEXA)) + flag = IProblem.InvalidHexa; + else if (errorTokenName.equals(Scanner.INVALID_OCTAL)) + flag = IProblem.InvalidOctal; + else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT)) + flag = IProblem.InvalidCharacterConstant; + else if (errorTokenName.equals(Scanner.INVALID_ESCAPE)) + flag = IProblem.InvalidEscape; + else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) { + flag = IProblem.InvalidUnicodeEscape; + // better locate the error message + char[] source = scanner.source; + int checkPos = scanner.currentPosition - 1; + if (checkPos >= source.length) + checkPos = source.length - 1; + while (checkPos >= startPos) { + if (source[checkPos] == '\\') + break; + checkPos--; + } + startPos = checkPos; + } else if (errorTokenName.equals(Scanner.INVALID_FLOAT)) + flag = IProblem.InvalidFloat; + else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING)) + flag = IProblem.UnterminatedString; + else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT)) + flag = IProblem.UnterminatedComment; + else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING)) + flag = IProblem.UnterminatedString; + String[] arguments = flag == IProblem.ParsingErrorNoSuggestion + ? new String[]{errorTokenName} + : NoArgument; + this.handle(flag, arguments, arguments, + // this is the current -invalid- token position + startPos, scanner.currentPosition - 1, + parser.compilationUnit.compilationResult); + } + public void shouldReturn(TypeBinding returnType, AstNode location) { + this.handle(IProblem.ShouldReturnValue, new String[]{new String(returnType + .readableName())}, new String[]{new String(returnType + .shortReadableName())}, location.sourceStart, location.sourceEnd); + } + public void signalNoImplicitStringConversionForCharArrayExpression( + Expression expression) { + this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression, + NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd); + } + public void staticAndInstanceConflict(MethodBinding currentMethod, + MethodBinding inheritedMethod) { + if (currentMethod.isStatic()) + this + .handle( + // This static method cannot hide the instance method from %1 + // 8.4.6.4 - If a class inherits more than one method with + // the same signature a static (non-abstract) method cannot + // hide an instance method. + IProblem.CannotHideAnInstanceMethodWithAStaticMethod, + new String[]{new String(inheritedMethod.declaringClass + .readableName())}, new String[]{new String( + inheritedMethod.declaringClass.shortReadableName())}, + currentMethod.sourceStart(), currentMethod.sourceEnd()); + else + this + .handle( + // This instance method cannot override the static method from %1 + // 8.4.6.4 - If a class inherits more than one method with + // the same signature an instance (non-abstract) method + // cannot override a static method. + IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod, + new String[]{new String(inheritedMethod.declaringClass + .readableName())}, new String[]{new String( + inheritedMethod.declaringClass.shortReadableName())}, + currentMethod.sourceStart(), currentMethod.sourceEnd()); + } + public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, + FieldBinding field) { + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, + arguments, fieldRef.sourceStart, fieldRef.sourceEnd); + } + public void staticFieldAccessToNonStaticVariable( + QualifiedNameReference nameRef, FieldBinding field) { + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, + arguments, nameRef.sourceStart, nameRef.sourceEnd); + } + public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef, + FieldBinding field) { + String[] arguments = new String[]{new String(field.readableName())}; + this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, + arguments, nameRef.sourceStart, nameRef.sourceEnd); + } + public void staticInheritedMethodConflicts(SourceTypeBinding type, + MethodBinding concreteMethod, MethodBinding[] abstractMethods) { + this.handle( + // The static method %1 conflicts with the abstract method in %2 + // 8.4.6.4 - If a class inherits more than one method with the + // same signature it is an error for one to be static + // (non-abstract) and the other abstract. + IProblem.StaticInheritedMethodConflicts, new String[]{ + new String(concreteMethod.readableName()), + new String(abstractMethods[0].declaringClass.readableName())}, + new String[]{new String(concreteMethod.readableName()), + new String(abstractMethods[0].declaringClass.shortReadableName())}, + type.sourceStart(), type.sourceEnd()); + } + public void stringConstantIsExceedingUtf8Limit(AstNode location) { + this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument, + NoArgument, location.sourceStart, location.sourceEnd); + } + public void superclassMustBeAClass(SourceTypeBinding type, + TypeReference superclassRef, ReferenceBinding superType) { + this.handle(IProblem.SuperclassMustBeAClass, new String[]{ + new String(superType.readableName()), new String(type.sourceName())}, + new String[]{new String(superType.shortReadableName()), + new String(type.sourceName())}, superclassRef.sourceStart, + superclassRef.sourceEnd); + } + public void superinterfaceMustBeAnInterface(SourceTypeBinding type, + TypeDeclaration typeDecl, ReferenceBinding superType) { + this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[]{ + new String(superType.readableName()), new String(type.sourceName())}, + new String[]{new String(superType.shortReadableName()), + new String(type.sourceName())}, typeDecl.sourceStart, + typeDecl.sourceEnd); + } + public void task(String tag, String message, String priority, int start, + int end) { + this.handle(IProblem.Task, new String[]{tag, message, priority/* + * secret + * argument + * that is + * not + * surfaced + * in + * getMessage() + */}, new String[]{tag, message, priority/* + * secret argument that is not + * surfaced in getMessage() + */}, start, end); + } + public void tooManyDimensions(AstNode expression) { + this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument, + expression.sourceStart, expression.sourceEnd); + } + public void tooManyFields(TypeDeclaration typeDeclaration) { + this.handle(IProblem.TooManyFields, new String[]{new String( + typeDeclaration.binding.readableName())}, new String[]{new String( + typeDeclaration.binding.shortReadableName())}, Abort | Error, + typeDeclaration.sourceStart, typeDeclaration.sourceEnd); + } + public void tooManyMethods(TypeDeclaration typeDeclaration) { + this.handle(IProblem.TooManyMethods, new String[]{new String( + typeDeclaration.binding.readableName())}, new String[]{new String( + typeDeclaration.binding.shortReadableName())}, Abort | Error, + typeDeclaration.sourceStart, typeDeclaration.sourceEnd); + } + public void typeCastError(CastExpression expression, TypeBinding leftType, + TypeBinding rightType) { + String leftName = new String(leftType.readableName()); + String rightName = new String(rightType.readableName()); + String leftShortName = new String(leftType.shortReadableName()); + String rightShortName = new String(rightType.shortReadableName()); + if (leftShortName.equals(rightShortName)) { + leftShortName = leftName; + rightShortName = rightName; + } + this.handle(IProblem.IllegalCast, new String[]{rightName, leftName}, + new String[]{rightShortName, leftShortName}, expression.sourceStart, + expression.sourceEnd); + } + public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, + TypeDeclaration typeDecl) { + this.referenceContext = typeDecl; // report the problem against the + // type not the entire compilation + // unit + String[] arguments = new String[]{new String(compUnitDecl.getFileName()), + new String(typeDecl.name)}; + this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments, + typeDecl.sourceStart, typeDecl.sourceEnd, + compUnitDecl.compilationResult); + } + public void typeMismatchError(TypeBinding resultType, + TypeBinding expectedType, AstNode location) { + String resultTypeName = new String(resultType.readableName()); + String expectedTypeName = new String(expectedType.readableName()); + String resultTypeShortName = new String(resultType.shortReadableName()); + String expectedTypeShortName = new String(expectedType.shortReadableName()); + if (resultTypeShortName.equals(expectedTypeShortName)) { + resultTypeShortName = resultTypeName; + expectedTypeShortName = expectedTypeName; + } + this.handle(IProblem.TypeMismatch, new String[]{resultTypeName, + expectedTypeName}, new String[]{resultTypeShortName, + expectedTypeShortName}, location.sourceStart, location.sourceEnd); + } + public void typeMismatchErrorActualTypeExpectedType(Expression expression, + TypeBinding constantType, TypeBinding expectedType) { + String constantTypeName = new String(constantType.readableName()); + String expectedTypeName = new String(expectedType.readableName()); + String constantTypeShortName = new String(constantType.shortReadableName()); + String expectedTypeShortName = new String(expectedType.shortReadableName()); + if (constantTypeShortName.equals(expectedTypeShortName)) { + constantTypeShortName = constantTypeName; + expectedTypeShortName = expectedTypeName; + } + this.handle(IProblem.TypeMismatch, new String[]{constantTypeName, + expectedTypeName}, new String[]{constantTypeShortName, + expectedTypeShortName}, expression.sourceStart, expression.sourceEnd); + } + public void undefinedLabel(BranchStatement statement) { + String[] arguments = new String[]{new String(statement.label)}; + this.handle(IProblem.UndefinedLabel, arguments, arguments, + statement.sourceStart, statement.sourceEnd); + } + public void unexpectedStaticModifierForField(SourceTypeBinding type, + FieldDeclaration fieldDecl) { + String[] arguments = new String[]{fieldDecl.name()}; + this.handle(IProblem.UnexpectedStaticModifierForField, arguments, + arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void unexpectedStaticModifierForMethod(ReferenceBinding type, + AbstractMethodDeclaration methodDecl) { + String[] arguments = new String[]{new String(type.sourceName()), + new String(methodDecl.selector)}; + this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments, + arguments, methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void unhandledException(TypeBinding exceptionType, AstNode location) { + boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration) + && ((ConstructorDeclaration) referenceContext).isDefaultConstructor(); + boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall) + && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper); + this.handle(insideDefaultConstructor + ? IProblem.UnhandledExceptionInDefaultConstructor + : (insideImplicitConstructorCall + ? IProblem.UndefinedConstructorInImplicitConstructorCall + : IProblem.UnhandledException), new String[]{new String( + exceptionType.readableName())}, new String[]{new String(exceptionType + .shortReadableName())}, location.sourceStart, location.sourceEnd); + } + public void uninitializedBlankFinalField(FieldBinding binding, + AstNode location) { + String[] arguments = new String[]{new String(binding.readableName())}; + this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void uninitializedLocalVariable(LocalVariableBinding binding, + AstNode location) { + String[] arguments = new String[]{new String(binding.readableName())}; + this.handle(IProblem.UninitializedLocalVariable, arguments, arguments, + location.sourceStart, location.sourceEnd); + } + public void unmatchedBracket(int position, ReferenceContext context, + CompilationResult compilationResult) { + this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position, + position, context, compilationResult); + } + public void unnecessaryEnclosingInstanceSpecification(Expression expression, + ReferenceBinding targetType) { + this.handle(IProblem.IllegalEnclosingInstanceSpecification, + new String[]{new String(targetType.readableName())}, + new String[]{new String(targetType.shortReadableName())}, + expression.sourceStart, expression.sourceEnd); + } + public void unnecessaryReceiverForStaticMethod(AstNode location, + MethodBinding method) { + this.handle(IProblem.NonStaticAccessToStaticMethod, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), parametersAsShortString(method)}, + location.sourceStart, location.sourceEnd); + } + public void unnecessaryReceiverForStaticField(AstNode location, + FieldBinding field) { + this.handle(IProblem.NonStaticAccessToStaticField, + new String[]{new String(field.declaringClass.readableName()), + new String(field.name)}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name)}, location.sourceStart, location.sourceEnd); + } + public void unreachableCode(Statement statement) { + this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument, + statement.sourceStart, statement.sourceEnd); + } + public void unreachableExceptionHandler(ReferenceBinding exceptionType, + AstNode location) { + this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void unresolvableReference(NameReference nameRef, Binding binding) { + int severity = Error; + /* + * also need to check that the searchedType is the receiver type if + * (binding instanceof ProblemBinding) { ProblemBinding problem = + * (ProblemBinding) binding; if (problem.searchType != null && + * problem.searchType.isHierarchyInconsistent()) severity = SecondaryError; } + */ + String[] arguments = new String[]{new String(binding.readableName())}; + this.handle(IProblem.UndefinedName, arguments, arguments, severity, + nameRef.sourceStart, nameRef.sourceEnd); + } + public void unusedArgument(LocalDeclaration localDecl) { + String[] arguments = new String[]{localDecl.name()}; + this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void unusedImport(ImportReference importRef) { + String[] arguments = new String[]{CharOperation.toString(importRef.tokens)}; + this.handle(IProblem.UnusedImport, arguments, arguments, + importRef.sourceStart, importRef.sourceEnd); + } + public void unusedLocalVariable(LocalDeclaration localDecl) { + String[] arguments = new String[]{localDecl.name()}; + this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments, + localDecl.sourceStart, localDecl.sourceEnd); + } + public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) { + if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore) + return; + // no complaint for no-arg constructors (or default ones) - known + // pattern to block instantiation + if (constructorDecl.arguments == null + || constructorDecl.arguments.length == 0) + return; + MethodBinding constructor = constructorDecl.binding; + this.handle(IProblem.UnusedPrivateConstructor, new String[]{ + new String(constructor.declaringClass.readableName()), + parametersAsString(constructor)}, new String[]{ + new String(constructor.declaringClass.shortReadableName()), + parametersAsShortString(constructor)}, constructorDecl.sourceStart, + constructorDecl.sourceEnd); + } + public void unusedPrivateField(FieldDeclaration fieldDecl) { + if (computeSeverity(IProblem.UnusedPrivateField) == Ignore) + return; + FieldBinding field = fieldDecl.binding; + if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) + && field.isStatic() && field.isFinal() + && TypeBinding.LongBinding == field.type) { + return; // do not report unused serialVersionUID field + } + this.handle(IProblem.UnusedPrivateField, new String[]{ + new String(field.declaringClass.readableName()), + new String(field.name),}, new String[]{ + new String(field.declaringClass.shortReadableName()), + new String(field.name),}, fieldDecl.sourceStart, fieldDecl.sourceEnd); + } + public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) { + if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore) + return; + MethodBinding method = methodDecl.binding; + // no report for serialization support 'void + // readObject(ObjectInputStream)' + if (!method.isStatic() + && TypeBinding.VoidBinding == method.returnType + && method.parameters.length == 1 + && method.parameters[0].dimensions() == 0 + && CharOperation.equals(method.selector, TypeConstants.READOBJECT) + && CharOperation.equals( + TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, + method.parameters[0].readableName())) { + return; + } + // no report for serialization support 'void + // writeObject(ObjectOutputStream)' + if (!method.isStatic() + && TypeBinding.VoidBinding == method.returnType + && method.parameters.length == 1 + && method.parameters[0].dimensions() == 0 + && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT) + && CharOperation.equals( + TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, + method.parameters[0].readableName())) { + return; + } + // no report for serialization support 'Object readResolve()' + if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id + && method.parameters.length == 0 + && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) { + return; + } + // no report for serialization support 'Object writeReplace()' + if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id + && method.parameters.length == 0 + && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) { + return; + } + this.handle(IProblem.UnusedPrivateMethod, new String[]{ + new String(method.declaringClass.readableName()), + new String(method.selector), parametersAsString(method)}, new String[]{ + new String(method.declaringClass.shortReadableName()), + new String(method.selector), parametersAsShortString(method)}, + methodDecl.sourceStart, methodDecl.sourceEnd); + } + public void unusedPrivateType(TypeDeclaration typeDecl) { + if (computeSeverity(IProblem.UnusedPrivateType) == Ignore) + return; + ReferenceBinding type = typeDecl.binding; + this.handle(IProblem.UnusedPrivateType, new String[]{new String(type + .readableName()),}, + new String[]{new String(type.shortReadableName()),}, + typeDecl.sourceStart, typeDecl.sourceEnd); + } + public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) { + this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument, + sourceStart, sourceEnd); + } + public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) { + String[] arguments = new String[]{new String(varDecl.name)}; + this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments, + varDecl.sourceStart, varDecl.sourceEnd); + } + public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) { + String[] arguments = new String[]{new String(varDecl.name)}; + this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments, + varDecl.sourceStart, varDecl.sourceEnd); + } + public void visibilityConflict(MethodBinding currentMethod, + MethodBinding inheritedMethod) { + this.handle( + // Cannot reduce the visibility of the inherited method from %1 + // 8.4.6.3 - The access modifier of an hiding method must + // provide at least as much access as the hidden method. + // 8.4.6.3 - The access modifier of an overiding method must + // provide at least as much access as the overriden method. + IProblem.MethodReducesVisibility, new String[]{new String( + inheritedMethod.declaringClass.readableName())}, + new String[]{new String(inheritedMethod.declaringClass + .shortReadableName())}, currentMethod.sourceStart(), currentMethod + .sourceEnd()); + } + public void wrongSequenceOfExceptionTypesError(TryStatement statement, + int under, int upper) { + //the two catch block under and upper are in an incorrect order. + //under should be define BEFORE upper in the source + TypeReference typeRef = statement.catchArguments[under].type; + this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, + typeRef.sourceStart, typeRef.sourceEnd); + } + public void nonExternalizedStringLiteral(AstNode location) { + this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument, + location.sourceStart, location.sourceEnd); + } + public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) { + this.handle(IProblem.TooManyBytesForStringConstant, + new String[]{new String(typeDeclaration.binding.readableName())}, + new String[]{new String(typeDeclaration.binding.shortReadableName())}, + Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd); + } + public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) { + this.handle(IProblem.TooManyConstantsInConstantPool, + new String[]{new String(typeDeclaration.binding.readableName())}, + new String[]{new String(typeDeclaration.binding.shortReadableName())}, + Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd); + } + private boolean isKeyword(char[] tokenSource) { + /* + * This code is heavily grammar dependant + */ + if (tokenSource == null) { + return false; + } + try { + Scanner scanner = new Scanner(); + scanner.setSource(tokenSource); + int token = scanner.getNextToken(); + char[] currentKeyword; + try { + currentKeyword = scanner.getCurrentIdentifierSource(); + } catch (ArrayIndexOutOfBoundsException e) { + return false; + } + int nextToken = scanner.getNextToken(); + if (nextToken == Scanner.TokenNameEOF + && scanner.startPosition == scanner.source.length) { // to + // handle + // case + // where + // we + // had + // an + // ArrayIndexOutOfBoundsException + // while reading the last token + switch (token) { + case Scanner.TokenNameERROR : + if (CharOperation.equals("goto".toCharArray(), currentKeyword) + || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$ + return true; + } else { + return false; + } + case Scanner.TokenNameabstract : + // case Scanner.TokenNameassert: + // case Scanner.TokenNamebyte: + case Scanner.TokenNamebreak : + // case Scanner.TokenNameboolean: + case Scanner.TokenNamecase : + // case Scanner.TokenNamechar: + case Scanner.TokenNamecatch : + case Scanner.TokenNameclass : + case Scanner.TokenNamecontinue : + case Scanner.TokenNamedo : + // case Scanner.TokenNamedouble: + case Scanner.TokenNamedefault : + case Scanner.TokenNameelse : + case Scanner.TokenNameextends : + case Scanner.TokenNamefor : + // case Scanner.TokenNamefinal: + // case Scanner.TokenNamefloat: + // case Scanner.TokenNamefalse : + case Scanner.TokenNamefinally : + case Scanner.TokenNameif : + // case Scanner.TokenNameint: + // case Scanner.TokenNameimport: + case Scanner.TokenNameinterface : + case Scanner.TokenNameimplements : + case Scanner.TokenNameinstanceof : + // case Scanner.TokenNamelong: + case Scanner.TokenNamenew : + // case Scanner.TokenNamenull : + // case Scanner.TokenNamenative: + case Scanner.TokenNamepublic : + // case Scanner.TokenNamepackage: + case Scanner.TokenNameprivate : + case Scanner.TokenNameprotected : + case Scanner.TokenNamereturn : + // case Scanner.TokenNameshort: + case Scanner.TokenNamesuper : + case Scanner.TokenNamestatic : + case Scanner.TokenNameswitch : + // case Scanner.TokenNamestrictfp: + // case Scanner.TokenNamesynchronized: + case Scanner.TokenNametry : + case Scanner.TokenNamethis : + // case Scanner.TokenNametrue : + case Scanner.TokenNamethrow : + // case Scanner.TokenNamethrows: + // case Scanner.TokenNametransient: + // case Scanner.TokenNamevoid: + // case Scanner.TokenNamevolatile: + case Scanner.TokenNamewhile : + return true; + default : + return false; + } + } else { + return false; + } + } catch (InvalidInputException e) { + return false; + } + } + // jsurfer start + public void phpParsingError(String[] messageArguments, + int problemStartPosition, int problemEndPosition, + ReferenceContext context, CompilationResult compilationResult) { + this.handle(IProblem.PHPParsingError, NoArgument, messageArguments, + problemStartPosition, problemEndPosition, context, compilationResult); + } + public void phpParsingWarning(String[] messageArguments, + int problemStartPosition, int problemEndPosition, + ReferenceContext context, CompilationResult compilationResult) { + this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments, + problemStartPosition, problemEndPosition, context, compilationResult); + } + public void phpVarDeprecatedWarning( + int problemStartPosition, int problemEndPosition, + ReferenceContext context, CompilationResult compilationResult) { + this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[]{}, + problemStartPosition, problemEndPosition, context, compilationResult); + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/messages.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/messages.properties index b4ea5fa..33b1294 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/messages.properties +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/messages.properties @@ -152,7 +152,10 @@ 208 = Array constants can only be used in initializers 209 = Syntax error on keyword "{0}"; {1} expected 210 = Syntax error on keyword "{0}", no accurate correction available -211 = Parse error "{0}" + +211 = Parser error "{0}" +212 = Parser warning "{0}" +213 = Keyword 'var' is deprecated. Please use 'public' 'private' or 'protected' modifier for field declarations. 220 = Unmatched bracket 221 = The primitive type {0} of {1} does not have a field {2} 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 30ed629..ecfed39 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 @@ -1315,7 +1315,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { case TokenNameCOLON : // : (15.24) return ":"; //$NON-NLS-1$ - case TokenNameCOLON_COLON : // : (15.24) + case TokenNamePAAMAYIM_NEKUDOTAYIM : // : (15.24) return "::"; //$NON-NLS-1$ case TokenNameEQUAL_EQUAL : // == (15.20, 15.20.1, 15.20.2, 15.20.3) -- 1.7.1