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