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