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.debug.ui.PHPDebugUiMessages;
18 import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
19 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
20 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
21 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
22 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
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.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.php.HTMLCompletionProcessor;
41 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
42 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
43 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
44 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
45 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
46 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
47 import net.sourceforge.phpeclipse.ui.WebUI;
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.DefaultIndentLineAutoEditStrategy;
56 import org.eclipse.jface.text.DefaultInformationControl;
57 import org.eclipse.jface.text.IAutoEditStrategy;
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.PropertyChangeEvent;
88 import org.eclipse.swt.SWT;
89 import org.eclipse.swt.widgets.Shell;
90 import org.eclipse.ui.texteditor.ITextEditor;
93 * Configuration for an <code>SourceViewer</code> which shows PHP code.
95 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
97 * Preference key used to look up display tab width.
101 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
104 * Preference key for inserting spaces rather than tabs.
108 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
110 // public static final String HTML_DEFAULT =
111 // IPHPPartitionScannerConstants.HTML;
112 // IDocument.DEFAULT_CONTENT_TYPE;
113 // private JavaTextTools fJavaTextTools;
115 private ITextEditor fTextEditor;
118 * The document partitioning.
122 private String fDocumentPartitioning;
124 private ContentFormatter fFormatter;
127 * Single token scanner.
129 static class SingleTokenScanner extends BufferedRuleBasedScanner {
130 public SingleTokenScanner(TextAttribute attribute) {
131 setDefaultReturnToken(new Token(attribute));
136 * The document partitioning.
140 // private String fDocumentPartitioning;
142 * The Java source code scanner
146 private AbstractJavaScanner fCodeScanner;
149 * The Java multi-line comment scanner
153 private AbstractJavaScanner fMultilineCommentScanner;
156 * The Java single-line comment scanner
160 private AbstractJavaScanner fSinglelineCommentScanner;
163 * The PHP double quoted string scanner
165 private AbstractJavaScanner fStringDQScanner;
168 * The PHP single quoted string scanner
170 private AbstractJavaScanner fStringSQScanner;
173 * The Javadoc scanner
177 private AbstractJavaScanner fJavaDocScanner;
180 * The preference store, can be read-only
184 private IPreferenceStore fPreferenceStore;
191 private IColorManager fColorManager;
193 private XMLTextTools fXMLTextTools;
195 private XMLConfiguration xmlConfiguration;
198 * Creates a new Java source viewer configuration for viewers in the given
199 * editor using the given preference store, the color manager and the
200 * specified document partitioning.
202 * Creates a Java source viewer configuration in the new setup without text
203 * tools. Clients are allowed to call
204 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and
206 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the
207 * resulting Java source viewer configuration.
210 * @param colorManager
212 * @param preferenceStore
213 * the preference store, can be read-only
215 * the editor in which the configured viewer(s) will reside
216 * @param partitioning
217 * the document partitioning for this configuration
220 public PHPSourceViewerConfiguration(IColorManager colorManager,
221 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 = new XMLTextTools(getPreferenceStore());
229 //XMLPlugin.getDefault().getXMLTextTools();
230 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
231 fColorManager = colorManager;
232 fPreferenceStore = preferenceStore;
233 fTextEditor = editor;
234 fDocumentPartitioning = partitioning;
236 initializeScanners();
240 * Creates a new Java source viewer configuration for viewers in the given
241 * editor using the given Java tools.
244 * the Java text tools to be used
246 * the editor in which the configured viewer(s) will reside
248 * @deprecated As of 3.0, replaced by
249 * {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
251 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor
252 // editor, String partitioning) {
253 // fJavaTextTools = tools;
254 // fColorManager = tools.getColorManager();
255 // fPreferenceStore = createPreferenceStore();
256 // fDocumentPartitioning = partitioning;
257 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
258 // fMultilineCommentScanner = (AbstractJavaScanner)
259 // fJavaTextTools.getMultilineCommentScanner();
260 // fSinglelineCommentScanner = (AbstractJavaScanner)
261 // fJavaTextTools.getSinglelineCommentScanner();
262 // fStringDQScanner = (AbstractJavaScanner)
263 // fJavaTextTools.getStringScanner();
264 // fJavaDocScanner = (AbstractJavaScanner)
265 // fJavaTextTools.getJavaDocScanner();
266 // fTextEditor = editor;
267 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
268 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
271 * Returns the color manager for this configuration.
273 * @return the color manager
275 protected IColorManager getColorManager() {
276 return fColorManager;
280 * Initializes the scanners.
284 private void initializeScanners() {
285 // Assert.isTrue(isNewSetup());
286 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
287 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(),
288 fPreferenceStore, IPreferenceConstants.PHP_MULTILINE_COMMENT);
289 fSinglelineCommentScanner = new SingleTokenPHPScanner(
290 getColorManager(), fPreferenceStore,
291 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
292 // fStringDQScanner = new SingleTokenPHPScanner(getColorManager(),
293 // fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ);
294 fStringDQScanner = new PHPStringDQCodeScanner(getColorManager(),
296 fStringSQScanner = new SingleTokenPHPScanner(getColorManager(),
297 fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
298 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(),
303 * Determines whether the preference change encoded by the given event
304 * changes the behavior of one of its contained components.
307 * the event to be investigated
308 * @return <code>true</code> if event causes a behavioral change
311 public boolean affectsTextPresentation(PropertyChangeEvent event) {
312 return fCodeScanner.affectsBehavior(event)
313 || fMultilineCommentScanner.affectsBehavior(event)
314 || fSinglelineCommentScanner.affectsBehavior(event)
315 || fStringDQScanner.affectsBehavior(event)
316 || fStringSQScanner.affectsBehavior(event)
317 || fJavaDocScanner.affectsBehavior(event);
321 * Adapts the behavior of the contained components to the change encoded in
324 * Clients are not allowed to call this method if the old setup with text
329 * the event to which to adapt
330 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager,
331 * IPreferenceStore, ITextEditor, String)
334 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
335 // Assert.isTrue(isNewSetup());
336 if (fCodeScanner.affectsBehavior(event))
337 fCodeScanner.adaptToPreferenceChange(event);
338 if (fMultilineCommentScanner.affectsBehavior(event))
339 fMultilineCommentScanner.adaptToPreferenceChange(event);
340 if (fSinglelineCommentScanner.affectsBehavior(event))
341 fSinglelineCommentScanner.adaptToPreferenceChange(event);
342 if (fStringDQScanner.affectsBehavior(event))
343 fStringDQScanner.adaptToPreferenceChange(event);
344 if (fStringSQScanner.affectsBehavior(event))
345 fStringSQScanner.adaptToPreferenceChange(event);
346 if (fJavaDocScanner.affectsBehavior(event))
347 fJavaDocScanner.adaptToPreferenceChange(event);
351 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
353 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
354 // if (fFormatter == null) {
355 // fFormatter = new ContentFormatter();
356 // fFormattingStrategy = new HTMLFormattingStrategy(this,
358 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
359 // fFormatter.enablePartitionAwareFormatting(false);
360 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
362 // return fFormatter;
363 if (fFormatter == null) {
365 fFormatter = new ContentFormatter();
366 IFormattingStrategy strategy = new JavaFormattingStrategy(
368 fFormatter.setFormattingStrategy(strategy,
369 IDocument.DEFAULT_CONTENT_TYPE);
370 fFormatter.enablePartitionAwareFormatting(false);
372 .setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
378 * Returns the names of the document position categories used by the
379 * document partitioners created by this object to manage their partition
380 * information. If the partitioners don't use document position categories,
381 * the returned result is <code>null</code>.
383 * @return the partition managing position categories or <code>null</code>
386 public String[] getPartitionManagingPositionCategories() {
387 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
391 // * Returns the names of the document position categories used by the
393 // * partitioners created by this object to manage their partition
395 // * If the partitioners don't use document position categories, the
397 // * result is <code>null</code>.
399 // * @return the partition managing position categories or
401 // * if there is none
403 // private String[] getPartitionManagingPositionCategories() {
404 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
406 public ITextEditor getEditor() {
411 * Returns the preference store used by this configuration to initialize the
412 * individual bits and pieces.
414 * @return the preference store used to initialize this configuration
418 protected IPreferenceStore getPreferenceStore() {
419 return WebUI.getDefault().getPreferenceStore();
423 // * Method declared on SourceViewerConfiguration
425 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
426 // return new PHPAnnotationHover();
429 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
431 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
432 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
436 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
439 public IAnnotationHover getOverviewRulerAnnotationHover(
440 ISourceViewer sourceViewer) {
441 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
444 public IAutoEditStrategy[] getAutoEditStrategies(
445 ISourceViewer sourceViewer, String contentType) {
446 IAutoEditStrategy strategy = new DefaultIndentLineAutoEditStrategy();
447 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
448 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
449 strategy = new JavaDocAutoIndentStrategy(
450 getConfiguredDocumentPartitioning(sourceViewer));
451 else if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
452 strategy = new JavaStringAutoIndentStrategyDQ(
453 getConfiguredDocumentPartitioning(sourceViewer));
454 else if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
455 strategy = new JavaStringAutoIndentStrategySQ(
456 getConfiguredDocumentPartitioning(sourceViewer));
458 strategy = (PHPDocumentPartitioner.PHP_TEMPLATE_DATA
460 || PHPDocumentPartitioner.PHP_SCRIPT_CODE
462 || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
463 || IPHPPartitions.PHP_PARTITIONING.equals(contentType)
464 || PHPPartitionScanner.PHP_SCRIPTING_AREA
465 .equals(contentType) ? new PHPAutoIndentStrategy()
466 : new DefaultIndentLineAutoEditStrategy());
467 IAutoEditStrategy[] result = new IAutoEditStrategy[1];
468 result[0] = strategy;
473 * Returns the PHP source code scanner for this configuration.
475 * @return the PHP source code scanner
477 protected RuleBasedScanner getCodeScanner() {
478 return fCodeScanner; // fJavaTextTools.getCodeScanner();
482 * Returns the Java multi-line comment scanner for this configuration.
484 * @return the Java multi-line comment scanner
487 protected RuleBasedScanner getMultilineCommentScanner() {
488 return fMultilineCommentScanner;
492 * Returns the Java single-line comment scanner for this configuration.
494 * @return the Java single-line comment scanner
497 protected RuleBasedScanner getSinglelineCommentScanner() {
498 return fSinglelineCommentScanner;
502 * Returns the PHP double quoted string scanner for this configuration.
504 * @return the PHP double quoted string scanner
506 protected RuleBasedScanner getStringDQScanner() {
507 return fStringDQScanner;
511 * Returns the PHP single quoted string scanner for this configuration.
513 * @return the PHP single quoted string scanner
515 protected RuleBasedScanner getStringSQScanner() {
516 return fStringSQScanner;
520 * Returns the HTML source code scanner for this configuration.
522 * @return the HTML source code scanner
524 // protected RuleBasedScanner getHTMLScanner() {
525 // return fJavaTextTools.getHTMLScanner();
528 * Returns the Smarty source code scanner for this configuration.
530 * @return the Smarty source code scanner
532 // protected RuleBasedScanner getSmartyScanner() {
533 // return fJavaTextTools.getSmartyScanner();
536 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
539 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
541 public IReconciler getReconciler(ISourceViewer sourceViewer) {
543 final ITextEditor editor = getEditor();
544 if (editor != null && editor.isEditable()) {
546 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(
547 editor, getConfiguredDocumentPartitioning(sourceViewer));
548 JavaReconciler reconciler = new JavaReconciler(editor, strategy,
550 reconciler.setIsIncrementalReconciler(false);
551 reconciler.setProgressMonitor(new NullProgressMonitor());
552 reconciler.setDelay(500);
560 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer,
564 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer,
565 String contentType) {
566 JavaEditorTextHoverDescriptor[] hoverDescs = WebUI
567 .getDefault().getJavaEditorTextHoverDescriptors();
568 int stateMasks[] = new int[hoverDescs.length];
569 int stateMasksLength = 0;
570 for (int i = 0; i < hoverDescs.length; i++) {
571 if (hoverDescs[i].isEnabled()) {
573 int stateMask = hoverDescs[i].getStateMask();
574 while (j < stateMasksLength) {
575 if (stateMasks[j] == stateMask)
579 if (j == stateMasksLength)
580 stateMasks[stateMasksLength++] = stateMask;
583 if (stateMasksLength == hoverDescs.length)
585 int[] shortenedStateMasks = new int[stateMasksLength];
586 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0,
588 return shortenedStateMasks;
592 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
595 public ITextHover getTextHover(ISourceViewer sourceViewer,
596 String contentType, int stateMask) {
597 JavaEditorTextHoverDescriptor[] hoverDescs = WebUI
598 .getDefault().getJavaEditorTextHoverDescriptors();
600 while (i < hoverDescs.length) {
601 if (hoverDescs[i].isEnabled()
602 && hoverDescs[i].getStateMask() == stateMask)
603 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
607 // if (fEditor != null) {
608 // IEditorInput editorInput = fEditor.getEditorInput();
609 // if (editorInput instanceof IFileEditorInput) {
611 // IFile f = ((IFileEditorInput) editorInput).getFile();
612 // return new PHPTextHover(f.getProject());
613 // } catch (NullPointerException e) {
614 // // this exception occurs, if getTextHover is called by
615 // // preference pages !
619 // return new PHPTextHover(null);
623 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
625 public ITextHover getTextHover(ISourceViewer sourceViewer,
626 String contentType) {
627 return getTextHover(sourceViewer, contentType,
628 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
632 * Returns the SmartyDoc source code scanner for this configuration.
634 * @return the SmartyDoc source code scanner
636 // protected RuleBasedScanner getSmartyDocScanner() {
637 // return fJavaTextTools.getSmartyDocScanner();
640 * Returns the PHPDoc source code scanner for this configuration.
642 * @return the PHPDoc source code scanner
644 protected RuleBasedScanner getPHPDocScanner() {
645 return fJavaDocScanner; // fJavaTextTools.getJavaDocScanner();
649 * (non-Javadoc) Method declared on SourceViewerConfiguration
651 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
652 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
653 PHPPartitionScanner.PHP_SCRIPTING_AREA,
655 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT,
656 IPHPPartitions.PHP_PARTITIONING,
657 IPHPPartitions.PHP_SINGLELINE_COMMENT,
658 IPHPPartitions.PHP_MULTILINE_COMMENT,
659 IPHPPartitions.PHP_PHPDOC_COMMENT,
660 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ,
661 IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS,
662 IPHPPartitions.CSS_MULTILINE_COMMENT,
663 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT,
664 IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT,
666 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT,
667 XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
668 XMLPartitionScanner.XML_ATTRIBUTE,
669 XMLPartitionScanner.XML_CDATA,
671 XMLPartitionScanner.DTD_INTERNAL,
672 XMLPartitionScanner.DTD_INTERNAL_PI,
673 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
674 XMLPartitionScanner.DTD_INTERNAL_DECL,
676 PHPDocumentPartitioner.PHP_TEMPLATE_DATA,
677 PHPDocumentPartitioner.PHP_SCRIPT_CODE };
680 public String[] getConfiguredHTMLContentTypes() {
681 return new String[] { XMLPartitionScanner.XML_PI,
682 XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
683 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE,
684 XMLPartitionScanner.XML_CDATA,
686 XMLPartitionScanner.DTD_INTERNAL,
687 XMLPartitionScanner.DTD_INTERNAL_PI,
688 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
689 XMLPartitionScanner.DTD_INTERNAL_DECL, };
692 public String[] getConfiguredPHPContentTypes() {
693 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
694 IPHPPartitions.PHP_PARTITIONING,
695 IPHPPartitions.PHP_SINGLELINE_COMMENT,
696 IPHPPartitions.PHP_MULTILINE_COMMENT,
697 IPHPPartitions.PHP_PHPDOC_COMMENT,
698 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ,
699 IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS,
700 IPHPPartitions.CSS_MULTILINE_COMMENT,
701 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT,
702 IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
706 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
709 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
710 if (fDocumentPartitioning != null)
711 return fDocumentPartitioning;
712 return super.getConfiguredDocumentPartitioning(sourceViewer);
716 * (non-Javadoc) Method declared on SourceViewerConfiguration
718 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
719 ContentAssistant assistant = new ContentAssistant();
720 IContentAssistProcessor processor = new HTMLCompletionProcessor(
723 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
724 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
725 assistant.setContentAssistProcessor(processor,
726 IPHPPartitions.HTML_MULTILINE_COMMENT);
728 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
729 assistant.setContentAssistProcessor(processor,
730 IPHPPartitions.CSS_MULTILINE_COMMENT);
731 assistant.setContentAssistProcessor(processor,
732 IPHPPartitions.JAVASCRIPT);
733 assistant.setContentAssistProcessor(processor,
734 IPHPPartitions.JS_MULTILINE_COMMENT);
735 // TODO define special smarty partition content assist
736 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
737 assistant.setContentAssistProcessor(processor,
738 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
740 assistant.setContentAssistProcessor(processor,
741 PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
742 String[] htmlTypes = getConfiguredHTMLContentTypes();
743 for (int i = 0; i < htmlTypes.length; i++) {
744 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
746 processor = new PHPCompletionProcessor(getEditor());
748 assistant.setContentAssistProcessor(processor,
749 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
750 assistant.setContentAssistProcessor(processor,
751 IPHPPartitions.PHP_PARTITIONING);
752 assistant.setContentAssistProcessor(processor,
753 IPHPPartitions.PHP_STRING_DQ);
754 assistant.setContentAssistProcessor(processor,
755 IPHPPartitions.PHP_STRING_SQ);
756 assistant.setContentAssistProcessor(processor,
757 IPHPPartitions.PHP_STRING_HEREDOC);
759 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(
760 getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
761 // assistant.enableAutoActivation(true);
762 // assistant.setAutoActivationDelay(500);
763 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
764 // ContentAssistPreference.configure(assistant, getPreferenceStore());
765 // assistant.setContextInformationPopupOrientation(
766 // ContentAssistant.CONTEXT_INFO_ABOVE);
767 // assistant.setContextInformationPopupBackground(
768 // PHPEditorEnvironment.getPHPColorProvider().getColor(
769 // new RGB(150, 150, 0)));
770 ContentAssistPreference.configure(assistant, getPreferenceStore());
772 .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
774 .setInformationControlCreator(getInformationControlCreator(sourceViewer));
779 * (non-Javadoc) Method declared on SourceViewerConfiguration
781 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
783 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
785 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
786 // null); //$NON-NLS-1$
789 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
792 public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
793 String contentType) {
794 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
798 * (non-Javadoc) Method declared on SourceViewerConfiguration
800 public ITextDoubleClickStrategy getDoubleClickStrategy(
801 ISourceViewer sourceViewer, String contentType) {
802 return new PHPDoubleClickSelector();
806 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
808 public String[] getIndentPrefixes(ISourceViewer sourceViewer,
809 String contentType) {
810 Vector vector = new Vector();
811 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
812 final IPreferenceStore preferences = WebUI.getDefault()
813 .getPreferenceStore();
814 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
815 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
816 for (int i = 0; i <= tabWidth; i++) {
817 StringBuffer prefix = new StringBuffer();
819 for (int j = 0; j + i < tabWidth; j++)
824 for (int j = 0; j < i; j++)
829 vector.add(prefix.toString());
831 vector.add(""); //$NON-NLS-1$
832 return (String[]) vector.toArray(new String[vector.size()]);
836 * @return <code>true</code> iff the new setup without text tools is in
841 // private boolean isNewSetup() {
842 // return fJavaTextTools == null;
845 * Creates and returns a preference store which combines the preference
846 * stores from the text tools and which is read-only.
848 * @return the read-only preference store
851 // private IPreferenceStore createPreferenceStore() {
852 // Assert.isTrue(!isNewSetup());
853 // IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
854 // if (fJavaTextTools.getCorePreferenceStore() == null)
855 // return new ChainedPreferenceStore(new IPreferenceStore[] {
856 // fJavaTextTools.getPreferenceStore(), generalTextStore });
858 // return new ChainedPreferenceStore(new IPreferenceStore[] {
859 // fJavaTextTools.getPreferenceStore(),
860 // new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()),
861 // generalTextStore });
864 * (non-Javadoc) Method declared on SourceViewerConfiguration
866 public IPresentationReconciler getPresentationReconciler(
867 ISourceViewer sourceViewer) {
868 // PHPColorProvider provider =
869 // PHPEditorEnvironment.getPHPColorProvider();
870 // JavaColorManager provider =
871 // PHPEditorEnvironment.getPHPColorProvider();
872 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
874 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
876 // DefaultDamagerRepairer dr = new
877 // DefaultDamagerRepairer(getHTMLScanner());
878 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
879 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
880 // dr = new DefaultDamagerRepairer(getHTMLScanner());
881 // reconciler.setDamager(dr, IPHPPartitions.HTML);
882 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
883 // dr = new DefaultDamagerRepairer(getHTMLScanner());
884 // reconciler.setDamager(dr, IPHPPartitions.CSS);
885 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
886 // dr = new DefaultDamagerRepairer(getHTMLScanner());
887 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
888 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
889 // dr = new DefaultDamagerRepairer(getHTMLScanner());
890 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
891 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
892 // dr = new DefaultDamagerRepairer(getHTMLScanner());
893 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
894 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
895 // DefaultDamagerRepairer phpDR = new
896 // DefaultDamagerRepairer(getSmartyScanner());
897 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
898 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
899 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
900 // phpReconciler.setDamager(phpDR,
901 // IPHPPartitions.SMARTY_MULTILINE_COMMENT);
902 // phpReconciler.setRepairer(phpDR,
903 // IPHPPartitions.SMARTY_MULTILINE_COMMENT);
904 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new
905 // TextAttribute(fJavaTextTools.getColorManager().getColor(
906 // PHPColorProvider.MULTI_LINE_COMMENT))));
907 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
908 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
910 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(
912 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
913 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
915 phpDR = new DefaultDamagerRepairer(getCodeScanner());
916 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
917 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
919 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
920 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
921 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
923 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
924 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
925 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
926 phpDR = new DefaultDamagerRepairer(getStringSQScanner());
927 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
928 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
929 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
930 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
931 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
932 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
933 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
934 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
935 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
936 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
937 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
939 PresentationReconciler reconciler = new PresentationReconciler();
941 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
943 // JavaTextTools jspTextTools =
944 // PHPeclipsePlugin.getDefault().getJavaTextTools();
945 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
946 getPHPDocScanner());// jspTextTools.getJSPTextScanner());
947 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
948 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
950 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new
951 // TextAttribute(fJavaTextTools.getColorManager().getColor(
952 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
953 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
954 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
957 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration
958 .getPresentationReconciler(sourceViewer), xmlConfiguration
959 .getConfiguredContentTypes(sourceViewer),
960 PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
963 configureEmbeddedPresentationReconciler(reconciler, phpReconciler,
964 getConfiguredPHPContentTypes(),
965 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
970 private void configureEmbeddedPresentationReconciler(
971 PresentationReconciler reconciler,
972 IPresentationReconciler embedded, String[] types, String defaultType) {
973 for (int i = 0; i < types.length; i++) {
974 String type = types[i];
976 IPresentationDamager damager = embedded.getDamager(type);
977 IPresentationRepairer repairer = embedded.getRepairer(type);
979 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
983 reconciler.setDamager(damager, type);
984 reconciler.setRepairer(repairer, type);
989 * (non-Javadoc) Method declared on SourceViewerConfiguration
991 public int getTabWidth(ISourceViewer sourceViewer) {
992 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
996 * (non-Javadoc) Method declared on SourceViewerConfiguration
998 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
1000 // if (fEditor != null) {
1001 // IEditorInput editorInput = fEditor.getEditorInput();
1002 // if (editorInput instanceof IFileEditorInput) {
1004 // IFile f = ((IFileEditorInput) editorInput).getFile();
1005 // return new PHPTextHover(f.getProject());
1006 // } catch (NullPointerException e) {
1007 // // this exception occurs, if getTextHover is called by preference pages
1012 // return new PHPTextHover(null);
1015 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
1018 public IInformationControlCreator getInformationControlCreator(
1019 ISourceViewer sourceViewer) {
1020 return new IInformationControlCreator() {
1021 public IInformationControl createInformationControl(Shell parent) {
1023 // return new DefaultInformationControl(parent, SWT.NONE,
1024 // new HTMLTextPresenter(true));
1025 return new DefaultInformationControl(parent,
1026 new HTMLTextPresenter(true));
1027 // return new HoverBrowserControl(parent);
1033 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
1036 public IInformationPresenter getInformationPresenter(
1037 ISourceViewer sourceViewer) {
1038 InformationPresenter presenter = new InformationPresenter(
1039 getInformationPresenterControlCreator(sourceViewer));
1041 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
1042 IInformationProvider provider = new JavaInformationProvider(getEditor());
1043 presenter.setInformationProvider(provider,
1044 IDocument.DEFAULT_CONTENT_TYPE);
1045 presenter.setInformationProvider(provider,
1046 IPHPPartitions.PHP_PHPDOC_COMMENT);
1047 // presenter.setInformationProvider(provider,
1048 // IPHPPartitions.JAVA_CHARACTER);
1049 presenter.setSizeConstraints(60, 10, true, true);
1054 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
1057 // public IInformationPresenter getInformationPresenter(ISourceViewer
1059 // InformationPresenter presenter= new
1060 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
1061 // IInformationProvider provider= new JavaInformationProvider(getEditor());
1062 // presenter.setInformationProvider(provider,
1063 // IDocument.DEFAULT_CONTENT_TYPE);
1064 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
1065 // presenter.setSizeConstraints(60, 10, true, true);
1066 // return presenter;
1069 * Returns the information presenter control creator. The creator is a
1070 * factory creating the presenter controls for the given source viewer. This
1071 * implementation always returns a creator for
1072 * <code>DefaultInformationControl</code> instances.
1074 * @param sourceViewer
1075 * the source viewer to be configured by this configuration
1076 * @return an information control creator
1079 private IInformationControlCreator getInformationPresenterControlCreator(
1080 ISourceViewer sourceViewer) {
1081 return new IInformationControlCreator() {
1082 public IInformationControl createInformationControl(Shell parent) {
1083 int shellStyle = SWT.RESIZE;
1084 int style = SWT.V_SCROLL | SWT.H_SCROLL;
1085 return new DefaultInformationControl(parent, shellStyle, style,
1086 new HTMLTextPresenter(false));
1087 // return new HoverBrowserControl(parent);
1093 * Returns the outline presenter control creator. The creator is a factory
1094 * creating outline presenter controls for the given source viewer. This
1095 * implementation always returns a creator for
1096 * <code>JavaOutlineInformationControl</code> instances.
1098 * @param sourceViewer
1099 * the source viewer to be configured by this configuration
1100 * @return an information control creator
1103 private IInformationControlCreator getOutlinePresenterControlCreator(
1104 ISourceViewer sourceViewer) {
1105 return new IInformationControlCreator() {
1106 public IInformationControl createInformationControl(Shell parent) {
1107 int shellStyle = SWT.RESIZE;
1108 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
1109 return new JavaOutlineInformationControl(parent, shellStyle,
1116 * Returns the outline presenter which will determine and shown information
1117 * requested for the current cursor position.
1119 * @param sourceViewer
1120 * the source viewer to be configured by this configuration
1121 * @param doCodeResolve
1122 * a boolean which specifies whether code resolve should be used
1123 * to compute the Java element
1124 * @return an information presenter
1127 public IInformationPresenter getOutlinePresenter(
1128 ISourceViewer sourceViewer, boolean doCodeResolve) {
1129 InformationPresenter presenter = new InformationPresenter(
1130 getOutlinePresenterControlCreator(sourceViewer));
1131 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
1132 IInformationProvider provider = new JavaElementProvider(getEditor(),
1134 presenter.setInformationProvider(provider,
1135 IDocument.DEFAULT_CONTENT_TYPE);
1136 presenter.setInformationProvider(provider,
1137 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
1138 presenter.setInformationProvider(provider,
1139 IPHPPartitions.PHP_PARTITIONING);
1140 presenter.setInformationProvider(provider,
1141 IPHPPartitions.PHP_PHPDOC_COMMENT);
1142 presenter.setInformationProvider(provider,
1143 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
1144 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
1145 presenter.setInformationProvider(provider,
1146 IPHPPartitions.HTML_MULTILINE_COMMENT);
1147 presenter.setSizeConstraints(40, 20, true, false);