misc changes
[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.PHPeclipsePlugin;
14 import net.sourceforge.phpeclipse.phpeditor.php.HTMLPartitionScanner;
15 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
16 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
17 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
18 import net.sourceforge.phpeclipse.phpeditor.php.SmartyCodeScanner;
19 import net.sourceforge.phpeclipse.phpeditor.php.SmartyDocCodeScanner;
20 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
21 import net.sourceforge.phpeclipse.xml.ui.internal.text.SingleTokenScanner;
22 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
23 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
24
25 import org.eclipse.core.runtime.Preferences;
26 import org.eclipse.jface.preference.IPreferenceStore;
27 import org.eclipse.jface.text.IDocument;
28 import org.eclipse.jface.text.IDocumentExtension3;
29 import org.eclipse.jface.text.IDocumentPartitioner;
30 import org.eclipse.jface.text.rules.DefaultPartitioner;
31 import org.eclipse.jface.text.rules.IPartitionTokenScanner;
32 import org.eclipse.jface.text.rules.RuleBasedScanner;
33 import org.eclipse.jface.text.rules.Token;
34 import org.eclipse.jface.util.IPropertyChangeListener;
35 import org.eclipse.jface.util.PropertyChangeEvent;
36
37 //
38 //import org.phpeclipse.phpdt.internal.ui.text.FastJavaPartitionScanner;
39 //import org.phpeclipse.phpdt.internal.ui.text.JavaColorManager;
40 //import org.phpeclipse.phpdt.internal.ui.text.JavaPartitionScanner;
41 //import org.phpeclipse.phpdt.internal.ui.text.SingleTokenJavaScanner;
42 //import org.phpeclipse.phpdt.internal.ui.text.php.JavaCodeScanner;
43 //import org.phpeclipse.phpdt.internal.ui.text.phpdoc.JavaDocScanner;
44
45 /**
46  * Tools required to configure a Java text viewer. The color manager and all scanner exist only one time, i.e. the same instances
47  * are returned to all clients. Thus, clients share those tools.
48  * <p>
49  * This class may be instantiated; it is not intended to be subclassed.
50  * </p>
51  */
52 public class JavaTextTools implements IPHPPartitions {
53 //  private static final String[] TOKENS = { 
54 //  JSPScriptScanner.JSP_DEFAULT, 
55 //  JSPScriptScanner.JSP_BRACKET };
56   private final static String[] LEGAL_CONTENT_TYPES = new String[] { 
57           PHP_PHPDOC_COMMENT, 
58           PHP_MULTILINE_COMMENT,
59       PHP_SINGLELINE_COMMENT, 
60       PHP_STRING_DQ, 
61       PHP_STRING_SQ };
62   
63   private static XMLPartitionScanner HTML_PARTITION_SCANNER = null;
64
65   private static FastJavaPartitionScanner PHP_PARTITION_SCANNER = null;
66
67   private static HTMLPartitionScanner SMARTY_PARTITION_SCANNER = null;
68
69   private static XMLPartitionScanner XML_PARTITION_SCANNER = null;
70
71   // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
72   // PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
73 //  private final static String[] TYPES = new String[] { 
74 //      IPHPPartitions.PHP_PARTITIONING, 
75 //      IPHPPartitions.PHP_PHPDOC_COMMENT,
76 //  //      IPHPPartitions.HTML,
77 //      //      IPHPPartitions.HTML_MULTILINE_COMMENT,
78 //      IPHPPartitions.JAVASCRIPT, 
79 //      IPHPPartitions.CSS, 
80 //      IPHPPartitions.SMARTY, 
81 //      IPHPPartitions.SMARTY_MULTILINE_COMMENT };
82
83   /**
84    * This tools' preference listener.
85    */
86   private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
87     public void propertyChange(PropertyChangeEvent event) {
88       adaptToPreferenceChange(event);
89     }
90
91     public void propertyChange(Preferences.PropertyChangeEvent event) {
92       adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event
93           .getNewValue()));
94     }
95   };
96
97   //  /** The color manager */
98   private JavaColorManager colorManager;
99
100   /** The PHP source code scanner */
101   private PHPCodeScanner fCodeScanner;
102
103   /** The PHP multiline comment scanner */
104   private SingleTokenPHPScanner fMultilineCommentScanner;
105
106   /** The Java singleline comment scanner */
107   private SingleTokenPHPScanner fSinglelineCommentScanner;
108
109   /** The Java string scanner */
110   private SingleTokenPHPScanner fStringScanner;
111
112   /** The PHPDoc scanner */
113   private PHPDocCodeScanner fPHPDocScanner;
114
115   /** The HTML scanner */
116   //  private HTMLCodeScanner fHTMLScanner;
117   /** The Smarty scanner */
118   private SmartyCodeScanner fSmartyScanner;
119
120   /** The SmartyDoc scanner */
121   private SmartyDocCodeScanner fSmartyDocScanner;
122   
123   /** The Java partitions scanner. */
124   private FastJavaPartitionScanner fPartitionScanner;   
125   
126   /** The preference store */
127   private IPreferenceStore fPreferenceStore;
128   
129   /** The XML Language text tools */
130   private XMLTextTools xmlTextTools;
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
147   /** The PHP plain text scanner */
148 //  private RuleBasedScanner jspTextScanner;
149
150   /** The PHP brackets scanner */
151 //  private RuleBasedScanner jspBracketScanner;
152
153   /**
154    * Creates a new Java text tools collection.
155    * 
156    * @param store
157    *          the preference store to initialize the text tools. The text tool instance installs a listener on the passed preference
158    *          store to adapt itself to changes in the preference store. In general <code>PreferenceConstants.
159    *                    getPreferenceStore()</code>
160    *          should be used to initialize the text tools.
161    * @param coreStore
162    *          optional preference store to initialize the text tools. The text tool instance installs a listener on the passed
163    *          preference store to adapt itself to changes in the preference store.
164    * @see org.eclipse.jdt.ui.PreferenceConstants#getPreferenceStore()
165    * @since 2.1
166    */
167   public JavaTextTools(IPreferenceStore store, Preferences coreStore) {
168     this(store, coreStore, true);
169   }
170
171   /**
172    * Creates a new Java text tools collection.
173    * 
174    * @param store
175    *          the preference store to initialize the text tools. The text tool instance installs a listener on the passed preference
176    *          store to adapt itself to changes in the preference store. In general <code>PreferenceConstants.
177    *                    getPreferenceStore()</code>
178    *          shoould be used to initialize the text tools.
179    * @param coreStore
180    *          optional preference store to initialize the text tools. The text tool instance installs a listener on the passed
181    *          preference store to adapt itself to changes in the preference store.
182    * @param autoDisposeOnDisplayDispose
183    *          if <code>true</code> the color manager automatically disposes all managed colors when the current display gets
184    *          disposed and all calls to {@link org.eclipse.jface.text.source.ISharedTextColors#dispose()}are ignored.
185    * @see org.eclipse.jdt.ui.PreferenceConstants#getPreferenceStore()
186    * @since 2.1
187    */
188   public JavaTextTools(IPreferenceStore store, Preferences coreStore, boolean autoDisposeOnDisplayDispose) {
189     //    super(store, TOKENS, );
190 //  REVISIT: preference store
191         xmlTextTools = new XMLTextTools(
192                 XMLPlugin.getDefault().getPreferenceStore());
193         
194     colorManager = new JavaColorManager(autoDisposeOnDisplayDispose);
195     fPreferenceStore = store;
196     fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
197
198     fCorePreferenceStore = coreStore;
199     if (fCorePreferenceStore != null)
200       fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
201
202     fCodeScanner = new PHPCodeScanner((JavaColorManager) colorManager, store);
203     fMultilineCommentScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store,
204         IPreferenceConstants.PHP_MULTILINE_COMMENT);
205     fSinglelineCommentScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store,
206         IPreferenceConstants.PHP_SINGLELINE_COMMENT);
207     fStringScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
208     fPHPDocScanner = new PHPDocCodeScanner((JavaColorManager) colorManager, store);
209     //    fHTMLScanner = new HTMLCodeScanner((JavaColorManager)fColorManager, store);
210     fSmartyScanner = new SmartyCodeScanner((JavaColorManager) colorManager, store);
211     fSmartyDocScanner = new SmartyDocCodeScanner((JavaColorManager) colorManager, store);
212
213     fPartitionScanner= new FastJavaPartitionScanner();
214
215 //    jspScriptScanner = new JSPScriptScanner();
216     //  fPartitionScanner = new FastJavaPartitionScanner();
217     //    fPartitionScanner = new PHPPartitionScanner();
218
219 //    jspBracketScanner = new RuleBasedScanner();
220 //    jspBracketScanner.setDefaultReturnToken(new Token(JSPScriptScanner.JSP_BRACKET));
221 //    jspTextScanner = new RuleBasedScanner();
222 //    jspTextScanner.setDefaultReturnToken(new Token(JSPScriptScanner.JSP_DEFAULT));
223   }
224
225   /**
226          * 
227          */
228         public XMLTextTools getXMLTextTools() {
229                 return xmlTextTools;
230         }
231   /**
232    * Disposes all the individual tools of this tools collection.
233    */
234   public void dispose() {
235
236     fCodeScanner = null;
237     fMultilineCommentScanner = null;
238     fSinglelineCommentScanner = null;
239     fStringScanner = 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 fStringScanner;
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   /**
421    * Sets up the Java document partitioner for the given document for the given partitioning.
422    * 
423    * @param document
424    *          the document to be set up
425    * @param partitioning
426    *          the document partitioning
427    * @param element
428    *          TODO
429    * 
430    * @since 3.0
431    */
432 //  public void setupJavaDocumentPartitioner(IDocument document, String partitioning, Object element) {
433 //    IDocumentPartitioner partitioner = createDocumentPartitioner(".php");
434 //
435 //    //                if (document instanceof IDocumentExtension3) {
436 //    //                        IDocumentExtension3 extension3= (IDocumentExtension3) document;
437 //    //                        extension3.setDocumentPartitioner(partitioning, partitioner);
438 //    //                } else {
439 //    document.setDocumentPartitioner(partitioner);
440 //    //                }
441 //    partitioner.connect(document);
442 //  }
443
444   public void setupHTMLDocumentPartitioner(IDocument document, String partitioning, Object element) {
445     IDocumentPartitioner partitioner = createDocumentPartitioner(".html");
446
447     //          if (document instanceof IDocumentExtension3) {
448     //                  IDocumentExtension3 extension3= (IDocumentExtension3) document;
449     //                  extension3.setDocumentPartitioner(partitioning, partitioner);
450     //          } else {
451     document.setDocumentPartitioner(partitioner);
452     //          }
453     partitioner.connect(document);
454   }
455
456   public void setupSmartyDocumentPartitioner(IDocument document, String partitioning, Object element) {
457     IDocumentPartitioner partitioner = createDocumentPartitioner(".tpl");
458
459     //          if (document instanceof IDocumentExtension3) {
460     //                  IDocumentExtension3 extension3= (IDocumentExtension3) document;
461     //                  extension3.setDocumentPartitioner(partitioning, partitioner);
462     //          } else {
463     document.setDocumentPartitioner(partitioner);
464     //          }
465     partitioner.connect(document);
466   }
467
468   /**
469    * Returns the names of the document position categories used by the document partitioners created by this object to manage their
470    * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
471    * 
472    * @return the partition managing position categories or <code>null</code> if there is none
473    */
474   public String[] getPartitionManagingPositionCategories() {
475     return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
476   }
477
478   /**
479          * Determines whether the preference change encoded by the given event
480          * changes the behavior of one its contained components.
481          * 
482          * @param event the event to be investigated
483          * @return <code>true</code> if event causes a behavioral change
484          * @since 2.0
485          * @deprecated As of 3.0, replaced by {@link org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration#affectsTextPresentation(PropertyChangeEvent)}
486          */
487 //  public boolean affectsBehavior(PropertyChangeEvent event) {
488 //    return fCodeScanner.affectsBehavior(event) 
489 //        || fMultilineCommentScanner.affectsBehavior(event)
490 //        || fSinglelineCommentScanner.affectsBehavior(event) 
491 //        || fStringScanner.affectsBehavior(event)
492 //        || fPHPDocScanner.affectsBehavior(event);
493 //  }
494
495   /**
496    * Adapts the behavior of the contained components to the change encoded in the given event.
497    * 
498    * @param event
499    *          the event to which to adapt
500    * @since 2.0
501    */
502   protected void adaptToPreferenceChange(PropertyChangeEvent event) {
503     if (fCodeScanner.affectsBehavior(event))
504       fCodeScanner.adaptToPreferenceChange(event);
505     if (fMultilineCommentScanner.affectsBehavior(event))
506       fMultilineCommentScanner.adaptToPreferenceChange(event);
507     if (fSinglelineCommentScanner.affectsBehavior(event))
508       fSinglelineCommentScanner.adaptToPreferenceChange(event);
509 //    if (fStringScanner.affectsBehavior(event))
510 //      fStringScanner.adaptToPreferenceChange(event);
511     if (fPHPDocScanner.affectsBehavior(event))
512       fPHPDocScanner.adaptToPreferenceChange(event);
513     //    if (fHTMLScanner.affectsBehavior(event))
514     //      fHTMLScanner.adaptToPreferenceChange(event);
515     if (fSmartyScanner.affectsBehavior(event))
516       fSmartyScanner.adaptToPreferenceChange(event);
517     if (fSmartyDocScanner.affectsBehavior(event))
518       fSmartyDocScanner.adaptToPreferenceChange(event);
519 //    if (XMLPlugin.getDefault().getXMLTextTools().affectsBehavior(event)) {
520 //      XMLPlugin.getDefault().getXMLTextTools().adaptToPreferenceChange(event);
521 //    }
522   }
523
524   /**
525    * Return a partitioner for .html files.
526    */
527   public IDocumentPartitioner createHTMLPartitioner() {
528 //    return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
529     return xmlTextTools.createXMLPartitioner();
530   }
531
532 //  private static IDocumentPartitioner createIncludePartitioner() {
533 //    //    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
534 //    return new DefaultPartitioner(getPHPPartitionScanner(), FastJavaPartitionScanner.PHP_PARTITION_TYPES);
535 //
536 //  }
537
538 //  private static IDocumentPartitioner createJavaScriptPartitioner() {
539 //    return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
540 //  }
541
542   /**
543    * Return a partitioner for .php files.  
544    */
545   public IDocumentPartitioner createPHPPartitioner() {
546     //    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
547     return new DefaultPartitioner(getPHPPartitionScanner(), LEGAL_CONTENT_TYPES);
548   } 
549
550   private IDocumentPartitioner createJSPPartitioner() {
551         return new PHPDocumentPartitioner(
552             getJSPPartitionScanner(), getPHPPartitionScanner());
553 //    return new JSPDocumentPartitioner(getJSPPartitionScanner(), jspScriptScanner);
554   }
555  
556   /**
557    *  
558    */
559 //  public IPartitionTokenScanner getJSPScriptScanner() {
560 //    return jspScriptScanner;
561 //  }
562
563   private IDocumentPartitioner createSmartyPartitioner() {
564     return new DefaultPartitioner(getSmartyPartitionScanner(), XMLTextTools.TYPES);
565   }
566
567   private IDocumentPartitioner createXMLPartitioner() {
568 //    return new DefaultPartitioner(getXMLPartitionScanner(), XMLTextTools.TYPES);
569     return xmlTextTools.createXMLPartitioner();
570   }
571
572 //  private IDocumentPartitioner createCSSPartitioner() {
573 //    return new DefaultPartitioner(getHTMLPartitionScanner(), XMLTextTools.TYPES);
574 //  }
575
576   /**
577    * Return a scanner for creating html partitions.
578    */
579 //  private static XMLPartitionScanner getHTMLPartitionScanner() {
580 //    //    if (HTML_PARTITION_SCANNER == null)
581 //    //      HTML_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.HTML_FILE);
582 //    //    return HTML_PARTITION_SCANNER;^
583 //    if (HTML_PARTITION_SCANNER == null)
584 //      HTML_PARTITION_SCANNER = new XMLPartitionScanner(false);
585 //    return HTML_PARTITION_SCANNER;
586 //  }
587
588   /**
589    * Return a scanner for creating php partitions.
590    */ 
591   private FastJavaPartitionScanner getPHPPartitionScanner() {
592 //    if (PHP_PARTITION_SCANNER == null)
593 //      PHP_PARTITION_SCANNER = new FastJavaPartitionScanner(); //new PHPPartitionScanner(IPHPPartitions.PHP_FILE);
594 //    return PHP_PARTITION_SCANNER;
595     return fPartitionScanner;
596   }
597
598   /**
599    * Returns a scanner which is configured to scan plain text in JSP.
600    * 
601    * @return a JSP text scanner
602    */
603 //  public RuleBasedScanner getJSPTextScanner() {
604 //    return jspTextScanner;
605 //  }
606
607   /**
608    * Returns a scanner which is configured to scan plain text in JSP.
609    * 
610    * @return a JSP text scanner
611    */
612 //  public RuleBasedScanner getJSPBracketScanner() {
613 //    return jspBracketScanner;
614 //  }
615
616   /**
617    * Return a scanner for creating smarty partitions.
618    */
619   private static HTMLPartitionScanner getSmartyPartitionScanner() {
620     if (SMARTY_PARTITION_SCANNER == null)
621       SMARTY_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.SMARTY_FILE);
622     return SMARTY_PARTITION_SCANNER;
623   }
624
625   /**
626    * Return a scanner for creating xml partitions.
627    */
628   private static XMLPartitionScanner getXMLPartitionScanner() {
629     //    if (XML_PARTITION_SCANNER == null)
630     //      XML_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.XML_FILE);
631     //    return XML_PARTITION_SCANNER;
632     if (XML_PARTITION_SCANNER == null)
633       XML_PARTITION_SCANNER = new XMLPartitionScanner(false);
634     return XML_PARTITION_SCANNER;
635   }
636   
637   private PHPPartitionScanner getJSPPartitionScanner() {
638     if (jspPartitionScanner == null)
639       jspPartitionScanner = new PHPPartitionScanner();
640     return jspPartitionScanner;
641   }
642
643   /**
644          * Sets up the Java document partitioner for the given document for the default partitioning.
645          * 
646          * @param document the document to be set up
647          * @since 3.0
648          */
649         public void setupJavaDocumentPartitioner(IDocument document) {
650                 setupJavaDocumentPartitioner(document, IDocumentExtension3.DEFAULT_PARTITIONING);
651         }
652
653         /**
654          * Sets up the Java document partitioner for the given document for the given partitioning.
655          * 
656          * @param document the document to be set up
657          * @param partitioning the document partitioning
658          * @since 3.0
659          */
660         public void setupJavaDocumentPartitioner(IDocument document, String partitioning) {
661                 IDocumentPartitioner partitioner= createDocumentPartitioner();
662                 if (document instanceof IDocumentExtension3) {
663                         IDocumentExtension3 extension3= (IDocumentExtension3) document;
664                         extension3.setDocumentPartitioner(partitioning, partitioner);
665                 } else {
666                         document.setDocumentPartitioner(partitioner);
667                 }
668                 partitioner.connect(document);
669         }
670
671         /**
672          * Returns this text tool's preference store.
673          * 
674          * @return the preference store
675          * @since 3.0
676          */
677         protected IPreferenceStore getPreferenceStore() {
678                 return fPreferenceStore;
679         }
680
681         /**
682          * Returns this text tool's core preference store.
683          * 
684          * @return the core preference store
685          * @since 3.0
686          */
687         protected Preferences getCorePreferenceStore() {
688                 return fCorePreferenceStore;
689         }
690 }