Improved xml scanner for this bug
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / ui / text / JavaTextTools.java
1 package net.sourceforge.phpdt.ui.text;
2
3 /*
4  * (c) Copyright IBM Corp. 2000, 2001.
5  * All Rights Reserved.
6  */
7
8 import net.sourceforge.phpdt.internal.ui.text.FastJavaPartitionScanner;
9 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
10 import net.sourceforge.phpdt.internal.ui.text.JavaColorManager;
11 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
12 import net.sourceforge.phpeclipse.IPreferenceConstants;
13 import net.sourceforge.phpeclipse.phpeditor.php.HTMLPartitionScanner;
14 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
15 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
16 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
17 import net.sourceforge.phpeclipse.phpeditor.php.SmartyCodeScanner;
18 import net.sourceforge.phpeclipse.phpeditor.php.SmartyDocCodeScanner;
19 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
20 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
21 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
22
23 import org.eclipse.core.runtime.Preferences;
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.text.IDocument;
26 import org.eclipse.jface.text.IDocumentExtension3;
27 import org.eclipse.jface.text.IDocumentPartitioner;
28 import org.eclipse.jface.text.rules.DefaultPartitioner;
29 import org.eclipse.jface.text.rules.RuleBasedScanner;
30 import org.eclipse.jface.util.IPropertyChangeListener;
31 import org.eclipse.jface.util.PropertyChangeEvent;
32
33 //
34 //import org.phpeclipse.phpdt.internal.ui.text.FastJavaPartitionScanner;
35 //import org.phpeclipse.phpdt.internal.ui.text.JavaColorManager;
36 //import org.phpeclipse.phpdt.internal.ui.text.JavaPartitionScanner;
37 //import org.phpeclipse.phpdt.internal.ui.text.SingleTokenJavaScanner;
38 //import org.phpeclipse.phpdt.internal.ui.text.php.JavaCodeScanner;
39 //import org.phpeclipse.phpdt.internal.ui.text.phpdoc.JavaDocScanner;
40
41 /**
42  * Tools required to configure a Java text viewer. The color manager and all scanner exist only one time, i.e. the same instances
43  * are returned to all clients. Thus, clients share those tools.
44  * <p>
45  * This class may be instantiated; it is not intended to be subclassed.
46  * </p>
47  */
48 public class JavaTextTools implements IPHPPartitions {
49   //  private static final String[] TOKENS = {
50   //  JSPScriptScanner.JSP_DEFAULT,
51   //  JSPScriptScanner.JSP_BRACKET };
52   private final static String[] LEGAL_CONTENT_TYPES = new String[] {
53       PHP_PHPDOC_COMMENT,
54       PHP_MULTILINE_COMMENT,
55       PHP_SINGLELINE_COMMENT,
56       PHP_STRING_DQ,
57       PHP_STRING_SQ };
58
59   private static XMLPartitionScanner HTML_PARTITION_SCANNER = null;
60
61   private static FastJavaPartitionScanner PHP_PARTITION_SCANNER = null;
62
63   private static HTMLPartitionScanner SMARTY_PARTITION_SCANNER = null;
64
65   private static XMLPartitionScanner XML_PARTITION_SCANNER = null;
66
67   // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
68   // PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
69   //  private final static String[] TYPES = new String[] {
70   //      IPHPPartitions.PHP_PARTITIONING,
71   //      IPHPPartitions.PHP_PHPDOC_COMMENT,
72   //  // IPHPPartitions.HTML,
73   //      // IPHPPartitions.HTML_MULTILINE_COMMENT,
74   //      IPHPPartitions.JAVASCRIPT,
75   //      IPHPPartitions.CSS,
76   //      IPHPPartitions.SMARTY,
77   //      IPHPPartitions.SMARTY_MULTILINE_COMMENT };
78
79   /**
80    * This tools' preference listener.
81    */
82   private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
83     public void propertyChange(PropertyChangeEvent event) {
84       adaptToPreferenceChange(event);
85     }
86
87     public void propertyChange(Preferences.PropertyChangeEvent event) {
88       adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event
89           .getNewValue()));
90     }
91   };
92
93   //  /** The color manager */
94   private JavaColorManager colorManager;
95
96   /** The PHP source code scanner */
97   private PHPCodeScanner fCodeScanner;
98
99   /** The PHP multiline comment scanner */
100   private SingleTokenPHPScanner fMultilineCommentScanner;
101
102   /** The Java singleline comment scanner */
103   private SingleTokenPHPScanner fSinglelineCommentScanner;
104
105   /** The PHP double quoted string scanner */
106 //  private SingleTokenPHPScanner fStringDQScanner;
107
108   /** The PHP single quoted string scanner */
109 //  private SingleTokenPHPScanner fStringSQScanner;
110   
111   /** The PHPDoc scanner */
112   private PHPDocCodeScanner fPHPDocScanner;
113
114   /** The HTML scanner */
115   //  private HTMLCodeScanner fHTMLScanner;
116   /** The Smarty scanner */
117   private SmartyCodeScanner fSmartyScanner;
118
119   /** The SmartyDoc scanner */
120   private SmartyDocCodeScanner fSmartyDocScanner;
121
122   /** The Java partitions scanner. */
123   private FastJavaPartitionScanner fPartitionScanner;
124
125   /** The preference store */
126   private IPreferenceStore fPreferenceStore;
127
128   /** The XML Language text tools */
129   private XMLTextTools xmlTextTools;
130
131   /**
132    * The core preference store.
133    * 
134    * @since 2.1
135    */
136   private Preferences fCorePreferenceStore;
137
138   /** The preference change listener */
139   private PreferenceListener fPreferenceListener = new PreferenceListener();
140
141   /** The JSP partitions scanner */
142   private PHPPartitionScanner jspPartitionScanner = null;
143
144   /** The JSP script subpartitions scanner */
145   //  private JSPScriptScanner jspScriptScanner;
146   /** The PHP plain text scanner */
147   //  private RuleBasedScanner jspTextScanner;
148   /** The PHP brackets scanner */
149   //  private RuleBasedScanner jspBracketScanner;
150   /**
151    * Creates a new Java text tools collection.
152    * 
153    * @param store
154    *          the preference store to initialize the text tools. The text tool instance installs a listener on the passed preference
155    *          store to adapt itself to changes in the preference store. In general <code>PreferenceConstants.
156    *                    getPreferenceStore()</code>
157    *          should be used to initialize the text tools.
158    * @param coreStore
159    *          optional preference store to initialize the text tools. The text tool instance installs a listener on the passed
160    *          preference store to adapt itself to changes in the preference store.
161    * @see net.sourceforge.phpdt.ui.PreferenceConstants#getPreferenceStore()
162    * @since 2.1
163    */
164   public JavaTextTools(IPreferenceStore store, Preferences coreStore) {
165     this(store, coreStore, true);
166   }
167
168   /**
169    * Creates a new Java text tools collection.
170    * 
171    * @param store
172    *          the preference store to initialize the text tools. The text tool instance installs a listener on the passed preference
173    *          store to adapt itself to changes in the preference store. In general <code>PreferenceConstants.
174    *                    getPreferenceStore()</code>
175    *          shoould be used to initialize the text tools.
176    * @param coreStore
177    *          optional preference store to initialize the text tools. The text tool instance installs a listener on the passed
178    *          preference store to adapt itself to changes in the preference store.
179    * @param autoDisposeOnDisplayDispose
180    *          if <code>true</code> the color manager automatically disposes all managed colors when the current display gets
181    *          disposed and all calls to {@link org.eclipse.jface.text.source.ISharedTextColors#dispose()}are ignored.
182    * @see net.sourceforge.phpdt.ui.PreferenceConstants#getPreferenceStore()
183    * @since 2.1
184    */
185   public JavaTextTools(IPreferenceStore store, Preferences coreStore, boolean autoDisposeOnDisplayDispose) {
186     //    super(store, TOKENS, );
187     //  REVISIT: preference store
188     xmlTextTools = new XMLTextTools(XMLPlugin.getDefault().getPreferenceStore());
189
190     colorManager = new JavaColorManager(autoDisposeOnDisplayDispose);
191     fPreferenceStore = store;
192     fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
193
194     fCorePreferenceStore = coreStore;
195     if (fCorePreferenceStore != null)
196       fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
197
198     fCodeScanner = new PHPCodeScanner((JavaColorManager) colorManager, store);
199     fMultilineCommentScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store,
200         IPreferenceConstants.PHP_MULTILINE_COMMENT);
201     fSinglelineCommentScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store,
202         IPreferenceConstants.PHP_SINGLELINE_COMMENT);
203 //    fStringDQScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
204 //    fStringSQScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
205     
206     fPHPDocScanner = new PHPDocCodeScanner((JavaColorManager) colorManager, store);
207     //    fHTMLScanner = new HTMLCodeScanner((JavaColorManager)fColorManager, store);
208     fSmartyScanner = new SmartyCodeScanner((JavaColorManager) colorManager, store);
209     fSmartyDocScanner = new SmartyDocCodeScanner((JavaColorManager) colorManager, store);
210
211     fPartitionScanner = new FastJavaPartitionScanner();
212
213     //    jspScriptScanner = new JSPScriptScanner();
214     //  fPartitionScanner = new FastJavaPartitionScanner();
215     //    fPartitionScanner = new PHPPartitionScanner();
216
217     //    jspBracketScanner = new RuleBasedScanner();
218     //    jspBracketScanner.setDefaultReturnToken(new Token(JSPScriptScanner.JSP_BRACKET));
219     //    jspTextScanner = new RuleBasedScanner();
220     //    jspTextScanner.setDefaultReturnToken(new Token(JSPScriptScanner.JSP_DEFAULT));
221   }
222
223   /**
224    *  
225    */
226   public XMLTextTools getXMLTextTools() {
227     return xmlTextTools;
228   }
229
230   /**
231    * Disposes all the individual tools of this tools collection.
232    */
233   public void dispose() {
234
235     fCodeScanner = null;
236     fMultilineCommentScanner = null;
237     fSinglelineCommentScanner = null;
238 //    fStringDQScanner = null;
239 //    fStringSQScanner = null;
240     fPHPDocScanner = null;
241     //    fPartitionScanner = null;
242
243     if (colorManager != null) {
244       colorManager.dispose();
245       colorManager = null;
246     }
247
248     if (fPreferenceStore != null) {
249       fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
250       fPreferenceStore = null;
251
252       if (fCorePreferenceStore != null) {
253         fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
254         fCorePreferenceStore = null;
255       }
256
257       fPreferenceListener = null;
258     }
259   }
260
261   /**
262    * Returns the color manager which is used to manage any Java-specific colors needed for such things like syntax highlighting.
263    * 
264    * @return the color manager to be used for Java text viewers
265    */
266   public JavaColorManager getColorManager() {
267     return (JavaColorManager) colorManager;
268   }
269
270   /**
271    * Returns a scanner which is configured to scan Java source code.
272    * 
273    * @return a Java source code scanner
274    */
275   public RuleBasedScanner getCodeScanner() {
276     return fCodeScanner;
277   }
278
279   /**
280    * Returns a scanner which is configured to scan Java multiline comments.
281    * 
282    * @return a Java multiline comment scanner
283    * 
284    * @since 2.0
285    */
286   public RuleBasedScanner getMultilineCommentScanner() {
287     return fMultilineCommentScanner;
288   }
289
290   /**
291    * Returns a scanner which is configured to scan HTML code.
292    * 
293    * @return a HTML scanner
294    * 
295    * @since 2.0
296    */
297   //  public RuleBasedScanner getHTMLScanner() {
298   //    return fHTMLScanner;
299   //  }
300   /**
301    * Returns a scanner which is configured to scan Smarty code.
302    * 
303    * @return a Smarty scanner
304    * 
305    * @since 2.0
306    */
307   public RuleBasedScanner getSmartyScanner() {
308     return fSmartyScanner;
309   }
310
311   /**
312    * Returns a scanner which is configured to scan Smarty code.
313    * 
314    * @return a Smarty scanner
315    * 
316    * @since 2.0
317    */
318   public RuleBasedScanner getSmartyDocScanner() {
319     return fSmartyDocScanner;
320   }
321
322   /**
323    * Returns a scanner which is configured to scan Java singleline comments.
324    * 
325    * @return a Java singleline comment scanner
326    * 
327    * @since 2.0
328    */
329   public RuleBasedScanner getSinglelineCommentScanner() {
330     return fSinglelineCommentScanner;
331   }
332
333   /**
334    * Returns a scanner which is configured to scan Java strings.
335    * 
336    * @return a Java string scanner
337    * 
338    * @since 2.0
339    */
340 //  public RuleBasedScanner getStringScanner() {
341 //    return fStringDQScanner;
342 //  }
343
344   /**
345    * Returns a scanner which is configured to scan JavaDoc compliant comments. Notes that the start sequence "/**" and the
346    * corresponding end sequence are part of the JavaDoc comment.
347    * 
348    * @return a JavaDoc scanner
349    */
350   public RuleBasedScanner getJavaDocScanner() {
351     return fPHPDocScanner;
352   }
353
354   /**
355    * Returns a scanner which is configured to scan Java-specific partitions, which are multi-line comments, JavaDoc comments, and
356    * regular Java source code.
357    * 
358    * @return a Java partition scanner
359    */
360   //  public IPartitionTokenScanner getPartitionScanner() {
361   //    return fPartitionScanner;
362   //  }
363   /**
364    * Factory method for creating a PHP-specific document partitioner using this object's partitions scanner. This method is a
365    * convenience method.
366    * 
367    * @return a newly created Java document partitioner
368    */
369   public IDocumentPartitioner createDocumentPartitioner() {
370     return createDocumentPartitioner(".php");
371   }
372
373   /**
374    * Factory method for creating a PHP-specific document partitioner using this object's partitions scanner. This method is a
375    * convenience method.
376    * 
377    * @return a newly created Java document partitioner
378    */
379   public IDocumentPartitioner createDocumentPartitioner(String extension) {
380
381     //    String[] types =
382     //      new String[] {
383     //        FastJavaPartitionScanner.JAVA_DOC,
384     //        FastJavaPartitionScanner.JAVA_MULTI_LINE_COMMENT,
385     //        FastJavaPartitionScanner.JAVA_SINGLE_LINE_COMMENT,
386     //        FastJavaPartitionScanner.JAVA_STRING };
387     //
388     //    return new DefaultPartitioner(getPartitionScanner(), types);
389     IDocumentPartitioner partitioner = null;
390     //  System.out.println(extension);
391     if (extension.equalsIgnoreCase(".html") || extension.equalsIgnoreCase(".htm")) {
392       // html
393       partitioner = createHTMLPartitioner();
394       partitioner = createJSPPartitioner();
395     } else if (extension.equalsIgnoreCase(".xml")) {
396       // xml
397       partitioner = createXMLPartitioner();
398       //    } else if (extension.equalsIgnoreCase(".js")) {
399       //      // javascript
400       //      partitioner = createJavaScriptPartitioner();
401       //    } else if (extension.equalsIgnoreCase(".css")) {
402       //      // cascading style sheets
403       //      partitioner = createCSSPartitioner();
404     } else if (extension.equalsIgnoreCase(".tpl")) {
405       // smarty ?
406       partitioner = createSmartyPartitioner();
407       //    } else if (extension.equalsIgnoreCase(".inc")) {
408       //      // php include files ?
409       //      partitioner = createIncludePartitioner();
410     }
411
412     if (partitioner == null) {
413       partitioner = createJSPPartitioner();
414     }
415
416     return partitioner;
417   }
418
419   /**
420    * Sets up the Java document partitioner for the given document for the given partitioning.
421    * 
422    * @param document
423    *          the document to be set up
424    * @param partitioning
425    *          the document partitioning
426    * @param element
427    *          TODO
428    * 
429    * @since 3.0
430    */
431   //  public void setupJavaDocumentPartitioner(IDocument document, String partitioning, Object element) {
432   //    IDocumentPartitioner partitioner = createDocumentPartitioner(".php");
433   //
434   //    // if (document instanceof IDocumentExtension3) {
435   //    // IDocumentExtension3 extension3= (IDocumentExtension3) document;
436   //    // extension3.setDocumentPartitioner(partitioning, partitioner);
437   //    // } else {
438   //    document.setDocumentPartitioner(partitioner);
439   //    // }
440   //    partitioner.connect(document);
441   //  }
442   public void setupHTMLDocumentPartitioner(IDocument document, String partitioning, Object element) {
443     IDocumentPartitioner partitioner = createDocumentPartitioner(".html");
444
445     //          if (document instanceof IDocumentExtension3) {
446     //                  IDocumentExtension3 extension3= (IDocumentExtension3) document;
447     //                  extension3.setDocumentPartitioner(partitioning, partitioner);
448     //          } else {
449     document.setDocumentPartitioner(partitioner);
450     //          }
451     partitioner.connect(document);
452   }
453
454   public void setupSmartyDocumentPartitioner(IDocument document, String partitioning, Object element) {
455     IDocumentPartitioner partitioner = createDocumentPartitioner(".tpl");
456
457     //          if (document instanceof IDocumentExtension3) {
458     //                  IDocumentExtension3 extension3= (IDocumentExtension3) document;
459     //                  extension3.setDocumentPartitioner(partitioning, partitioner);
460     //          } else {
461     document.setDocumentPartitioner(partitioner);
462     //          }
463     partitioner.connect(document);
464   }
465
466   /**
467    * Returns the names of the document position categories used by the document partitioners created by this object to manage their
468    * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
469    * 
470    * @return the partition managing position categories or <code>null</code> if there is none
471    */
472   public String[] getPartitionManagingPositionCategories() {
473     return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
474   }
475
476   /**
477    * Determines whether the preference change encoded by the given event changes the behavior of one its contained components.
478    * 
479    * @param event
480    *          the event to be investigated
481    * @return <code>true</code> if event causes a behavioral change
482    * @since 2.0
483    * @deprecated As of 3.0, replaced by
484    *             {@link net.sourceforge.phpdt.ui.text.JavaSourceViewerConfiguration#affectsTextPresentation(PropertyChangeEvent)}
485    */
486   //  public boolean affectsBehavior(PropertyChangeEvent event) {
487   //    return fCodeScanner.affectsBehavior(event)
488   //        || fMultilineCommentScanner.affectsBehavior(event)
489   //        || fSinglelineCommentScanner.affectsBehavior(event)
490   //        || fStringDQScanner.affectsBehavior(event)
491   //        || fPHPDocScanner.affectsBehavior(event);
492   //  }
493   /**
494    * Adapts the behavior of the contained components to the change encoded in the given event.
495    * 
496    * @param event
497    *          the event to which to adapt
498    * @since 2.0
499    */
500   protected void adaptToPreferenceChange(PropertyChangeEvent event) {
501     if (fCodeScanner.affectsBehavior(event))
502       fCodeScanner.adaptToPreferenceChange(event);
503     if (fMultilineCommentScanner.affectsBehavior(event))
504       fMultilineCommentScanner.adaptToPreferenceChange(event);
505     if (fSinglelineCommentScanner.affectsBehavior(event))
506       fSinglelineCommentScanner.adaptToPreferenceChange(event);
507     //    if (fStringDQScanner.affectsBehavior(event))
508     //      fStringDQScanner.adaptToPreferenceChange(event);
509     if (fPHPDocScanner.affectsBehavior(event))
510       fPHPDocScanner.adaptToPreferenceChange(event);
511     //    if (fHTMLScanner.affectsBehavior(event))
512     //      fHTMLScanner.adaptToPreferenceChange(event);
513     if (fSmartyScanner.affectsBehavior(event))
514       fSmartyScanner.adaptToPreferenceChange(event);
515     if (fSmartyDocScanner.affectsBehavior(event))
516       fSmartyDocScanner.adaptToPreferenceChange(event);
517     //    if (XMLPlugin.getDefault().getXMLTextTools().affectsBehavior(event)) {
518     //      XMLPlugin.getDefault().getXMLTextTools().adaptToPreferenceChange(event);
519     //    }
520   }
521
522   /**
523    * Return a partitioner for .html files.
524    */
525   public IDocumentPartitioner createHTMLPartitioner() {
526     //    return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
527     return xmlTextTools.createXMLPartitioner();
528   }
529
530   //  private static IDocumentPartitioner createIncludePartitioner() {
531   //    // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
532   //    return new DefaultPartitioner(getPHPPartitionScanner(), FastJavaPartitionScanner.PHP_PARTITION_TYPES);
533   //
534   //  }
535
536   //  private static IDocumentPartitioner createJavaScriptPartitioner() {
537   //    return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
538   //  }
539
540   /**
541    * Return a partitioner for .php files.
542    */
543   public IDocumentPartitioner createPHPPartitioner() {
544     //    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
545     return new DefaultPartitioner(getPHPPartitionScanner(), LEGAL_CONTENT_TYPES);
546   }
547
548   private IDocumentPartitioner createJSPPartitioner() {
549     return new PHPDocumentPartitioner(getJSPPartitionScanner(), getPHPPartitionScanner());
550     //    return new JSPDocumentPartitioner(getJSPPartitionScanner(), jspScriptScanner);
551   }
552
553   /**
554    *  
555    */
556   //  public IPartitionTokenScanner getJSPScriptScanner() {
557   //    return jspScriptScanner;
558   //  }
559   private IDocumentPartitioner createSmartyPartitioner() {
560     return new DefaultPartitioner(getSmartyPartitionScanner(), XMLTextTools.TYPES);
561   }
562
563   private IDocumentPartitioner createXMLPartitioner() {
564     //    return new DefaultPartitioner(getXMLPartitionScanner(), XMLTextTools.TYPES);
565     return xmlTextTools.createXMLPartitioner();
566   }
567
568   //  private IDocumentPartitioner createCSSPartitioner() {
569   //    return new DefaultPartitioner(getHTMLPartitionScanner(), XMLTextTools.TYPES);
570   //  }
571
572   /**
573    * Return a scanner for creating html partitions.
574    */
575   //  private static XMLPartitionScanner getHTMLPartitionScanner() {
576   //    // if (HTML_PARTITION_SCANNER == null)
577   //    // HTML_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.HTML_FILE);
578   //    // return HTML_PARTITION_SCANNER;^
579   //    if (HTML_PARTITION_SCANNER == null)
580   //      HTML_PARTITION_SCANNER = new XMLPartitionScanner(false);
581   //    return HTML_PARTITION_SCANNER;
582   //  }
583   /**
584    * Return a scanner for creating php partitions.
585    */
586   private FastJavaPartitionScanner getPHPPartitionScanner() {
587     //    if (PHP_PARTITION_SCANNER == null)
588     //      PHP_PARTITION_SCANNER = new FastJavaPartitionScanner(); //new PHPPartitionScanner(IPHPPartitions.PHP_FILE);
589     //    return PHP_PARTITION_SCANNER;
590     return fPartitionScanner;
591   }
592
593   /**
594    * Returns a scanner which is configured to scan plain text in JSP.
595    * 
596    * @return a JSP text scanner
597    */
598   //  public RuleBasedScanner getJSPTextScanner() {
599   //    return jspTextScanner;
600   //  }
601   /**
602    * Returns a scanner which is configured to scan plain text in JSP.
603    * 
604    * @return a JSP text scanner
605    */
606   //  public RuleBasedScanner getJSPBracketScanner() {
607   //    return jspBracketScanner;
608   //  }
609   /**
610    * Return a scanner for creating smarty partitions.
611    */
612   private static HTMLPartitionScanner getSmartyPartitionScanner() {
613     if (SMARTY_PARTITION_SCANNER == null)
614       SMARTY_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.SMARTY_FILE);
615     return SMARTY_PARTITION_SCANNER;
616   }
617
618   /**
619    * Return a scanner for creating xml partitions.
620    */
621 //  private static XMLPartitionScanner getXMLPartitionScanner() {
622 //    //    if (XML_PARTITION_SCANNER == null)
623 //    //      XML_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.XML_FILE);
624 //    //    return XML_PARTITION_SCANNER;
625 //    if (XML_PARTITION_SCANNER == null)
626 //      XML_PARTITION_SCANNER = new XMLPartitionScanner(false);
627 //    return XML_PARTITION_SCANNER;
628 //  }
629
630   private PHPPartitionScanner getJSPPartitionScanner() {
631     if (jspPartitionScanner == null)
632       jspPartitionScanner = new PHPPartitionScanner();
633     return jspPartitionScanner;
634   }
635
636   /**
637    * Sets up the Java document partitioner for the given document for the default partitioning.
638    * 
639    * @param document
640    *          the document to be set up
641    * @since 3.0
642    */
643   public void setupJavaDocumentPartitioner(IDocument document) {
644     setupJavaDocumentPartitioner(document, IDocumentExtension3.DEFAULT_PARTITIONING);
645   }
646
647   /**
648    * Sets up the Java document partitioner for the given document for the given partitioning.
649    * 
650    * @param document
651    *          the document to be set up
652    * @param partitioning
653    *          the document partitioning
654    * @since 3.0
655    */
656   public void setupJavaDocumentPartitioner(IDocument document, String partitioning) {
657     IDocumentPartitioner partitioner = createDocumentPartitioner();
658     if (document instanceof IDocumentExtension3) {
659       IDocumentExtension3 extension3 = (IDocumentExtension3) document;
660       extension3.setDocumentPartitioner(partitioning, partitioner);
661     } else {
662       document.setDocumentPartitioner(partitioner);
663     }
664     partitioner.connect(document);
665   }
666
667   /**
668    * Returns this text tool's preference store.
669    * 
670    * @return the preference store
671    * @since 3.0
672    */
673   protected IPreferenceStore getPreferenceStore() {
674     return fPreferenceStore;
675   }
676
677   /**
678    * Returns this text tool's core preference store.
679    * 
680    * @return the core preference store
681    * @since 3.0
682    */
683   protected Preferences getCorePreferenceStore() {
684     return fCorePreferenceStore;
685   }
686 }