fix for http://sourceforge.net/tracker/index.php?func=detail&aid=1431317&group_id...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / ui / text / PHPStringDQCodeScanner.java
index 943f0df..85dbb75 100644 (file)
@@ -30,55 +30,75 @@ import org.eclipse.jface.text.rules.WordRule;
  */
 public final class PHPStringDQCodeScanner extends AbstractJavaScanner {
 
-  private static String[] fgTokenProperties = { IPreferenceConstants.PHP_STRING_DQ, IPreferenceConstants.PHP_VARIABLE };
+  private static String[] fgTokenProperties = { IPreferenceConstants.PHP_STRING_DQ, IPreferenceConstants.PHP_VARIABLE, IPreferenceConstants.PHP_VARIABLE_DOLLAR};
 
   private class PHPWordRule extends WordRule {
-    private StringBuffer fBuffer = new StringBuffer();
-
-    public PHPWordRule(IWordDetector detector) {
-      super(detector, Token.UNDEFINED);
-    }
-
-    public PHPWordRule(IWordDetector detector, IToken defaultToken) {
-      super(detector, defaultToken);
-    }
-
-    public IToken evaluate(ICharacterScanner scanner) {
-      int c = scanner.read();
-
-      if (fDetector.isWordStart((char) c)) {
-        if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
-
-          fBuffer.setLength(0);
-          do {
-            fBuffer.append((char) c);
-            c = scanner.read();
-          } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
-          scanner.unread();
-
-          return getToken(IPreferenceConstants.PHP_VARIABLE);
-        }
-      }
-
-      scanner.unread();
-      return Token.UNDEFINED;
-    }
+       private StringBuffer fBuffer = new StringBuffer();
+
+       public PHPWordRule(IWordDetector detector) {
+         super(detector, Token.UNDEFINED);
+       }
+
+       public PHPWordRule(IWordDetector detector, IToken defaultToken) {
+         super(detector, defaultToken);
+       }
+
+       public IToken evaluate(ICharacterScanner scanner) {
+         int c = scanner.read();
+         boolean isUnderscore = false;
+         if (fDetector.isWordStart((char) c)) {
+               if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
+
+                 fBuffer.setLength(0);
+                 fBuffer.append((char) c);
+                 c = scanner.read();
+                 if (c=='_') {
+                         isUnderscore = true;
+                 }
+                 while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)) {
+                       fBuffer.append((char) c);
+                       c = scanner.read();
+                       // hack for coloring object elements with variable color instead of string color
+                       if (c=='-') {
+                               int c2=scanner.read();
+                               if (c2=='>') {
+                                       fBuffer.append(c);
+                                       fBuffer.append(c2);
+                                       c=scanner.read();
+                               }
+                               else {
+                                       scanner.unread();
+                               }
+                       }
+                       // hack end
+                 }
+                 scanner.unread();
+                 if (isUnderscore) {
+                         return getToken(IPreferenceConstants.PHP_VARIABLE_DOLLAR);
+                 }
+                 return getToken(IPreferenceConstants.PHP_VARIABLE);
+               }
+         }
+
+         scanner.unread();
+         return Token.UNDEFINED;
+       }
   }
 
   public PHPStringDQCodeScanner(IColorManager manager, IPreferenceStore store) {
-    super(manager, store);
-    initialize();
+       super(manager, store);
+       initialize();
   }
 
   public IDocument getDocument() {
-    return fDocument;
+       return fDocument;
   }
 
   /*
    * @see AbstractJavaScanner#getTokenProperties()
    */
   protected String[] getTokenProperties() {
-    return fgTokenProperties;
+       return fgTokenProperties;
   }
 
   /*
@@ -86,16 +106,16 @@ public final class PHPStringDQCodeScanner extends AbstractJavaScanner {
    */
   protected List createRules() {
 
-    List list = new ArrayList();
+       List list = new ArrayList();
 
-    // Add rule for tags.
-    Token token = getToken(IPreferenceConstants.PHP_STRING_DQ);
-    PHPWordRule wordRule = new PHPWordRule(new PHPVariableDetector(), token);
+       // Add rule for tags.
+       Token token = getToken(IPreferenceConstants.PHP_STRING_DQ);
+       PHPWordRule wordRule = new PHPWordRule(new PHPVariableDetector(), token);
 
-    list.add(wordRule);
+       list.add(wordRule);
 
-    setDefaultReturnToken(getToken(IPreferenceConstants.PHP_STRING_DQ));
-    return list;
+       setDefaultReturnToken(getToken(IPreferenceConstants.PHP_STRING_DQ));
+       return list;
   }
 }