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