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.PreferencesAdapter;
28 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
29 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategyDQ;
30 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategySQ;
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.JavaDocAutoIndentStrategy;
35 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
36 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
37 import net.sourceforge.phpdt.ui.PreferenceConstants;
38 import net.sourceforge.phpeclipse.IPreferenceConstants;
39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
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.xml.ui.XMLPlugin;
49 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
50 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
51 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
53 import org.eclipse.core.runtime.NullProgressMonitor;
54 import org.eclipse.jface.preference.IPreferenceStore;
55 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
56 import org.eclipse.jface.text.DefaultInformationControl;
57 import org.eclipse.jface.text.IAutoIndentStrategy;
58 import org.eclipse.jface.text.IDocument;
59 import org.eclipse.jface.text.IInformationControl;
60 import org.eclipse.jface.text.IInformationControlCreator;
61 import org.eclipse.jface.text.ITextDoubleClickStrategy;
62 import org.eclipse.jface.text.ITextHover;
63 import org.eclipse.jface.text.ITextViewerExtension2;
64 import org.eclipse.jface.text.TextAttribute;
65 import org.eclipse.jface.text.contentassist.ContentAssistant;
66 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
67 import org.eclipse.jface.text.contentassist.IContentAssistant;
68 import org.eclipse.jface.text.formatter.ContentFormatter;
69 import org.eclipse.jface.text.formatter.IContentFormatter;
70 import org.eclipse.jface.text.formatter.IFormattingStrategy;
71 import org.eclipse.jface.text.information.IInformationPresenter;
72 import org.eclipse.jface.text.information.IInformationProvider;
73 import org.eclipse.jface.text.information.InformationPresenter;
74 import org.eclipse.jface.text.presentation.IPresentationDamager;
75 import org.eclipse.jface.text.presentation.IPresentationReconciler;
76 import org.eclipse.jface.text.presentation.IPresentationRepairer;
77 import org.eclipse.jface.text.presentation.PresentationReconciler;
78 import org.eclipse.jface.text.reconciler.IReconciler;
79 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
80 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
81 import org.eclipse.jface.text.rules.DefaultPartitioner;
82 import org.eclipse.jface.text.rules.RuleBasedScanner;
83 import org.eclipse.jface.text.rules.Token;
84 import org.eclipse.jface.text.source.IAnnotationHover;
85 import org.eclipse.jface.text.source.ISourceViewer;
86 import org.eclipse.jface.text.source.SourceViewerConfiguration;
87 import org.eclipse.jface.util.Assert;
88 import org.eclipse.jface.util.PropertyChangeEvent;
89 import org.eclipse.swt.SWT;
90 import org.eclipse.swt.widgets.Shell;
91 import org.eclipse.ui.editors.text.EditorsUI;
92 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
93 import org.eclipse.ui.texteditor.ITextEditor;
96 * Configuration for an <code>SourceViewer</code> which shows PHP code.
98 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
100 * Preference key used to look up display tab width.
104 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
107 * Preference key for inserting spaces rather than tabs.
111 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
113 // public static final String HTML_DEFAULT =
114 // IPHPPartitionScannerConstants.HTML;
115 //IDocument.DEFAULT_CONTENT_TYPE;
116 private JavaTextTools fJavaTextTools;
118 private ITextEditor fTextEditor;
121 * The document partitioning.
125 private String fDocumentPartitioning;
127 private ContentFormatter fFormatter;
129 private HTMLFormattingStrategy fFormattingStrategy;
132 * Single token scanner.
134 static class SingleTokenScanner extends BufferedRuleBasedScanner {
135 public SingleTokenScanner(TextAttribute attribute) {
136 setDefaultReturnToken(new Token(attribute));
141 * The document partitioning.
145 // private String fDocumentPartitioning;
147 * The Java source code scanner
151 private AbstractJavaScanner fCodeScanner;
154 * The Java multi-line comment scanner
158 private AbstractJavaScanner fMultilineCommentScanner;
161 * The Java single-line comment scanner
165 private AbstractJavaScanner fSinglelineCommentScanner;
168 * The Java string scanner
172 private AbstractJavaScanner fStringScanner;
175 * The Javadoc scanner
179 private AbstractJavaScanner fJavaDocScanner;
182 * The preference store, can be read-only
186 private IPreferenceStore fPreferenceStore;
193 private IColorManager fColorManager;
195 private XMLTextTools fXMLTextTools;
197 private XMLConfiguration xmlConfiguration;
200 * Creates a new Java source viewer configuration for viewers in the given editor using the given preference store, the color
201 * manager and the specified document partitioning.
203 * Creates a Java source viewer configuration in the new setup without text tools. Clients are allowed to call
204 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and disallowed to call
205 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the resulting Java source viewer configuration.
208 * @param colorManager
210 * @param preferenceStore
211 * the preference store, can be read-only
213 * the editor in which the configured viewer(s) will reside
214 * @param partitioning
215 * the document partitioning for this configuration
218 public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor,
219 String partitioning) {
220 fColorManager = colorManager;
221 fPreferenceStore = preferenceStore;
222 fTextEditor = editor;
223 fDocumentPartitioning = partitioning;
224 // fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
225 fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
226 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
227 fColorManager = colorManager;
228 fPreferenceStore = preferenceStore;
229 fTextEditor = editor;
230 fDocumentPartitioning = partitioning;
232 initializeScanners();
236 * Creates a new Java source viewer configuration for viewers in the given editor using the given Java tools.
239 * the Java text tools to be used
241 * the editor in which the configured viewer(s) will reside
243 * @deprecated As of 3.0, replaced by
244 * {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
246 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor editor, String partitioning) {
247 // fJavaTextTools = tools;
248 // fColorManager = tools.getColorManager();
249 // fPreferenceStore = createPreferenceStore();
250 // fDocumentPartitioning = partitioning;
251 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
252 // fMultilineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getMultilineCommentScanner();
253 // fSinglelineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getSinglelineCommentScanner();
254 // fStringScanner = (AbstractJavaScanner) fJavaTextTools.getStringScanner();
255 // fJavaDocScanner = (AbstractJavaScanner) fJavaTextTools.getJavaDocScanner();
256 // fTextEditor = editor;
257 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
258 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
261 * Returns the color manager for this configuration.
263 * @return the color manager
265 protected IColorManager getColorManager() {
266 return fColorManager;
270 * Initializes the scanners.
274 private void initializeScanners() {
275 Assert.isTrue(isNewSetup());
276 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
277 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
278 IPreferenceConstants.PHP_MULTILINE_COMMENT);
279 fSinglelineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
280 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
281 fStringScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING);
282 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore);
286 * Determines whether the preference change encoded by the given event changes the behavior of one of its contained components.
289 * the event to be investigated
290 * @return <code>true</code> if event causes a behavioral change
293 public boolean affectsTextPresentation(PropertyChangeEvent event) {
294 return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
295 || fSinglelineCommentScanner.affectsBehavior(event) || fStringScanner.affectsBehavior(event)
296 || fJavaDocScanner.affectsBehavior(event);
300 * Adapts the behavior of the contained components to the change encoded in the given event.
302 * Clients are not allowed to call this method if the old setup with text tools is in use.
306 * the event to which to adapt
307 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
310 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
311 Assert.isTrue(isNewSetup());
312 if (fCodeScanner.affectsBehavior(event))
313 fCodeScanner.adaptToPreferenceChange(event);
314 if (fMultilineCommentScanner.affectsBehavior(event))
315 fMultilineCommentScanner.adaptToPreferenceChange(event);
316 if (fSinglelineCommentScanner.affectsBehavior(event))
317 fSinglelineCommentScanner.adaptToPreferenceChange(event);
318 if (fStringScanner.affectsBehavior(event))
319 fStringScanner.adaptToPreferenceChange(event);
320 if (fJavaDocScanner.affectsBehavior(event))
321 fJavaDocScanner.adaptToPreferenceChange(event);
325 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
327 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
328 // if (fFormatter == null) {
329 // fFormatter = new ContentFormatter();
330 // fFormattingStrategy = new HTMLFormattingStrategy(this,
332 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
333 // fFormatter.enablePartitionAwareFormatting(false);
334 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
336 // return fFormatter;
337 if (fFormatter == null) {
339 fFormatter = new ContentFormatter();
340 IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer);
341 fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
342 fFormatter.enablePartitionAwareFormatting(false);
343 fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
349 * Returns the names of the document position categories used by the document partitioners created by this object to manage their
350 * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
352 * @return the partition managing position categories or <code>null</code> if there is none
354 public String[] getPartitionManagingPositionCategories() {
355 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
359 // * Returns the names of the document position categories used by the
361 // * partitioners created by this object to manage their partition
363 // * If the partitioners don't use document position categories, the
365 // * result is <code>null</code>.
367 // * @return the partition managing position categories or
369 // * if there is none
371 // private String[] getPartitionManagingPositionCategories() {
372 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
374 public ITextEditor getEditor() {
379 * Returns the preference store used by this configuration to initialize the individual bits and pieces.
381 * @return the preference store used to initialize this configuration
385 protected IPreferenceStore getPreferenceStore() {
386 return PHPeclipsePlugin.getDefault().getPreferenceStore();
390 // * Method declared on SourceViewerConfiguration
392 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
393 // return new PHPAnnotationHover();
396 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
398 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
399 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
403 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
406 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
407 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
411 * (non-Javadoc) Method declared on SourceViewerConfiguration
413 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
414 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
415 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
416 return new JavaDocAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
417 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
418 return new JavaStringAutoIndentStrategyDQ(getConfiguredDocumentPartitioning(sourceViewer));
419 if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
420 return new JavaStringAutoIndentStrategySQ(getConfiguredDocumentPartitioning(sourceViewer));
422 return (PHPDocumentPartitioner.PHP_TEMPLATE_DATA.equals(contentType)
423 || PHPDocumentPartitioner.PHP_SCRIPT_CODE.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
424 || IPHPPartitions.PHP_PARTITIONING.equals(contentType) || PHPPartitionScanner.PHP_SCRIPTING_AREA.equals(contentType) ? new PHPAutoIndentStrategy()
425 : new DefaultAutoIndentStrategy());
429 * Returns the PHP source code scanner for this configuration.
431 * @return the PHP source code scanner
433 protected RuleBasedScanner getCodeScanner() {
434 return fCodeScanner; //fJavaTextTools.getCodeScanner();
438 * Returns the Java multi-line comment scanner for this configuration.
440 * @return the Java multi-line comment scanner
443 protected RuleBasedScanner getMultilineCommentScanner() {
444 return fMultilineCommentScanner;
448 * Returns the Java single-line comment scanner for this configuration.
450 * @return the Java single-line comment scanner
453 protected RuleBasedScanner getSinglelineCommentScanner() {
454 return fSinglelineCommentScanner;
458 * Returns the Java string scanner for this configuration.
460 * @return the Java string scanner
463 protected RuleBasedScanner getStringScanner() {
464 return fStringScanner;
468 * Returns the HTML source code scanner for this configuration.
470 * @return the HTML source code scanner
472 // protected RuleBasedScanner getHTMLScanner() {
473 // return fJavaTextTools.getHTMLScanner();
476 * Returns the Smarty source code scanner for this configuration.
478 * @return the Smarty source code scanner
480 // protected RuleBasedScanner getSmartyScanner() {
481 // return fJavaTextTools.getSmartyScanner();
484 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
487 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
489 public IReconciler getReconciler(ISourceViewer sourceViewer) {
491 final ITextEditor editor = getEditor();
492 if (editor != null && editor.isEditable()) {
494 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(editor,
495 getConfiguredDocumentPartitioning(sourceViewer));
496 JavaReconciler reconciler = new JavaReconciler(editor, strategy, false);
497 reconciler.setIsIncrementalReconciler(false);
498 reconciler.setProgressMonitor(new NullProgressMonitor());
499 reconciler.setDelay(500);
506 // public IReconciler getReconciler(ISourceViewer sourceViewer) {
507 // if (getEditor() != null && getEditor().isEditable()) {
508 // JavaReconciler reconciler = new JavaReconciler(getEditor(),
509 // new JavaReconcilingStrategy(getEditor()), false);
510 // reconciler.setProgressMonitor(new NullProgressMonitor());
511 // reconciler.setDelay(500);
512 // return reconciler;
517 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String)
520 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
521 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
522 int stateMasks[] = new int[hoverDescs.length];
523 int stateMasksLength = 0;
524 for (int i = 0; i < hoverDescs.length; i++) {
525 if (hoverDescs[i].isEnabled()) {
527 int stateMask = hoverDescs[i].getStateMask();
528 while (j < stateMasksLength) {
529 if (stateMasks[j] == stateMask)
533 if (j == stateMasksLength)
534 stateMasks[stateMasksLength++] = stateMask;
537 if (stateMasksLength == hoverDescs.length)
539 int[] shortenedStateMasks = new int[stateMasksLength];
540 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, stateMasksLength);
541 return shortenedStateMasks;
545 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
548 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
549 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
551 while (i < hoverDescs.length) {
552 if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask)
553 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
557 // if (fEditor != null) {
558 // IEditorInput editorInput = fEditor.getEditorInput();
559 // if (editorInput instanceof IFileEditorInput) {
561 // IFile f = ((IFileEditorInput) editorInput).getFile();
562 // return new PHPTextHover(f.getProject());
563 // } catch (NullPointerException e) {
564 // // this exception occurs, if getTextHover is called by
565 // // preference pages !
569 // return new PHPTextHover(null);
573 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
575 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
576 return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
580 * Returns the SmartyDoc source code scanner for this configuration.
582 * @return the SmartyDoc source code scanner
584 // protected RuleBasedScanner getSmartyDocScanner() {
585 // return fJavaTextTools.getSmartyDocScanner();
588 * Returns the PHPDoc source code scanner for this configuration.
590 * @return the PHPDoc source code scanner
592 protected RuleBasedScanner getPHPDocScanner() {
593 return fJavaDocScanner; //fJavaTextTools.getJavaDocScanner();
597 * (non-Javadoc) Method declared on SourceViewerConfiguration
599 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
600 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP_SCRIPTING_AREA,
602 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT, IPHPPartitions.PHP_PARTITIONING,
603 IPHPPartitions.PHP_SINGLELINE_COMMENT, IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT,
604 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
605 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY,
606 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
608 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
609 XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
611 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
612 XMLPartitionScanner.DTD_INTERNAL_DECL,
614 PHPDocumentPartitioner.PHP_TEMPLATE_DATA, PHPDocumentPartitioner.PHP_SCRIPT_CODE };
617 public String[] getConfiguredHTMLContentTypes() {
618 return new String[] { XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
619 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
621 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
622 XMLPartitionScanner.DTD_INTERNAL_DECL, };
625 public String[] getConfiguredPHPContentTypes() {
626 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitions.PHP_PARTITIONING, IPHPPartitions.PHP_SINGLELINE_COMMENT,
627 IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT, IPHPPartitions.PHP_STRING_DQ,
628 IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
629 IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
633 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
636 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
637 if (fDocumentPartitioning != null)
638 return fDocumentPartitioning;
639 return super.getConfiguredDocumentPartitioning(sourceViewer);
643 * (non-Javadoc) Method declared on SourceViewerConfiguration
645 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
646 ContentAssistant assistant = new ContentAssistant();
647 IContentAssistProcessor processor = new HTMLCompletionProcessor(getEditor());
648 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
649 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
650 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
652 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
653 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
654 assistant.setContentAssistProcessor(processor, IPHPPartitions.JAVASCRIPT);
655 assistant.setContentAssistProcessor(processor, IPHPPartitions.JS_MULTILINE_COMMENT);
656 // TODO define special smarty partition content assist
657 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
658 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
660 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
661 String[] htmlTypes = getConfiguredHTMLContentTypes();
662 for (int i = 0; i < htmlTypes.length; i++) {
663 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
665 processor = new PHPCompletionProcessor(getEditor());
667 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
668 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
669 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
670 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
672 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
673 // assistant.enableAutoActivation(true);
674 // assistant.setAutoActivationDelay(500);
675 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
676 // ContentAssistPreference.configure(assistant, getPreferenceStore());
677 // assistant.setContextInformationPopupOrientation(
678 // ContentAssistant.CONTEXT_INFO_ABOVE);
679 // assistant.setContextInformationPopupBackground(
680 // PHPEditorEnvironment.getPHPColorProvider().getColor(
681 // new RGB(150, 150, 0)));
682 ContentAssistPreference.configure(assistant, getPreferenceStore());
683 assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
684 assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
689 * (non-Javadoc) Method declared on SourceViewerConfiguration
691 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
693 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
695 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
696 // null); //$NON-NLS-1$
699 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
702 public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
703 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
707 * (non-Javadoc) Method declared on SourceViewerConfiguration
709 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
710 return new PHPDoubleClickSelector();
714 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
716 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
717 Vector vector = new Vector();
718 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
719 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault().getPreferenceStore();
720 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
721 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
722 for (int i = 0; i <= tabWidth; i++) {
723 StringBuffer prefix = new StringBuffer();
725 for (int j = 0; j + i < tabWidth; j++)
730 for (int j = 0; j < i; j++)
735 vector.add(prefix.toString());
737 vector.add(""); //$NON-NLS-1$
738 return (String[]) vector.toArray(new String[vector.size()]);
742 * @return <code>true</code> iff the new setup without text tools is in use.
746 private boolean isNewSetup() {
747 return fJavaTextTools == null;
751 * Creates and returns a preference store which combines the preference stores from the text tools and which is read-only.
753 * @return the read-only preference store
756 private IPreferenceStore createPreferenceStore() {
757 Assert.isTrue(!isNewSetup());
758 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
759 if (fJavaTextTools.getCorePreferenceStore() == null)
760 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(), generalTextStore });
762 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(),
763 new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()), generalTextStore });
767 * (non-Javadoc) Method declared on SourceViewerConfiguration
769 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
770 // PHPColorProvider provider =
771 // PHPEditorEnvironment.getPHPColorProvider();
772 // JavaColorManager provider =
773 // PHPEditorEnvironment.getPHPColorProvider();
774 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
775 phpReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
777 // DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
778 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
779 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
780 // dr = new DefaultDamagerRepairer(getHTMLScanner());
781 // reconciler.setDamager(dr, IPHPPartitions.HTML);
782 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
783 // dr = new DefaultDamagerRepairer(getHTMLScanner());
784 // reconciler.setDamager(dr, IPHPPartitions.CSS);
785 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
786 // dr = new DefaultDamagerRepairer(getHTMLScanner());
787 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
788 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
789 // dr = new DefaultDamagerRepairer(getHTMLScanner());
790 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
791 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
792 // dr = new DefaultDamagerRepairer(getHTMLScanner());
793 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
794 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
795 // DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getSmartyScanner());
796 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
797 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
798 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
799 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
800 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
801 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
802 // PHPColorProvider.MULTI_LINE_COMMENT))));
803 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
804 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
806 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getCodeScanner());
807 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
808 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
810 phpDR = new DefaultDamagerRepairer(getCodeScanner());
811 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
812 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
814 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
815 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
816 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
818 phpDR = new DefaultDamagerRepairer(getStringScanner());
819 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
820 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
821 phpDR = new DefaultDamagerRepairer(getStringScanner());
822 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
823 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
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);