From e4b026c274c72865267a9ad31a53823e884d59d6 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 19 Jun 2008 13:45:05 +0000 Subject: [PATCH] Fix for 237016: C Compare Viewer does not colorize doxygen comments --- core/org.eclipse.cdt.ui/plugin.xml | 15 ++++++++++----- .../ui/compare/AbstractMergeViewer.java | 6 ------ .../internal/ui/compare/AsmMergeViewer.java | 16 ++++++---------- .../cdt/internal/ui/compare/CMergeViewer.java | 13 ++++++++++--- .../ui/compare/CStructureCreator.java | 13 ++++++------- .../asm/AsmDocumentSetupParticipant.java | 18 ++---------------- .../internal/ui/editor/asm/AsmTextTools.java | 17 ++++++++++++++++- .../ui/text/CSourceViewerConfiguration.java | 19 +++++++++++++++++-- 8 files changed, 67 insertions(+), 50 deletions(-) diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 19eb8afc6dc..51723de19d4 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -1101,7 +1101,7 @@ point="org.eclipse.compare.contentMergeViewers"> + commandId="org.eclipse.ui.views.showView" + schemeId="org.eclipse.cdt.ui.visualstudio" + sequence="M1+M3+B"> + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AbstractMergeViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AbstractMergeViewer.java index 0d929ea9a4a..0fe7f3c056c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AbstractMergeViewer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AbstractMergeViewer.java @@ -16,7 +16,6 @@ import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.contentmergeviewer.TextMergeViewer; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.TextViewer; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; @@ -136,11 +135,6 @@ abstract class AbstractMergeViewer extends TextMergeViewer { return ICPartitions.C_PARTITIONING; } - @Override - protected IDocumentPartitioner getDocumentPartitioner() { - return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(null); - } - @Override protected void configureTextViewer(TextViewer textViewer) { if (textViewer instanceof SourceViewer) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java index 5f5106a9a7f..8e64ba8b532 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java @@ -13,13 +13,13 @@ package org.eclipse.cdt.internal.ui.compare; import org.eclipse.compare.CompareConfiguration; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.widgets.Composite; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.text.ICPartitions; - import org.eclipse.cdt.internal.ui.editor.asm.AsmSourceViewerConfiguration; import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools; @@ -43,9 +43,6 @@ public class AsmMergeViewer extends AbstractMergeViewer { super(parent, style, configuration); } - /* - * @see org.eclipse.cdt.internal.ui.compare.AbstractMergeViewer#getSourceViewerConfiguration() - */ @Override protected SourceViewerConfiguration getSourceViewerConfiguration() { if (fSourceViewerConfiguration == null) { @@ -56,17 +53,16 @@ public class AsmMergeViewer extends AbstractMergeViewer { return fSourceViewerConfiguration; } - /* - * @see org.eclipse.cdt.internal.ui.compare.AbstractMergeViewer#getTitle() - */ @Override public String getTitle() { return CUIPlugin.getResourceString(TITLE); } - /* - * @see org.eclipse.cdt.internal.ui.compare.AbstractMergeViewer#handlePropertyChange(org.eclipse.jface.util.PropertyChangeEvent) - */ + @Override + protected IDocumentPartitioner getDocumentPartitioner() { + return CUIPlugin.getDefault().getAsmTextTools().createDocumentPartitioner(); + } + @Override protected void handlePropertyChange(PropertyChangeEvent event) { super.handlePropertyChange(event); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java index a7697c19c66..8ab9687f4f6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java @@ -14,15 +14,18 @@ package org.eclipse.cdt.internal.ui.compare; import org.eclipse.compare.CompareConfiguration; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.widgets.Composite; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.text.ICPartitions; +import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner; import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; import org.eclipse.cdt.internal.ui.text.CTextTools; +import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager; /** * A merge viewer for C/C++ code. @@ -47,14 +50,18 @@ public class CMergeViewer extends AbstractMergeViewer { return fSourceViewerConfiguration; } + @Override + protected IDocumentPartitioner getDocumentPartitioner() { + // use workspace default for highlighting doc comments in compare viewer + IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getWorkspaceCommentOwner(); + return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(owner); + } + @Override public String getTitle() { return CUIPlugin.getResourceString(TITLE); } - /* - * @see org.eclipse.cdt.internal.ui.compare.AbstractMergeViewer#handlePropertyChange(org.eclipse.jface.util.PropertyChangeEvent) - */ @Override protected void handlePropertyChange(PropertyChangeEvent event) { super.handlePropertyChange(event); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java index 9b6054bd447..6610ad50fc2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java @@ -48,9 +48,12 @@ import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.text.ICPartitions; +import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner; import org.eclipse.cdt.internal.core.dom.NullCodeReaderFactory; +import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager; + /** * A structure creator for C/C++ translation units. */ @@ -151,20 +154,16 @@ public class CStructureCreator extends StructureCreator { return language; } - /* - * @see org.eclipse.compare.structuremergeviewer.StructureCreator#getDocumentPartitioning() - */ @Override protected String getDocumentPartitioning() { return ICPartitions.C_PARTITIONING; } - /* - * @see org.eclipse.compare.structuremergeviewer.StructureCreator#getDocumentPartitioner() - */ @Override protected IDocumentPartitioner getDocumentPartitioner() { - return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(null); + // use workspace default for highlighting doc comments in compare viewer + IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getWorkspaceCommentOwner(); + return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(owner); } private static String readString(IStreamContentAccessor sa) throws CoreException { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmDocumentSetupParticipant.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmDocumentSetupParticipant.java index 8eb3f7e4224..b9dd9bcfd6d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmDocumentSetupParticipant.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmDocumentSetupParticipant.java @@ -17,12 +17,9 @@ import org.eclipse.core.runtime.IExecutableExtension; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentExtension3; import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.rules.FastPartitioner; - +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.text.ICPartitions; -import org.eclipse.cdt.internal.ui.text.asm.AsmPartitionScanner; - /** * Document setup participant for asesembly content. */ @@ -37,7 +34,7 @@ public class AsmDocumentSetupParticipant implements IDocumentSetupParticipant, I * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument) */ public void setup(IDocument document) { - IDocumentPartitioner partitioner= createDocumentPartitioner(); + IDocumentPartitioner partitioner= CUIPlugin.getDefault().getAsmTextTools().createDocumentPartitioner(); if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3= (IDocumentExtension3) document; extension3.setDocumentPartitioner(ICPartitions.C_PARTITIONING, partitioner); @@ -47,17 +44,6 @@ public class AsmDocumentSetupParticipant implements IDocumentSetupParticipant, I partitioner.connect(document); } - private IDocumentPartitioner createDocumentPartitioner() { - String[] types= new String[] { - ICPartitions.C_MULTI_LINE_COMMENT, - ICPartitions.C_SINGLE_LINE_COMMENT, - ICPartitions.C_STRING, - ICPartitions.C_CHARACTER, - ICPartitions.C_PREPROCESSOR - }; - return new FastPartitioner(new AsmPartitionScanner(), types); - } - /* * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) */ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java index da97711174a..64c1dc00f3e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java @@ -15,12 +15,15 @@ package org.eclipse.cdt.internal.ui.editor.asm; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.rules.FastPartitioner; import org.eclipse.jface.text.rules.RuleBasedScanner; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.cdt.core.model.AssemblyLanguage; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.text.ICPartitions; import org.eclipse.cdt.ui.text.ITokenStore; import org.eclipse.cdt.ui.text.ITokenStoreFactory; @@ -28,6 +31,7 @@ import org.eclipse.cdt.internal.ui.text.CCommentScanner; import org.eclipse.cdt.internal.ui.text.ICColorConstants; import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner; import org.eclipse.cdt.internal.ui.text.TokenStore; +import org.eclipse.cdt.internal.ui.text.asm.AsmPartitionScanner; import org.eclipse.cdt.internal.ui.text.util.CColorManager; @@ -223,5 +227,16 @@ public class AsmTextTools { if (fPreprocessorScanner.affectsBehavior(event)) fPreprocessorScanner.adaptToPreferenceChange(event); } - + + public IDocumentPartitioner createDocumentPartitioner() { + String[] types= new String[] { + ICPartitions.C_MULTI_LINE_COMMENT, + ICPartitions.C_SINGLE_LINE_COMMENT, + ICPartitions.C_STRING, + ICPartitions.C_CHARACTER, + ICPartitions.C_PREPROCESSOR + }; + return new FastPartitioner(new AsmPartitionScanner(), types); + } + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java index f2701f6bf50..d76db76e793 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java @@ -20,6 +20,7 @@ import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; @@ -326,12 +327,19 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration { /** * Returns the C multi-line doc comment scanner for this configuration. * - * @return the C multi-line doc comment scanner, may be null + * @return the C multi-line doc comment scanner */ protected ICTokenScanner getMultilineDocCommentScanner(IResource resource) { if (fMultilineDocCommentScanner == null) { + if (resource == null) { + resource= ResourcesPlugin.getWorkspace().getRoot(); + } IDocCommentViewerConfiguration owner= DocCommentOwnerManager.getInstance().getCommentOwner(resource).getMultilineConfiguration(); fMultilineDocCommentScanner= owner.createCommentScanner(getTokenStoreFactory()); + if (fMultilineDocCommentScanner == null) { + // fallback: normal comment highlighting + fMultilineDocCommentScanner= fMultilineCommentScanner; + } } return fMultilineDocCommentScanner; } @@ -339,12 +347,19 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration { /** * Returns the C single-line doc comment scanner for this configuration. * - * @return the C single-line doc comment scanner, may be null + * @return the C single-line doc comment scanner */ protected ICTokenScanner getSinglelineDocCommentScanner(IResource resource) { if (fSinglelineDocCommentScanner == null) { + if (resource == null) { + resource= ResourcesPlugin.getWorkspace().getRoot(); + } IDocCommentViewerConfiguration owner= DocCommentOwnerManager.getInstance().getCommentOwner(resource).getSinglelineConfiguration(); fSinglelineDocCommentScanner= owner.createCommentScanner(getTokenStoreFactory()); + if (fSinglelineDocCommentScanner == null) { + // fallback: normal comment highlighting + fSinglelineDocCommentScanner= fSinglelineCommentScanner; + } } return fSinglelineDocCommentScanner; }