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
9 IBM Corporation - Initial implementation
11 **********************************************************************/
12 package net.sourceforge.phpdt.ui.text;
14 import java.util.Vector;
16 import net.sourceforge.phpdt.core.JavaCore;
17 import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
18 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
19 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
20 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
21 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
22 import net.sourceforge.phpdt.internal.ui.text.JavaCompositeReconcilingStrategy;
23 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
24 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
25 import net.sourceforge.phpdt.internal.ui.text.JavaPresentationReconciler;
26 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
27 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
28 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategyDQ;
29 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategySQ;
30 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
31 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
32 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaInformationProvider;
33 import net.sourceforge.phpdt.internal.ui.text.phpdoc.JavaDocAutoIndentStrategy;
34 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
35 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
36 import net.sourceforge.phpdt.ui.PreferenceConstants;
37 import net.sourceforge.phpeclipse.IPreferenceConstants;
38 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
40 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
41 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
42 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
43 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
44 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
45 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
46 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
47 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
48 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
49 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
51 import org.eclipse.core.runtime.NullProgressMonitor;
52 import org.eclipse.jface.preference.IPreferenceStore;
53 import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
54 import org.eclipse.jface.text.DefaultInformationControl;
55 import org.eclipse.jface.text.IAutoEditStrategy;
56 import org.eclipse.jface.text.IDocument;
57 import org.eclipse.jface.text.IInformationControl;
58 import org.eclipse.jface.text.IInformationControlCreator;
59 import org.eclipse.jface.text.ITextDoubleClickStrategy;
60 import org.eclipse.jface.text.ITextHover;
61 import org.eclipse.jface.text.ITextViewerExtension2;
62 import org.eclipse.jface.text.TextAttribute;
63 import org.eclipse.jface.text.contentassist.ContentAssistant;
64 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
65 import org.eclipse.jface.text.contentassist.IContentAssistant;
66 import org.eclipse.jface.text.formatter.ContentFormatter;
67 import org.eclipse.jface.text.formatter.IContentFormatter;
68 import org.eclipse.jface.text.formatter.IFormattingStrategy;
69 import org.eclipse.jface.text.information.IInformationPresenter;
70 import org.eclipse.jface.text.information.IInformationProvider;
71 import org.eclipse.jface.text.information.InformationPresenter;
72 import org.eclipse.jface.text.presentation.IPresentationDamager;
73 import org.eclipse.jface.text.presentation.IPresentationReconciler;
74 import org.eclipse.jface.text.presentation.IPresentationRepairer;
75 import org.eclipse.jface.text.presentation.PresentationReconciler;
76 import org.eclipse.jface.text.reconciler.IReconciler;
77 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
78 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
79 import org.eclipse.jface.text.rules.DefaultPartitioner;
80 import org.eclipse.jface.text.rules.RuleBasedScanner;
81 import org.eclipse.jface.text.rules.Token;
82 import org.eclipse.jface.text.source.IAnnotationHover;
83 import org.eclipse.jface.text.source.ISourceViewer;
84 import org.eclipse.jface.text.source.SourceViewerConfiguration;
85 import org.eclipse.jface.util.PropertyChangeEvent;
86 import org.eclipse.swt.SWT;
87 import org.eclipse.swt.widgets.Shell;
88 import org.eclipse.ui.texteditor.ITextEditor;
91 * Configuration for an <code>SourceViewer</code> which shows PHP code.
93 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
95 * Preference key used to look up display tab width.
99 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
102 * Preference key for inserting spaces rather than tabs.
106 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
108 // public static final String HTML_DEFAULT =
109 // IPHPPartitionScannerConstants.HTML;
110 //IDocument.DEFAULT_CONTENT_TYPE;
111 // private JavaTextTools fJavaTextTools;
113 private ITextEditor fTextEditor;
116 * The document partitioning.
120 private String fDocumentPartitioning;
122 private ContentFormatter fFormatter;
125 * Single token scanner.
127 static class SingleTokenScanner extends BufferedRuleBasedScanner {
128 public SingleTokenScanner(TextAttribute attribute) {
129 setDefaultReturnToken(new Token(attribute));
134 * The document partitioning.
138 // private String fDocumentPartitioning;
140 * The Java source code scanner
144 private AbstractJavaScanner fCodeScanner;
147 * The Java multi-line comment scanner
151 private AbstractJavaScanner fMultilineCommentScanner;
154 * The Java single-line comment scanner
158 private AbstractJavaScanner fSinglelineCommentScanner;
161 * The PHP double quoted string scanner
163 private AbstractJavaScanner fStringDQScanner;
165 * The PHP single quoted string scanner
167 private AbstractJavaScanner fStringSQScanner;
170 * The Javadoc scanner
174 private AbstractJavaScanner fJavaDocScanner;
177 * The preference store, can be read-only
181 private IPreferenceStore fPreferenceStore;
188 private IColorManager fColorManager;
190 private XMLTextTools fXMLTextTools;
192 private XMLConfiguration xmlConfiguration;
195 * Creates a new Java source viewer configuration for viewers in the given editor using the given preference store, the color
196 * manager and the specified document partitioning.
198 * Creates a Java source viewer configuration in the new setup without text tools. Clients are allowed to call
199 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and disallowed to call
200 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the resulting Java source viewer configuration.
203 * @param colorManager
205 * @param preferenceStore
206 * the preference store, can be read-only
208 * the editor in which the configured viewer(s) will reside
209 * @param partitioning
210 * the document partitioning for this configuration
213 public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor,
214 String partitioning) {
215 fColorManager = colorManager;
216 fPreferenceStore = preferenceStore;
217 fTextEditor = editor;
218 fDocumentPartitioning = partitioning;
219 // fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
220 fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
221 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
222 fColorManager = colorManager;
223 fPreferenceStore = preferenceStore;
224 fTextEditor = editor;
225 fDocumentPartitioning = partitioning;
227 initializeScanners();
231 * Creates a new Java source viewer configuration for viewers in the given editor using the given Java tools.
234 * the Java text tools to be used
236 * the editor in which the configured viewer(s) will reside
238 * @deprecated As of 3.0, replaced by
239 * {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
241 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor editor, String partitioning) {
242 // fJavaTextTools = tools;
243 // fColorManager = tools.getColorManager();
244 // fPreferenceStore = createPreferenceStore();
245 // fDocumentPartitioning = partitioning;
246 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
247 // fMultilineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getMultilineCommentScanner();
248 // fSinglelineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getSinglelineCommentScanner();
249 // fStringDQScanner = (AbstractJavaScanner) fJavaTextTools.getStringScanner();
250 // fJavaDocScanner = (AbstractJavaScanner) fJavaTextTools.getJavaDocScanner();
251 // fTextEditor = editor;
252 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
253 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
256 * Returns the color manager for this configuration.
258 * @return the color manager
260 protected IColorManager getColorManager() {
261 return fColorManager;
265 * Initializes the scanners.
269 private void initializeScanners() {
270 // Assert.isTrue(isNewSetup());
271 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
272 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
273 IPreferenceConstants.PHP_MULTILINE_COMMENT);
274 fSinglelineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
275 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
276 // fStringDQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ);
277 fStringDQScanner = new PHPStringDQCodeScanner(getColorManager(), fPreferenceStore);
278 fStringSQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
279 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore);
283 * Determines whether the preference change encoded by the given event changes the behavior of one of its contained components.
286 * the event to be investigated
287 * @return <code>true</code> if event causes a behavioral change
290 public boolean affectsTextPresentation(PropertyChangeEvent event) {
291 return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
292 || fSinglelineCommentScanner.affectsBehavior(event) || fStringDQScanner.affectsBehavior(event)|| fStringSQScanner.affectsBehavior(event)
293 || fJavaDocScanner.affectsBehavior(event);
297 * Adapts the behavior of the contained components to the change encoded in the given event.
299 * Clients are not allowed to call this method if the old setup with text tools is in use.
303 * the event to which to adapt
304 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
307 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
308 // Assert.isTrue(isNewSetup());
309 if (fCodeScanner.affectsBehavior(event))
310 fCodeScanner.adaptToPreferenceChange(event);
311 if (fMultilineCommentScanner.affectsBehavior(event))
312 fMultilineCommentScanner.adaptToPreferenceChange(event);
313 if (fSinglelineCommentScanner.affectsBehavior(event))
314 fSinglelineCommentScanner.adaptToPreferenceChange(event);
315 if (fStringDQScanner.affectsBehavior(event))
316 fStringDQScanner.adaptToPreferenceChange(event);
317 if (fStringSQScanner.affectsBehavior(event))
318 fStringSQScanner.adaptToPreferenceChange(event);
319 if (fJavaDocScanner.affectsBehavior(event))
320 fJavaDocScanner.adaptToPreferenceChange(event);
324 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
326 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
327 // if (fFormatter == null) {
328 // fFormatter = new ContentFormatter();
329 // fFormattingStrategy = new HTMLFormattingStrategy(this,
331 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
332 // fFormatter.enablePartitionAwareFormatting(false);
333 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
335 // return fFormatter;
336 if (fFormatter == null) {
338 fFormatter = new ContentFormatter();
339 IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer);
340 fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
341 fFormatter.enablePartitionAwareFormatting(false);
342 fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
348 * Returns the names of the document position categories used by the document partitioners created by this object to manage their
349 * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
351 * @return the partition managing position categories or <code>null</code> if there is none
353 public String[] getPartitionManagingPositionCategories() {
354 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
358 // * Returns the names of the document position categories used by the
360 // * partitioners created by this object to manage their partition
362 // * If the partitioners don't use document position categories, the
364 // * result is <code>null</code>.
366 // * @return the partition managing position categories or
368 // * if there is none
370 // private String[] getPartitionManagingPositionCategories() {
371 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
373 public ITextEditor getEditor() {
378 * Returns the preference store used by this configuration to initialize the individual bits and pieces.
380 * @return the preference store used to initialize this configuration
384 protected IPreferenceStore getPreferenceStore() {
385 return PHPeclipsePlugin.getDefault().getPreferenceStore();
389 // * Method declared on SourceViewerConfiguration
391 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
392 // return new PHPAnnotationHover();
395 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
397 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
398 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
402 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
405 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
406 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
410 * (non-Javadoc) Method declared on SourceViewerConfiguration
412 public IAutoEditStrategy getAutoEditStrategy(ISourceViewer sourceViewer, String contentType) {
413 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
414 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
415 return new JavaDocAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
416 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
417 return new JavaStringAutoIndentStrategyDQ(getConfiguredDocumentPartitioning(sourceViewer));
418 if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
419 return new JavaStringAutoIndentStrategySQ(getConfiguredDocumentPartitioning(sourceViewer));
421 return (PHPDocumentPartitioner.PHP_TEMPLATE_DATA.equals(contentType)
422 || PHPDocumentPartitioner.PHP_SCRIPT_CODE.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
423 || IPHPPartitions.PHP_PARTITIONING.equals(contentType) || PHPPartitionScanner.PHP_SCRIPTING_AREA.equals(contentType) ? new PHPAutoIndentStrategy()
424 : new DefaultIndentLineAutoEditStrategy());
428 * Returns the PHP source code scanner for this configuration.
430 * @return the PHP source code scanner
432 protected RuleBasedScanner getCodeScanner() {
433 return fCodeScanner; //fJavaTextTools.getCodeScanner();
437 * Returns the Java multi-line comment scanner for this configuration.
439 * @return the Java multi-line comment scanner
442 protected RuleBasedScanner getMultilineCommentScanner() {
443 return fMultilineCommentScanner;
447 * Returns the Java single-line comment scanner for this configuration.
449 * @return the Java single-line comment scanner
452 protected RuleBasedScanner getSinglelineCommentScanner() {
453 return fSinglelineCommentScanner;
457 * Returns the PHP double quoted string scanner for this configuration.
459 * @return the PHP double quoted string scanner
461 protected RuleBasedScanner getStringDQScanner() {
462 return fStringDQScanner;
466 * Returns the PHP single quoted string scanner for this configuration.
468 * @return the PHP single quoted string scanner
470 protected RuleBasedScanner getStringSQScanner() {
471 return fStringSQScanner;
474 * Returns the HTML source code scanner for this configuration.
476 * @return the HTML source code scanner
478 // protected RuleBasedScanner getHTMLScanner() {
479 // return fJavaTextTools.getHTMLScanner();
482 * Returns the Smarty source code scanner for this configuration.
484 * @return the Smarty source code scanner
486 // protected RuleBasedScanner getSmartyScanner() {
487 // return fJavaTextTools.getSmartyScanner();
490 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
493 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
495 public IReconciler getReconciler(ISourceViewer sourceViewer) {
497 final ITextEditor editor = getEditor();
498 if (editor != null && editor.isEditable()) {
500 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(editor,
501 getConfiguredDocumentPartitioning(sourceViewer));
502 JavaReconciler reconciler = new JavaReconciler(editor, strategy, false);
503 reconciler.setIsIncrementalReconciler(false);
504 reconciler.setProgressMonitor(new NullProgressMonitor());
505 reconciler.setDelay(500);
513 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String)
516 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
517 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
518 int stateMasks[] = new int[hoverDescs.length];
519 int stateMasksLength = 0;
520 for (int i = 0; i < hoverDescs.length; i++) {
521 if (hoverDescs[i].isEnabled()) {
523 int stateMask = hoverDescs[i].getStateMask();
524 while (j < stateMasksLength) {
525 if (stateMasks[j] == stateMask)
529 if (j == stateMasksLength)
530 stateMasks[stateMasksLength++] = stateMask;
533 if (stateMasksLength == hoverDescs.length)
535 int[] shortenedStateMasks = new int[stateMasksLength];
536 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, stateMasksLength);
537 return shortenedStateMasks;
541 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
544 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
545 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
547 while (i < hoverDescs.length) {
548 if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask)
549 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
553 // if (fEditor != null) {
554 // IEditorInput editorInput = fEditor.getEditorInput();
555 // if (editorInput instanceof IFileEditorInput) {
557 // IFile f = ((IFileEditorInput) editorInput).getFile();
558 // return new PHPTextHover(f.getProject());
559 // } catch (NullPointerException e) {
560 // // this exception occurs, if getTextHover is called by
561 // // preference pages !
565 // return new PHPTextHover(null);
569 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
571 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
572 return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
576 * Returns the SmartyDoc source code scanner for this configuration.
578 * @return the SmartyDoc source code scanner
580 // protected RuleBasedScanner getSmartyDocScanner() {
581 // return fJavaTextTools.getSmartyDocScanner();
584 * Returns the PHPDoc source code scanner for this configuration.
586 * @return the PHPDoc source code scanner
588 protected RuleBasedScanner getPHPDocScanner() {
589 return fJavaDocScanner; //fJavaTextTools.getJavaDocScanner();
593 * (non-Javadoc) Method declared on SourceViewerConfiguration
595 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
596 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP_SCRIPTING_AREA,
598 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT, IPHPPartitions.PHP_PARTITIONING,
599 IPHPPartitions.PHP_SINGLELINE_COMMENT, IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT,
600 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
601 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY,
602 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
604 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
605 XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
607 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
608 XMLPartitionScanner.DTD_INTERNAL_DECL,
610 PHPDocumentPartitioner.PHP_TEMPLATE_DATA, PHPDocumentPartitioner.PHP_SCRIPT_CODE };
613 public String[] getConfiguredHTMLContentTypes() {
614 return new String[] { XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
615 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
617 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
618 XMLPartitionScanner.DTD_INTERNAL_DECL, };
621 public String[] getConfiguredPHPContentTypes() {
622 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitions.PHP_PARTITIONING, IPHPPartitions.PHP_SINGLELINE_COMMENT,
623 IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT, IPHPPartitions.PHP_STRING_DQ,
624 IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
625 IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
629 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
632 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
633 if (fDocumentPartitioning != null)
634 return fDocumentPartitioning;
635 return super.getConfiguredDocumentPartitioning(sourceViewer);
639 * (non-Javadoc) Method declared on SourceViewerConfiguration
641 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
642 ContentAssistant assistant = new ContentAssistant();
643 IContentAssistProcessor processor = new HTMLCompletionProcessor(getEditor());
644 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
645 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
646 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
648 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
649 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
650 assistant.setContentAssistProcessor(processor, IPHPPartitions.JAVASCRIPT);
651 assistant.setContentAssistProcessor(processor, IPHPPartitions.JS_MULTILINE_COMMENT);
652 // TODO define special smarty partition content assist
653 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
654 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
656 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
657 String[] htmlTypes = getConfiguredHTMLContentTypes();
658 for (int i = 0; i < htmlTypes.length; i++) {
659 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
661 processor = new PHPCompletionProcessor(getEditor());
663 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
664 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
665 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
666 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
667 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_HEREDOC);
669 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
670 // assistant.enableAutoActivation(true);
671 // assistant.setAutoActivationDelay(500);
672 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
673 // ContentAssistPreference.configure(assistant, getPreferenceStore());
674 // assistant.setContextInformationPopupOrientation(
675 // ContentAssistant.CONTEXT_INFO_ABOVE);
676 // assistant.setContextInformationPopupBackground(
677 // PHPEditorEnvironment.getPHPColorProvider().getColor(
678 // new RGB(150, 150, 0)));
679 ContentAssistPreference.configure(assistant, getPreferenceStore());
680 assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
681 assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
686 * (non-Javadoc) Method declared on SourceViewerConfiguration
688 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
690 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
692 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
693 // null); //$NON-NLS-1$
696 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
699 public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
700 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
704 * (non-Javadoc) Method declared on SourceViewerConfiguration
706 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
707 return new PHPDoubleClickSelector();
711 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
713 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
714 Vector vector = new Vector();
715 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
716 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault().getPreferenceStore();
717 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
718 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
719 for (int i = 0; i <= tabWidth; i++) {
720 StringBuffer prefix = new StringBuffer();
722 for (int j = 0; j + i < tabWidth; j++)
727 for (int j = 0; j < i; j++)
732 vector.add(prefix.toString());
734 vector.add(""); //$NON-NLS-1$
735 return (String[]) vector.toArray(new String[vector.size()]);
739 * @return <code>true</code> iff the new setup without text tools is in use.
743 // private boolean isNewSetup() {
744 // return fJavaTextTools == null;
748 * Creates and returns a preference store which combines the preference stores from the text tools and which is read-only.
750 * @return the read-only preference store
753 // private IPreferenceStore createPreferenceStore() {
754 // Assert.isTrue(!isNewSetup());
755 // IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
756 // if (fJavaTextTools.getCorePreferenceStore() == null)
757 // return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(), generalTextStore });
759 // return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(),
760 // new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()), generalTextStore });
764 * (non-Javadoc) Method declared on SourceViewerConfiguration
766 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
767 // PHPColorProvider provider =
768 // PHPEditorEnvironment.getPHPColorProvider();
769 // JavaColorManager provider =
770 // PHPEditorEnvironment.getPHPColorProvider();
771 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
772 phpReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
774 // DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
775 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
776 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
777 // dr = new DefaultDamagerRepairer(getHTMLScanner());
778 // reconciler.setDamager(dr, IPHPPartitions.HTML);
779 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
780 // dr = new DefaultDamagerRepairer(getHTMLScanner());
781 // reconciler.setDamager(dr, IPHPPartitions.CSS);
782 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
783 // dr = new DefaultDamagerRepairer(getHTMLScanner());
784 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
785 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
786 // dr = new DefaultDamagerRepairer(getHTMLScanner());
787 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
788 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
789 // dr = new DefaultDamagerRepairer(getHTMLScanner());
790 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
791 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
792 // DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getSmartyScanner());
793 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
794 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
795 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
796 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
797 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
798 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
799 // PHPColorProvider.MULTI_LINE_COMMENT))));
800 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
801 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
803 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getCodeScanner());
804 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
805 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
807 phpDR = new DefaultDamagerRepairer(getCodeScanner());
808 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
809 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
811 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
812 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
813 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
815 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
816 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
817 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
818 phpDR = new DefaultDamagerRepairer(getStringSQScanner());
819 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
820 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
821 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
822 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
823 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
824 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
825 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
826 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
827 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
828 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
829 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
831 PresentationReconciler reconciler = new PresentationReconciler();
832 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
834 // JavaTextTools jspTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
835 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getPHPDocScanner());//jspTextTools.getJSPTextScanner());
836 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
837 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
839 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
840 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
841 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
842 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
845 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration.getPresentationReconciler(sourceViewer), xmlConfiguration
846 .getConfiguredContentTypes(sourceViewer), PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
849 configureEmbeddedPresentationReconciler(reconciler, phpReconciler, getConfiguredPHPContentTypes(),
850 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
855 private void configureEmbeddedPresentationReconciler(PresentationReconciler reconciler, IPresentationReconciler embedded,
856 String[] types, String defaultType) {
857 for (int i = 0; i < types.length; i++) {
858 String type = types[i];
860 IPresentationDamager damager = embedded.getDamager(type);
861 IPresentationRepairer repairer = embedded.getRepairer(type);
863 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
867 reconciler.setDamager(damager, type);
868 reconciler.setRepairer(repairer, type);
873 * (non-Javadoc) Method declared on SourceViewerConfiguration
875 public int getTabWidth(ISourceViewer sourceViewer) {
876 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
880 * (non-Javadoc) Method declared on SourceViewerConfiguration
882 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
884 // if (fEditor != null) {
885 // IEditorInput editorInput = fEditor.getEditorInput();
886 // if (editorInput instanceof IFileEditorInput) {
888 // IFile f = ((IFileEditorInput) editorInput).getFile();
889 // return new PHPTextHover(f.getProject());
890 // } catch (NullPointerException e) {
891 // // this exception occurs, if getTextHover is called by preference pages
896 // return new PHPTextHover(null);
899 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
902 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
903 return new IInformationControlCreator() {
904 public IInformationControl createInformationControl(Shell parent) {
905 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
906 // return new HoverBrowserControl(parent);
912 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
915 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
916 InformationPresenter presenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
917 presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
918 IInformationProvider provider = new JavaInformationProvider(getEditor());
919 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
920 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
921 // presenter.setInformationProvider(provider, IPHPPartitions.JAVA_CHARACTER);
922 presenter.setSizeConstraints(60, 10, true, true);
927 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
930 // public IInformationPresenter getInformationPresenter(ISourceViewer
932 // InformationPresenter presenter= new
933 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
934 // IInformationProvider provider= new JavaInformationProvider(getEditor());
935 // presenter.setInformationProvider(provider,
936 // IDocument.DEFAULT_CONTENT_TYPE);
937 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
938 // presenter.setSizeConstraints(60, 10, true, true);
942 * Returns the information presenter control creator. The creator is a factory creating the presenter controls for the given
943 * source viewer. This implementation always returns a creator for <code>DefaultInformationControl</code> instances.
945 * @param sourceViewer
946 * the source viewer to be configured by this configuration
947 * @return an information control creator
950 private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
951 return new IInformationControlCreator() {
952 public IInformationControl createInformationControl(Shell parent) {
953 int shellStyle = SWT.RESIZE;
954 int style = SWT.V_SCROLL | SWT.H_SCROLL;
955 return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
956 // return new HoverBrowserControl(parent);
962 * Returns the outline presenter control creator. The creator is a factory creating outline presenter controls for the given
963 * source viewer. This implementation always returns a creator for <code>JavaOutlineInformationControl</code> instances.
965 * @param sourceViewer
966 * the source viewer to be configured by this configuration
967 * @return an information control creator
970 private IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer) {
971 return new IInformationControlCreator() {
972 public IInformationControl createInformationControl(Shell parent) {
973 int shellStyle = SWT.RESIZE;
974 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
975 return new JavaOutlineInformationControl(parent, shellStyle, treeStyle);
981 * Returns the outline presenter which will determine and shown information requested for the current cursor position.
983 * @param sourceViewer
984 * the source viewer to be configured by this configuration
985 * @param doCodeResolve
986 * a boolean which specifies whether code resolve should be used to compute the Java element
987 * @return an information presenter
990 public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {
991 InformationPresenter presenter = new InformationPresenter(getOutlinePresenterControlCreator(sourceViewer));
992 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
993 IInformationProvider provider = new JavaElementProvider(getEditor(), doCodeResolve);
994 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
995 presenter.setInformationProvider(provider, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
996 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PARTITIONING);
997 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
998 presenter.setInformationProvider(provider, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
999 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
1000 presenter.setInformationProvider(provider, IPHPPartitions.HTML_MULTILINE_COMMENT);
1001 presenter.setSizeConstraints(40, 20, true, false);