From 0685dc716a5e1583a83ec860bd843146bd35e483 Mon Sep 17 00:00:00 2001 From: khartlage Date: Fri, 16 Jul 2004 17:22:14 +0000 Subject: [PATCH] Bug 841370 - open declaration for projects wih external workspace misc parser improvements --- .../src/net/sourceforge/phpdt/core/JavaCore.java | 14 ++++- .../sourceforge/phpdt/core/compiler/IProblem.java | 2 + .../internal/compiler/impl/CompilerOptions.java | 15 +++++- .../phpdt/internal/compiler/parser/Parser.java | 57 ++++++++++++++++++-- .../internal/compiler/problem/ProblemReporter.java | 24 ++++++++- .../internal/compiler/problem/messages.properties | 2 + .../ui/preferences/CompilerConfigurationBlock.java | 12 ++++- .../ui/preferences/PreferencesMessages.properties | 2 + .../actions/PHPOpenDeclarationEditorAction.java | 9 ++-- .../phpeclipse/builder/IdentifierIndexManager.java | 2 +- 10 files changed, 123 insertions(+), 16 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java index e47f5c4..9ae3318 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java @@ -296,7 +296,13 @@ public class JavaCore { */ public static final String COMPILER_PB_PHP_VAR_DEPRECATED = PLUGIN_ID + ".compiler.problem.phpVarDeprecatedWarning"; //$NON-NLS-1$ - + + public static final String COMPILER_PB_PHP_KEYWORD = PLUGIN_ID + + ".compiler.problem.phpBadStyleKeywordWarning"; //$NON-NLS-1$ + + public static final String COMPILER_PB_PHP_UPPERCASE_IDENTIFIER = PLUGIN_ID + + ".compiler.problem.phpBadStyleUppercaseIdentifierWarning"; //$NON-NLS-1$ + /** * Possible configurable option ID. * @@ -2888,7 +2894,11 @@ public class JavaCore { preferences.setDefault(COMPILER_PB_PHP_VAR_DEPRECATED, WARNING); optionNames.add(COMPILER_PB_PHP_VAR_DEPRECATED); - + preferences.setDefault(COMPILER_PB_PHP_KEYWORD, WARNING); + optionNames.add(COMPILER_PB_PHP_KEYWORD); + preferences.setDefault(COMPILER_PB_PHP_UPPERCASE_IDENTIFIER, IGNORE); + optionNames.add(COMPILER_PB_PHP_UPPERCASE_IDENTIFIER); + preferences.setDefault(COMPILER_PB_UNREACHABLE_CODE, ERROR); optionNames.add(COMPILER_PB_UNREACHABLE_CODE); 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 5674266..d8be369 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 @@ -367,6 +367,8 @@ public interface IProblem { int PHPParsingError = Syntax + Internal + 211; int PHPParsingWarning = Syntax + Internal + 212; int PHPVarDeprecatedWarning = Syntax + Internal + 213; + int PHPBadStyleKeywordWarning = Syntax + Internal + 214; + int PHPBadStyleUppercaseIdentifierWarning = Syntax + Internal + 215; int UnmatchedBracket = Syntax + Internal + 220; int NoFieldOnBaseType = FieldRelated + 221; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/impl/CompilerOptions.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/impl/CompilerOptions.java index c2e2a16..9149e3b 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/impl/CompilerOptions.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/impl/CompilerOptions.java @@ -28,7 +28,8 @@ public class CompilerOptions implements ProblemReasons, ProblemSeverities, ICons * Option IDs */ public static final String OPTION_PHPVarDeprecatedWarning = "net.sourceforge.phpeclipse.compiler.problem.phpVarDeprecatedWarning"; //$NON-NLS-1$ - + public static final String OPTION_PHPBadStyleKeywordWarning = "net.sourceforge.phpeclipse.compiler.problem.phpBadStyleKeywordWarning"; //$NON-NLS-1$ + public static final String OPTION_PHPBadStyleUppercaseIdentifierWarning = "net.sourceforge.phpeclipse.compiler.problem.phpBadStyleUppercaseIdentifierWarning"; //$NON-NLS-1$ public static final String OPTION_LocalVariableAttribute = "net.sourceforge.phpeclipse.compiler.debug.localVariable"; //$NON-NLS-1$ public static final String OPTION_LineNumberAttribute = "net.sourceforge.phpeclipse.compiler.debug.lineNumber"; //$NON-NLS-1$ public static final String OPTION_SourceFileAttribute = "net.sourceforge.phpeclipse.compiler.debug.sourceFile"; //$NON-NLS-1$ @@ -149,6 +150,8 @@ public class CompilerOptions implements ProblemReasons, ProblemSeverities, ICons public static final long MissingJavadocComments = 0x10000000000L; public static final long PHPVarDeprecatedWarning = 0x20000000000L; + public static final long PHPBadStyleKeywordWarning = 0x40000000000L; + public static final long PHPBadStyleUppercaseIdentifierWarning = 0x80000000000L; // Default severity level for handlers public long errorThreshold = 0; @@ -164,7 +167,9 @@ public class CompilerOptions implements ProblemReasons, ProblemSeverities, ICons | NoImplicitStringConversion | FinallyBlockNotCompleting | AssertUsedAsAnIdentifier - | PHPVarDeprecatedWarning; + | PHPVarDeprecatedWarning + | PHPBadStyleKeywordWarning + | PHPBadStyleUppercaseIdentifierWarning; // Debug attributes public static final int Source = 1; // SourceFileAttribute @@ -251,6 +256,8 @@ public class CompilerOptions implements ProblemReasons, ProblemSeverities, ICons public Map getMap() { Map optionsMap = new HashMap(30); optionsMap.put(OPTION_PHPVarDeprecatedWarning, getSeverityString(PHPVarDeprecatedWarning)); + optionsMap.put(OPTION_PHPBadStyleKeywordWarning, getSeverityString(PHPBadStyleKeywordWarning)); + optionsMap.put(OPTION_PHPBadStyleUppercaseIdentifierWarning, getSeverityString(PHPBadStyleUppercaseIdentifierWarning)); optionsMap.put(OPTION_LocalVariableAttribute, (this.produceDebugAttributes & Vars) != 0 ? GENERATE : DO_NOT_GENERATE); optionsMap.put(OPTION_LineNumberAttribute, (this.produceDebugAttributes & Lines) != 0 ? GENERATE : DO_NOT_GENERATE); @@ -473,6 +480,8 @@ public class CompilerOptions implements ProblemReasons, ProblemSeverities, ICons } } if ((optionValue = optionsMap.get(OPTION_PHPVarDeprecatedWarning)) != null) updateSeverity(PHPVarDeprecatedWarning, optionValue); + if ((optionValue = optionsMap.get(OPTION_PHPBadStyleKeywordWarning)) != null) updateSeverity(PHPBadStyleKeywordWarning, optionValue); + if ((optionValue = optionsMap.get(OPTION_PHPBadStyleUppercaseIdentifierWarning)) != null) updateSeverity(PHPBadStyleUppercaseIdentifierWarning, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportMethodWithConstructorName)) != null) updateSeverity(MethodWithConstructorName, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportOverridingPackageDefaultMethod)) != null) updateSeverity(OverriddenPackageDefaultMethod, optionValue); @@ -574,6 +583,8 @@ public class CompilerOptions implements ProblemReasons, ProblemSeverities, ICons StringBuffer buf = new StringBuffer("CompilerOptions:"); //$NON-NLS-1$ buf.append("\n\t- var is deprecated keyword: ").append(getSeverityString(PHPVarDeprecatedWarning)); //$NON-NLS-1$ + buf.append("\n\t- don't use keywords as identifiers: ").append(getSeverityString(PHPBadStyleKeywordWarning)); //$NON-NLS-1$ + buf.append("\n\t- non-variable idenifiers should contain only uppercase characters: ").append(getSeverityString(PHPBadStyleUppercaseIdentifierWarning)); //$NON-NLS-1$ buf.append("\n\t- local variables debug attributes: ").append((this.produceDebugAttributes & Vars) != 0 ? "ON" : " OFF"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ buf.append("\n\t- line number debug attributes: ").append((this.produceDebugAttributes & Lines) != 0 ? "ON" : " OFF"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 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 137bf14..e7491b1 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 @@ -1258,7 +1258,7 @@ public class Parser //extends PHPParserSuperclass // '(' parameter_list ')' method_body initializeModifiers(); int declarationSourceStart = scanner.getCurrentTokenStartPosition(); - ; + if (token == TokenNamevar) { checkAndSetModifiers(AccPublic); problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), @@ -1477,9 +1477,10 @@ public class Parser //extends PHPParserSuperclass if (Scanner.isIdentifierOrKeyword(token)) { methodDecl.selector = scanner.getCurrentIdentifierSource(); if (token > TokenNameKEYWORD) { - reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].", - scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition()); -// throwSyntaxError("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "]."); + problemReporter.phpKeywordWarning(new String[]{scanner.toStringAction(token)}, scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), + referenceContext, compilationUnit.compilationResult); +// reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].", +// scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition()); } getNextToken(); if (token == TokenNameLPAREN) { @@ -1488,7 +1489,7 @@ public class Parser //extends PHPParserSuperclass throwSyntaxError("'(' expected in function declaration."); } if (token != TokenNameRPAREN) { - parameter_list(); + parameter_list(); } if (token != TokenNameRPAREN) { throwSyntaxError("')' expected in function declaration."); @@ -2461,14 +2462,21 @@ public class Parser //extends PHPParserSuperclass //| class_constant '(' function_call_parameter_list ')' //| static_member '(' function_call_parameter_list ')' //| variable_without_objects '(' function_call_parameter_list ')' + char[] defineName = null; + int startPos=0; + int endPos=0; if (Scanner.TRACE) { System.out.println("TRACE: function_call()"); } if (token == TokenNameIdentifier) { + defineName = scanner.getCurrentIdentifierSource(); + startPos = scanner.getCurrentTokenStartPosition(); + endPos = scanner.getCurrentTokenEndPosition(); getNextToken(); switch (token) { case TokenNamePAAMAYIM_NEKUDOTAYIM : // static member: + defineName = null; getNextToken(); if (token == TokenNameIdentifier) { // class _constant @@ -2483,6 +2491,45 @@ public class Parser //extends PHPParserSuperclass variable_without_objects(); } if (token != TokenNameLPAREN) { + if (defineName!=null) { + // does this identifier contain only uppercase characters? + if (defineName.length==3) { + if (defineName[0]=='d' && + defineName[1]=='i' && + defineName[2]=='e' ) { + defineName=null; + } + } else if (defineName.length==4) { + if (defineName[0]=='t' && + defineName[1]=='r' && + defineName[2]=='u' && + defineName[3]=='e' ) { + defineName=null; + } else if (defineName[0]=='n' && + defineName[1]=='u' && + defineName[2]=='l' && + defineName[3]=='l' ) { + defineName=null; + } + } else if (defineName.length==5) { + if (defineName[0]=='f' && + defineName[1]=='a' && + defineName[2]=='l' && + defineName[3]=='s' && + defineName[4]=='e' ) { + defineName=null; + } + } + if (defineName!=null) { + for (int i=0; i 0) { - String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot() - .getLocation().toString(); +// String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot() +// .getLocation().toString(); + + String workspaceLocation = fProject.getLocation().toString()+File.separatorChar; // TODO show all entries of the list in a dialog box // at the moment always the first entry will be opened if (locationsList.size() > 1) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java index 03810ee..6772af2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java @@ -343,7 +343,7 @@ public class IdentifierIndexManager { // InputStream iStream; LineCreator lineCreator = createLineCreator(); try { - addInputStream(new BufferedInputStream(fileToParse.getContents()), fileToParse.getFullPath().toString(), lineCreator); + addInputStream(new BufferedInputStream(fileToParse.getContents()), fileToParse.getProjectRelativePath().toString(), lineCreator); } catch (CoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); -- 1.7.1