Prepared better HEREDOC support; see comment for bug #1319276
[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       PHP_STRING_HEREDOC};
59
60 //  private static XMLPartitionScanner HTML_PARTITION_SCANNER = null;
61
62 //  private static FastJavaPartitionScanner PHP_PARTITION_SCANNER = null;
63
64   private static HTMLPartitionScanner SMARTY_PARTITION_SCANNER = null;
65
66 //  private static XMLPartitionScanner XML_PARTITION_SCANNER = null;
67
68   // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
69   // PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
70   //  private final static String[] TYPES = new String[] {
71   //      IPHPPartitions.PHP_PARTITIONING,
72   //      IPHPPartitions.PHP_PHPDOC_COMMENT,
73   //  // IPHPPartitions.HTML,
74   //      // IPHPPartitions.HTML_MULTILINE_COMMENT,
75   //      IPHPPartitions.JAVASCRIPT,
76   //      IPHPPartitions.CSS,
77   //      IPHPPartitions.SMARTY,
78   //      IPHPPartitions.SMARTY_MULTILINE_COMMENT };
79
80   /**
81    * This tools' preference listener.
82    */
83   private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
84     public void propertyChange(PropertyChangeEvent event) {
85       adaptToPreferenceChange(event);
86     }
87
88     public void propertyChange(Preferences.PropertyChangeEvent event) {
89       adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event
90           .getNewValue()));
91     }
92   };
93
94   //  /** The color manager */
95   private JavaColorManager colorManager;
96
97   /** The PHP source code scanner */
98   private PHPCodeScanner fCodeScanner;
99
100   /** The PHP multiline comment scanner */
101   private SingleTokenPHPScanner fMultilineCommentScanner;
102
103   /** The Java singleline comment scanner */
104   private SingleTokenPHPScanner fSinglelineCommentScanner;
105
106   /** The PHP double quoted string scanner */
107 //  private SingleTokenPHPScanner fStringDQScanner;
108
109   /** The PHP single quoted string scanner */
110 //  private SingleTokenPHPScanner fStringSQScanner;
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 //    fStringDQScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
205 //    fStringSQScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
206
207     fPHPDocScanner = new PHPDocCodeScanner((JavaColorManager) colorManager, store);
208     //    fHTMLScanner = new HTMLCodeScanner((JavaColorManager)fColorManager, store);
209     fSmartyScanner = new SmartyCodeScanner((JavaColorManager) colorManager, store);
210     fSmartyDocScanner = new SmartyDocCodeScanner((JavaColorManager) colorManager, store);
211
212     fPartitionScanner = new FastJavaPartitionScanner();
213
214     //    jspScriptScanner = new JSPScriptScanner();
215     //  fPartitionScanner = new FastJavaPartitionScanner();
216     //    fPartitionScanner = new PHPPartitionScanner();
217
218     //    jspBracketScanner = new RuleBasedScanner();
219     //    jspBracketScanner.setDefaultReturnToken(new Token(JSPScriptScanner.JSP_BRACKET));
220     //    jspTextScanner = new RuleBasedScanner();
221     //    jspTextScanner.setDefaultReturnToken(new Token(JSPScriptScanner.JSP_DEFAULT));
222   }
223
224   /**
225    *
226    */
227   public XMLTextTools getXMLTextTools() {
228     return xmlTextTools;
229   }
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 //    fStringDQScanner = null;
240 //    fStringSQScanner = null;
241     fPHPDocScanner = null;
242     //    fPartitionScanner = null;
243
244     if (colorManager != null) {
245       colorManager.dispose();
246       colorManager = null;
247     }
248
249     if (fPreferenceStore != null) {
250       fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
251       fPreferenceStore = null;
252
253       if (fCorePreferenceStore != null) {
254         fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
255         fCorePreferenceStore = null;
256       }
257
258       fPreferenceListener = null;
259     }
260   }
261
262   /**
263    * Returns the color manager which is used to manage any Java-specific colors needed for such things like syntax highlighting.
264    *
265    * @return the color manager to be used for Java text viewers
266    */
267   public JavaColorManager getColorManager() {
268     return (JavaColorManager) colorManager;
269   }
270
271   /**
272    * Returns a scanner which is configured to scan Java source code.
273    *
274    * @return a Java source code scanner
275    */
276   public RuleBasedScanner getCodeScanner() {
277     return fCodeScanner;
278   }
279
280   /**
281    * Returns a scanner which is configured to scan Java multiline comments.
282    *
283    * @return a Java multiline comment scanner
284    *
285    * @since 2.0
286    */
287   public RuleBasedScanner getMultilineCommentScanner() {
288     return fMultilineCommentScanner;
289   }
290
291   /**
292    * Returns a scanner which is configured to scan HTML code.
293    *
294    * @return a HTML scanner
295    *
296    * @since 2.0
297    */
298   //  public RuleBasedScanner getHTMLScanner() {
299   //    return fHTMLScanner;
300   //  }
301   /**
302    * Returns a scanner which is configured to scan Smarty code.
303    *
304    * @return a Smarty scanner
305    *
306    * @since 2.0
307    */
308   public RuleBasedScanner getSmartyScanner() {
309     return fSmartyScanner;
310   }
311
312   /**
313    * Returns a scanner which is configured to scan Smarty code.
314    *
315    * @return a Smarty scanner
316    *
317    * @since 2.0
318    */
319   public RuleBasedScanner getSmartyDocScanner() {
320     return fSmartyDocScanner;
321   }
322
323   /**
324    * Returns a scanner which is configured to scan Java singleline comments.
325    *
326    * @return a Java singleline comment scanner
327    *
328    * @since 2.0
329    */
330   public RuleBasedScanner getSinglelineCommentScanner() {
331     return fSinglelineCommentScanner;
332   }
333
334   /**
335    * Returns a scanner which is configured to scan Java strings.
336    *
337    * @return a Java string scanner
338    *
339    * @since 2.0
340    */
341 //  public RuleBasedScanner getStringScanner() {
342 //    return fStringDQScanner;
343 //  }
344
345   /**
346    * Returns a scanner which is configured to scan JavaDoc compliant comments. Notes that the start sequence "/**" and the
347    * corresponding end sequence are part of the JavaDoc comment.
348    *
349    * @return a JavaDoc scanner
350    */
351   public RuleBasedScanner getJavaDocScanner() {
352     return fPHPDocScanner;
353   }
354
355   /**
356    * Returns a scanner which is configured to scan Java-specific partitions, which are multi-line comments, JavaDoc comments, and
357    * regular Java source code.
358    *
359    * @return a Java partition scanner
360    */
361   //  public IPartitionTokenScanner getPartitionScanner() {
362   //    return fPartitionScanner;
363   //  }
364   /**
365    * Factory method for creating a PHP-specific document partitioner using this object's partitions scanner. This method is a
366    * convenience method.
367    *
368    * @return a newly created Java document partitioner
369    */
370   public IDocumentPartitioner createDocumentPartitioner() {
371     return createDocumentPartitioner(".php");
372   }
373
374   /**
375    * Factory method for creating a PHP-specific document partitioner using this object's partitions scanner. This method is a
376    * convenience method.
377    *
378    * @return a newly created Java document partitioner
379    */
380   public IDocumentPartitioner createDocumentPartitioner(String extension) {
381
382     //    String[] types =
383     //      new String[] {
384     //        FastJavaPartitionScanner.JAVA_DOC,
385     //        FastJavaPartitionScanner.JAVA_MULTI_LINE_COMMENT,
386     //        FastJavaPartitionScanner.JAVA_SINGLE_LINE_COMMENT,
387     //        FastJavaPartitionScanner.JAVA_STRING };
388     //
389     //    return new DefaultPartitioner(getPartitionScanner(), types);
390     IDocumentPartitioner partitioner = null;
391     //  System.out.println(extension);
392     if (extension.equalsIgnoreCase(".html") || extension.equalsIgnoreCase(".htm")) {
393       // html
394       partitioner = createHTMLPartitioner();
395       partitioner = createJSPPartitioner();
396     } else if (extension.equalsIgnoreCase(".xml")) {
397       // xml
398       partitioner = createXMLPartitioner();
399       //    } else if (extension.equalsIgnoreCase(".js")) {
400       //      // javascript
401       //      partitioner = createJavaScriptPartitioner();
402       //    } else if (extension.equalsIgnoreCase(".css")) {
403       //      // cascading style sheets
404       //      partitioner = createCSSPartitioner();
405     } else if (extension.equalsIgnoreCase(".tpl")) {
406       // smarty ?
407       partitioner = createSmartyPartitioner();
408       //    } else if (extension.equalsIgnoreCase(".inc")) {
409       //      // php include files ?
410       //      partitioner = createIncludePartitioner();
411     }
412
413     if (partitioner == null) {
414       partitioner = createJSPPartitioner();
415     }
416
417     return partitioner;
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   public void setupHTMLDocumentPartitioner(IDocument document, String partitioning, Object element) {
444     IDocumentPartitioner partitioner = createDocumentPartitioner(".html");
445
446     //          if (document instanceof IDocumentExtension3) {
447     //                  IDocumentExtension3 extension3= (IDocumentExtension3) document;
448     //                  extension3.setDocumentPartitioner(partitioning, partitioner);
449     //          } else {
450     document.setDocumentPartitioner(partitioner);
451     //          }
452     partitioner.connect(document);
453   }
454
455   public void setupSmartyDocumentPartitioner(IDocument document, String partitioning, Object element) {
456     IDocumentPartitioner partitioner = createDocumentPartitioner(".tpl");
457
458     //          if (document instanceof IDocumentExtension3) {
459     //                  IDocumentExtension3 extension3= (IDocumentExtension3) document;
460     //                  extension3.setDocumentPartitioner(partitioning, partitioner);
461     //          } else {
462     document.setDocumentPartitioner(partitioner);
463     //          }
464     partitioner.connect(document);
465   }
466
467   /**
468    * Returns the names of the document position categories used by the document partitioners created by this object to manage their
469    * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
470    *
471    * @return the partition managing position categories or <code>null</code> if there is none
472    */
473   public String[] getPartitionManagingPositionCategories() {
474     return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
475   }
476
477   /**
478    * Determines whether the preference change encoded by the given event changes the behavior of one its contained components.
479    *
480    * @param event
481    *          the event to be investigated
482    * @return <code>true</code> if event causes a behavioral change
483    * @since 2.0
484    * @deprecated As of 3.0, replaced by
485    *             {@link net.sourceforge.phpdt.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   //        || fStringDQScanner.affectsBehavior(event)
492   //        || fPHPDocScanner.affectsBehavior(event);
493   //  }
494   /**
495    * Adapts the behavior of the contained components to the change encoded in the given event.
496    *
497    * @param event
498    *          the event to which to adapt
499    * @since 2.0
500    */
501   protected void adaptToPreferenceChange(PropertyChangeEvent event) {
502     if (fCodeScanner.affectsBehavior(event))
503       fCodeScanner.adaptToPreferenceChange(event);
504     if (fMultilineCommentScanner.affectsBehavior(event))
505       fMultilineCommentScanner.adaptToPreferenceChange(event);
506     if (fSinglelineCommentScanner.affectsBehavior(event))
507       fSinglelineCommentScanner.adaptToPreferenceChange(event);
508     //    if (fStringDQScanner.affectsBehavior(event))
509     //      fStringDQScanner.adaptToPreferenceChange(event);
510     if (fPHPDocScanner.affectsBehavior(event))
511       fPHPDocScanner.adaptToPreferenceChange(event);
512     //    if (fHTMLScanner.affectsBehavior(event))
513     //      fHTMLScanner.adaptToPreferenceChange(event);
514     if (fSmartyScanner.affectsBehavior(event))
515       fSmartyScanner.adaptToPreferenceChange(event);
516     if (fSmartyDocScanner.affectsBehavior(event))
517       fSmartyDocScanner.adaptToPreferenceChange(event);
518     //    if (XMLPlugin.getDefault().getXMLTextTools().affectsBehavior(event)) {
519     //      XMLPlugin.getDefault().getXMLTextTools().adaptToPreferenceChange(event);
520     //    }
521   }
522
523   /**
524    * Return a partitioner for .html files.
525    */
526   public IDocumentPartitioner createHTMLPartitioner() {
527     //    return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
528     return xmlTextTools.createXMLPartitioner();
529   }
530
531   //  private static IDocumentPartitioner createIncludePartitioner() {
532   //    // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
533   //    return new DefaultPartitioner(getPHPPartitionScanner(), FastJavaPartitionScanner.PHP_PARTITION_TYPES);
534   //
535   //  }
536
537   //  private static IDocumentPartitioner createJavaScriptPartitioner() {
538   //    return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
539   //  }
540
541   /**
542    * Return a partitioner for .php files.
543    */
544   public IDocumentPartitioner createPHPPartitioner() {
545     //    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
546     return new DefaultPartitioner(getPHPPartitionScanner(), LEGAL_CONTENT_TYPES);
547   }
548
549   private IDocumentPartitioner createJSPPartitioner() {
550     return new PHPDocumentPartitioner(getJSPPartitionScanner());
551     //    return new JSPDocumentPartitioner(getJSPPartitionScanner(), jspScriptScanner);
552   }
553
554   /**
555    *
556    */
557   //  public IPartitionTokenScanner getJSPScriptScanner() {
558   //    return jspScriptScanner;
559   //  }
560   private IDocumentPartitioner createSmartyPartitioner() {
561     return new DefaultPartitioner(getSmartyPartitionScanner(), XMLTextTools.TYPES);
562   }
563
564   private IDocumentPartitioner createXMLPartitioner() {
565     //    return new DefaultPartitioner(getXMLPartitionScanner(), XMLTextTools.TYPES);
566     return xmlTextTools.createXMLPartitioner();
567   }
568
569   //  private IDocumentPartitioner createCSSPartitioner() {
570   //    return new DefaultPartitioner(getHTMLPartitionScanner(), XMLTextTools.TYPES);
571   //  }
572
573   /**
574    * Return a scanner for creating html partitions.
575    */
576   //  private static XMLPartitionScanner getHTMLPartitionScanner() {
577   //    // if (HTML_PARTITION_SCANNER == null)
578   //    // HTML_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.HTML_FILE);
579   //    // return HTML_PARTITION_SCANNER;^
580   //    if (HTML_PARTITION_SCANNER == null)
581   //      HTML_PARTITION_SCANNER = new XMLPartitionScanner(false);
582   //    return HTML_PARTITION_SCANNER;
583   //  }
584   /**
585    * Return a scanner for creating php partitions.
586    */
587   private FastJavaPartitionScanner getPHPPartitionScanner() {
588     //    if (PHP_PARTITION_SCANNER == null)
589     //      PHP_PARTITION_SCANNER = new FastJavaPartitionScanner(); //new PHPPartitionScanner(IPHPPartitions.PHP_FILE);
590     //    return PHP_PARTITION_SCANNER;
591     return fPartitionScanner;
592   }
593
594   /**
595    * Returns a scanner which is configured to scan plain text in JSP.
596    *
597    * @return a JSP text scanner
598    */
599   //  public RuleBasedScanner getJSPTextScanner() {
600   //    return jspTextScanner;
601   //  }
602   /**
603    * Returns a scanner which is configured to scan plain text in JSP.
604    *
605    * @return a JSP text scanner
606    */
607   //  public RuleBasedScanner getJSPBracketScanner() {
608   //    return jspBracketScanner;
609   //  }
610   /**
611    * Return a scanner for creating smarty partitions.
612    */
613   private static HTMLPartitionScanner getSmartyPartitionScanner() {
614     if (SMARTY_PARTITION_SCANNER == null)
615       SMARTY_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.SMARTY_FILE);
616     return SMARTY_PARTITION_SCANNER;
617   }
618
619   /**
620    * Return a scanner for creating xml partitions.
621    */
622 //  private static XMLPartitionScanner getXMLPartitionScanner() {
623 //    //    if (XML_PARTITION_SCANNER == null)
624 //    //      XML_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.XML_FILE);
625 //    //    return XML_PARTITION_SCANNER;
626 //    if (XML_PARTITION_SCANNER == null)
627 //      XML_PARTITION_SCANNER = new XMLPartitionScanner(false);
628 //    return XML_PARTITION_SCANNER;
629 //  }
630
631   private PHPPartitionScanner getJSPPartitionScanner() {
632     if (jspPartitionScanner == null)
633       jspPartitionScanner = new PHPPartitionScanner();
634     return jspPartitionScanner;
635   }
636
637   /**
638    * Sets up the Java document partitioner for the given document for the default partitioning.
639    *
640    * @param document
641    *          the document to be set up
642    * @since 3.0
643    */
644   public void setupJavaDocumentPartitioner(IDocument document) {
645     setupJavaDocumentPartitioner(document, IDocumentExtension3.DEFAULT_PARTITIONING);
646   }
647
648   /**
649    * Sets up the Java document partitioner for the given document for the given partitioning.
650    *
651    * @param document
652    *          the document to be set up
653    * @param partitioning
654    *          the document partitioning
655    * @since 3.0
656    */
657   public void setupJavaDocumentPartitioner(IDocument document, String partitioning) {
658     IDocumentPartitioner partitioner = createDocumentPartitioner();
659     if (document instanceof IDocumentExtension3) {
660       IDocumentExtension3 extension3 = (IDocumentExtension3) document;
661       extension3.setDocumentPartitioner(partitioning, partitioner);
662     } else {
663       document.setDocumentPartitioner(partitioner);
664     }
665     partitioner.connect(document);
666   }
667
668   /**
669    * Returns this text tool's preference store.
670    *
671    * @return the preference store
672    * @since 3.0
673    */
674   protected IPreferenceStore getPreferenceStore() {
675     return fPreferenceStore;
676   }
677
678   /**
679    * Returns this text tool's core preference store.
680    *
681    * @return the core preference store
682    * @since 3.0
683    */
684   protected Preferences getCorePreferenceStore() {
685     return fCorePreferenceStore;
686   }
687 }