improved syntax highlighting scanners and preferences
authorkhartlage <khartlage>
Sun, 11 Jul 2004 10:17:51 +0000 (10:17 +0000)
committerkhartlage <khartlage>
Sun, 11 Jul 2004 10:17:51 +0000 (10:17 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/AbstractImageBuilder.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BatchImageBuilder.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/IncrementalImageBuilder.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/PreferencesMessages.properties
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/JavaTextTools.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLCodeScanner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/SmartyCodeScanner.java

index f760a22..807d777 100644 (file)
@@ -247,16 +247,16 @@ protected void createErrorFor(IResource resource, String message) {
 //     newState.record(sourceLocator, qualifiedRefs, simpleRefs, mainTypeName, definedTypeNames);
 //}
 
-protected IContainer createFolder(IPath packagePath, IContainer outputFolder) throws CoreException {
-       if (packagePath.isEmpty()) return outputFolder;
-       IFolder folder = outputFolder.getFolder(packagePath);
-       if (!folder.exists()) {
-               createFolder(packagePath.removeLastSegments(1), outputFolder);
-               folder.create(true, true, null);
-               folder.setDerived(true);
-       }
-       return folder;
-}
+//protected IContainer createFolder(IPath packagePath, IContainer outputFolder) throws CoreException {
+//     if (packagePath.isEmpty()) return outputFolder;
+//     IFolder folder = outputFolder.getFolder(packagePath);
+//     if (!folder.exists()) {
+//             createFolder(packagePath.removeLastSegments(1), outputFolder);
+//             folder.create(true, true, null);
+//             folder.setDerived(true);
+//     }
+//     return folder;
+//}
 
 protected RuntimeException internalException(CoreException t) {
        ImageBuilderInternalException imageBuilderException = new ImageBuilderInternalException(t);
index aad863d..c924195 100644 (file)
@@ -205,7 +205,7 @@ protected void copyExtraResourcesBack(ClasspathMultiDirectory sourceLocation, fi
 
                                                IPath folderPath = resource.getFullPath();
                                                if (isAlsoProject && isExcludedFromProject(folderPath)) return false; // the sourceFolder == project
-                                               createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
+//                                             createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
                                }
                                return true;
                        }
@@ -233,7 +233,7 @@ protected void copyPackages(ClasspathMultiDirectory sourceLocation) throws CoreE
 
                                                IPath folderPath = resource.getFullPath();
                                                if (isAlsoProject && isExcludedFromProject(folderPath)) return false; // the sourceFolder == project
-                                               createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
+//                                             createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
                                }
                                return true;
                        }
