improved parser string handling
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPSourceViewerConfiguration.java
1 /**********************************************************************
2  Copyright (c) 2000, 2002 IBM Corp. and others.
3  All rights reserved. This program and the accompanying materials
4  are made available under the terms of the Common Public License v1.0
5  which accompanies this distribution, and is available at
6  http://www.eclipse.org/legal/cpl-v10.html
7
8  Contributors:
9  IBM Corporation - Initial implementation
10  Klaus Hartlage - www.eclipseproject.de
11  **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
13 import java.util.Vector;
14
15 import net.sourceforge.phpdt.core.JavaCore;
16 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
17 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
18 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
19 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
20 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
21 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
22 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
23 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
24 import net.sourceforge.phpdt.internal.ui.text.java.JavaReconcilingStrategy;
25 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategy;
26 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
27 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
28 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
29 import net.sourceforge.phpdt.ui.PreferenceConstants;
30 import net.sourceforge.phpdt.ui.text.JavaTextTools;
31 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
32 import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
33 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
34 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
35 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
36 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
37 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
38
39 import org.eclipse.core.runtime.NullProgressMonitor;
40 import org.eclipse.jface.preference.IPreferenceStore;
41 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
42 import org.eclipse.jface.text.DefaultInformationControl;
43 import org.eclipse.jface.text.IAutoIndentStrategy;
44 import org.eclipse.jface.text.IDocument;
45 import org.eclipse.jface.text.IInformationControl;
46 import org.eclipse.jface.text.IInformationControlCreator;
47 import org.eclipse.jface.text.ITextDoubleClickStrategy;
48 import org.eclipse.jface.text.ITextHover;
49 import org.eclipse.jface.text.ITextViewerExtension2;
50 import org.eclipse.jface.text.TextAttribute;
51 import org.eclipse.jface.text.contentassist.ContentAssistant;
52 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
53 import org.eclipse.jface.text.contentassist.IContentAssistant;
54 import org.eclipse.jface.text.formatter.ContentFormatter;
55 import org.eclipse.jface.text.formatter.IContentFormatter;
56 import org.eclipse.jface.text.formatter.IFormattingStrategy;
57 import org.eclipse.jface.text.information.IInformationPresenter;
58 import org.eclipse.jface.text.information.IInformationProvider;
59 import org.eclipse.jface.text.information.InformationPresenter;
60 import org.eclipse.jface.text.presentation.IPresentationReconciler;
61 import org.eclipse.jface.text.presentation.PresentationReconciler;
62 import org.eclipse.jface.text.reconciler.IReconciler;
63 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
64 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
65 import org.eclipse.jface.text.rules.DefaultPartitioner;
66 import org.eclipse.jface.text.rules.RuleBasedScanner;
67 import org.eclipse.jface.text.rules.Token;
68 import org.eclipse.jface.text.source.IAnnotationHover;
69 import org.eclipse.jface.text.source.ISourceViewer;
70 import org.eclipse.jface.text.source.SourceViewerConfiguration;
71 import org.eclipse.swt.SWT;
72 import org.eclipse.swt.widgets.Shell;
73 /**
74  * Configuration for an <code>SourceViewer</code> which shows PHP code.
75  */
76 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
77         /**
78          * Preference key used to look up display tab width.
79          * 
80          * @since 2.0
81          */
82         public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
83         /**
84          * Preference key for inserting spaces rather than tabs.
85          * 
86          * @since 2.0
87          */
88         public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
89         //  public static final String HTML_DEFAULT =
90         // IPHPPartitionScannerConstants.HTML;
91         //IDocument.DEFAULT_CONTENT_TYPE;
92         private JavaTextTools fJavaTextTools;
93         private PHPEditor fEditor;
94         private ContentFormatter fFormatter;
95         private HTMLFormattingStrategy fFormattingStrategy;
96         /**
97          * Single token scanner.
98          */
99         static class SingleTokenScanner extends BufferedRuleBasedScanner {
100                 public SingleTokenScanner(TextAttribute attribute) {
101                         setDefaultReturnToken(new Token(attribute));
102                 }
103         };
104         /**
105          * Default constructor.
106          */
107         public PHPSourceViewerConfiguration(JavaTextTools textTools,
108                         PHPEditor editor) {
109                 fJavaTextTools = textTools;
110                 fEditor = editor;
111         }
112         /*
113          * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
114          */
115         public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
116                 //    if (fFormatter == null) {
117                 //      fFormatter = new ContentFormatter();
118                 //      fFormattingStrategy = new HTMLFormattingStrategy(this,
119                 // sourceViewer);
120                 //      fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
121                 //      fFormatter.enablePartitionAwareFormatting(false);
122                 //      fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
123                 //    }
124                 //    return fFormatter;
125                 if (fFormatter == null) {
126                         //ContentFormatter
127                         fFormatter = new ContentFormatter();
128                         IFormattingStrategy strategy = new JavaFormattingStrategy(
129                                         sourceViewer);
130                         fFormatter.setFormattingStrategy(strategy,
131                                         IDocument.DEFAULT_CONTENT_TYPE);
132                         fFormatter.enablePartitionAwareFormatting(false);
133                         fFormatter
134                                         .setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
135                 }
136                 return fFormatter;
137         }
138         /**
139          * Returns the names of the document position categories used by the
140          * document partitioners created by this object to manage their partition
141          * information. If the partitioners don't use document position categories,
142          * the returned result is <code>null</code>.
143          * 
144          * @return the partition managing position categories or <code>null</code>
145          *         if there is none
146          */
147         public String[] getPartitionManagingPositionCategories() {
148                 return new String[]{DefaultPartitioner.CONTENT_TYPES_CATEGORY};
149         }
150         //  /**
151         //   * Returns the names of the document position categories used by the
152         // document
153         //   * partitioners created by this object to manage their partition
154         // information.
155         //   * If the partitioners don't use document position categories, the
156         // returned
157         //   * result is <code>null</code>.
158         //   *
159         //   * @return the partition managing position categories or
160         // <code>null</code>
161         //   * if there is none
162         //   */
163         //  private String[] getPartitionManagingPositionCategories() {
164         //    return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
165         //  }
166         public PHPEditor getEditor() {
167                 return fEditor;
168         }
169         /**
170          * Returns the preference store used by this configuration to initialize
171          * the individual bits and pieces.
172          * 
173          * @return the preference store used to initialize this configuration
174          * 
175          * @since 2.0
176          */
177         protected IPreferenceStore getPreferenceStore() {
178                 return PHPeclipsePlugin.getDefault().getPreferenceStore();
179         }
180         //  /* (non-Javadoc)
181         //   * Method declared on SourceViewerConfiguration
182         //   */
183         //  public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
184         //    return new PHPAnnotationHover();
185         //  }
186         /*
187          * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
188          */
189         public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
190                 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
191         }
192         /*
193          * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
194          * @since 3.0
195          */
196         public IAnnotationHover getOverviewRulerAnnotationHover(
197                         ISourceViewer sourceViewer) {
198                 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
199         }
200         /*
201          * (non-Javadoc) Method declared on SourceViewerConfiguration
202          */
203         public IAutoIndentStrategy getAutoIndentStrategy(
204                         ISourceViewer sourceViewer, String contentType) {
205                 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
206                         return new JavaStringAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
207
208                 return (IPHPPartitions.PHP_PARTITIONING.equals(contentType)
209                                 ? new PHPAutoIndentStrategy()
210                                 : new DefaultAutoIndentStrategy());
211         }
212         /**
213          * Returns the PHP source code scanner for this configuration.
214          * 
215          * @return the PHP source code scanner
216          */
217         protected RuleBasedScanner getCodeScanner() {
218                 return fJavaTextTools.getCodeScanner();
219         }
220         /**
221          * Returns the HTML source code scanner for this configuration.
222          * 
223          * @return the HTML source code scanner
224          */
225         protected RuleBasedScanner getHTMLScanner() {
226                 return fJavaTextTools.getHTMLScanner();
227         }
228         /**
229          * Returns the Smarty source code scanner for this configuration.
230          * 
231          * @return the Smarty source code scanner
232          */
233         protected RuleBasedScanner getSmartyScanner() {
234                 return fJavaTextTools.getSmartyScanner();
235         }
236         /*
237          * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
238          */
239         public IReconciler getReconciler(ISourceViewer sourceViewer) {
240                 if (getEditor() != null && getEditor().isEditable()) {
241                         JavaReconciler reconciler = new JavaReconciler(getEditor(),
242                                         new JavaReconcilingStrategy(getEditor()), false);
243                         reconciler.setProgressMonitor(new NullProgressMonitor());
244                         reconciler.setDelay(500);
245                         return reconciler;
246                 }
247                 return null;
248         }
249         /*
250          * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer,
251          *      String)
252          * @since 2.1
253          */
254         public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer,
255                         String contentType) {
256                 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
257                                 .getDefault().getJavaEditorTextHoverDescriptors();
258                 int stateMasks[] = new int[hoverDescs.length];
259                 int stateMasksLength = 0;
260                 for (int i = 0; i < hoverDescs.length; i++) {
261                         if (hoverDescs[i].isEnabled()) {
262                                 int j = 0;
263                                 int stateMask = hoverDescs[i].getStateMask();
264                                 while (j < stateMasksLength) {
265                                         if (stateMasks[j] == stateMask)
266                                                 break;
267                                         j++;
268                                 }
269                                 if (j == stateMasksLength)
270                                         stateMasks[stateMasksLength++] = stateMask;
271                         }
272                 }
273                 if (stateMasksLength == hoverDescs.length)
274                         return stateMasks;
275                 int[] shortenedStateMasks = new int[stateMasksLength];
276                 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0,
277                                 stateMasksLength);
278                 return shortenedStateMasks;
279         }
280         /*
281          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
282          * @since 2.1
283          */
284         public ITextHover getTextHover(ISourceViewer sourceViewer,
285                         String contentType, int stateMask) {
286                 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
287                                 .getDefault().getJavaEditorTextHoverDescriptors();
288                 int i = 0;
289                 while (i < hoverDescs.length) {
290                         if (hoverDescs[i].isEnabled()
291                                         && hoverDescs[i].getStateMask() == stateMask)
292                                 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
293                         i++;
294                 }
295                 return null;
296 //              if (fEditor != null) {
297 //                      IEditorInput editorInput = fEditor.getEditorInput();
298 //                      if (editorInput instanceof IFileEditorInput) {
299 //                              try {
300 //                                      IFile f = ((IFileEditorInput) editorInput).getFile();
301 //                                      return new PHPTextHover(f.getProject());
302 //                              } catch (NullPointerException e) {
303 //                                      // this exception occurs, if getTextHover is called by
304 //                                      // preference pages !
305 //                              }
306 //                      }
307 //              }
308 //              return new PHPTextHover(null);
309         }
310         /*
311          * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
312          */
313         public ITextHover getTextHover(ISourceViewer sourceViewer,
314                         String contentType) {
315                 return getTextHover(sourceViewer, contentType,
316                                 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
317         }
318         /**
319          * Returns the SmartyDoc source code scanner for this configuration.
320          * 
321          * @return the SmartyDoc source code scanner
322          */
323         protected RuleBasedScanner getSmartyDocScanner() {
324                 return fJavaTextTools.getSmartyDocScanner();
325         }
326         /**
327          * Returns the PHPDoc source code scanner for this configuration.
328          * 
329          * @return the PHPDoc source code scanner
330          */
331         protected RuleBasedScanner getPHPDocScanner() {
332                 return fJavaTextTools.getJavaDocScanner();
333         }
334         /*
335          * (non-Javadoc) Method declared on SourceViewerConfiguration
336          */
337         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
338                 return new String[]{IPHPPartitions.HTML,
339                                 IPHPPartitions.HTML_MULTILINE_COMMENT,
340                                 IPHPPartitions.PHP_PARTITIONING,
341                                 IPHPPartitions.PHP_PHPDOC_COMMENT,
342                                 IPHPPartitions.CSS,
343                                 IPHPPartitions.CSS_MULTILINE_COMMENT,
344                                 IPHPPartitions.JAVASCRIPT,
345                                 IPHPPartitions.JS_MULTILINE_COMMENT,
346                                 IPHPPartitions.SMARTY,
347                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
348                                 IDocument.DEFAULT_CONTENT_TYPE};
349         }
350         /*
351          * (non-Javadoc) Method declared on SourceViewerConfiguration
352          */
353         public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
354                 ContentAssistant assistant = new ContentAssistant();
355                 IContentAssistProcessor processor = new HTMLCompletionProcessor();
356                 assistant.setContentAssistProcessor(processor,
357                                 IPHPPartitions.HTML);
358                 assistant.setContentAssistProcessor(processor,
359                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
360                 assistant.setContentAssistProcessor(processor,
361                                 IDocument.DEFAULT_CONTENT_TYPE);
362                 assistant.setContentAssistProcessor(processor,
363                                 IPHPPartitions.CSS);
364                 assistant.setContentAssistProcessor(processor,
365                                 IPHPPartitions.CSS_MULTILINE_COMMENT);
366                 assistant.setContentAssistProcessor(processor,
367                                 IPHPPartitions.JAVASCRIPT);
368                 assistant.setContentAssistProcessor(processor,
369                                 IPHPPartitions.JS_MULTILINE_COMMENT);
370                 // TODO define special smarty partition content assist
371                 assistant.setContentAssistProcessor(processor,
372                                 IPHPPartitions.SMARTY);
373                 assistant.setContentAssistProcessor(processor,
374                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
375                 assistant.setContentAssistProcessor(new PHPCompletionProcessor(),
376                                 IPHPPartitions.PHP_PARTITIONING);
377                 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(),
378                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
379                 //    assistant.enableAutoActivation(true);
380                 //    assistant.setAutoActivationDelay(500);
381                 //    assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
382                 //    ContentAssistPreference.configure(assistant, getPreferenceStore());
383                 //    assistant.setContextInformationPopupOrientation(
384                 //      ContentAssistant.CONTEXT_INFO_ABOVE);
385                 //    assistant.setContextInformationPopupBackground(
386                 //      PHPEditorEnvironment.getPHPColorProvider().getColor(
387                 //        new RGB(150, 150, 0)));
388                 ContentAssistPreference.configure(assistant, getPreferenceStore());
389                 assistant
390                                 .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
391                 assistant
392                                 .setInformationControlCreator(getInformationControlCreator(sourceViewer));
393                 return assistant;
394         }
395         /*
396          * (non-Javadoc) Method declared on SourceViewerConfiguration
397          */
398         //  public String getDefaultPrefix(ISourceViewer sourceViewer, String
399         // contentType) {
400         //    return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
401         // //$NON-NLS-1$
402         //    // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
403         // null); //$NON-NLS-1$
404         //  }
405         /*
406          * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
407          * @since 2.0
408          */
409         public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
410                         String contentType) {
411                 return new String[]{"//", ""}; //$NON-NLS-1$ //$NON-NLS-2$
412         }
413         /*
414          * (non-Javadoc) Method declared on SourceViewerConfiguration
415          */
416         public ITextDoubleClickStrategy getDoubleClickStrategy(
417                         ISourceViewer sourceViewer, String contentType) {
418                 return new PHPDoubleClickSelector();
419         }
420         /*
421          * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
422          */
423         public String[] getIndentPrefixes(ISourceViewer sourceViewer,
424                         String contentType) {
425                 Vector vector = new Vector();
426                 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
427                 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault()
428                                 .getPreferenceStore();
429                 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
430                 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
431                 for (int i = 0; i <= tabWidth; i++) {
432                         StringBuffer prefix = new StringBuffer();
433                         if (useSpaces) {
434                                 for (int j = 0; j + i < tabWidth; j++)
435                                         prefix.append(' ');
436                                 if (i != 0)
437                                         prefix.append('\t');
438                         } else {
439                                 for (int j = 0; j < i; j++)
440                                         prefix.append(' ');
441                                 if (i != tabWidth)
442                                         prefix.append('\t');
443                         }
444                         vector.add(prefix.toString());
445                 }
446                 vector.add(""); //$NON-NLS-1$
447                 return (String[]) vector.toArray(new String[vector.size()]);
448         }
449         /*
450          * (non-Javadoc) Method declared on SourceViewerConfiguration
451          */
452         public IPresentationReconciler getPresentationReconciler(
453                         ISourceViewer sourceViewer) {
454                 //  PHPColorProvider provider =
455                 // PHPEditorEnvironment.getPHPColorProvider();
456                 //    JavaColorManager provider =
457                 // PHPEditorEnvironment.getPHPColorProvider();
458                 PresentationReconciler reconciler = new PresentationReconciler();
459                 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
460                 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
461                 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
462                 dr = new DefaultDamagerRepairer(getHTMLScanner());
463                 reconciler.setDamager(dr, IPHPPartitions.HTML);
464                 reconciler.setRepairer(dr, IPHPPartitions.HTML);
465                 dr = new DefaultDamagerRepairer(getHTMLScanner());
466                 reconciler.setDamager(dr, IPHPPartitions.CSS);
467                 reconciler.setRepairer(dr, IPHPPartitions.CSS);
468                 dr = new DefaultDamagerRepairer(getHTMLScanner());
469                 reconciler.setDamager(dr,
470                                 IPHPPartitions.CSS_MULTILINE_COMMENT);
471                 reconciler.setRepairer(dr,
472                                 IPHPPartitions.CSS_MULTILINE_COMMENT);
473                 dr = new DefaultDamagerRepairer(getHTMLScanner());
474                 reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
475                 reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
476                 dr = new DefaultDamagerRepairer(getHTMLScanner());
477                 reconciler.setDamager(dr,
478                                 IPHPPartitions.JS_MULTILINE_COMMENT);
479                 reconciler.setRepairer(dr,
480                                 IPHPPartitions.JS_MULTILINE_COMMENT);
481                 dr = new DefaultDamagerRepairer(getSmartyScanner());
482                 reconciler.setDamager(dr, IPHPPartitions.SMARTY);
483                 reconciler.setRepairer(dr, IPHPPartitions.SMARTY);
484                 dr = new DefaultDamagerRepairer(getSmartyDocScanner());
485                 reconciler.setDamager(dr,
486                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
487                 reconciler.setRepairer(dr,
488                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
489                 dr = new DefaultDamagerRepairer(new SingleTokenScanner(
490                                 new TextAttribute(fJavaTextTools.getColorManager().getColor(
491                                                 PHPColorProvider.MULTI_LINE_COMMENT))));
492                 reconciler.setDamager(dr,
493                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
494                 reconciler.setRepairer(dr,
495                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
496                 dr = new DefaultDamagerRepairer(getCodeScanner());
497                 reconciler.setDamager(dr, IPHPPartitions.PHP_PARTITIONING);
498                 reconciler.setRepairer(dr, IPHPPartitions.PHP_PARTITIONING);
499                 dr = new DefaultDamagerRepairer(getPHPDocScanner());
500                 reconciler.setDamager(dr,
501                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
502                 reconciler.setRepairer(dr,
503                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
504                 return reconciler;
505         }
506         /*
507          * (non-Javadoc) Method declared on SourceViewerConfiguration
508          */
509         public int getTabWidth(ISourceViewer sourceViewer) {
510                 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
511         }
512         /*
513          * (non-Javadoc) Method declared on SourceViewerConfiguration
514          */
515         //  public ITextHover getTextHover(ISourceViewer sourceViewer, String
516         // contentType) {
517         //    if (fEditor != null) {
518         //      IEditorInput editorInput = fEditor.getEditorInput();
519         //      if (editorInput instanceof IFileEditorInput) {
520         //        try {
521         //          IFile f = ((IFileEditorInput) editorInput).getFile();
522         //          return new PHPTextHover(f.getProject());
523         //        } catch (NullPointerException e) {
524         //          // this exception occurs, if getTextHover is called by preference pages
525         // !
526         //        }
527         //      }
528         //    }
529         //    return new PHPTextHover(null);
530         //  }
531         /*
532          * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
533          * @since 2.0
534          */
535         public IInformationControlCreator getInformationControlCreator(
536                         ISourceViewer sourceViewer) {
537                 return new IInformationControlCreator() {
538                         public IInformationControl createInformationControl(Shell parent) {
539                                 return new DefaultInformationControl(parent, SWT.NONE,
540                                                 new HTMLTextPresenter(true));
541                                 // return new HoverBrowserControl(parent);
542                         }
543                 };
544         }
545         /*
546          * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
547          * @since 2.0
548          */
549         //      public IInformationPresenter getInformationPresenter(ISourceViewer
550         // sourceViewer) {
551         //              InformationPresenter presenter= new
552         // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
553         //              IInformationProvider provider= new JavaInformationProvider(getEditor());
554         //              presenter.setInformationProvider(provider,
555         // IDocument.DEFAULT_CONTENT_TYPE);
556         //              presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
557         //              presenter.setSizeConstraints(60, 10, true, true);
558         //              return presenter;
559         //      }
560         /**
561          * Returns the information presenter control creator. The creator is a
562          * factory creating the presenter controls for the given source viewer.
563          * This implementation always returns a creator for <code>DefaultInformationControl</code>
564          * instances.
565          * 
566          * @param sourceViewer
567          *            the source viewer to be configured by this configuration
568          * @return an information control creator
569          * @since 2.1
570          */
571         private IInformationControlCreator getInformationPresenterControlCreator(
572                         ISourceViewer sourceViewer) {
573                 return new IInformationControlCreator() {
574                         public IInformationControl createInformationControl(Shell parent) {
575                                 int shellStyle = SWT.RESIZE;
576                                 int style = SWT.V_SCROLL | SWT.H_SCROLL;
577                                 return new DefaultInformationControl(parent, shellStyle, style,
578                                                 new HTMLTextPresenter(false));
579                                 // return new HoverBrowserControl(parent);
580                         }
581                 };
582         }
583         /**
584          * Returns the outline presenter control creator. The creator is a factory
585          * creating outline presenter controls for the given source viewer. This
586          * implementation always returns a creator for <code>JavaOutlineInformationControl</code>
587          * instances.
588          * 
589          * @param sourceViewer
590          *            the source viewer to be configured by this configuration
591          * @return an information control creator
592          * @since 2.1
593          */
594         private IInformationControlCreator getOutlinePresenterControlCreator(
595                         ISourceViewer sourceViewer) {
596                 return new IInformationControlCreator() {
597                         public IInformationControl createInformationControl(Shell parent) {
598                                 int shellStyle = SWT.RESIZE;
599                                 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
600                                 return new JavaOutlineInformationControl(parent, shellStyle,
601                                                 treeStyle);
602                         }
603                 };
604         }
605         /**
606          * Returns the outline presenter which will determine and shown information
607          * requested for the current cursor position.
608          * 
609          * @param sourceViewer
610          *            the source viewer to be configured by this configuration
611          * @param doCodeResolve
612          *            a boolean which specifies whether code resolve should be used
613          *            to compute the Java element
614          * @return an information presenter
615          * @since 2.1
616          */
617         public IInformationPresenter getOutlinePresenter(
618                         ISourceViewer sourceViewer, boolean doCodeResolve) {
619                 InformationPresenter presenter = new InformationPresenter(
620                                 getOutlinePresenterControlCreator(sourceViewer));
621                 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
622                 IInformationProvider provider = new JavaElementProvider(getEditor(),
623                                 doCodeResolve);
624                 presenter.setInformationProvider(provider,
625                                 IDocument.DEFAULT_CONTENT_TYPE);
626                 presenter.setInformationProvider(provider,
627                                 IPHPPartitions.PHP_PARTITIONING);
628                 presenter.setInformationProvider(provider,
629                                 IPHPPartitions.PHP_PHPDOC_COMMENT);
630                 presenter.setInformationProvider(provider,
631                                 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
632                 presenter.setInformationProvider(provider,
633                                 IPHPPartitions.HTML);
634                 presenter.setInformationProvider(provider,
635                                 IPHPPartitions.HTML_MULTILINE_COMMENT);
636                 presenter.setSizeConstraints(40, 20, true, false);
637                 return presenter;
638         }
639 }