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
10 Klaus Hartlage - www.eclipseproject.de
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.JavaColorManager;
23 import net.sourceforge.phpdt.internal.ui.text.JavaCompositeReconcilingStrategy;
24 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
25 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
26 import net.sourceforge.phpdt.internal.ui.text.JavaPresentationReconciler;
27 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
28 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
29 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
30 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategy;
31 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
32 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
33 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaInformationProvider;
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.PHPEditor;
40 import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
41 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
42 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
43 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
44 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
45 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
46 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
47 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
48 import net.sourceforge.phpeclipse.phpeditor.php.SmartyCodeScanner;
49 import net.sourceforge.phpeclipse.phpeditor.php.SmartyDocCodeScanner;
50 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
51 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
52 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
53 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
54 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
56 import org.eclipse.core.runtime.NullProgressMonitor;
57 import org.eclipse.jface.preference.IPreferenceStore;
58 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
59 import org.eclipse.jface.text.DefaultInformationControl;
60 import org.eclipse.jface.text.IAutoIndentStrategy;
61 import org.eclipse.jface.text.IDocument;
62 import org.eclipse.jface.text.IInformationControl;
63 import org.eclipse.jface.text.IInformationControlCreator;
64 import org.eclipse.jface.text.ITextDoubleClickStrategy;
65 import org.eclipse.jface.text.ITextHover;
66 import org.eclipse.jface.text.ITextViewerExtension2;
67 import org.eclipse.jface.text.TextAttribute;
68 import org.eclipse.jface.text.contentassist.ContentAssistant;
69 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
70 import org.eclipse.jface.text.contentassist.IContentAssistant;
71 import org.eclipse.jface.text.formatter.ContentFormatter;
72 import org.eclipse.jface.text.formatter.IContentFormatter;
73 import org.eclipse.jface.text.formatter.IFormattingStrategy;
74 import org.eclipse.jface.text.information.IInformationPresenter;
75 import org.eclipse.jface.text.information.IInformationProvider;
76 import org.eclipse.jface.text.information.InformationPresenter;
77 import org.eclipse.jface.text.presentation.IPresentationDamager;
78 import org.eclipse.jface.text.presentation.IPresentationReconciler;
79 import org.eclipse.jface.text.presentation.IPresentationRepairer;
80 import org.eclipse.jface.text.presentation.PresentationReconciler;
81 import org.eclipse.jface.text.reconciler.IReconciler;
82 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
83 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
84 import org.eclipse.jface.text.rules.DefaultPartitioner;
85 import org.eclipse.jface.text.rules.RuleBasedScanner;
86 import org.eclipse.jface.text.rules.Token;
87 import org.eclipse.jface.text.source.IAnnotationHover;
88 import org.eclipse.jface.text.source.ISourceViewer;
89 import org.eclipse.jface.text.source.SourceViewerConfiguration;
90 import org.eclipse.jface.util.Assert;
91 import org.eclipse.jface.util.PropertyChangeEvent;
92 import org.eclipse.swt.SWT;
93 import org.eclipse.swt.widgets.Shell;
94 import org.eclipse.ui.editors.text.EditorsUI;
95 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
96 import org.eclipse.ui.texteditor.ITextEditor;
99 * Configuration for an <code>SourceViewer</code> which shows PHP code.
101 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
103 * Preference key used to look up display tab width.
107 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
110 * Preference key for inserting spaces rather than tabs.
114 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
116 // public static final String HTML_DEFAULT =
117 // IPHPPartitionScannerConstants.HTML;
118 //IDocument.DEFAULT_CONTENT_TYPE;
119 private JavaTextTools fJavaTextTools;
121 private ITextEditor fTextEditor;
124 * The document partitioning.
128 private String fDocumentPartitioning;
130 private ContentFormatter fFormatter;
132 private HTMLFormattingStrategy fFormattingStrategy;
135 * Single token scanner.
137 static class SingleTokenScanner extends BufferedRuleBasedScanner {
138 public SingleTokenScanner(TextAttribute attribute) {
139 setDefaultReturnToken(new Token(attribute));
144 * The document partitioning.
148 // private String fDocumentPartitioning;
150 * The Java source code scanner
154 private AbstractJavaScanner fCodeScanner;
157 * The Java multi-line comment scanner
161 private AbstractJavaScanner fMultilineCommentScanner;
164 * The Java single-line comment scanner
168 private AbstractJavaScanner fSinglelineCommentScanner;
171 * The Java string scanner
175 private AbstractJavaScanner fStringScanner;
178 * The Javadoc scanner
182 private AbstractJavaScanner fJavaDocScanner;
185 * The preference store, can be read-only
189 private IPreferenceStore fPreferenceStore;
196 private IColorManager fColorManager;
198 private XMLTextTools fXMLTextTools;
200 private XMLConfiguration xmlConfiguration;
203 * Creates a new Java source viewer configuration for viewers in the given editor using the given preference store, the color
204 * manager and the specified document partitioning.
206 * Creates a Java source viewer configuration in the new setup without text tools. Clients are allowed to call
207 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and disallowed to call
208 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the resulting Java source viewer configuration.
211 * @param colorManager
213 * @param preferenceStore
214 * the preference store, can be read-only
216 * the editor in which the configured viewer(s) will reside
217 * @param partitioning
218 * the document partitioning for this configuration
221 public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor,
222 String partitioning) {
223 fColorManager = colorManager;
224 fPreferenceStore = preferenceStore;
225 fTextEditor = editor;
226 fDocumentPartitioning = partitioning;
227 // fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
228 fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
229 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
230 fColorManager= colorManager;
231 fPreferenceStore= preferenceStore;
233 fDocumentPartitioning= partitioning;
235 initializeScanners();
239 * Creates a new Java source viewer configuration for viewers in the given editor
240 * using the given Java tools.
242 * @param tools the Java text tools to be used
243 * @param editor the editor in which the configured viewer(s) will reside
245 * @deprecated As of 3.0, replaced by {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
247 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor editor, String partitioning) {
248 // fJavaTextTools = tools;
249 // fColorManager = tools.getColorManager();
250 // fPreferenceStore = createPreferenceStore();
251 // fDocumentPartitioning = partitioning;
252 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
253 // fMultilineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getMultilineCommentScanner();
254 // fSinglelineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getSinglelineCommentScanner();
255 // fStringScanner = (AbstractJavaScanner) fJavaTextTools.getStringScanner();
256 // fJavaDocScanner = (AbstractJavaScanner) fJavaTextTools.getJavaDocScanner();
257 // fTextEditor = editor;
258 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
259 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
263 * Returns the color manager for this configuration.
265 * @return the color manager
267 protected IColorManager getColorManager() {
268 return fColorManager;
272 * Initializes the scanners.
276 private void initializeScanners() {
277 Assert.isTrue(isNewSetup());
278 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
279 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
280 IPreferenceConstants.PHP_MULTILINE_COMMENT);
281 fSinglelineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
282 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
283 fStringScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING);
284 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore);
288 * Determines whether the preference change encoded by the given event changes the behavior of one of its contained components.
291 * the event to be investigated
292 * @return <code>true</code> if event causes a behavioral change
295 public boolean affectsTextPresentation(PropertyChangeEvent event) {
296 return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
297 || fSinglelineCommentScanner.affectsBehavior(event) || fStringScanner.affectsBehavior(event)
298 || fJavaDocScanner.affectsBehavior(event);
302 * Adapts the behavior of the contained components to the change encoded in the given event.
304 * Clients are not allowed to call this method if the old setup with text tools is in use.
308 * the event to which to adapt
309 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
312 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
313 Assert.isTrue(isNewSetup());
314 if (fCodeScanner.affectsBehavior(event))
315 fCodeScanner.adaptToPreferenceChange(event);
316 if (fMultilineCommentScanner.affectsBehavior(event))
317 fMultilineCommentScanner.adaptToPreferenceChange(event);
318 if (fSinglelineCommentScanner.affectsBehavior(event))
319 fSinglelineCommentScanner.adaptToPreferenceChange(event);
320 if (fStringScanner.affectsBehavior(event))
321 fStringScanner.adaptToPreferenceChange(event);
322 if (fJavaDocScanner.affectsBehavior(event))
323 fJavaDocScanner.adaptToPreferenceChange(event);
327 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
329 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
330 // if (fFormatter == null) {
331 // fFormatter = new ContentFormatter();
332 // fFormattingStrategy = new HTMLFormattingStrategy(this,
334 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
335 // fFormatter.enablePartitionAwareFormatting(false);
336 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
338 // return fFormatter;
339 if (fFormatter == null) {
341 fFormatter = new ContentFormatter();
342 IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer);
343 fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
344 fFormatter.enablePartitionAwareFormatting(false);
345 fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
351 * Returns the names of the document position categories used by the document partitioners created by this object to manage their
352 * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
354 * @return the partition managing position categories or <code>null</code> if there is none
356 public String[] getPartitionManagingPositionCategories() {
357 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
361 // * Returns the names of the document position categories used by the
363 // * partitioners created by this object to manage their partition
365 // * If the partitioners don't use document position categories, the
367 // * result is <code>null</code>.
369 // * @return the partition managing position categories or
371 // * if there is none
373 // private String[] getPartitionManagingPositionCategories() {
374 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
376 public ITextEditor getEditor() {
381 * Returns the preference store used by this configuration to initialize the individual bits and pieces.
383 * @return the preference store used to initialize this configuration
387 protected IPreferenceStore getPreferenceStore() {
388 return PHPeclipsePlugin.getDefault().getPreferenceStore();
392 // * Method declared on SourceViewerConfiguration
394 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
395 // return new PHPAnnotationHover();
398 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
400 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
401 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
405 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
408 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
409 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
413 * (non-Javadoc) Method declared on SourceViewerConfiguration
415 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
416 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType) || IPHPPartitions.PHP_STRING_SQ.equals(contentType))
417 return new JavaStringAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
419 return (PHPDocumentPartitioner.PHP_TEMPLATE_DATA.equals(contentType)
420 || PHPDocumentPartitioner.PHP_SCRIPT_CODE.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
421 || IPHPPartitions.PHP_PARTITIONING.equals(contentType) || PHPPartitionScanner.PHP_SCRIPTING_AREA.equals(contentType) ? new PHPAutoIndentStrategy()
422 : new DefaultAutoIndentStrategy());
426 * Returns the PHP source code scanner for this configuration.
428 * @return the PHP source code scanner
430 protected RuleBasedScanner getCodeScanner() {
431 return fCodeScanner; //fJavaTextTools.getCodeScanner();
434 * Returns the Java multi-line comment scanner for this configuration.
436 * @return the Java multi-line comment scanner
439 protected RuleBasedScanner getMultilineCommentScanner() {
440 return fMultilineCommentScanner;
444 * Returns the Java single-line comment scanner for this configuration.
446 * @return the Java single-line comment scanner
449 protected RuleBasedScanner getSinglelineCommentScanner() {
450 return fSinglelineCommentScanner;
454 * Returns the Java string scanner for this configuration.
456 * @return the Java string scanner
459 protected RuleBasedScanner getStringScanner() {
460 return fStringScanner;
463 * Returns the HTML source code scanner for this configuration.
465 * @return the HTML source code scanner
467 // protected RuleBasedScanner getHTMLScanner() {
468 // return fJavaTextTools.getHTMLScanner();
471 * Returns the Smarty source code scanner for this configuration.
473 * @return the Smarty source code scanner
475 // protected RuleBasedScanner getSmartyScanner() {
476 // return fJavaTextTools.getSmartyScanner();
480 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
483 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
485 public IReconciler getReconciler(ISourceViewer sourceViewer) {
487 final ITextEditor editor = getEditor();
488 if (editor != null && editor.isEditable()) {
490 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(editor,
491 getConfiguredDocumentPartitioning(sourceViewer));
492 JavaReconciler reconciler = new JavaReconciler(editor, strategy, false);
493 reconciler.setIsIncrementalReconciler(false);
494 reconciler.setProgressMonitor(new NullProgressMonitor());
495 reconciler.setDelay(500);
502 // public IReconciler getReconciler(ISourceViewer sourceViewer) {
503 // if (getEditor() != null && getEditor().isEditable()) {
504 // JavaReconciler reconciler = new JavaReconciler(getEditor(),
505 // new JavaReconcilingStrategy(getEditor()), false);
506 // reconciler.setProgressMonitor(new NullProgressMonitor());
507 // reconciler.setDelay(500);
508 // return reconciler;
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();
585 * Returns the PHPDoc source code scanner for this configuration.
587 * @return the PHPDoc source code scanner
589 protected RuleBasedScanner getPHPDocScanner() {
590 return fJavaDocScanner; //fJavaTextTools.getJavaDocScanner();
594 * (non-Javadoc) Method declared on SourceViewerConfiguration
596 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
597 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP_SCRIPTING_AREA,
599 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT, IPHPPartitions.PHP_PARTITIONING,
600 IPHPPartitions.PHP_SINGLELINE_COMMENT, IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT,
601 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
602 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY,
603 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
605 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
606 XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
608 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
609 XMLPartitionScanner.DTD_INTERNAL_DECL,
611 PHPDocumentPartitioner.PHP_TEMPLATE_DATA, PHPDocumentPartitioner.PHP_SCRIPT_CODE };
614 public String[] getConfiguredHTMLContentTypes() {
615 return new String[] { XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
616 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
618 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
619 XMLPartitionScanner.DTD_INTERNAL_DECL, };
622 public String[] getConfiguredPHPContentTypes() {
623 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitions.PHP_PARTITIONING, IPHPPartitions.PHP_SINGLELINE_COMMENT,
624 IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT, IPHPPartitions.PHP_STRING_DQ,
625 IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
626 IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
630 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
633 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
634 if (fDocumentPartitioning != null)
635 return fDocumentPartitioning;
636 return super.getConfiguredDocumentPartitioning(sourceViewer);
640 * (non-Javadoc) Method declared on SourceViewerConfiguration
642 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
643 ContentAssistant assistant = new ContentAssistant();
644 IContentAssistProcessor processor = new HTMLCompletionProcessor(getEditor());
645 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
646 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
647 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
649 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
650 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
651 assistant.setContentAssistProcessor(processor, IPHPPartitions.JAVASCRIPT);
652 assistant.setContentAssistProcessor(processor, IPHPPartitions.JS_MULTILINE_COMMENT);
653 // TODO define special smarty partition content assist
654 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
655 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
657 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
658 String[] htmlTypes = getConfiguredHTMLContentTypes();
659 for (int i = 0; i < htmlTypes.length; i++) {
660 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
662 processor = new PHPCompletionProcessor(getEditor());
664 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
665 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
666 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
667 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
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(getStringScanner());
816 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
817 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
818 phpDR = new DefaultDamagerRepairer(getStringScanner());
819 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
820 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
821 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
822 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
823 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
824 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
825 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
826 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
828 PresentationReconciler reconciler = new PresentationReconciler();
829 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
831 JavaTextTools jspTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
832 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getPHPDocScanner());//jspTextTools.getJSPTextScanner());
833 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
834 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
836 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
837 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
838 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
839 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
842 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration.getPresentationReconciler(sourceViewer), xmlConfiguration
843 .getConfiguredContentTypes(sourceViewer), PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
846 configureEmbeddedPresentationReconciler(reconciler, phpReconciler, getConfiguredPHPContentTypes(),
847 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
852 private void configureEmbeddedPresentationReconciler(PresentationReconciler reconciler, IPresentationReconciler embedded,
853 String[] types, String defaultType) {
854 for (int i = 0; i < types.length; i++) {
855 String type = types[i];
857 IPresentationDamager damager = embedded.getDamager(type);
858 IPresentationRepairer repairer = embedded.getRepairer(type);
860 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
864 reconciler.setDamager(damager, type);
865 reconciler.setRepairer(repairer, type);
870 * (non-Javadoc) Method declared on SourceViewerConfiguration
872 public int getTabWidth(ISourceViewer sourceViewer) {
873 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
877 * (non-Javadoc) Method declared on SourceViewerConfiguration
879 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
881 // if (fEditor != null) {
882 // IEditorInput editorInput = fEditor.getEditorInput();
883 // if (editorInput instanceof IFileEditorInput) {
885 // IFile f = ((IFileEditorInput) editorInput).getFile();
886 // return new PHPTextHover(f.getProject());
887 // } catch (NullPointerException e) {
888 // // this exception occurs, if getTextHover is called by preference pages
893 // return new PHPTextHover(null);
896 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
899 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
900 return new IInformationControlCreator() {
901 public IInformationControl createInformationControl(Shell parent) {
902 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
903 // return new HoverBrowserControl(parent);
909 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
912 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
913 InformationPresenter presenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
914 presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
915 IInformationProvider provider = new JavaInformationProvider(getEditor());
916 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
917 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
918 // presenter.setInformationProvider(provider, IPHPPartitions.JAVA_CHARACTER);
919 presenter.setSizeConstraints(60, 10, true, true);
924 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
927 // public IInformationPresenter getInformationPresenter(ISourceViewer
929 // InformationPresenter presenter= new
930 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
931 // IInformationProvider provider= new JavaInformationProvider(getEditor());
932 // presenter.setInformationProvider(provider,
933 // IDocument.DEFAULT_CONTENT_TYPE);
934 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
935 // presenter.setSizeConstraints(60, 10, true, true);
939 * Returns the information presenter control creator. The creator is a factory creating the presenter controls for the given
940 * source viewer. This implementation always returns a creator for <code>DefaultInformationControl</code> instances.
942 * @param sourceViewer
943 * the source viewer to be configured by this configuration
944 * @return an information control creator
947 private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
948 return new IInformationControlCreator() {
949 public IInformationControl createInformationControl(Shell parent) {
950 int shellStyle = SWT.RESIZE;
951 int style = SWT.V_SCROLL | SWT.H_SCROLL;
952 return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
953 // return new HoverBrowserControl(parent);
959 * Returns the outline presenter control creator. The creator is a factory creating outline presenter controls for the given
960 * source viewer. This implementation always returns a creator for <code>JavaOutlineInformationControl</code> instances.
962 * @param sourceViewer
963 * the source viewer to be configured by this configuration
964 * @return an information control creator
967 private IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer) {
968 return new IInformationControlCreator() {
969 public IInformationControl createInformationControl(Shell parent) {
970 int shellStyle = SWT.RESIZE;
971 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
972 return new JavaOutlineInformationControl(parent, shellStyle, treeStyle);
978 * Returns the outline presenter which will determine and shown information requested for the current cursor position.
980 * @param sourceViewer
981 * the source viewer to be configured by this configuration
982 * @param doCodeResolve
983 * a boolean which specifies whether code resolve should be used to compute the Java element
984 * @return an information presenter
987 public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {
988 InformationPresenter presenter = new InformationPresenter(getOutlinePresenterControlCreator(sourceViewer));
989 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
990 IInformationProvider provider = new JavaElementProvider(getEditor(), doCodeResolve);
991 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
992 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PARTITIONING);
993 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
994 presenter.setInformationProvider(provider, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
995 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
996 presenter.setInformationProvider(provider, IPHPPartitions.HTML_MULTILINE_COMMENT);
997 presenter.setSizeConstraints(40, 20, true, false);