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.xml.ui.XMLPlugin;
47 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
48 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
49 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
51 import org.eclipse.core.runtime.NullProgressMonitor;
52 import org.eclipse.jface.preference.IPreferenceStore;
53 import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
54 import org.eclipse.jface.text.DefaultInformationControl;
55 import org.eclipse.jface.text.IAutoEditStrategy;
56 import org.eclipse.jface.text.IDocument;
57 import org.eclipse.jface.text.IInformationControl;
58 import org.eclipse.jface.text.IInformationControlCreator;
59 import org.eclipse.jface.text.ITextDoubleClickStrategy;
60 import org.eclipse.jface.text.ITextHover;
61 import org.eclipse.jface.text.ITextViewerExtension2;
62 import org.eclipse.jface.text.TextAttribute;
63 import org.eclipse.jface.text.contentassist.ContentAssistant;
64 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
65 import org.eclipse.jface.text.contentassist.IContentAssistant;
66 import org.eclipse.jface.text.formatter.ContentFormatter;
67 import org.eclipse.jface.text.formatter.IContentFormatter;
68 import org.eclipse.jface.text.formatter.IFormattingStrategy;
69 import org.eclipse.jface.text.information.IInformationPresenter;
70 import org.eclipse.jface.text.information.IInformationProvider;
71 import org.eclipse.jface.text.information.InformationPresenter;
72 import org.eclipse.jface.text.presentation.IPresentationDamager;
73 import org.eclipse.jface.text.presentation.IPresentationReconciler;
74 import org.eclipse.jface.text.presentation.IPresentationRepairer;
75 import org.eclipse.jface.text.presentation.PresentationReconciler;
76 import org.eclipse.jface.text.reconciler.IReconciler;
77 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
78 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
79 import org.eclipse.jface.text.rules.DefaultPartitioner;
80 import org.eclipse.jface.text.rules.RuleBasedScanner;
81 import org.eclipse.jface.text.rules.Token;
82 import org.eclipse.jface.text.source.IAnnotationHover;
83 import org.eclipse.jface.text.source.ISourceViewer;
84 import org.eclipse.jface.text.source.SourceViewerConfiguration;
85 import org.eclipse.jface.util.PropertyChangeEvent;
86 import org.eclipse.swt.SWT;
87 import org.eclipse.swt.widgets.Shell;
88 import org.eclipse.ui.texteditor.ITextEditor;
91 * Configuration for an <code>SourceViewer</code> which shows PHP code.
93 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
95 * Preference key used to look up display tab width.
99 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
102 * Preference key for inserting spaces rather than tabs.
106 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
108 // public static final String HTML_DEFAULT =
109 // IPHPPartitionScannerConstants.HTML;
110 //IDocument.DEFAULT_CONTENT_TYPE;
111 // private JavaTextTools fJavaTextTools;
113 private ITextEditor fTextEditor;
116 * The document partitioning.
120 private String fDocumentPartitioning;
122 private ContentFormatter fFormatter;
125 * Single token scanner.
127 static class SingleTokenScanner extends BufferedRuleBasedScanner {
128 public SingleTokenScanner(TextAttribute attribute) {
129 setDefaultReturnToken(new Token(attribute));
134 * The document partitioning.
138 // private String fDocumentPartitioning;
140 * The Java source code scanner
144 private AbstractJavaScanner fCodeScanner;
147 * The Java multi-line comment scanner
151 private AbstractJavaScanner fMultilineCommentScanner;
154 * The Java single-line comment scanner
158 private AbstractJavaScanner fSinglelineCommentScanner;
161 * The PHP double quoted string scanner
163 private AbstractJavaScanner fStringDQScanner;
165 * The PHP single quoted string scanner
167 private AbstractJavaScanner fStringSQScanner;
170 * The Javadoc scanner
174 private AbstractJavaScanner fJavaDocScanner;
177 * The preference store, can be read-only
181 private IPreferenceStore fPreferenceStore;
188 private IColorManager fColorManager;
190 private XMLTextTools fXMLTextTools;
192 private XMLConfiguration xmlConfiguration;
195 * Creates a new Java source viewer configuration for viewers in the given editor using the given preference store, the color
196 * manager and the specified document partitioning.
198 * Creates a Java source viewer configuration in the new setup without text tools. Clients are allowed to call
199 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and disallowed to call
200 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the resulting Java source viewer configuration.
203 * @param colorManager
205 * @param preferenceStore
206 * the preference store, can be read-only
208 * the editor in which the configured viewer(s) will reside
209 * @param partitioning
210 * the document partitioning for this configuration
213 public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor,
214 String partitioning) {
215 fColorManager = colorManager;
216 fPreferenceStore = preferenceStore;
217 fTextEditor = editor;
218 fDocumentPartitioning = partitioning;
219 // fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
220 fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
221 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
222 fColorManager = colorManager;
223 fPreferenceStore = preferenceStore;
224 fTextEditor = editor;
225 fDocumentPartitioning = partitioning;
227 initializeScanners();
231 * Creates a new Java source viewer configuration for viewers in the given editor using the given Java tools.
234 * the Java text tools to be used
236 * the editor in which the configured viewer(s) will reside
238 * @deprecated As of 3.0, replaced by
239 * {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
241 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor editor, String partitioning) {
242 // fJavaTextTools = tools;
243 // fColorManager = tools.getColorManager();
244 // fPreferenceStore = createPreferenceStore();
245 // fDocumentPartitioning = partitioning;
246 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
247 // fMultilineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getMultilineCommentScanner();
248 // fSinglelineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getSinglelineCommentScanner();
249 // fStringDQScanner = (AbstractJavaScanner) fJavaTextTools.getStringScanner();
250 // fJavaDocScanner = (AbstractJavaScanner) fJavaTextTools.getJavaDocScanner();
251 // fTextEditor = editor;
252 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
253 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
256 * Returns the color manager for this configuration.
258 * @return the color manager
260 protected IColorManager getColorManager() {
261 return fColorManager;
265 * Initializes the scanners.
269 private void initializeScanners() {
270 // Assert.isTrue(isNewSetup());
271 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
272 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
273 IPreferenceConstants.PHP_MULTILINE_COMMENT);
274 fSinglelineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
275 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
276 // fStringDQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ);
277 fStringDQScanner = new PHPStringDQCodeScanner(getColorManager(), fPreferenceStore);
278 fStringSQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
279 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore);
283 * Determines whether the preference change encoded by the given event changes the behavior of one of its contained components.
286 * the event to be investigated
287 * @return <code>true</code> if event causes a behavioral change
290 public boolean affectsTextPresentation(PropertyChangeEvent event) {
291 return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
292 || fSinglelineCommentScanner.affectsBehavior(event) || fStringDQScanner.affectsBehavior(event)|| fStringSQScanner.affectsBehavior(event)
293 || fJavaDocScanner.affectsBehavior(event);
297 * Adapts the behavior of the contained components to the change encoded in the given event.
299 * Clients are not allowed to call this method if the old setup with text tools is in use.
303 * the event to which to adapt
304 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
307 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
308 // Assert.isTrue(isNewSetup());
309 if (fCodeScanner.affectsBehavior(event))
310 fCodeScanner.adaptToPreferenceChange(event);
311 if (fMultilineCommentScanner.affectsBehavior(event))
312 fMultilineCommentScanner.adaptToPreferenceChange(event);
313 if (fSinglelineCommentScanner.affectsBehavior(event))
314 fSinglelineCommentScanner.adaptToPreferenceChange(event);
315 if (fStringDQScanner.affectsBehavior(event))
316 fStringDQScanner.adaptToPreferenceChange(event);
317 if (fStringSQScanner.affectsBehavior(event))
318 fStringSQScanner.adaptToPreferenceChange(event);
319 if (fJavaDocScanner.affectsBehavior(event))
320 fJavaDocScanner.adaptToPreferenceChange(event);
324 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
326 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
327 // if (fFormatter == null) {
328 // fFormatter = new ContentFormatter();
329 // fFormattingStrategy = new HTMLFormattingStrategy(this,
331 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
332 // fFormatter.enablePartitionAwareFormatting(false);
333 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
335 // return fFormatter;
336 if (fFormatter == null) {
338 fFormatter = new ContentFormatter();
339 IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer);
340 fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
341 fFormatter.enablePartitionAwareFormatting(false);
342 fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
348 * Returns the names of the document position categories used by the document partitioners created by this object to manage their
349 * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
351 * @return the partition managing position categories or <code>null</code> if there is none
353 public String[] getPartitionManagingPositionCategories() {
354 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
358 // * Returns the names of the document position categories used by the
360 // * partitioners created by this object to manage their partition
362 // * If the partitioners don't use document position categories, the
364 // * result is <code>null</code>.
366 // * @return the partition managing position categories or
368 // * if there is none
370 // private String[] getPartitionManagingPositionCategories() {
371 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
373 public ITextEditor getEditor() {
378 * Returns the preference store used by this configuration to initialize the individual bits and pieces.
380 * @return the preference store used to initialize this configuration
384 protected IPreferenceStore getPreferenceStore() {
385 return PHPeclipsePlugin.getDefault().getPreferenceStore();
389 // * Method declared on SourceViewerConfiguration
391 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
392 // return new PHPAnnotationHover();
395 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
397 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
398 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
402 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
405 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
406 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
409 public IAutoEditStrategy[] getAutoEditStrategies(
410 ISourceViewer sourceViewer, String contentType) {
411 IAutoEditStrategy strategy = new DefaultIndentLineAutoEditStrategy();
412 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
413 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
414 strategy = new JavaDocAutoIndentStrategy(
415 getConfiguredDocumentPartitioning(sourceViewer));
416 else if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
417 strategy = new JavaStringAutoIndentStrategyDQ(
418 getConfiguredDocumentPartitioning(sourceViewer));
419 else if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
420 strategy = new JavaStringAutoIndentStrategySQ(
421 getConfiguredDocumentPartitioning(sourceViewer));
423 strategy = (PHPDocumentPartitioner.PHP_TEMPLATE_DATA
425 || PHPDocumentPartitioner.PHP_SCRIPT_CODE
427 || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
428 || IPHPPartitions.PHP_PARTITIONING.equals(contentType)
429 || PHPPartitionScanner.PHP_SCRIPTING_AREA
430 .equals(contentType) ? new PHPAutoIndentStrategy()
431 : new DefaultIndentLineAutoEditStrategy());
432 IAutoEditStrategy[] result = new IAutoEditStrategy[1];
433 result[0] = strategy;
438 * Returns the PHP source code scanner for this configuration.
440 * @return the PHP source code scanner
442 protected RuleBasedScanner getCodeScanner() {
443 return fCodeScanner; //fJavaTextTools.getCodeScanner();
447 * Returns the Java multi-line comment scanner for this configuration.
449 * @return the Java multi-line comment scanner
452 protected RuleBasedScanner getMultilineCommentScanner() {
453 return fMultilineCommentScanner;
457 * Returns the Java single-line comment scanner for this configuration.
459 * @return the Java single-line comment scanner
462 protected RuleBasedScanner getSinglelineCommentScanner() {
463 return fSinglelineCommentScanner;
467 * Returns the PHP double quoted string scanner for this configuration.
469 * @return the PHP double quoted string scanner
471 protected RuleBasedScanner getStringDQScanner() {
472 return fStringDQScanner;
476 * Returns the PHP single quoted string scanner for this configuration.
478 * @return the PHP single quoted string scanner
480 protected RuleBasedScanner getStringSQScanner() {
481 return fStringSQScanner;
484 * Returns the HTML source code scanner for this configuration.
486 * @return the HTML source code scanner
488 // protected RuleBasedScanner getHTMLScanner() {
489 // return fJavaTextTools.getHTMLScanner();
492 * Returns the Smarty source code scanner for this configuration.
494 * @return the Smarty source code scanner
496 // protected RuleBasedScanner getSmartyScanner() {
497 // return fJavaTextTools.getSmartyScanner();
500 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
503 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
505 public IReconciler getReconciler(ISourceViewer sourceViewer) {
507 final ITextEditor editor = getEditor();
508 if (editor != null && editor.isEditable()) {
510 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(editor,
511 getConfiguredDocumentPartitioning(sourceViewer));
512 JavaReconciler reconciler = new JavaReconciler(editor, strategy, false);
513 reconciler.setIsIncrementalReconciler(false);
514 reconciler.setProgressMonitor(new NullProgressMonitor());
515 reconciler.setDelay(500);
523 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String)
526 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
527 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
528 int stateMasks[] = new int[hoverDescs.length];
529 int stateMasksLength = 0;
530 for (int i = 0; i < hoverDescs.length; i++) {
531 if (hoverDescs[i].isEnabled()) {
533 int stateMask = hoverDescs[i].getStateMask();
534 while (j < stateMasksLength) {
535 if (stateMasks[j] == stateMask)
539 if (j == stateMasksLength)
540 stateMasks[stateMasksLength++] = stateMask;
543 if (stateMasksLength == hoverDescs.length)
545 int[] shortenedStateMasks = new int[stateMasksLength];
546 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, stateMasksLength);
547 return shortenedStateMasks;
551 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
554 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
555 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
557 while (i < hoverDescs.length) {
558 if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask)
559 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
563 // if (fEditor != null) {
564 // IEditorInput editorInput = fEditor.getEditorInput();
565 // if (editorInput instanceof IFileEditorInput) {
567 // IFile f = ((IFileEditorInput) editorInput).getFile();
568 // return new PHPTextHover(f.getProject());
569 // } catch (NullPointerException e) {
570 // // this exception occurs, if getTextHover is called by
571 // // preference pages !
575 // return new PHPTextHover(null);
579 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
581 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
582 return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
586 * Returns the SmartyDoc source code scanner for this configuration.
588 * @return the SmartyDoc source code scanner
590 // protected RuleBasedScanner getSmartyDocScanner() {
591 // return fJavaTextTools.getSmartyDocScanner();
594 * Returns the PHPDoc source code scanner for this configuration.
596 * @return the PHPDoc source code scanner
598 protected RuleBasedScanner getPHPDocScanner() {
599 return fJavaDocScanner; //fJavaTextTools.getJavaDocScanner();
603 * (non-Javadoc) Method declared on SourceViewerConfiguration
605 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
606 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP_SCRIPTING_AREA,
608 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT, IPHPPartitions.PHP_PARTITIONING,
609 IPHPPartitions.PHP_SINGLELINE_COMMENT, IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT,
610 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
611 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY,
612 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
614 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
615 XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
617 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
618 XMLPartitionScanner.DTD_INTERNAL_DECL,
620 PHPDocumentPartitioner.PHP_TEMPLATE_DATA, PHPDocumentPartitioner.PHP_SCRIPT_CODE };
623 public String[] getConfiguredHTMLContentTypes() {
624 return new String[] { XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
625 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
627 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
628 XMLPartitionScanner.DTD_INTERNAL_DECL, };
631 public String[] getConfiguredPHPContentTypes() {
632 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitions.PHP_PARTITIONING, IPHPPartitions.PHP_SINGLELINE_COMMENT,
633 IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT, IPHPPartitions.PHP_STRING_DQ,
634 IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
635 IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
639 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
642 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
643 if (fDocumentPartitioning != null)
644 return fDocumentPartitioning;
645 return super.getConfiguredDocumentPartitioning(sourceViewer);
649 * (non-Javadoc) Method declared on SourceViewerConfiguration
651 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
652 ContentAssistant assistant = new ContentAssistant();
653 IContentAssistProcessor processor = new HTMLCompletionProcessor(getEditor());
654 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
655 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
656 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
658 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
659 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
660 assistant.setContentAssistProcessor(processor, IPHPPartitions.JAVASCRIPT);
661 assistant.setContentAssistProcessor(processor, IPHPPartitions.JS_MULTILINE_COMMENT);
662 // TODO define special smarty partition content assist
663 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
664 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
666 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
667 String[] htmlTypes = getConfiguredHTMLContentTypes();
668 for (int i = 0; i < htmlTypes.length; i++) {
669 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
671 processor = new PHPCompletionProcessor(getEditor());
673 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
674 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
675 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
676 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
677 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_HEREDOC);
679 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
680 // assistant.enableAutoActivation(true);
681 // assistant.setAutoActivationDelay(500);
682 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
683 // ContentAssistPreference.configure(assistant, getPreferenceStore());
684 // assistant.setContextInformationPopupOrientation(
685 // ContentAssistant.CONTEXT_INFO_ABOVE);
686 // assistant.setContextInformationPopupBackground(
687 // PHPEditorEnvironment.getPHPColorProvider().getColor(
688 // new RGB(150, 150, 0)));
689 ContentAssistPreference.configure(assistant, getPreferenceStore());
690 assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
691 assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
696 * (non-Javadoc) Method declared on SourceViewerConfiguration
698 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
700 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
702 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
703 // null); //$NON-NLS-1$
706 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
709 public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
710 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
714 * (non-Javadoc) Method declared on SourceViewerConfiguration
716 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
717 return new PHPDoubleClickSelector();
721 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
723 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
724 Vector vector = new Vector();
725 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
726 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault().getPreferenceStore();
727 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
728 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
729 for (int i = 0; i <= tabWidth; i++) {
730 StringBuffer prefix = new StringBuffer();
732 for (int j = 0; j + i < tabWidth; j++)
737 for (int j = 0; j < i; j++)
742 vector.add(prefix.toString());
744 vector.add(""); //$NON-NLS-1$
745 return (String[]) vector.toArray(new String[vector.size()]);
749 * @return <code>true</code> iff the new setup without text tools is in use.
753 // private boolean isNewSetup() {
754 // return fJavaTextTools == null;
758 * Creates and returns a preference store which combines the preference stores from the text tools and which is read-only.
760 * @return the read-only preference store
763 // private IPreferenceStore createPreferenceStore() {
764 // Assert.isTrue(!isNewSetup());
765 // IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
766 // if (fJavaTextTools.getCorePreferenceStore() == null)
767 // return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(), generalTextStore });
769 // return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(),
770 // new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()), generalTextStore });
774 * (non-Javadoc) Method declared on SourceViewerConfiguration
776 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
777 // PHPColorProvider provider =
778 // PHPEditorEnvironment.getPHPColorProvider();
779 // JavaColorManager provider =
780 // PHPEditorEnvironment.getPHPColorProvider();
781 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
782 phpReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
784 // DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
785 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
786 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
787 // dr = new DefaultDamagerRepairer(getHTMLScanner());
788 // reconciler.setDamager(dr, IPHPPartitions.HTML);
789 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
790 // dr = new DefaultDamagerRepairer(getHTMLScanner());
791 // reconciler.setDamager(dr, IPHPPartitions.CSS);
792 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
793 // dr = new DefaultDamagerRepairer(getHTMLScanner());
794 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
795 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
796 // dr = new DefaultDamagerRepairer(getHTMLScanner());
797 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
798 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
799 // dr = new DefaultDamagerRepairer(getHTMLScanner());
800 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
801 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
802 // DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getSmartyScanner());
803 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
804 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
805 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
806 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
807 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
808 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
809 // PHPColorProvider.MULTI_LINE_COMMENT))));
810 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
811 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
813 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getCodeScanner());
814 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
815 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
817 phpDR = new DefaultDamagerRepairer(getCodeScanner());
818 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
819 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
821 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
822 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
823 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
825 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
826 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
827 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
828 phpDR = new DefaultDamagerRepairer(getStringSQScanner());
829 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
830 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
831 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
832 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
833 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
834 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
835 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
836 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
837 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
838 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
839 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
841 PresentationReconciler reconciler = new PresentationReconciler();
842 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
844 // JavaTextTools jspTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
845 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getPHPDocScanner());//jspTextTools.getJSPTextScanner());
846 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
847 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
849 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
850 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
851 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
852 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
855 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration.getPresentationReconciler(sourceViewer), xmlConfiguration
856 .getConfiguredContentTypes(sourceViewer), PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
859 configureEmbeddedPresentationReconciler(reconciler, phpReconciler, getConfiguredPHPContentTypes(),
860 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
865 private void configureEmbeddedPresentationReconciler(PresentationReconciler reconciler, IPresentationReconciler embedded,
866 String[] types, String defaultType) {
867 for (int i = 0; i < types.length; i++) {
868 String type = types[i];
870 IPresentationDamager damager = embedded.getDamager(type);
871 IPresentationRepairer repairer = embedded.getRepairer(type);
873 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
877 reconciler.setDamager(damager, type);
878 reconciler.setRepairer(repairer, type);
883 * (non-Javadoc) Method declared on SourceViewerConfiguration
885 public int getTabWidth(ISourceViewer sourceViewer) {
886 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
890 * (non-Javadoc) Method declared on SourceViewerConfiguration
892 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
894 // if (fEditor != null) {
895 // IEditorInput editorInput = fEditor.getEditorInput();
896 // if (editorInput instanceof IFileEditorInput) {
898 // IFile f = ((IFileEditorInput) editorInput).getFile();
899 // return new PHPTextHover(f.getProject());
900 // } catch (NullPointerException e) {
901 // // this exception occurs, if getTextHover is called by preference pages
906 // return new PHPTextHover(null);
909 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
912 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
913 return new IInformationControlCreator() {
914 public IInformationControl createInformationControl(Shell parent) {
915 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
916 // return new HoverBrowserControl(parent);
922 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
925 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
926 InformationPresenter presenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
927 presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
928 IInformationProvider provider = new JavaInformationProvider(getEditor());
929 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
930 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
931 // presenter.setInformationProvider(provider, IPHPPartitions.JAVA_CHARACTER);
932 presenter.setSizeConstraints(60, 10, true, true);
937 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
940 // public IInformationPresenter getInformationPresenter(ISourceViewer
942 // InformationPresenter presenter= new
943 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
944 // IInformationProvider provider= new JavaInformationProvider(getEditor());
945 // presenter.setInformationProvider(provider,
946 // IDocument.DEFAULT_CONTENT_TYPE);
947 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
948 // presenter.setSizeConstraints(60, 10, true, true);
952 * Returns the information presenter control creator. The creator is a factory creating the presenter controls for the given
953 * source viewer. This implementation always returns a creator for <code>DefaultInformationControl</code> instances.
955 * @param sourceViewer
956 * the source viewer to be configured by this configuration
957 * @return an information control creator
960 private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
961 return new IInformationControlCreator() {
962 public IInformationControl createInformationControl(Shell parent) {
963 int shellStyle = SWT.RESIZE;
964 int style = SWT.V_SCROLL | SWT.H_SCROLL;
965 return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
966 // return new HoverBrowserControl(parent);
972 * Returns the outline presenter control creator. The creator is a factory creating outline presenter controls for the given
973 * source viewer. This implementation always returns a creator for <code>JavaOutlineInformationControl</code> instances.
975 * @param sourceViewer
976 * the source viewer to be configured by this configuration
977 * @return an information control creator
980 private IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer) {
981 return new IInformationControlCreator() {
982 public IInformationControl createInformationControl(Shell parent) {
983 int shellStyle = SWT.RESIZE;
984 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
985 return new JavaOutlineInformationControl(parent, shellStyle, treeStyle);
991 * Returns the outline presenter which will determine and shown information requested for the current cursor position.
993 * @param sourceViewer
994 * the source viewer to be configured by this configuration
995 * @param doCodeResolve
996 * a boolean which specifies whether code resolve should be used to compute the Java element
997 * @return an information presenter
1000 public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {
1001 InformationPresenter presenter = new InformationPresenter(getOutlinePresenterControlCreator(sourceViewer));
1002 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
1003 IInformationProvider provider = new JavaElementProvider(getEditor(), doCodeResolve);
1004 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
1005 presenter.setInformationProvider(provider, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
1006 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PARTITIONING);
1007 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
1008 presenter.setInformationProvider(provider, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
1009 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
1010 presenter.setInformationProvider(provider, IPHPPartitions.HTML_MULTILINE_COMMENT);
1011 presenter.setSizeConstraints(40, 20, true, false);