index dc13acf..c738342 100644 (file)
@@ -414,7 +414,7 @@ public class IncrementalImageBuilder extends AbstractImageBuilder {
                     removedPackagePath).exists()) {
                   // only a package fragment was removed, same as removing
                   // multiple source files
-                  createFolder(removedPackagePath, md.binaryFolder); // ensure
+//                  createFolder(removedPackagePath, md.binaryFolder); // ensure
                   // package
                   // exists
                   // in the
@@ -556,7 +556,7 @@ public class IncrementalImageBuilder extends AbstractImageBuilder {
 //              }
               if (PHPBuilder.DEBUG)
                 System.out.println("Copying changed file " + resourcePath); //$NON-NLS-1$
-              createFolder(resourcePath.removeLastSegments(1), md.binaryFolder); // ensure
+            //  createFolder(resourcePath.removeLastSegments(1), md.binaryFolder); // ensure
               // package
               // exists
               // in
index 602acdc..f645c57 100644 (file)
@@ -684,9 +684,9 @@ JavaEditorPreferencePage.AnnotationDecoration.IBEAM=IBeam
 
 PHPEditorPreferencePage.multiLineComment=Multi-line comment
 PHPEditorPreferencePage.singleLineComment=Single-line comment
-PHPEditorPreferencePage.tags=PHP tags
+PHPEditorPreferencePage.tags=PHP/Smarty tags
 PHPEditorPreferencePage.keywords=Keywords
-PHPEditorPreferencePage.functionNames=Predefined function names
+PHPEditorPreferencePage.functionNames=Predefined function names 
 PHPEditorPreferencePage.variables=Variables
 PHPEditorPreferencePage.constants=Constants
 PHPEditorPreferencePage.types=Types
index 5c025c8..0d592a8 100644 (file)
@@ -47,7 +47,6 @@ import org.eclipse.ui.part.FileEditorInput;
 public class JavaTextTools {
 
   private static PHPPartitionScanner HTML_PARTITION_SCANNER = null;
-
   private static PHPPartitionScanner PHP_PARTITION_SCANNER = null;
   private static PHPPartitionScanner SMARTY_PARTITION_SCANNER = null;
 
@@ -119,23 +118,37 @@ public class JavaTextTools {
    * @see org.phpeclipse.phpdt.ui.PreferenceConstants#getPreferenceStore()
    * @since 2.0
    */
-  public JavaTextTools(IPreferenceStore store) {
-    fPreferenceStore = store;
-    fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
-
-    fColorManager = new JavaColorManager();
-    fCodeScanner = new PHPCodeScanner(fColorManager, store);
-    fMultilineCommentScanner = new SingleTokenPHPScanner(fColorManager, store, IPreferenceConstants.PHP_MULTILINE_COMMENT);
-    fSinglelineCommentScanner = new SingleTokenPHPScanner(fColorManager, store, IPreferenceConstants.PHP_SINGLELINE_COMMENT);
-    fStringScanner = new SingleTokenPHPScanner(fColorManager, store, IPreferenceConstants.PHP_STRING);
-    fPHPDocScanner = new PHPDocCodeScanner(fColorManager, store);
-    fHTMLScanner = new HTMLCodeScanner(fColorManager, store);
-    fSmartyScanner = new SmartyCodeScanner(fColorManager, store);
-    fSmartyDocScanner = new SmartyDocCodeScanner(fColorManager, store);
-//    fPartitionScanner = new FastJavaPartitionScanner();
-    fPartitionScanner = new PHPPartitionScanner();
-  }
-
+//  public JavaTextTools(IPreferenceStore store) {
+//    fPreferenceStore = store;
+//    fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
+//
+//    fColorManager = new JavaColorManager();
+//    fCodeScanner = new PHPCodeScanner(fColorManager, store);
+//    fMultilineCommentScanner = new SingleTokenPHPScanner(fColorManager, store, IPreferenceConstants.PHP_MULTILINE_COMMENT);
+//    fSinglelineCommentScanner = new SingleTokenPHPScanner(fColorManager, store, IPreferenceConstants.PHP_SINGLELINE_COMMENT);
+//    fStringScanner = new SingleTokenPHPScanner(fColorManager, store, IPreferenceConstants.PHP_STRING);
+//    fPHPDocScanner = new PHPDocCodeScanner(fColorManager, store);
+//    fHTMLScanner = new HTMLCodeScanner(fColorManager, store);
+//    fSmartyScanner = new SmartyCodeScanner(fColorManager, store);
+//    fSmartyDocScanner = new SmartyDocCodeScanner(fColorManager, store);
+////    fPartitionScanner = new FastJavaPartitionScanner();
+//    fPartitionScanner = new PHPPartitionScanner();
+//  }
+  /**
+        * Creates a new Java text tools collection.
+        * @param store the preference store to initialize the text tools. The text tool
+        *                      instance installs a listener on the passed preference store to adapt itself to 
+        *                      changes in the preference store. In general <code>PreferenceConstants.
+        *                      getPreferenceStore()</code> should be used to initialize the text tools.
+        * @param coreStore optional preference store to initialize the text tools. The text tool
+        *                      instance installs a listener on the passed preference store to adapt itself to 
+        *                      changes in the preference store.
+        * @see org.eclipse.jdt.ui.PreferenceConstants#getPreferenceStore()
+        * @since 2.1
+        */
+       public JavaTextTools(IPreferenceStore store, Preferences coreStore) {
+               this(store, coreStore, true);
+       }
   /**
    * Creates a new Java text tools collection.
    * 
@@ -161,6 +174,7 @@ public class JavaTextTools {
       fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
 
     fColorManager = new JavaColorManager(autoDisposeOnDisplayDispose);
+    
     fCodeScanner = new PHPCodeScanner(fColorManager, store);
     fMultilineCommentScanner = new SingleTokenPHPScanner(fColorManager, store, IPreferenceConstants.PHP_MULTILINE_COMMENT);
     fSinglelineCommentScanner = new SingleTokenPHPScanner(fColorManager, store, IPreferenceConstants.PHP_SINGLELINE_COMMENT);
@@ -463,6 +477,12 @@ public class JavaTextTools {
       fStringScanner.adaptToPreferenceChange(event);
     if (fPHPDocScanner.affectsBehavior(event))
       fPHPDocScanner.adaptToPreferenceChange(event);
+    if (fHTMLScanner.affectsBehavior(event))
+      fHTMLScanner.adaptToPreferenceChange(event);
+    if (fSmartyScanner.affectsBehavior(event))
+      fSmartyScanner.adaptToPreferenceChange(event);
+    if (fSmartyDocScanner.affectsBehavior(event))
+      fSmartyDocScanner.adaptToPreferenceChange(event);
   }
 
   /**
index 33497bd..0352e0c 100644 (file)
@@ -62,6 +62,7 @@ public interface IPreferenceConstants {
         * @since 3.0
         */
   public static final String PHP_OPERATOR = "__php_operator"; //$NON-NLS-1$
+  
   /**
         * A named preference that holds the color used to render operators and brackets.
         * <p>
index ebc134d..8ba1bbb 100644 (file)
@@ -606,12 +606,16 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements
     return fProblemMarkerManager;
   }
 
+//  public synchronized JavaTextTools getJavaTextTools() {
+//    if (fJavaTextTools == null)
+//      fJavaTextTools = new JavaTextTools(getPreferenceStore());
+//    return fJavaTextTools;
+//  }
   public synchronized JavaTextTools getJavaTextTools() {
-    if (fJavaTextTools == null)
-      fJavaTextTools = new JavaTextTools(getPreferenceStore());
-    return fJavaTextTools;
-  }
-
+       if (fJavaTextTools == null)
+               fJavaTextTools= new JavaTextTools(getPreferenceStore(), JavaCore.getPlugin().getPluginPreferences());
+       return fJavaTextTools;
+}
   public IFile getLastEditorFile() {
     return fLastEditorFile;
   }
index 450c3b4..7ff01e8 100644 (file)
@@ -14,7 +14,10 @@ package net.sourceforge.phpeclipse.phpeditor.php;
 import java.util.ArrayList;
 import java.util.List;
 
+import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
 import net.sourceforge.phpdt.internal.ui.text.JavaColorManager;
+import net.sourceforge.phpdt.ui.text.IColorManager;
+import net.sourceforge.phpeclipse.IPreferenceConstants;
 import net.sourceforge.phpeclipse.phpeditor.util.HTMLWordDetector;
 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
 import net.sourceforge.phpeclipse.phpeditor.util.PHPWhitespaceDetector;
@@ -25,7 +28,6 @@ import org.eclipse.jface.text.rules.ICharacterScanner;
 import org.eclipse.jface.text.rules.IRule;
 import org.eclipse.jface.text.rules.IToken;
 import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.RuleBasedScanner;
 import org.eclipse.jface.text.rules.SingleLineRule;
 import org.eclipse.jface.text.rules.Token;
 import org.eclipse.jface.text.rules.WhitespaceRule;
@@ -34,16 +36,35 @@ import org.eclipse.jface.text.rules.WordRule;
 /**
  * A HTML code scanner.
  */
-public class HTMLCodeScanner extends RuleBasedScanner {
-
-  private static String[] fgKeywords = {
-  };
-
-  private static String[] fgTypes = {
-  };
-
-  private IToken keyword;
-
+public class HTMLCodeScanner extends AbstractJavaScanner {
+
+//  private static String[] fgKeywords = {
+//  };
+//
+//  private static String[] fgTypes = {
+//  };
+
+//  private IToken keyword;
+  private static String[] fgTokenProperties =
+  {
+    IPreferenceConstants.PHP_MULTILINE_COMMENT,
+    IPreferenceConstants.PHP_SINGLELINE_COMMENT,
+         IPreferenceConstants.PHP_TAG,
+    IPreferenceConstants.PHP_KEYWORD,
+    IPreferenceConstants.PHP_FUNCTIONNAME,
+    IPreferenceConstants.PHP_VARIABLE,
+    IPreferenceConstants.PHP_STRING,
+    IPreferenceConstants.PHP_TYPE,
+    IPreferenceConstants.PHP_CONSTANT,
+    IPreferenceConstants.PHP_DEFAULT,
+    IPreferenceConstants.PHP_OPERATOR,
+    IPreferenceConstants.PHP_KEYWORD_RETURN};
+  /*
+   * @see AbstractJavaScanner#getTokenProperties()
+   */
+  protected String[] getTokenProperties() {
+    return fgTokenProperties;
+  }
   private class HTMLWordRule extends WordRule {
     private StringBuffer fBuffer = new StringBuffer();
 
@@ -80,7 +101,7 @@ public class HTMLCodeScanner extends RuleBasedScanner {
           scanner.unread();
 
           if (tagBegin) {
-            return keyword;
+            return getToken(IPreferenceConstants.PHP_KEYWORD);
           }
           IToken token = (IToken) fWords.get(fBuffer.toString());
           if (token != null)
@@ -109,46 +130,50 @@ public class HTMLCodeScanner extends RuleBasedScanner {
   /**
    * Creates a Java code scanner
    */
-  public HTMLCodeScanner(JavaColorManager provider, IPreferenceStore store) {
+  public HTMLCodeScanner(IColorManager manager, IPreferenceStore store) {
+    super(manager, store);
+    initialize();
+  }
+
+  /*
+   * @see AbstractJavaScanner#createRules()
+   */
+  protected List createRules() {
+    List rules = new ArrayList();
 
-    keyword = new Token(new TextAttribute(provider.getColor(PHPColorProvider.KEYWORD)));
-    IToken type = new Token(new TextAttribute(provider.getColor(PHPColorProvider.FUNCTION_NAME)));
-    IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING)));
-    IToken comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.SINGLE_LINE_COMMENT)));
-    IToken multi_comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)));
-    IToken other = new Token(new TextAttribute(provider.getColor(PHPColorProvider.DEFAULT)));
+//  keyword = new Token(new TextAttribute(provider.getColor(PHPColorProvider.KEYWORD)));
+//  IToken type = new Token(new TextAttribute(provider.getColor(PHPColorProvider.FUNCTION_NAME)));
+//    IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING)));
+//  IToken comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.SINGLE_LINE_COMMENT)));
+//  IToken multi_comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)));
+//    IToken other = new Token(new TextAttribute(provider.getColor(PHPColorProvider.DEFAULT)));
 
-    //variable = new Token(new TextAttribute(provider.getColor(PHPColorProvider.VARIABLE)));
+  //variable = new Token(new TextAttribute(provider.getColor(PHPColorProvider.VARIABLE)));
 
-    List rules = new ArrayList();
 
-    // Add rule for single line comments.
-    //rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
-    //rules.add(new EndOfLineRule("#", comment));
-
-    // Add rule for strings and character constants.
-    rules.add(new SingleLineRule("\"", "\"", string)); //$NON-NLS-2$ //$NON-NLS-1$
-    // rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-
-    // rules.add(new SingleLineRule("//", "//", php_comment));
-    // rules.add(new MultiLineRule("/*", "*/", multi_comment));
-
-    // Add generic whitespace rule.
-    rules.add(new WhitespaceRule(new PHPWhitespaceDetector()));
-
-    // Add word rule for keywords, types, and constants.
-    HTMLWordRule wordRule = new HTMLWordRule(new HTMLWordDetector(), other);
-    for (int i = 0; i < fgKeywords.length; i++)
-      wordRule.addWord(fgKeywords[i], keyword);
-    for (int i = 0; i < fgTypes.length; i++)
-      wordRule.addWord(fgTypes[i], type);
-    //   for (int i = 0; i < fgConstants.length; i++)
-    //     wordRule.addWord(fgConstants[i], type);
-    rules.add(wordRule);
-
-    IRule[] result = new IRule[rules.size()];
-    rules.toArray(result);
-    setRules(result);
-  }
+  // Add rule for single line comments.
+  //rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
+  //rules.add(new EndOfLineRule("#", comment));
 
+  // Add rule for strings and character constants.
+  rules.add(new SingleLineRule("\"", "\"", getToken(IPreferenceConstants.PHP_STRING))); //$NON-NLS-2$ //$NON-NLS-1$
+  // rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
+
+  // rules.add(new SingleLineRule("//", "//", php_comment));
+  // rules.add(new MultiLineRule("/*", "*/", multi_comment));
+
+  // Add generic whitespace rule.
+  rules.add(new WhitespaceRule(new PHPWhitespaceDetector()));
+
+  // Add word rule for keywords, types, and constants.
+  HTMLWordRule wordRule = new HTMLWordRule(new HTMLWordDetector(), getToken(IPreferenceConstants.PHP_DEFAULT));
+//  for (int i = 0; i < fgKeywords.length; i++)
+//    wordRule.addWord(fgKeywords[i], keyword);
+//  for (int i = 0; i < fgTypes.length; i++)
+//    wordRule.addWord(fgTypes[i], type);
+  rules.add(wordRule);
+  
+  setDefaultReturnToken(getToken(IPreferenceConstants.PHP_DEFAULT));
+return rules;
+  }
 }
index 1b74a75..9bf5601 100644 (file)
@@ -433,6 +433,7 @@ public class PHPCodeScanner extends AbstractJavaScanner {
        
     rules.add(wordRule);
     
+    setDefaultReturnToken(getToken(IPreferenceConstants.PHP_DEFAULT));
     return rules;
   }
 }
index 278e954..bb74616 100644 (file)
@@ -130,7 +130,7 @@ public class SmartyCodeScanner extends AbstractJavaScanner {
     {
       IPreferenceConstants.PHP_MULTILINE_COMMENT,
       IPreferenceConstants.PHP_SINGLELINE_COMMENT,
-                       IPreferenceConstants.PHP_TAG,
+         IPreferenceConstants.PHP_TAG,
       IPreferenceConstants.PHP_KEYWORD,
       IPreferenceConstants.PHP_FUNCTIONNAME,
       IPreferenceConstants.PHP_VARIABLE,
@@ -198,7 +198,7 @@ public class SmartyCodeScanner extends AbstractJavaScanner {
 //        wordRule.addWord(elbuffer.getName(), constant);
 //    }
     rules.add(wordRule);
-
+    setDefaultReturnToken(getToken(IPreferenceConstants.PHP_DEFAULT));
     return rules;
   }
 }