1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
11 **********************************************************************/
12 package net.sourceforge.phpdt.ui.text;
14 import java.util.Vector;
16 import net.sourceforge.phpdt.core.JavaCore;
17 import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
18 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
19 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
20 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
21 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
22 import net.sourceforge.phpdt.internal.ui.text.JavaCompositeReconcilingStrategy;
23 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
24 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
25 import net.sourceforge.phpdt.internal.ui.text.JavaPresentationReconciler;
26 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
27 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
28 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategyDQ;
29 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategySQ;
30 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
31 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
32 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaInformationProvider;
33 import net.sourceforge.phpdt.internal.ui.text.phpdoc.JavaDocAutoIndentStrategy;
34 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
35 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
36 import net.sourceforge.phpdt.ui.PreferenceConstants;
37 import net.sourceforge.phpeclipse.IPreferenceConstants;
38 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
40 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
41 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
42 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
43 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
44 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
45 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
46 import net.sourceforge.phpeclipse.ui.WebUI;
47 //import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
48 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
49 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
50 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
52 import org.eclipse.core.runtime.NullProgressMonitor;
53 import org.eclipse.jface.preference.IPreferenceStore;
54 import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
55 import org.eclipse.jface.text.DefaultInformationControl;
56 import org.eclipse.jface.text.IAutoEditStrategy;
57 import org.eclipse.jface.text.IDocument;
58 import org.eclipse.jface.text.IInformationControl;
59 import org.eclipse.jface.text.IInformationControlCreator;
60 import org.eclipse.jface.text.ITextDoubleClickStrategy;
61 import org.eclipse.jface.text.ITextHover;
62 import org.eclipse.jface.text.ITextViewerExtension2;
63 import org.eclipse.jface.text.TextAttribute;
64 import org.eclipse.jface.text.contentassist.ContentAssistant;
65 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
66 import org.eclipse.jface.text.contentassist.IContentAssistant;
67 import org.eclipse.jface.text.formatter.ContentFormatter;
68 import org.eclipse.jface.text.formatter.IContentFormatter;
69 import org.eclipse.jface.text.formatter.IFormattingStrategy;
70 import org.eclipse.jface.text.information.IInformationPresenter;
71 import org.eclipse.jface.text.information.IInformationProvider;
72 import org.eclipse.jface.text.information.InformationPresenter;
73 import org.eclipse.jface.text.presentation.IPresentationDamager;
74 import org.eclipse.jface.text.presentation.IPresentationReconciler;
75 import org.eclipse.jface.text.presentation.IPresentationRepairer;
76 import org.eclipse.jface.text.presentation.PresentationReconciler;
77 import org.eclipse.jface.text.reconciler.IReconciler;
78 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
79 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
80 import org.eclipse.jface.text.rules.DefaultPartitioner;
81 import org.eclipse.jface.text.rules.RuleBasedScanner;
82 import org.eclipse.jface.text.rules.Token;
83 import org.eclipse.jface.text.source.IAnnotationHover;
84 import org.eclipse.jface.text.source.ISourceViewer;
85 import org.eclipse.jface.text.source.SourceViewerConfiguration;
86 import org.eclipse.jface.util.PropertyChangeEvent;
87 import org.eclipse.swt.SWT;
88 import org.eclipse.swt.widgets.Shell;
89 import org.eclipse.ui.texteditor.ITextEditor;
92 * Configuration for an <code>SourceViewer</code> which shows PHP code.
94 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
96 * Preference key used to look up display tab width.
100 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
103 * Preference key for inserting spaces rather than tabs.
107 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
109 // public static final String HTML_DEFAULT =
110 // IPHPPartitionScannerConstants.HTML;
111 // IDocument.DEFAULT_CONTENT_TYPE;
112 // private JavaTextTools fJavaTextTools;
114 private ITextEditor fTextEditor;
117 * The document partitioning.
121 private String fDocumentPartitioning;
123 private ContentFormatter fFormatter;
126 * Single token scanner.
128 static class SingleTokenScanner extends BufferedRuleBasedScanner {
129 public SingleTokenScanner(TextAttribute attribute) {
130 setDefaultReturnToken(new Token(attribute));
135 * The document partitioning.
139 // private String fDocumentPartitioning;
141 * The Java source code scanner
145 private AbstractJavaScanner fCodeScanner;
148 * The Java multi-line comment scanner
152 private AbstractJavaScanner fMultilineCommentScanner;
155 * The Java single-line comment scanner
159 private AbstractJavaScanner fSinglelineCommentScanner;
162 * The PHP double quoted string scanner
164 private AbstractJavaScanner fStringDQScanner;
167 * The PHP single quoted string scanner
169 private AbstractJavaScanner fStringSQScanner;
172 * The Javadoc scanner
176 private AbstractJavaScanner fJavaDocScanner;
179 * The preference store, can be read-only
183 private IPreferenceStore fPreferenceStore;
190 private IColorManager fColorManager;
192 private XMLTextTools fXMLTextTools;
194 private XMLConfiguration xmlConfiguration;
197 * Creates a new Java source viewer configuration for viewers in the given
198 * editor using the given preference store, the color manager and the
199 * specified document partitioning.
201 * Creates a Java source viewer configuration in the new setup without text
202 * tools. Clients are allowed to call
203 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and
205 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the
206 * resulting Java source viewer configuration.
209 * @param colorManager
211 * @param preferenceStore
212 * the preference store, can be read-only
214 * the editor in which the configured viewer(s) will reside
215 * @param partitioning
216 * the document partitioning for this configuration
219 public PHPSourceViewerConfiguration(IColorManager colorManager,
220 IPreferenceStore preferenceStore, ITextEditor editor,
221 String partitioning) {
222 fColorManager = colorManager;
223 fPreferenceStore = preferenceStore;
224 fTextEditor = editor;
225 fDocumentPartitioning = partitioning;
226 // fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
227 fXMLTextTools = new XMLTextTools(getPreferenceStore());
228 //XMLPlugin.getDefault().getXMLTextTools();
229 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
230 fColorManager = colorManager;
231 fPreferenceStore = preferenceStore;
232 fTextEditor = editor;
233 fDocumentPartitioning = partitioning;
235 initializeScanners();
239 * Creates a new Java source viewer configuration for viewers in the given
240 * editor using the given Java tools.
243 * the Java text tools to be used
245 * the editor in which the configured viewer(s) will reside
247 * @deprecated As of 3.0, replaced by
248 * {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
250 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor
251 // editor, String partitioning) {
252 // fJavaTextTools = tools;
253 // fColorManager = tools.getColorManager();
254 // fPreferenceStore = createPreferenceStore();
255 // fDocumentPartitioning = partitioning;
256 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
257 // fMultilineCommentScanner = (AbstractJavaScanner)
258 // fJavaTextTools.getMultilineCommentScanner();
259 // fSinglelineCommentScanner = (AbstractJavaScanner)
260 // fJavaTextTools.getSinglelineCommentScanner();
261 // fStringDQScanner = (AbstractJavaScanner)
262 // fJavaTextTools.getStringScanner();
263 // fJavaDocScanner = (AbstractJavaScanner)
264 // fJavaTextTools.getJavaDocScanner();
265 // fTextEditor = editor;
266 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
267 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
270 * Returns the color manager for this configuration.
272 * @return the color manager
274 protected IColorManager getColorManager() {
275 return fColorManager;
279 * Initializes the scanners.
283 private void initializeScanners() {
284 // Assert.isTrue(isNewSetup());
285 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
286 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(),
287 fPreferenceStore, IPreferenceConstants.PHP_MULTILINE_COMMENT);
288 fSinglelineCommentScanner = new SingleTokenPHPScanner(
289 getColorManager(), fPreferenceStore,
290 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
291 // fStringDQScanner = new SingleTokenPHPScanner(getColorManager(),
292 // fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ);
293 fStringDQScanner = new PHPStringDQCodeScanner(getColorManager(),
295 fStringSQScanner = new SingleTokenPHPScanner(getColorManager(),
296 fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
297 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(),
302 * Determines whether the preference change encoded by the given event
303 * changes the behavior of one of its contained components.
306 * the event to be investigated
307 * @return <code>true</code> if event causes a behavioral change
310 public boolean affectsTextPresentation(PropertyChangeEvent event) {
311 return fCodeScanner.affectsBehavior(event)
312 || fMultilineCommentScanner.affectsBehavior(event)
313 || fSinglelineCommentScanner.affectsBehavior(event)
314 || fStringDQScanner.affectsBehavior(event)
315 || fStringSQScanner.affectsBehavior(event)
316 || fJavaDocScanner.affectsBehavior(event);
320 * Adapts the behavior of the contained components to the change encoded in
323 * Clients are not allowed to call this method if the old setup with text
328 * the event to which to adapt
329 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager,
330 * IPreferenceStore, ITextEditor, String)
333 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
334 // Assert.isTrue(isNewSetup());
335 if (fCodeScanner.affectsBehavior(event))
336 fCodeScanner.adaptToPreferenceChange(event);
337 if (fMultilineCommentScanner.affectsBehavior(event))
338 fMultilineCommentScanner.adaptToPreferenceChange(event);
339 if (fSinglelineCommentScanner.affectsBehavior(event))
340 fSinglelineCommentScanner.adaptToPreferenceChange(event);
341 if (fStringDQScanner.affectsBehavior(event))
342 fStringDQScanner.adaptToPreferenceChange(event);
343 if (fStringSQScanner.affectsBehavior(event))
344 fStringSQScanner.adaptToPreferenceChange(event);
345 if (fJavaDocScanner.affectsBehavior(event))
346 fJavaDocScanner.adaptToPreferenceChange(event);
350 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
352 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
353 // if (fFormatter == null) {
354 // fFormatter = new ContentFormatter();
355 // fFormattingStrategy = new HTMLFormattingStrategy(this,
357 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
358 // fFormatter.enablePartitionAwareFormatting(false);
359 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
361 // return fFormatter;
362 if (fFormatter == null) {
364 fFormatter = new ContentFormatter();
365 IFormattingStrategy strategy = new JavaFormattingStrategy(
367 fFormatter.setFormattingStrategy(strategy,
368 IDocument.DEFAULT_CONTENT_TYPE);
369 fFormatter.enablePartitionAwareFormatting(false);
371 .setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
377 * Returns the names of the document position categories used by the
378 * document partitioners created by this object to manage their partition
379 * information. If the partitioners don't use document position categories,
380 * the returned result is <code>null</code>.
382 * @return the partition managing position categories or <code>null</code>
385 public String[] getPartitionManagingPositionCategories() {
386 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
390 // * Returns the names of the document position categories used by the
392 // * partitioners created by this object to manage their partition
394 // * If the partitioners don't use document position categories, the
396 // * result is <code>null</code>.
398 // * @return the partition managing position categories or
400 // * if there is none
402 // private String[] getPartitionManagingPositionCategories() {
403 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
405 public ITextEditor getEditor() {
410 * Returns the preference store used by this configuration to initialize the
411 * individual bits and pieces.
413 * @return the preference store used to initialize this configuration
417 protected IPreferenceStore getPreferenceStore() {
418 return WebUI.getDefault().getPreferenceStore();
422 // * Method declared on SourceViewerConfiguration
424 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
425 // return new PHPAnnotationHover();
428 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
430 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
431 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
435 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
438 public IAnnotationHover getOverviewRulerAnnotationHover(
439 ISourceViewer sourceViewer) {
440 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
443 public IAutoEditStrategy[] getAutoEditStrategies(
444 ISourceViewer sourceViewer, String contentType) {
445 IAutoEditStrategy strategy = new DefaultIndentLineAutoEditStrategy();
446 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
447 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
448 strategy = new JavaDocAutoIndentStrategy(
449 getConfiguredDocumentPartitioning(sourceViewer));
450 else if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
451 strategy = new JavaStringAutoIndentStrategyDQ(
452 getConfiguredDocumentPartitioning(sourceViewer));
453 else if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
454 strategy = new JavaStringAutoIndentStrategySQ(
455 getConfiguredDocumentPartitioning(sourceViewer));
457 strategy = (PHPDocumentPartitioner.PHP_TEMPLATE_DATA
459 || PHPDocumentPartitioner.PHP_SCRIPT_CODE
461 || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
462 || IPHPPartitions.PHP_PARTITIONING.equals(contentType)
463 || PHPPartitionScanner.PHP_SCRIPTING_AREA
464 .equals(contentType) ? new PHPAutoIndentStrategy()
465 : new DefaultIndentLineAutoEditStrategy());
466 IAutoEditStrategy[] result = new IAutoEditStrategy[1];
467 result[0] = strategy;
472 * Returns the PHP source code scanner for this configuration.
474 * @return the PHP source code scanner
476 protected RuleBasedScanner getCodeScanner() {
477 return fCodeScanner; // fJavaTextTools.getCodeScanner();
481 * Returns the Java multi-line comment scanner for this configuration.
483 * @return the Java multi-line comment scanner
486 protected RuleBasedScanner getMultilineCommentScanner() {
487 return fMultilineCommentScanner;
491 * Returns the Java single-line comment scanner for this configuration.
493 * @return the Java single-line comment scanner
496 protected RuleBasedScanner getSinglelineCommentScanner() {
497 return fSinglelineCommentScanner;
501 * Returns the PHP double quoted string scanner for this configuration.
503 * @return the PHP double quoted string scanner
505 protected RuleBasedScanner getStringDQScanner() {
506 return fStringDQScanner;
510 * Returns the PHP single quoted string scanner for this configuration.
512 * @return the PHP single quoted string scanner
514 protected RuleBasedScanner getStringSQScanner() {
515 return fStringSQScanner;
519 * Returns the HTML source code scanner for this configuration.
521 * @return the HTML source code scanner
523 // protected RuleBasedScanner getHTMLScanner() {
524 // return fJavaTextTools.getHTMLScanner();
527 * Returns the Smarty source code scanner for this configuration.
529 * @return the Smarty source code scanner
531 // protected RuleBasedScanner getSmartyScanner() {
532 // return fJavaTextTools.getSmartyScanner();
535 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
538 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
540 public IReconciler getReconciler(ISourceViewer sourceViewer) {
542 final ITextEditor editor = getEditor();
543 if (editor != null && editor.isEditable()) {
545 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(
546 editor, getConfiguredDocumentPartitioning(sourceViewer));
547 JavaReconciler reconciler = new JavaReconciler(editor, strategy,
549 reconciler.setIsIncrementalReconciler(false);
550 reconciler.setProgressMonitor(new NullProgressMonitor());
551 reconciler.setDelay(500);
559 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer,
563 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer,
564 String contentType) {
565 JavaEditorTextHoverDescriptor[] hoverDescs = WebUI
566 .getDefault().getJavaEditorTextHoverDescriptors();
567 int stateMasks[] = new int[hoverDescs.length];
568 int stateMasksLength = 0;
569 for (int i = 0; i < hoverDescs.length; i++) {
570 if (hoverDescs[i].isEnabled()) {
572 int stateMask = hoverDescs[i].getStateMask();
573 while (j < stateMasksLength) {
574 if (stateMasks[j] == stateMask)
578 if (j == stateMasksLength)
579 stateMasks[stateMasksLength++] = stateMask;
582 if (stateMasksLength == hoverDescs.length)
584 int[] shortenedStateMasks = new int[stateMasksLength];
585 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0,
587 return shortenedStateMasks;
591 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
594 public ITextHover getTextHover(ISourceViewer sourceViewer,
595 String contentType, int stateMask) {
596 JavaEditorTextHoverDescriptor[] hoverDescs = WebUI
597 .getDefault().getJavaEditorTextHoverDescriptors();
599 while (i < hoverDescs.length) {
600 if (hoverDescs[i].isEnabled()
601 && hoverDescs[i].getStateMask() == stateMask)
602 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
606 // if (fEditor != null) {
607 // IEditorInput editorInput = fEditor.getEditorInput();
608 // if (editorInput instanceof IFileEditorInput) {
610 // IFile f = ((IFileEditorInput) editorInput).getFile();
611 // return new PHPTextHover(f.getProject());
612 // } catch (NullPointerException e) {
613 // // this exception occurs, if getTextHover is called by
614 // // preference pages !
618 // return new PHPTextHover(null);
622 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
624 public ITextHover getTextHover(ISourceViewer sourceViewer,
625 String contentType) {
626 return getTextHover(sourceViewer, contentType,
627 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
631 * Returns the SmartyDoc source code scanner for this configuration.
633 * @return the SmartyDoc source code scanner
635 // protected RuleBasedScanner getSmartyDocScanner() {
636 // return fJavaTextTools.getSmartyDocScanner();
639 * Returns the PHPDoc source code scanner for this configuration.
641 * @return the PHPDoc source code scanner
643 protected RuleBasedScanner getPHPDocScanner() {
644 return fJavaDocScanner; // fJavaTextTools.getJavaDocScanner();
648 * (non-Javadoc) Method declared on SourceViewerConfiguration
650 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
651 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
652 PHPPartitionScanner.PHP_SCRIPTING_AREA,
654 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT,
655 IPHPPartitions.PHP_PARTITIONING,
656 IPHPPartitions.PHP_SINGLELINE_COMMENT,
657 IPHPPartitions.PHP_MULTILINE_COMMENT,
658 IPHPPartitions.PHP_PHPDOC_COMMENT,
659 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ,
660 IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS,
661 IPHPPartitions.CSS_MULTILINE_COMMENT,
662 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT,
663 IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT,
665 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT,
666 XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
667 XMLPartitionScanner.XML_ATTRIBUTE,
668 XMLPartitionScanner.XML_CDATA,
670 XMLPartitionScanner.DTD_INTERNAL,
671 XMLPartitionScanner.DTD_INTERNAL_PI,
672 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
673 XMLPartitionScanner.DTD_INTERNAL_DECL,
675 PHPDocumentPartitioner.PHP_TEMPLATE_DATA,
676 PHPDocumentPartitioner.PHP_SCRIPT_CODE };
679 public String[] getConfiguredHTMLContentTypes() {
680 return new String[] { XMLPartitionScanner.XML_PI,
681 XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
682 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE,
683 XMLPartitionScanner.XML_CDATA,
685 XMLPartitionScanner.DTD_INTERNAL,
686 XMLPartitionScanner.DTD_INTERNAL_PI,
687 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
688 XMLPartitionScanner.DTD_INTERNAL_DECL, };
691 public String[] getConfiguredPHPContentTypes() {
692 return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
693 IPHPPartitions.PHP_PARTITIONING,
694 IPHPPartitions.PHP_SINGLELINE_COMMENT,
695 IPHPPartitions.PHP_MULTILINE_COMMENT,
696 IPHPPartitions.PHP_PHPDOC_COMMENT,
697 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ,
698 IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS,
699 IPHPPartitions.CSS_MULTILINE_COMMENT,
700 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT,
701 IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
705 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
708 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
709 if (fDocumentPartitioning != null)
710 return fDocumentPartitioning;
711 return super.getConfiguredDocumentPartitioning(sourceViewer);
715 * (non-Javadoc) Method declared on SourceViewerConfiguration
717 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
718 ContentAssistant assistant = new ContentAssistant();
719 IContentAssistProcessor processor = new HTMLCompletionProcessor(
722 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
723 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
724 assistant.setContentAssistProcessor(processor,
725 IPHPPartitions.HTML_MULTILINE_COMMENT);
727 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
728 assistant.setContentAssistProcessor(processor,
729 IPHPPartitions.CSS_MULTILINE_COMMENT);
730 assistant.setContentAssistProcessor(processor,
731 IPHPPartitions.JAVASCRIPT);
732 assistant.setContentAssistProcessor(processor,
733 IPHPPartitions.JS_MULTILINE_COMMENT);
734 // TODO define special smarty partition content assist
735 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
736 assistant.setContentAssistProcessor(processor,
737 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
739 assistant.setContentAssistProcessor(processor,
740 PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
741 String[] htmlTypes = getConfiguredHTMLContentTypes();
742 for (int i = 0; i < htmlTypes.length; i++) {
743 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
745 processor = new PHPCompletionProcessor(getEditor());
747 assistant.setContentAssistProcessor(processor,
748 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
749 assistant.setContentAssistProcessor(processor,
750 IPHPPartitions.PHP_PARTITIONING);
751 assistant.setContentAssistProcessor(processor,
752 IPHPPartitions.PHP_STRING_DQ);
753 assistant.setContentAssistProcessor(processor,
754 IPHPPartitions.PHP_STRING_SQ);
755 assistant.setContentAssistProcessor(processor,
756 IPHPPartitions.PHP_STRING_HEREDOC);
758 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(
759 getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
760 // assistant.enableAutoActivation(true);
761 // assistant.setAutoActivationDelay(500);
762 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
763 // ContentAssistPreference.configure(assistant, getPreferenceStore());
764 // assistant.setContextInformationPopupOrientation(
765 // ContentAssistant.CONTEXT_INFO_ABOVE);
766 // assistant.setContextInformationPopupBackground(
767 // PHPEditorEnvironment.getPHPColorProvider().getColor(
768 // new RGB(150, 150, 0)));
769 ContentAssistPreference.configure(assistant, getPreferenceStore());
771 .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
773 .setInformationControlCreator(getInformationControlCreator(sourceViewer));
778 * (non-Javadoc) Method declared on SourceViewerConfiguration
780 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
782 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
784 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
785 // null); //$NON-NLS-1$
788 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
791 public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
792 String contentType) {
793 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
797 * (non-Javadoc) Method declared on SourceViewerConfiguration
799 public ITextDoubleClickStrategy getDoubleClickStrategy(
800 ISourceViewer sourceViewer, String contentType) {
801 return new PHPDoubleClickSelector();
805 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
807 public String[] getIndentPrefixes(ISourceViewer sourceViewer,
808 String contentType) {
809 Vector vector = new Vector();
810 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
811 final IPreferenceStore preferences = WebUI.getDefault()
812 .getPreferenceStore();
813 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
814 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
815 for (int i = 0; i <= tabWidth; i++) {
816 StringBuffer prefix = new StringBuffer();
818 for (int j = 0; j + i < tabWidth; j++)
823 for (int j = 0; j < i; j++)
828 vector.add(prefix.toString());
830 vector.add(""); //$NON-NLS-1$
831 return (String[]) vector.toArray(new String[vector.size()]);
835 * @return <code>true</code> iff the new setup without text tools is in
840 // private boolean isNewSetup() {
841 // return fJavaTextTools == null;
844 * Creates and returns a preference store which combines the preference
845 * stores from the text tools and which is read-only.
847 * @return the read-only preference store
850 // private IPreferenceStore createPreferenceStore() {
851 // Assert.isTrue(!isNewSetup());
852 // IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
853 // if (fJavaTextTools.getCorePreferenceStore() == null)
854 // return new ChainedPreferenceStore(new IPreferenceStore[] {
855 // fJavaTextTools.getPreferenceStore(), generalTextStore });
857 // return new ChainedPreferenceStore(new IPreferenceStore[] {
858 // fJavaTextTools.getPreferenceStore(),
859 // new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()),
860 // generalTextStore });
863 * (non-Javadoc) Method declared on SourceViewerConfiguration
865 public IPresentationReconciler getPresentationReconciler(
866 ISourceViewer sourceViewer) {
867 // PHPColorProvider provider =
868 // PHPEditorEnvironment.getPHPColorProvider();
869 // JavaColorManager provider =
870 // PHPEditorEnvironment.getPHPColorProvider();
871 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
873 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
875 // DefaultDamagerRepairer dr = new
876 // DefaultDamagerRepairer(getHTMLScanner());
877 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
878 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
879 // dr = new DefaultDamagerRepairer(getHTMLScanner());
880 // reconciler.setDamager(dr, IPHPPartitions.HTML);
881 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
882 // dr = new DefaultDamagerRepairer(getHTMLScanner());
883 // reconciler.setDamager(dr, IPHPPartitions.CSS);
884 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
885 // dr = new DefaultDamagerRepairer(getHTMLScanner());
886 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
887 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
888 // dr = new DefaultDamagerRepairer(getHTMLScanner());
889 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
890 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
891 // dr = new DefaultDamagerRepairer(getHTMLScanner());
892 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
893 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
894 // DefaultDamagerRepairer phpDR = new
895 // DefaultDamagerRepairer(getSmartyScanner());
896 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
897 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
898 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
899 // phpReconciler.setDamager(phpDR,
900 // IPHPPartitions.SMARTY_MULTILINE_COMMENT);
901 // phpReconciler.setRepairer(phpDR,
902 // IPHPPartitions.SMARTY_MULTILINE_COMMENT);
903 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new
904 // TextAttribute(fJavaTextTools.getColorManager().getColor(
905 // PHPColorProvider.MULTI_LINE_COMMENT))));
906 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
907 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
909 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(
911 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
912 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
914 phpDR = new DefaultDamagerRepairer(getCodeScanner());
915 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
916 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
918 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
919 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
920 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
922 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
923 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
924 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
925 phpDR = new DefaultDamagerRepairer(getStringSQScanner());
926 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
927 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
928 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
929 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
930 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
931 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
932 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
933 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
934 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
935 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
936 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
938 PresentationReconciler reconciler = new PresentationReconciler();
940 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
942 // JavaTextTools jspTextTools =
943 // PHPeclipsePlugin.getDefault().getJavaTextTools();
944 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
945 getPHPDocScanner());// jspTextTools.getJSPTextScanner());
946 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
947 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
949 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new
950 // TextAttribute(fJavaTextTools.getColorManager().getColor(
951 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
952 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
953 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
956 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration
957 .getPresentationReconciler(sourceViewer), xmlConfiguration
958 .getConfiguredContentTypes(sourceViewer),
959 PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
962 configureEmbeddedPresentationReconciler(reconciler, phpReconciler,
963 getConfiguredPHPContentTypes(),
964 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
969 private void configureEmbeddedPresentationReconciler(
970 PresentationReconciler reconciler,
971 IPresentationReconciler embedded, String[] types, String defaultType) {
972 for (int i = 0; i < types.length; i++) {
973 String type = types[i];
975 IPresentationDamager damager = embedded.getDamager(type);
976 IPresentationRepairer repairer = embedded.getRepairer(type);
978 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
982 reconciler.setDamager(damager, type);
983 reconciler.setRepairer(repairer, type);
988 * (non-Javadoc) Method declared on SourceViewerConfiguration
990 public int getTabWidth(ISourceViewer sourceViewer) {
991 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
995 * (non-Javadoc) Method declared on SourceViewerConfiguration
997 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
999 // if (fEditor != null) {
1000 // IEditorInput editorInput = fEditor.getEditorInput();
1001 // if (editorInput instanceof IFileEditorInput) {
1003 // IFile f = ((IFileEditorInput) editorInput).getFile();
1004 // return new PHPTextHover(f.getProject());
1005 // } catch (NullPointerException e) {
1006 // // this exception occurs, if getTextHover is called by preference pages
1011 // return new PHPTextHover(null);
1014 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
1017 public IInformationControlCreator getInformationControlCreator(
1018 ISourceViewer sourceViewer) {
1019 return new IInformationControlCreator() {
1020 public IInformationControl createInformationControl(Shell parent) {
1021 return new DefaultInformationControl(parent, SWT.NONE,
1022 new HTMLTextPresenter(true));
1023 // return new HoverBrowserControl(parent);
1029 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
1032 public IInformationPresenter getInformationPresenter(
1033 ISourceViewer sourceViewer) {
1034 InformationPresenter presenter = new InformationPresenter(
1035 getInformationPresenterControlCreator(sourceViewer));
1037 .setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
1038 IInformationProvider provider = new JavaInformationProvider(getEditor());
1039 presenter.setInformationProvider(provider,
1040 IDocument.DEFAULT_CONTENT_TYPE);
1041 presenter.setInformationProvider(provider,
1042 IPHPPartitions.PHP_PHPDOC_COMMENT);
1043 // presenter.setInformationProvider(provider,
1044 // IPHPPartitions.JAVA_CHARACTER);
1045 presenter.setSizeConstraints(60, 10, true, true);
1050 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
1053 // public IInformationPresenter getInformationPresenter(ISourceViewer
1055 // InformationPresenter presenter= new
1056 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
1057 // IInformationProvider provider= new JavaInformationProvider(getEditor());
1058 // presenter.setInformationProvider(provider,
1059 // IDocument.DEFAULT_CONTENT_TYPE);
1060 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
1061 // presenter.setSizeConstraints(60, 10, true, true);
1062 // return presenter;
1065 * Returns the information presenter control creator. The creator is a
1066 * factory creating the presenter controls for the given source viewer. This
1067 * implementation always returns a creator for
1068 * <code>DefaultInformationControl</code> instances.
1070 * @param sourceViewer
1071 * the source viewer to be configured by this configuration
1072 * @return an information control creator
1075 private IInformationControlCreator getInformationPresenterControlCreator(
1076 ISourceViewer sourceViewer) {
1077 return new IInformationControlCreator() {
1078 public IInformationControl createInformationControl(Shell parent) {
1079 int shellStyle = SWT.RESIZE;
1080 int style = SWT.V_SCROLL | SWT.H_SCROLL;
1081 return new DefaultInformationControl(parent, shellStyle, style,
1082 new HTMLTextPresenter(false));
1083 // return new HoverBrowserControl(parent);
1089 * Returns the outline presenter control creator. The creator is a factory
1090 * creating outline presenter controls for the given source viewer. This
1091 * implementation always returns a creator for
1092 * <code>JavaOutlineInformationControl</code> instances.
1094 * @param sourceViewer
1095 * the source viewer to be configured by this configuration
1096 * @return an information control creator
1099 private IInformationControlCreator getOutlinePresenterControlCreator(
1100 ISourceViewer sourceViewer) {
1101 return new IInformationControlCreator() {
1102 public IInformationControl createInformationControl(Shell parent) {
1103 int shellStyle = SWT.RESIZE;
1104 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
1105 return new JavaOutlineInformationControl(parent, shellStyle,
1112 * Returns the outline presenter which will determine and shown information
1113 * requested for the current cursor position.
1115 * @param sourceViewer
1116 * the source viewer to be configured by this configuration
1117 * @param doCodeResolve
1118 * a boolean which specifies whether code resolve should be used
1119 * to compute the Java element
1120 * @return an information presenter
1123 public IInformationPresenter getOutlinePresenter(
1124 ISourceViewer sourceViewer, boolean doCodeResolve) {
1125 InformationPresenter presenter = new InformationPresenter(
1126 getOutlinePresenterControlCreator(sourceViewer));
1127 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
1128 IInformationProvider provider = new JavaElementProvider(getEditor(),
1130 presenter.setInformationProvider(provider,
1131 IDocument.DEFAULT_CONTENT_TYPE);
1132 presenter.setInformationProvider(provider,
1133 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
1134 presenter.setInformationProvider(provider,
1135 IPHPPartitions.PHP_PARTITIONING);
1136 presenter.setInformationProvider(provider,
1137 IPHPPartitions.PHP_PHPDOC_COMMENT);
1138 presenter.setInformationProvider(provider,
1139 IPHPPartitions.SMARTY_MULTILINE_COMMENT);
1140 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
1141 presenter.setInformationProvider(provider,
1142 IPHPPartitions.HTML_MULTILINE_COMMENT);
1143 presenter.setSizeConstraints(40, 20, true, false);