Bug 841370 - open declaration for projects wih external workspace
authorkhartlage <khartlage>
Fri, 16 Jul 2004 17:22:14 +0000 (17:22 +0000)
committerkhartlage <khartlage>
Fri, 16 Jul 2004 17:22:14 +0000 (17:22 +0000)
misc parser improvements

net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaCore.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IProblem.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/impl/CompilerOptions.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/ProblemReporter.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/problem/messages.properties
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/CompilerConfigurationBlock.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/PreferencesMessages.properties
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenDeclarationEditorAction.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java

index e47f5c4..9ae3318 100644 (file)
@@ -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);
 
index 5674266..d8be369 100644 (file)
@@ -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;
index c2e2a16..9149e3b 100644 (file)
@@ -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$
index 137bf14..e7491b1 100644 (file)
@@ -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<defineName.length;i++) {
+            if (Character.isLowerCase(defineName[i])) {  
+              problemReporter.phpUppercaseIdentifierWarning(startPos, endPos,
+                referenceContext, compilationUnit.compilationResult);
+              break;
+            }
+          }
+        }
+      }
       // TODO is this ok ?
       return;
       //      throwSyntaxError("'(' expected in function call.");
index c66a8c9..78baf7d 100644 (file)
@@ -376,7 +376,11 @@ public class ProblemReporter extends ProblemHandler implements ProblemReasons {
        switch(problemId){
            case IProblem.PHPVarDeprecatedWarning :
                  return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
-       
+           case IProblem.PHPBadStyleKeywordWarning :
+                 return this.options.getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
+           case IProblem.PHPBadStyleUppercaseIdentifierWarning :
+             return this.options.getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
+
                case IProblem.MaskedCatch : 
                        return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
 
@@ -2706,4 +2710,22 @@ public class ProblemReporter extends ProblemHandler implements ProblemReasons {
     this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[]{},
         problemStartPosition, problemEndPosition, context, compilationResult);
   }
+  
+  public void phpKeywordWarning(String[] messageArguments,
+      int problemStartPosition, int problemEndPosition,
+      ReferenceContext context, CompilationResult compilationResult) {
+    if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
+      return;
+    this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument, messageArguments,
+        problemStartPosition, problemEndPosition, context, compilationResult);
+  }
+  
+  public void phpUppercaseIdentifierWarning( 
+      int problemStartPosition, int problemEndPosition,
+      ReferenceContext context, CompilationResult compilationResult) {
+    if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
+      return;
+    this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument, new String[]{},
+        problemStartPosition, problemEndPosition, context, compilationResult);
+  }
 }
index 33b1294..03de9ae 100644 (file)
 211 = Parser error "{0}"
 212 = Parser warning "{0}"
 213 = Keyword 'var' is deprecated. Please use 'public' 'private' or 'protected' modifier for field declarations.
+214 = Bad style: don't use keyword "{0}" as an identifier.
+215 = Bad style: non-variable identifiers should contain only uppercase characters.
 
 220 = Unmatched bracket
 221 = The primitive type {0} of {1} does not have a field {2}
index 4dc5d04..684d617 100644 (file)
@@ -38,6 +38,8 @@ public class CompilerConfigurationBlock extends OptionsConfigurationBlock {
 
        // Preference store keys, see JavaCore.getOptions
     private static final String PREF_PB_PHP_VAR_DEPRECATED= JavaCore.COMPILER_PB_PHP_VAR_DEPRECATED;
+    private static final String PREF_PB_PHP_KEYWORD= JavaCore.COMPILER_PB_PHP_KEYWORD;
+    private static final String PREF_PB_PHP_UPPERCASE_IDENTIFIER= JavaCore.COMPILER_PB_PHP_UPPERCASE_IDENTIFIER;
        
 //     private static final String PREF_LOCAL_VARIABLE_ATTR=  JavaCore.COMPILER_LOCAL_VARIABLE_ATTR;
 //     private static final String PREF_LINE_NUMBER_ATTR= JavaCore.COMPILER_LINE_NUMBER_ATTR;
@@ -163,6 +165,8 @@ public class CompilerConfigurationBlock extends OptionsConfigurationBlock {
        
        private final static String[] KEYS= new String[] {
            PREF_PB_PHP_VAR_DEPRECATED,
+           PREF_PB_PHP_KEYWORD,
+           PREF_PB_PHP_UPPERCASE_IDENTIFIER,
 //             PREF_LOCAL_VARIABLE_ATTR, 
 //             PREF_LINE_NUMBER_ATTR, PREF_SOURCE_FILE_ATTR, PREF_CODEGEN_UNUSED_LOCAL,
 //             PREF_CODEGEN_TARGET_PLATFORM, 
@@ -299,7 +303,13 @@ public class CompilerConfigurationBlock extends OptionsConfigurationBlock {
 
                String label= PreferencesMessages.getString("CompilerConfigurationBlock.pb_var_deprecated.label"); //$NON-NLS-1$
                addComboBox(composite, label, PREF_PB_PHP_VAR_DEPRECATED, errorWarningIgnore, errorWarningIgnoreLabels, 0);                     
-
+               
+               label= PreferencesMessages.getString("CompilerConfigurationBlock.pb_keyword.label"); //$NON-NLS-1$
+               addComboBox(composite, label, PREF_PB_PHP_KEYWORD, errorWarningIgnore, errorWarningIgnoreLabels, 0);                    
+               
+               label= PreferencesMessages.getString("CompilerConfigurationBlock.pb_uppercase_identifier.label"); //$NON-NLS-1$
+               addComboBox(composite, label, PREF_PB_PHP_UPPERCASE_IDENTIFIER, errorWarningIgnore, errorWarningIgnoreLabels, 0);                       
+               
                label= PreferencesMessages.getString("CompilerConfigurationBlock.pb_overriding_pkg_dflt.label"); //$NON-NLS-1$
 //             addComboBox(composite, label, PREF_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD, errorWarningIgnore, errorWarningIgnoreLabels, 0);                      
 
index f645c57..3800019 100644 (file)
@@ -381,6 +381,8 @@ CompilerConfigurationBlock.compliance.group.label=JDK Compliance
 CompilerConfigurationBlock.classfiles.group.label=Classfile Generation
 
 CompilerConfigurationBlock.pb_var_deprecated.label=Keyword 'var' is deprecated:
+CompilerConfigurationBlock.pb_keyword.label=Don't use keyword as identifier:
+CompilerConfigurationBlock.pb_uppercase_identifier.label=Non-variable identifiers should contain only uppercase characters: 
 
 CompilerConfigurationBlock.pb_unreachable_code.label=&Unreachable code:
 CompilerConfigurationBlock.pb_invalid_import.label=Unresol&vable import statements:
index c4e5d76..43b848a 100644 (file)
@@ -8,8 +8,7 @@
  ******************************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.io.File;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
@@ -145,8 +144,10 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements
         List locationsList = indexManager.getLocations(word);
         if (locationsList != null && locationsList.size() > 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) {
index 03810ee..6772af2 100644 (file)
@@ -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();