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