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.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 = XMLPlugin.getDefault().getXMLTextTools();
228 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
229 fColorManager = colorManager;
230 fPreferenceStore = preferenceStore;
231 fTextEditor = editor;
232 fDocumentPartitioning = partitioning;
234 initializeScanners();
238 * Creates a new Java source viewer configuration for viewers in the given
239 * editor using the given Java tools.
242 * the Java text tools to be used
244 * the editor in which the configured viewer(s) will reside
246 * @deprecated As of 3.0, replaced by
247 * {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
249 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor
250 // editor, String partitioning) {
251 // fJavaTextTools = tools;
252 // fColorManager = tools.getColorManager();
253 // fPreferenceStore = createPreferenceStore();
254 // fDocumentPartitioning = partitioning;
255 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
256 // fMultilineCommentScanner = (AbstractJavaScanner)
257 // fJavaTextTools.getMultilineCommentScanner();
258 // fSinglelineCommentScanner = (AbstractJavaScanner)
259 // fJavaTextTools.getSinglelineCommentScanner();
260 // fStringDQScanner = (AbstractJavaScanner)
261 // fJavaTextTools.getStringScanner();
262 // fJavaDocScanner = (AbstractJavaScanner)
263 // fJavaTextTools.getJavaDocScanner();
264 // fTextEditor = editor;
265 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
266 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
269 * Returns the color manager for this configuration.
271 * @return the color manager
273 protected IColorManager getColorManager() {
274 return fColorManager;
278 * Initializes the scanners.
282 private void initializeScanners() {
283 // Assert.isTrue(isNewSetup());
284 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
285 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(),
286 fPreferenceStore, IPreferenceConstants.PHP_MULTILINE_COMMENT);
287 fSinglelineCommentScanner = new SingleTokenPHPScanner(
288 getColorManager(), fPreferenceStore,
289 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
290 // fStringDQScanner = new SingleTokenPHPScanner(getColorManager(),
291 // fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ);
292 fStringDQScanner = new PHPStringDQCodeScanner(getColorManager(),
294 fStringSQScanner = new SingleTokenPHPScanner(getColorManager(),
295 fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
296 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(),
301 * Determines whether the preference change encoded by the given event
302 * changes the behavior of one of its contained components.
305 * the event to be investigated
306 * @return <code>true</code> if event causes a behavioral change
309 public boolean affectsTextPresentation(PropertyChangeEvent event) {
310 return fCodeScanner.affectsBehavior(event)
311 || fMultilineCommentScanner.affectsBehavior(event)
312 || fSinglelineCommentScanner.affectsBehavior(event)
313 || fStringDQScanner.affectsBehavior(event)
314 || fStringSQScanner.affectsBehavior(event)
315 || fJavaDocScanner.affectsBehavior(event);
319 * Adapts the behavior of the contained components to the change encoded in
322 * Clients are not allowed to call this method if the old setup with text
327 * the event to which to adapt
328 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager,
329 * IPreferenceStore, ITextEditor, String)
332 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
333 // Assert.isTrue(isNewSetup());
334 if (fCodeScanner.affectsBehavior(event))
335 fCodeScanner.adaptToPreferenceChange(event);
336 if (fMultilineCommentScanner.affectsBehavior(event))
337 fMultilineCommentScanner.adaptToPreferenceChange(event);
338 if (fSinglelineCommentScanner.affectsBehavior(event))
339 fSinglelineCommentScanner.adaptToPreferenceChange(event);
340 if (fStringDQScanner.affectsBehavior(event))
341 fStringDQScanner.adaptToPreferenceChange(event);
342 if (fStringSQScanner.affectsBehavior(event))
343 fStringSQScanner.adaptToPreferenceChange(event);
344 if (fJavaDocScanner.affectsBehavior(event))
345 fJavaDocScanner.adaptToPreferenceChange(event);
349 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
351 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
352 // if (fFormatter == null) {
353 // fFormatter = new ContentFormatter();
354 // fFormattingStrategy = new HTMLFormattingStrategy(this,
356 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
357 // fFormatter.enablePartitionAwareFormatting(false);
358 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
360 // return fFormatter;
361 if (fFormatter == null) {
363 fFormatter = new ContentFormatter();
364 IFormattingStrategy strategy = new JavaFormattingStrategy(
366 fFormatter.setFormattingStrategy(strategy,
367 IDocument.DEFAULT_CONTENT_TYPE);
368 fFormatter.enablePartitionAwareFormatting(false);
370 .setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
376 * Returns the names of the document position categories used by the
377 * document partitioners created by this object to manage their partition
378 * information. If the partitioners don't use document position categories,
379 * the returned result is <code>null</code>.
381 * @return the partition managing position categories or <code>null</code>
384 public String[] getPartitionManagingPositionCategories() {
385 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
389 // * Returns the names of the document position categories used by the
391 // * partitioners created by this object to manage their partition
393 // * If the partitioners don't use document position categories, the
395 // * result is <code>null</code>.
397 // * @return the partition managing position categories or
399 // * if there is none
401 // private String[] getPartitionManagingPositionCategories() {
402 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
404 public ITextEditor getEditor() {
409 * Returns the preference store used by this configuration to initialize the
410 * individual bits and pieces.
412 * @return the preference store used to initialize this configuration
416 protected IPreferenceStore getPreferenceStore() {
417 return PHPeclipsePlugin.getDefault().getPreferenceStore();
421 // * Method declared on SourceViewerConfiguration
423 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
424 // return new PHPAnnotationHover();
427 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
429 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
430 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
434 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
437 public IAnnotationHover getOverviewRulerAnnotationHover(
438 ISourceViewer sourceViewer) {
439 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
442 public IAutoEditStrategy[] getAutoEditStrategies(
443 ISourceViewer sourceViewer, String contentType) {
444 IAutoEditStrategy strategy = new DefaultIndentLineAutoEditStrategy();
445 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
446 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
447 strategy = new JavaDocAutoIndentStrategy(
448 getConfiguredDocumentPartitioning(sourceViewer));
449 else if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
450 strategy = new JavaStringAutoIndentStrategyDQ(
451 getConfiguredDocumentPartitioning(sourceViewer));
452 else if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
453 strategy = new JavaStringAutoIndentStrategySQ(
454 getConfiguredDocumentPartitioning(sourceViewer));
456 strategy = (PHPDocumentPartitioner.PHP_TEMPLATE_DATA
458 || PHPDocumentPartitioner.PHP_SCRIPT_CODE
460 || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
461 || IPHPPartitions.PHP_PARTITIONING.equals(contentType)
462 || PHPPartitionScanner.PHP_SCRIPTING_AREA
463 .equals(contentType) ? new PHPAutoIndentStrategy()
464 : new DefaultIndentLineAutoEditStrategy());
465 IAutoEditStrategy[] result = new IAutoEditStrategy[1];
466 result[0] = strategy;
471 * Returns the PHP source code scanner for this configuration.
473 * @return the PHP source code scanner
475 protected RuleBasedScanner getCodeScanner() {
476 return fCodeScanner; // fJavaTextTools.getCodeScanner();
480 * Returns the Java multi-line comment scanner for this configuration.
482 * @return the Java multi-line comment scanner
485 protected RuleBasedScanner getMultilineCommentScanner() {
486 return fMultilineCommentScanner;
490 * Returns the Java single-line comment scanner for this configuration.
492 * @return the Java single-line comment scanner
495 protected RuleBasedScanner getSinglelineCommentScanner() {
496 return fSinglelineCommentScanner;
500 * Returns the PHP double quoted string scanner for this configuration.
502 * @return the PHP double quoted string scanner
504 protected RuleBasedScanner getStringDQScanner() {
505 return fStringDQScanner;
509 * Returns the PHP single quoted string scanner for this configuration.
511 * @return the PHP single quoted string scanner
513 protected RuleBasedScanner getStringSQScanner() {
514 return fStringSQScanner;
518 * Returns the HTML source code scanner for this configuration.
520 * @return the HTML source code scanner
522 // protected RuleBasedScanner getHTMLScanner() {
523 // return fJavaTextTools.getHTMLScanner();
526 * Returns the Smarty source code scanner for this configuration.
528 * @return the Smarty source code scanner
530 // protected RuleBasedScanner getSmartyScanner() {
531 // return fJavaTextTools.getSmartyScanner();
534 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
537 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
539 public IReconciler getReconciler(ISourceViewer sourceViewer) {
541 final ITextEditor editor = getEditor();
542 if (editor != null && editor.isEditable()) {
544 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(
545 editor, getConfiguredDocumentPartitioning(sourceViewer));
546 JavaReconciler reconciler = new JavaReconciler(editor, strategy,
548 reconciler.setIsIncrementalReconciler(false);
549 reconciler.setProgressMonitor(new NullProgressMonitor());
550 reconciler.setDelay(500);
558 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer,
562 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer,
563 String contentType) {
564 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
565 .getDefault().getJavaEditorTextHoverDescriptors();
566 int stateMasks[] = new int[hoverDescs.length];
567 int stateMasksLength = 0;
568 for (int i = 0; i < hoverDescs.length; i++) {
569 if (hoverDescs[i].isEnabled()) {
571 int stateMask = hoverDescs[i].getStateMask();
572 while (j < stateMasksLength) {
573 if (stateMasks[j] == stateMask)
577 if (j == stateMasksLength)
578 stateMasks[stateMasksLength++] = stateMask;
581 if (stateMasksLength == hoverDescs.length)
583 int[] shortenedStateMasks = new int[stateMasksLength];
584 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0,
586 return shortenedStateMasks;
590 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
593 public ITextHover getTextHover(ISourceViewer sourceViewer,
594 String contentType, int stateMask) {
595 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin
596 .getDefault().getJavaEditorTextHoverDescriptors();
598 while (i < hoverDescs.length) {
599 if (hoverDescs[i].isEnabled()
600 && hoverDescs[i].getStateMask() == stateMask)
601 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
605 // if (fEditor != null) {
606 // IEditorInput editorInput = fEditor.getEditorInput();
607 // if (editorInput instanceof IFileEditorInput) {
609 // IFile f = ((IFileEditorInput) editorInput).getFile();
610 // return new PHPTextHover(f.getProject());
611 // } catch (NullPointerException e) {
612 // // this exception occurs, if getTextHover is called by
613 // // preference pages !
617 // return new PHPTextHover(null);
621 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
623 public ITextHover getTextHover(ISourceViewer sourceViewer,
624 String contentType) {
625 return getTextHover(sourceViewer, contentType,
626 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
630 * Returns the SmartyDoc source code scanner for this configuration.
632 * @return the SmartyDoc source code scanner
634 // protected RuleBasedScanner getSmartyDocScanner() {
635 // return fJavaTextTools.getSmartyDocScanner();
638 * Returns the PHPDoc source code scanner for this configuration.
640 * @return the PHPDoc source code scanner
642 protected RuleBasedScanner getPHPDocScanner() {
643 return fJavaDocScanner; // fJavaTextTools.getJavaDocScanner();
647 * (non-Javadoc) Method declared on SourceViewerConfiguration
649 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
650 return new String[] {
651 IDocument.DEFAULT_CONTENT_TYPE,
652 PHPPartitionScanner.PHP_SCRIPTING_AREA,
655 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,
661 IPHPPartitions.PHP_STRING_SQ,
662 IPHPPartitions.PHP_STRING_HEREDOC,
664 IPHPPartitions.CSS_MULTILINE_COMMENT,
665 IPHPPartitions.JAVASCRIPT,
666 IPHPPartitions.JS_MULTILINE_COMMENT,
667 IPHPPartitions.SMARTY,
668 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
670 XMLPartitionScanner.XML_PI,
671 XMLPartitionScanner.XML_COMMENT,
672 XMLPartitionScanner.XML_DECL,
673 XMLPartitionScanner.XML_TAG,
674 XMLPartitionScanner.XML_ATTRIBUTE,
675 XMLPartitionScanner.XML_CDATA,
677 XMLPartitionScanner.DTD_INTERNAL,
678 XMLPartitionScanner.DTD_INTERNAL_PI,
679 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
680 XMLPartitionScanner.DTD_INTERNAL_DECL,
682 PHPDocumentPartitioner.PHP_TEMPLATE_DATA,
683 PHPDocumentPartitioner.PHP_SCRIPT_CODE };
686 public String[] getConfiguredHTMLContentTypes() {
687 return new String[] {
688 XMLPartitionScanner.XML_PI,
689 XMLPartitionScanner.XML_COMMENT,
690 XMLPartitionScanner.XML_DECL,
691 XMLPartitionScanner.XML_TAG,
692 XMLPartitionScanner.XML_ATTRIBUTE,
693 XMLPartitionScanner.XML_CDATA,
695 XMLPartitionScanner.DTD_INTERNAL,
696 XMLPartitionScanner.DTD_INTERNAL_PI,
697 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
698 XMLPartitionScanner.DTD_INTERNAL_DECL, };
701 public String[] getConfiguredPHPContentTypes() {
702 return new String[] {
703 IDocument.DEFAULT_CONTENT_TYPE,
704 IPHPPartitions.PHP_PARTITIONING,
705 IPHPPartitions.PHP_SINGLELINE_COMMENT,
706 IPHPPartitions.PHP_MULTILINE_COMMENT,
707 IPHPPartitions.PHP_PHPDOC_COMMENT,
708 IPHPPartitions.PHP_STRING_DQ,
709 IPHPPartitions.PHP_STRING_SQ,
710 IPHPPartitions.PHP_STRING_HEREDOC,
712 IPHPPartitions.CSS_MULTILINE_COMMENT,
713 IPHPPartitions.JAVASCRIPT,
714 IPHPPartitions.JS_MULTILINE_COMMENT,
715 IPHPPartitions.SMARTY,
716 IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
720 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
723 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
724 if (fDocumentPartitioning != null)
725 return fDocumentPartitioning;
726 return super.getConfiguredDocumentPartitioning(sourceViewer);
730 * (non-Javadoc) Method declared on SourceViewerConfiguration
732 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
733 ContentAssistant assistant = new ContentAssistant();
734 IContentAssistProcessor processor = new HTMLCompletionProcessor (getEditor());
735 assistant.setDocumentPartitioning (getConfiguredDocumentPartitioning(sourceViewer));
736 assistant.setContentAssistProcessor (processor, IPHPPartitions.HTML);
737 assistant.setContentAssistProcessor (processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
739 assistant.setContentAssistProcessor (processor, IPHPPartitions.CSS);
740 assistant.setContentAssistProcessor (processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
741 assistant.setContentAssistProcessor (processor, IPHPPartitions.JAVASCRIPT);
742 assistant.setContentAssistProcessor (processor, IPHPPartitions.JS_MULTILINE_COMMENT);
743 // TODO define special smarty partition content assist
744 assistant.setContentAssistProcessor (processor, IPHPPartitions.SMARTY);
745 assistant.setContentAssistProcessor (processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
747 assistant.setContentAssistProcessor (processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
748 String[] htmlTypes = getConfiguredHTMLContentTypes();
750 for (int i = 0; i < htmlTypes.length; i++) {
751 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
753 processor = new PHPCompletionProcessor (getEditor());
755 assistant.setContentAssistProcessor (processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
756 assistant.setContentAssistProcessor (processor, IPHPPartitions.PHP_PARTITIONING);
757 assistant.setContentAssistProcessor (processor, IPHPPartitions.PHP_STRING_DQ);
758 assistant.setContentAssistProcessor (processor, IPHPPartitions.PHP_STRING_SQ);
759 assistant.setContentAssistProcessor (processor, IPHPPartitions.PHP_STRING_HEREDOC);
761 assistant.setContentAssistProcessor (new PHPDocCompletionProcessor(
762 getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
763 // assistant.enableAutoActivation(true);
764 // assistant.setAutoActivationDelay(500);
765 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
766 // ContentAssistPreference.configure(assistant, getPreferenceStore());
767 // assistant.setContextInformationPopupOrientation(
768 // ContentAssistant.CONTEXT_INFO_ABOVE);
769 // assistant.setContextInformationPopupBackground(
770 // PHPEditorEnvironment.getPHPColorProvider().getColor(
771 // new RGB(150, 150, 0)));
772 ContentAssistPreference.configure (assistant, getPreferenceStore());
773 assistant.setContextInformationPopupOrientation (ContentAssistant.CONTEXT_INFO_ABOVE);
774 assistant.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 = PHPeclipsePlugin.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);