1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Bug 251406 - Make CSourceViewerConfiguration and friends public API

This commit is contained in:
Anton Leherbauer 2009-01-13 15:25:14 +00:00
parent cd81b282d5
commit f4ce07488d
52 changed files with 642 additions and 605 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
import java.io.File;
@ -47,12 +46,12 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
/**
@ -363,7 +362,7 @@ public class BasicCEditorTest extends BaseUITestCase {
}
public void testSyntaxHighlighting_Bug180433() throws Exception {
CColorManager colorMgr= CUIPlugin.getDefault().getTextTools().getColorManager();
IColorManager colorMgr= CUIPlugin.getDefault().getTextTools().getColorManager();
colorMgr.unbindColor(ICColorConstants.PP_DIRECTIVE);
colorMgr.bindColor(ICColorConstants.PP_DIRECTIVE, new RGB(7,7,7));
final Color ppDirectiveColor= colorMgr.getColor(ICColorConstants.PP_DIRECTIVE);

View file

@ -16,7 +16,6 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
@ -30,6 +29,7 @@ import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.text.CTextTools;
/**
* Tests to verify the C partitioning.
* Derived from JavaPartitionerTest.
@ -45,9 +45,10 @@ public class CPartitionerTest extends TestCase {
super(name);
}
@Override
protected void setUp() {
fTextTools= new CTextTools(new PreferenceStore());
fTextTools= new CTextTools();
fDocument= new Document();
IDocumentPartitioner partitioner= fTextTools.createDocumentPartitioner(null);
@ -67,6 +68,7 @@ public class CPartitionerTest extends TestCase {
return new TestSuite(CPartitionerTest.class);
}
@Override
protected void tearDown () {
fTextTools.dispose();
fTextTools= null;

View file

@ -28,9 +28,9 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
/**
* Abstract implementation of a merge viewer.

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,7 +8,6 @@
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.compare;
import org.eclipse.compare.CompareConfiguration;
@ -18,10 +17,11 @@ import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.AsmSourceViewerConfiguration;
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;
import org.eclipse.cdt.ui.text.IColorManager;
/**
* A merge viewer for assembly code.
@ -46,9 +46,9 @@ public class AsmMergeViewer extends AbstractMergeViewer {
@Override
protected SourceViewerConfiguration getSourceViewerConfiguration() {
if (fSourceViewerConfiguration == null) {
AsmTextTools tools= CUIPlugin.getDefault().getAsmTextTools();
IPreferenceStore store= getPreferenceStore();
fSourceViewerConfiguration= new AsmSourceViewerConfiguration(tools.getColorManager(), store, null, ICPartitions.C_PARTITIONING);
final IColorManager colorManager = CDTUITools.getColorManager();
fSourceViewerConfiguration= new AsmSourceViewerConfiguration(colorManager, store, null, ICPartitions.C_PARTITIONING);
}
return fSourceViewerConfiguration;
}
@ -60,7 +60,7 @@ public class AsmMergeViewer extends AbstractMergeViewer {
@Override
protected IDocumentPartitioner getDocumentPartitioner() {
return CUIPlugin.getDefault().getAsmTextTools().createDocumentPartitioner();
return CDTUITools.createAsmDocumentPartitioner();
}
@Override

View file

@ -20,10 +20,10 @@ import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
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;

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.text.CTextTools;
/**
* CDocumentSetupParticipant
*/

View file

@ -178,6 +178,7 @@ import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.actions.GenerateActionGroup;
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
@ -199,7 +200,6 @@ import org.eclipse.cdt.internal.ui.search.IOccurrencesFinder.OccurrenceLocation;
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
import org.eclipse.cdt.internal.ui.text.CPairMatcher;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CSourceViewerScalableConfiguration;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.CWordFinder;

View file

@ -48,8 +48,8 @@ import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
/**
* Source viewer for C/C++ et al.

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2006 QNX Software Systems and others.
* Copyright (c) 2002, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,11 +8,12 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.editors.text.StorageDocumentProvider;

View file

@ -28,13 +28,11 @@ import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.CPresentationReconciler;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CSourceViewerScalableConfiguration;
import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.IColorManagerExtension;
/**
* Semantic highlighting manager.
@ -584,10 +582,9 @@ public class SemanticHighlightingManager implements IPropertyChangeListener {
String property= event.getProperty();
Color color= fColorManager.getColor(property);
if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) {
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
ext.unbindColor(property);
ext.bindColor(property, rgb);
if ((color == null || !rgb.equals(color.getRGB()))) {
fColorManager.unbindColor(property);
fColorManager.bindColor(property, rgb);
color= fColorManager.getColor(property);
}
@ -614,17 +611,13 @@ public class SemanticHighlightingManager implements IPropertyChangeListener {
private void addColor(String colorKey) {
if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) {
RGB rgb= PreferenceConverter.getColor(fPreferenceStore, colorKey);
if (fColorManager instanceof IColorManagerExtension) {
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
ext.unbindColor(colorKey);
ext.bindColor(colorKey, rgb);
}
fColorManager.unbindColor(colorKey);
fColorManager.bindColor(colorKey, rgb);
}
}
private void removeColor(String colorKey) {
if (fColorManager instanceof IColorManagerExtension)
((IColorManagerExtension) fColorManager).unbindColor(colorKey);
fColorManager.unbindColor(colorKey);
}
/**

View file

@ -23,11 +23,11 @@ import org.eclipse.jface.text.rules.WordPatternRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.cdt.core.model.IAsmLanguage;
import org.eclipse.cdt.ui.text.AbstractCScanner;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
import org.eclipse.cdt.internal.ui.text.CWhitespaceRule;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
/*

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -17,7 +17,8 @@ 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.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.text.ICPartitions;
/**
@ -34,7 +35,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= CUIPlugin.getDefault().getAsmTextTools().createDocumentPartitioner();
IDocumentPartitioner partitioner= CDTUITools.createAsmDocumentPartitioner();
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3= (IDocumentExtension3) document;
extension3.setDocumentPartitioner(ICPartitions.C_PARTITIONING, partitioner);

View file

@ -19,12 +19,12 @@ import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.cdt.core.model.IAsmLanguage;
import org.eclipse.cdt.ui.text.AbstractCScanner;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
import org.eclipse.cdt.internal.ui.text.CHeaderRule;
import org.eclipse.cdt.internal.ui.text.CWhitespaceRule;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
import org.eclipse.cdt.internal.ui.text.PreprocessorRule;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;

View file

@ -52,9 +52,12 @@ import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.text.AsmSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.editor.AbstractCModelOutlinePage;
@ -99,8 +102,8 @@ public class AsmTextEditor extends TextEditor implements ISelectionChangedListen
// For now we are sharing with the CEditor and any changes in the
// setting of the CEditor will be reflected in this editor.
setPreferenceStore(store);
AsmTextTools tools= CUIPlugin.getDefault().getAsmTextTools();
setSourceViewerConfiguration(new AsmSourceViewerConfiguration(tools.getColorManager(), store, this, ICPartitions.C_PARTITIONING));
final IColorManager colorManager = CDTUITools.getColorManager();
setSourceViewerConfiguration(new AsmSourceViewerConfiguration(colorManager, store, this, ICPartitions.C_PARTITIONING));
setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider());
setEditorContextMenuId("#ASMEditorContext"); //$NON-NLS-1$
setRulerContextMenuId("#ASMEditorRulerContext"); //$NON-NLS-1$

View file

@ -13,7 +13,6 @@
*******************************************************************************/
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;
@ -23,12 +22,12 @@ 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.ICColorConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.ITokenStore;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
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;
@ -38,16 +37,16 @@ import org.eclipse.cdt.internal.ui.text.util.CColorManager;
/**
* This type shares all scanners and the color manager between
* its clients.
*
* @deprecated No longer used within CDT.
*/
@Deprecated
public class AsmTextTools {
private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
private class PreferenceListener implements IPropertyChangeListener {
public void propertyChange(PropertyChangeEvent event) {
adaptToPreferenceChange(event);
}
public void propertyChange(Preferences.PropertyChangeEvent event) {
adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
}
}
/** The color manager -- use the same as for C code */
@ -65,26 +64,16 @@ public class AsmTextTools {
/** The preference store */
private IPreferenceStore fPreferenceStore;
/** The core preference store */
private Preferences fCorePreferenceStore;
/** The preference change listener */
private PreferenceListener fPreferenceListener= new PreferenceListener();
/**
* Creates a new Asm text tools collection and eagerly creates
* and initializes all members of this collection.
*/
public AsmTextTools(IPreferenceStore store) {
this(store, null);
}
/**
* Creates a new Asm text tools collection and eagerly creates
* and initializes all members of this collection.
*/
public AsmTextTools(IPreferenceStore store, Preferences coreStore) {
fPreferenceStore = store != null ? store : CUIPlugin.getDefault().getPreferenceStore();
public AsmTextTools(IPreferenceStore store) {
fPreferenceStore = store != null ? store : CUIPlugin.getDefault().getCombinedPreferenceStore();
fColorManager= new CColorManager();
ITokenStoreFactory factory= new ITokenStoreFactory() {
@ -95,17 +84,12 @@ public class AsmTextTools {
fCodeScanner= new AsmCodeScanner(factory, AssemblyLanguage.getDefault());
fPreprocessorScanner= new AsmPreprocessorScanner(factory, AssemblyLanguage.getDefault());
fMultilineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
fSinglelineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
fMultilineCommentScanner= new CCommentScanner(factory, ICColorConstants.C_MULTI_LINE_COMMENT);
fSinglelineCommentScanner= new CCommentScanner(factory, ICColorConstants.C_SINGLE_LINE_COMMENT);
fStringScanner= new SingleTokenCScanner(factory, ICColorConstants.C_STRING);
// listener must be registered after initializing scanners
fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
fCorePreferenceStore= coreStore;
if (fCorePreferenceStore != null) {
fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
}
}
/**
@ -135,11 +119,6 @@ public class AsmTextTools {
fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
fPreferenceStore= null;
if (fCorePreferenceStore != null) {
fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
fCorePreferenceStore= null;
}
fPreferenceListener= null;
}
}
@ -229,14 +208,7 @@ public class AsmTextTools {
}
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);
return new FastPartitioner(new AsmPartitionScanner(), ICPartitions.ALL_ASM_PARTITIONS);
}
}

View file

@ -64,13 +64,13 @@ import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlighting;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightings;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedRange;
import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.SimpleCSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
import org.eclipse.cdt.internal.ui.util.PixelConverter;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -9,7 +9,6 @@
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences;
import org.eclipse.core.runtime.Assert;
@ -23,8 +22,8 @@ import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
public class CSourcePreviewerUpdater {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2007 QNX Software Systems and others.
* Copyright (c) 2002, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -9,7 +9,6 @@
* QNX Software Systems - Initial API and implementation
* Wind River Systems, Inc. - Bug fixes
*******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences;
import org.eclipse.jface.preference.IPreferenceStore;
@ -36,11 +35,11 @@ import org.eclipse.ui.texteditor.templates.TemplatePreferencePage;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CTextTools;
/**

View file

@ -33,11 +33,11 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.corext.template.c.CodeTemplateContextType;
import org.eclipse.cdt.internal.ui.text.CWordFinder;
import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.SimpleCSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
import org.eclipse.cdt.internal.ui.text.template.TemplateVariableProcessor;

View file

@ -42,9 +42,9 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.refactoring.CTextFileChange;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.compare.CMergeViewer;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CTextTools;
/**

View file

@ -24,10 +24,10 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
import org.eclipse.cdt.internal.ui.refactoring.CreateFileChange;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.util.ViewerPane;

View file

@ -21,6 +21,8 @@ import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.ui.text.AbstractCScanner;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;

View file

@ -15,11 +15,11 @@ package org.eclipse.cdt.internal.ui.text;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.AbstractCScanner;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.ui.text.TaskTagRule;
@ -29,26 +29,20 @@ import org.eclipse.cdt.ui.text.TaskTagRule;
*/
public class CCommentScanner extends AbstractCScanner {
private static String TASK_TAG_KEY= PreferenceConstants.EDITOR_TASK_TAG_COLOR;
private Preferences fCorePreferenceStore;
public CCommentScanner(ITokenStoreFactory tokenStoreFactory, String defaultTokenProperty) {
this(tokenStoreFactory, null, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG_KEY });
this(tokenStoreFactory, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG_KEY });
}
public CCommentScanner(ITokenStoreFactory tokenStoreFactory, Preferences coreStore, String defaultTokenProperty) {
this(tokenStoreFactory, coreStore, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG_KEY });
}
private CCommentScanner(ITokenStoreFactory tokenStoreFactory, Preferences coreStore, String defaultTokenProperty, String[] tokenProperties) {
private CCommentScanner(ITokenStoreFactory tokenStoreFactory, String defaultTokenProperty, String[] tokenProperties) {
super(tokenStoreFactory.createTokenStore(tokenProperties));
fCorePreferenceStore= coreStore;
setRules(createRules(defaultTokenProperty));
}
protected List<IRule> createRules(String defaultTokenProperty) {
setDefaultReturnToken(getToken(defaultTokenProperty));
IPreferenceStore store= fTokenStore.getPreferenceStore();
String taskWords= TaskTagRule.getTaskWords(store, fCorePreferenceStore);
String taskWords= TaskTagRule.getTaskWords(store, null);
TaskTagRule taskTagRule= new TaskTagRule(getToken(TASK_TAG_KEY), taskWords);
addPropertyChangeParticipant(taskTagRule);
return Collections.singletonList((IRule)taskTagRule);

View file

@ -20,6 +20,8 @@ import org.eclipse.jface.text.rules.PatternRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.ui.text.AbstractCScanner;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;

View file

@ -18,6 +18,8 @@ import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.editor.CEditor;

View file

@ -17,22 +17,14 @@ import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.ITokenStore;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
@ -40,153 +32,47 @@ import org.eclipse.cdt.internal.ui.text.util.CColorManager;
/**
* This type shares all scanners and the color manager between
* its clients.
* Tools required to configure a C/C++ source viewer.
* Scanners must be configured using a {@link CSourceViewerConfiguration}.
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*/
public class CTextTools {
private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
public void propertyChange(PropertyChangeEvent event) {
adaptToPreferenceChange(event);
}
public void propertyChange(Preferences.PropertyChangeEvent event) {
adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
}
}
/** The color manager */
private CColorManager fColorManager;
/** The C source code scanner */
private CCodeScanner fCodeScanner;
/** The C++ source code scanner */
private CCodeScanner fCppCodeScanner;
/** The C multiline comment scanner */
private CCommentScanner fMultilineCommentScanner;
/** The C singleline comment scanner */
private CCommentScanner fSinglelineCommentScanner;
/** The C string scanner */
private SingleTokenCScanner fStringScanner;
/** The C preprocessor scanner */
private CPreprocessorScanner fCPreprocessorScanner;
/** The C++ preprocessor scanner */
private CPreprocessorScanner fCppPreprocessorScanner;
/** The preference store */
private IPreferenceStore fPreferenceStore;
/** The core preference store */
private Preferences fCorePreferenceStore;
/** The preference change listener */
private PreferenceListener fPreferenceListener= new PreferenceListener();
/** The document partitioning used for the C partitioner */
private String fDocumentPartitioning = ICPartitions.C_PARTITIONING;
/**
* Creates a new C text tools collection and eagerly creates
* and initializes all members of this collection.
*/
public CTextTools(IPreferenceStore store) {
this(store, null, true);
}
/**
* Creates a new C text tools collection and eagerly creates
* and initializes all members of this collection.
*/
public CTextTools(IPreferenceStore store, Preferences coreStore) {
this(store, coreStore, true);
}
/**
* Creates a new C text tools collection and eagerly creates
* and initializes all members of this collection.
*/
public CTextTools(IPreferenceStore store, Preferences coreStore, boolean autoDisposeOnDisplayDispose) {
fPreferenceStore = store != null ? store : CUIPlugin.getDefault().getPreferenceStore();
fColorManager= new CColorManager(autoDisposeOnDisplayDispose);
ITokenStoreFactory factory= new ITokenStoreFactory() {
public ITokenStore createTokenStore(String[] propertyColorNames) {
return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
}
};
fMultilineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
fSinglelineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
fCodeScanner= new CCodeScanner(factory, GCCLanguage.getDefault());
fCppCodeScanner= new CCodeScanner(factory, GPPLanguage.getDefault());
fStringScanner= new SingleTokenCScanner(factory, ICColorConstants.C_STRING);
fCPreprocessorScanner= new CPreprocessorScanner(factory, GCCLanguage.getDefault());
fCppPreprocessorScanner= new CPreprocessorScanner(factory, GPPLanguage.getDefault());
fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
fCorePreferenceStore= coreStore;
if (fCorePreferenceStore != null) {
fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
}
}
/**
* Creates a new C text tools collection and eagerly creates
* and initializes all members of this collection.
* Creates a new C text tools instance.
*/
public CTextTools() {
this((IPreferenceStore)null);
fColorManager= new CColorManager(true);
}
/**
* Disposes all members of this tools collection.
*/
public void dispose() {
fCodeScanner= null;
fMultilineCommentScanner= null;
fSinglelineCommentScanner= null;
fStringScanner= null;
if (fColorManager != null) {
fColorManager.dispose();
fColorManager= null;
}
if (fPreferenceStore != null) {
fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
fPreferenceStore= null;
if (fCorePreferenceStore != null) {
fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
fCorePreferenceStore= null;
}
fPreferenceListener= null;
}
}
/**
* Gets the color manager.
*/
public CColorManager getColorManager() {
public IColorManager getColorManager() {
return fColorManager;
}
/**
* Gets the code scanner used.
*/
public RuleBasedScanner getCCodeScanner() {
return fCodeScanner;
}
/**
* Gets the code scanner used.
*/
public RuleBasedScanner getCppCodeScanner() {
return fCppCodeScanner;
}
/**
* Returns a scanner which is configured to scan
* C-specific partitions, which are multi-line comments,
* C-specific partitions, which are preprocessor directives, comments,
* and regular C source code.
*
* @param owner may be null
@ -203,97 +89,12 @@ public class CTextTools {
return new FastCPartitioner(getPartitionScanner(owner), ICPartitions.ALL_CPARTITIONS);
}
/**
* Returns a scanner which is configured to scan C multiline comments.
*
* @return a C multiline comment scanner
*/
public RuleBasedScanner getMultilineCommentScanner() {
return fMultilineCommentScanner;
}
/**
* Returns a scanner which is configured to scan C singleline comments.
*
* @return a C singleline comment scanner
*/
public RuleBasedScanner getSinglelineCommentScanner() {
return fSinglelineCommentScanner;
}
/**
* Returns a scanner which is configured to scan C strings.
*
* @return a C string scanner
*/
public RuleBasedScanner getStringScanner() {
return fStringScanner;
}
/**
* Returns a scanner which is configured to scan C preprocessor directives.
*
* @return a C preprocessor directives scanner
*/
public RuleBasedScanner getCPreprocessorScanner() {
return fCPreprocessorScanner;
}
/**
* Returns a scanner which is configured to scan C++ preprocessor directives.
*
* @return a C++ preprocessor directives scanner
*/
public RuleBasedScanner getCppPreprocessorScanner() {
return fCppPreprocessorScanner;
}
/**
* Determines whether the preference change encoded by the given event
* changes the behavior of one its contained components.
*
* @param event the event to be investigated
* @return <code>true</code> if event causes a behavioral change
*/
public boolean affectsBehavior(PropertyChangeEvent event) {
return fCodeScanner.affectsBehavior(event) ||
fCppCodeScanner.affectsBehavior(event) ||
fMultilineCommentScanner.affectsBehavior(event) ||
fSinglelineCommentScanner.affectsBehavior(event) ||
fStringScanner.affectsBehavior(event) ||
fCPreprocessorScanner.affectsBehavior(event);
}
/**
* Adapts the behavior of the contained components to the change
* encoded in the given event.
*
* @param event the event to whch to adapt
*/
public void adaptToPreferenceChange(PropertyChangeEvent event) {
if (fCodeScanner.affectsBehavior(event))
fCodeScanner.adaptToPreferenceChange(event);
if (fCppCodeScanner.affectsBehavior(event))
fCppCodeScanner.adaptToPreferenceChange(event);
if (fMultilineCommentScanner.affectsBehavior(event))
fMultilineCommentScanner.adaptToPreferenceChange(event);
if (fSinglelineCommentScanner.affectsBehavior(event))
fSinglelineCommentScanner.adaptToPreferenceChange(event);
if (fStringScanner.affectsBehavior(event))
fStringScanner.adaptToPreferenceChange(event);
if (fCPreprocessorScanner.affectsBehavior(event)) {
fCPreprocessorScanner.adaptToPreferenceChange(event);
fCppPreprocessorScanner.adaptToPreferenceChange(event);
}
}
/**
* Sets up the document partitioner for the given document for the given partitioning.
*
* @param document
* @param partitioning
* @param owner may be null
* @since 5.0
*/
public void setupCDocumentPartitioner(IDocument document, String partitioning, IDocCommentOwner owner) {
IDocumentPartitioner partitioner= createDocumentPartitioner(owner);
@ -312,7 +113,6 @@ public class CTextTools {
* @param document the document to be set up
* @param location the path of the resource backing the document. May be null.
* @param locationKind the type of path specified above. May be null.
* @since 3.0
*/
public void setupCDocument(IDocument document, IPath location, LocationKind locationKind) {
IDocCommentOwner owner= getDocumentationCommentOwner(location, locationKind);
@ -323,7 +123,6 @@ public class CTextTools {
* Sets up the given document for the default partitioning.
*
* @param document the document to be set up
* @since 3.0
*/
public void setupCDocument(IDocument document) {
setupCDocumentPartitioner(document, fDocumentPartitioning, null);
@ -333,7 +132,6 @@ public class CTextTools {
* Get the document partitioning used for the C partitioner.
*
* @return the document partitioning used for the C partitioner
* @since 3.1
*/
public String getDocumentPartitioning() {
return fDocumentPartitioning;
@ -341,8 +139,6 @@ public class CTextTools {
/**
* Set the document partitioning to be used for the C partitioner.
*
* @since 3.1
*/
public void setDocumentPartitioning(String documentPartitioning) {
fDocumentPartitioning = documentPartitioning;

View file

@ -1,40 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* QNX Software System
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
import org.eclipse.swt.graphics.RGB;
/**
* For internal use only. Not API. <p>
* A color manager extension is for extending
* <code>IColorManager</code> instances with new functionality.
*/
public interface IColorManagerExtension {
/**
* Remembers the given color specification under the given key.
*
* @param key the color key
* @param rgb the color specification
* @exception UnsupportedOperationException if there is already a
* color specification remembered under the given key
*/
void bindColor(String key, RGB rgb);
/**
* Forgets the color specification remembered under the given key.
* @param key the color key
*/
void unbindColor(String key);
}

View file

@ -23,9 +23,12 @@ import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.IColorManager;
/**
* A simple {@linkplain org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration C source viewer configuration}.
* A simple {@linkplain org.eclipse.cdt.ui.text.CSourceViewerConfiguration C source viewer configuration}.
* <p>
* This simple source viewer configuration basically provides syntax coloring
* and disables all other features like code assist, quick outlines, hyperlinking, etc.

View file

@ -12,70 +12,17 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
import java.util.List;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.cdt.ui.text.AbstractCScanner;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
/**
*
*/
public final class SingleTokenCScanner extends AbstractCScanner {
private String fProperty;
private int position, end;
private int size;
protected IToken fDefaultReturnToken;
public SingleTokenCScanner(ITokenStoreFactory factory, String property) {
super(factory.createTokenStore(new String[] {property}), 20);
fProperty= property;
setRules(createRules());
setDefaultReturnToken(getToken(property));
}
protected List<IRule> createRules() {
fDefaultReturnToken= getToken(fProperty);
setDefaultReturnToken(fDefaultReturnToken);
return null;
}
/**
* setRange -- sets the range to be scanned
*/
@Override
public void setRange(IDocument document, int offset, int length) {
super.setRange(document, offset, length);
position = offset;
size = length;
end = offset + length;
}
/**
* Returns the next token in the document.
*
* @return the next token in the document
*/
@Override
public IToken nextToken() {
fTokenOffset = position;
if(position < end) {
size = end - position;
position = end;
return fDefaultReturnToken;
}
return Token.EOF;
}
@Override
public int getTokenLength() {
return size;
}
}

View file

@ -29,6 +29,7 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.ui.text.ITokenStore;
@ -94,11 +95,8 @@ public class TokenStore implements ITokenStore {
private void addToken(String colorKey) {
if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) {
RGB rgb= PreferenceConverter.getColor(fPreferenceStore, colorKey);
if (fColorManager instanceof IColorManagerExtension) {
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
ext.unbindColor(colorKey);
ext.bindColor(colorKey, rgb);
}
fColorManager.unbindColor(colorKey);
fColorManager.bindColor(colorKey, rgb);
}
if (!fNeedsLazyColorLoading)
@ -228,11 +226,9 @@ public class TokenStore implements ITokenStore {
String property= event.getProperty();
Color color= fColorManager.getColor(property);
if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) {
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
ext.unbindColor(property);
ext.bindColor(property, rgb);
if ((color == null || !rgb.equals(color.getRGB()))) {
fColorManager.unbindColor(property);
fColorManager.bindColor(property, rgb);
color= fColorManager.getColor(property);
}

View file

@ -54,6 +54,7 @@ import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.cdt.internal.ui.text.CTextTools;
public class CCompletionProposal implements ICCompletionProposal, ICompletionProposalExtension, ICompletionProposalExtension2, ICompletionProposalExtension3 {
private String fDisplayString;

View file

@ -14,10 +14,11 @@ package org.eclipse.cdt.internal.ui.text.contentassist;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;

View file

@ -48,12 +48,12 @@ import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.core.model.ASTCache;
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.IColorManager;
public class CCorrectionAssistant extends QuickAssistAssistant {
private ITextViewer fViewer;

View file

@ -14,6 +14,7 @@
package org.eclipse.cdt.internal.ui.text.spelling;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
@ -24,15 +25,19 @@ import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.TypedRegion;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.ITokenStore;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.ui.text.doctools.IDocCommentDictionary;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
import org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.CPreprocessorScanner;
import org.eclipse.cdt.internal.ui.text.FastCPartitioner;
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentSpellDictionary;
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellChecker;
@ -43,6 +48,26 @@ import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellEventListener;
* C/C++ spelling engine
*/
public class CSpellingEngine extends SpellingEngine {
/**
* A dummy token store for use with a token scanner.
*/
private static class SimpleTokenStore implements ITokenStore {
public void ensureTokensInitialised() {
}
public IPreferenceStore getPreferenceStore() {
return null;
}
public IToken getToken(String property) {
return new Token(property);
}
public void adaptToPreferenceChange(PropertyChangeEvent event) {
}
public boolean affectsBehavior(PropertyChangeEvent event) {
return false;
}
}
/*
* @see org.eclipse.cdt.internal.ui.text.spelling.SpellingEngine#check(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IRegion[], org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellChecker, org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector, org.eclipse.core.runtime.IProgressMonitor)
*/
@ -95,8 +120,10 @@ public class CSpellingEngine extends SpellingEngine {
}
if (type.equals(ICPartitions.C_PREPROCESSOR)) {
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
RuleBasedScanner scanner = textTools.getCppPreprocessorScanner();
RuleBasedScanner scanner = new CPreprocessorScanner(new ITokenStoreFactory() {
public ITokenStore createTokenStore(String[] propertyColorNames) {
return new SimpleTokenStore();
}}, GPPLanguage.getDefault());
scanner.setRange(document, partition.getOffset(), partition.getLength());
int firstTokenOffset = -1;
int firstTokenLength = -1;

View file

@ -20,13 +20,13 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.IColorManagerExtension;
import org.eclipse.cdt.ui.text.IColorManager;
/**
* CDT color manager.
*/
public class CColorManager implements IColorManager, IColorManagerExtension {
public class CColorManager implements IColorManager {
protected Map<String, RGB> fKeyTable= new HashMap<String, RGB>(10);
protected Map<Display, Map<RGB, Color>> fDisplayTable= new HashMap<Display, Map<RGB, Color>>(2);
@ -120,7 +120,7 @@ public class CColorManager implements IColorManager, IColorManagerExtension {
}
/*
* @see IColorManagerExtension#bindColor(String, RGB)
* @see IColorManager#bindColor(String, RGB)
*/
public void bindColor(String key, RGB rgb) {
Object value= fKeyTable.get(key);
@ -131,7 +131,7 @@ public class CColorManager implements IColorManager, IColorManagerExtension {
}
/*
* @see IColorManagerExtension#unbindColor(String)
* @see IColorManager#unbindColor(String)
*/
public void unbindColor(String key) {
fKeyTable.remove(key);

View file

@ -307,7 +307,7 @@ public class EditorUtility {
/**
* Utility method to get an editor input for the given file system location.
* If the location denotes a workspace file, a <code>FileEditorInput</code>
* is returned, otherwise, the input is an <code>IStorageEditorInput</code>
* is returned, otherwise, the input is an <code>IURIEditorInput</code>
* assuming the location points to an existing file in the file system.
* The <code>ICElement</code> is used to determine the associated project
* in case the location can not be resolved to a workspace <code>IFile</code>.
@ -465,7 +465,7 @@ public class EditorUtility {
* If a context element is given and there are multiple matches in the workspace,
* a resource with the same project of the context element are preferred.
*
* @param locationURI a valid file system location
* @param locationURI a valid Eclipse file system URI
* @param context an element related to the target file, may be <code>null</code>
* @return an <code>IFile</code> or <code>null</code>
*/

View file

@ -0,0 +1,210 @@
/*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui;
import java.net.URI;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.runtime.IPath;
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.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
import org.eclipse.cdt.internal.ui.text.asm.AsmPartitionScanner;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
/**
* This class provides utilities for clients of the CDT UI plug-in.
* This class provides static methods for:
* <ul>
* <li>opening an editor on a C model element.</li>
* <li>accessing working copy manager and document provider used with C model elements.</li>
* <li>accessing color manager used for syntax coloring of C/C++ files.</li>
* </ul>
*
* @noinstantiate This class is not intended to be instantiated by clients.
* @since 5.1
*/
public final class CDTUITools {
private CDTUITools() {
// prevent instantiation
}
/**
* Returns the color manager which is used to manage
* colors needed for syntax highlighting.
*
* @return the color manager to be used for C/C++ text viewers
*/
public static IColorManager getColorManager() {
return CUIPlugin.getDefault().getTextTools().getColorManager();
}
/**
* Opens an editor on the given C model element in the active page. Valid are elements that are {@link ISourceReference}.
*
* @param element the input element
* @return returns the editor part of the opened editor or <code>null</code> if the element is not a {@link ISourceReference} or the
* file was opened in an external editor.
* @exception PartInitException if the editor could not be initialized or no workbench page is active
* @exception CModelException if this element does not exist or if an exception occurs while accessing its underlying resource
*/
public static IEditorPart openInEditor(ICElement element) throws CModelException, PartInitException {
return openInEditor(element, true, true);
}
/**
* Opens an editor on the given C model element in the active page. Valid are elements that are {@link ISourceReference}.
*
* @param element the input element
* @return returns the editor part of the opened editor or <code>null</code> if the element is not a {@link ISourceReference} or the
* file was opened in an external editor.
* @exception PartInitException if the editor could not be initialized or no workbench page is active
* @exception CModelException if this element does not exist or if an exception occurs while accessing its underlying resource
*/
public static IEditorPart openInEditor(ICElement element, boolean activate, boolean reveal) throws CModelException, PartInitException {
if (!(element instanceof ISourceReference)) {
return null;
}
IEditorPart part= EditorUtility.openInEditor(element, activate);
if (reveal && part != null) {
EditorUtility.revealInEditor(part, element);
}
return part;
}
/**
* Reveals the given C model element in the given editor..
*
* @param part the editor displaying a translation unit
* @param element the element to be revealed
*/
public static void revealInEditor(IEditorPart part, ICElement element) {
EditorUtility.revealInEditor(part, element);
}
/**
* Returns the working copy manager for the CDT UI plug-in.
*
* @return the working copy manager for the CDT UI plug-in
*/
public static IWorkingCopyManager getWorkingCopyManager() {
return CUIPlugin.getDefault().getWorkingCopyManager();
}
/**
* Returns the document provider used for C/C++ files.
*
* @return the document provider for C/C++ files.
*
* @see IDocumentProvider
*/
public static IDocumentProvider getDocumentProvider() {
return CUIPlugin.getDefault().getDocumentProvider();
}
/**
* Returns the <code>ICElement</code> element wrapped by the given editor input.
*
* @param editorInput the editor input
* @return the ICElement wrapped by <code>editorInput</code> or <code>null</code> if none
*/
public static ICElement getEditorInputCElement(IEditorInput editorInput) {
if (editorInput instanceof ITranslationUnitEditorInput) {
return ((ITranslationUnitEditorInput) editorInput).getTranslationUnit();
}
IWorkingCopy tu= CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
if (tu != null)
return tu;
return (ICElement)editorInput.getAdapter(ICElement.class);
}
/**
* Utility method to get an editor input for the given file system location.
* If the location denotes a workspace file, a <code>FileEditorInput</code>
* is returned, otherwise, the input is an <code>IURIEditorInput</code>
* assuming the location points to an existing file in an Eclipse file system.
* The <code>ICElement</code> is used to determine the associated project
* in case the location can not be resolved to a workspace <code>IFile</code>.
*
* @param locationURI a valid Eclipse file system URI
* @param context an element related to the target file, may be <code>null</code>
* @return an editor input
*/
public static IEditorInput getEditorInputForLocation(URI locationURI, ICElement context) {
return EditorUtility.getEditorInputForLocation(locationURI, context);
}
/**
* Utility method to get an editor input for the given file system location.
* If the location denotes a workspace file, a <code>FileEditorInput</code>
* is returned, otherwise, the input is an <code>IURIEditorInput</code>
* assuming the location points to an existing file in the file system.
* The <code>ICElement</code> is used to determine the associated project
* in case the location can not be resolved to a workspace <code>IFile</code>.
*
* @param location a valid file system location
* @param context an element related to the target file, may be <code>null</code>
* @return an editor input
*/
public static IEditorInput getEditorInputForLocation(IPath location, ICElement context) {
return EditorUtility.getEditorInputForLocation(location, context);
}
/**
* Sets up the given document for the default C/C++ partitioning.
*
* @param document the document to be set up
* @param location the path of the resource backing the document. May be null.
* @param locationKind the type of path specified above. May be null.
*/
public void setupCDocument(IDocument document, IPath location, LocationKind locationKind) {
CUIPlugin.getDefault().getTextTools().setupCDocument(document, location, locationKind);
}
/**
* Create a document partitioner suitable for Assembly source.
*/
public static IDocumentPartitioner createAsmDocumentPartitioner() {
return new FastPartitioner(new AsmPartitionScanner(), ICPartitions.ALL_ASM_PARTITIONS);
}
/**
* Sets up the given document for the default Assembly partitioning.
*
* @param document the document to be set up
*/
public void setupAsmDocument(IDocument document) {
IDocumentPartitioner partitioner= createAsmDocumentPartitioner();
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3= (IDocumentExtension3) document;
extension3.setDocumentPartitioner(ICPartitions.C_PARTITIONING, partitioner);
} else {
document.setDocumentPartitioner(partitioner);
}
partitioner.connect(document);
}
}

View file

@ -141,6 +141,7 @@ public class CUIPlugin extends AbstractUIPlugin {
* (value <code>"org.eclipse.cdt.ui.CHierarchyPerspective"</code>).
*
* @deprecated This perspective no longer exists.
* @noreference This field is not intended to be referenced by clients.
*/
@Deprecated
public static final String ID_CHIERARCHY_PERSPECTIVE = PLUGIN_ID + ".CHierarchyPerspective"; //$NON-NLS-1$
@ -151,6 +152,7 @@ public class CUIPlugin extends AbstractUIPlugin {
*
* @since 2.0
* @deprecated This perspective no longer exists.
* @noreference This field is not intended to be referenced by clients.
*/
@Deprecated
public static final String ID_CBROWSING_PERSPECTIVE = PLUGIN_ID + ".CBrowsingPerspective"; //$NON-NLS-1$
@ -161,6 +163,7 @@ public class CUIPlugin extends AbstractUIPlugin {
*
* @since 2.0
* @deprecated This view no longer exists.
* @noreference This field is not intended to be referenced by clients.
*/
@Deprecated
public static String ID_PROJECTS_VIEW = PLUGIN_ID + ".ProjectsView"; //$NON-NLS-1$
@ -171,6 +174,7 @@ public class CUIPlugin extends AbstractUIPlugin {
*
* @since 2.0
* @deprecated This view no longer exists.
* @noreference This field is not intended to be referenced by clients.
*/
@Deprecated
public static String ID_NAMESPACES_VIEW = PLUGIN_ID + ".NamespacesView"; //$NON-NLS-1$
@ -181,6 +185,7 @@ public class CUIPlugin extends AbstractUIPlugin {
*
* @since 2.0
* @deprecated This view no longer exists.
* @noreference This field is not intended to be referenced by clients.
*/
@Deprecated
public static String ID_TYPES_VIEW = PLUGIN_ID + ".TypesView"; //$NON-NLS-1$
@ -191,6 +196,7 @@ public class CUIPlugin extends AbstractUIPlugin {
*
* @since 2.0
* @deprecated This view no longer exists.
* @noreference This field is not intended to be referenced by clients.
*/
@Deprecated
public static String ID_MEMBERS_VIEW = PLUGIN_ID + ".MembersView"; //$NON-NLS-1$
@ -317,7 +323,7 @@ public class CUIPlugin extends AbstractUIPlugin {
/**
* Utility method with conventions
* @param logError TODO
* @param logError TODO
*/
public static void errorDialog(Shell shell, String title, String message, IStatus s, boolean logError) {
if (logError)
@ -333,7 +339,7 @@ public class CUIPlugin extends AbstractUIPlugin {
/**
* Utility method with conventions
* @param logError TODO
* @param logError TODO
*/
public static void errorDialog(Shell shell, String title, String message, Throwable t, boolean logError) {
if (logError)
@ -443,20 +449,24 @@ public class CUIPlugin extends AbstractUIPlugin {
}
/**
* Returns the shared text tools
* Returns the shared C/C++ text tools.
* @noreference This method is not intended to be referenced by clients.
*/
public CTextTools getTextTools() {
if (fTextTools == null)
fTextTools = new CTextTools(getPreferenceStore(), CCorePlugin.getDefault().getPluginPreferences());
fTextTools = new CTextTools();
return fTextTools;
}
/**
* Returns the shared assembly text tools
* Returns the shared assembly text tools.
* @deprecated Use methods provided by {@link CDTUITools} instead.
* @noreference This method is not intended to be referenced by clients.
*/
@Deprecated
public AsmTextTools getAsmTextTools() {
if (fAsmTextTools == null)
fAsmTextTools = new AsmTextTools(getPreferenceStore(), CCorePlugin.getDefault().getPluginPreferences());
fAsmTextTools = new AsmTextTools();
return fAsmTextTools;
}
@ -547,6 +557,10 @@ public class CUIPlugin extends AbstractUIPlugin {
fTextTools.dispose();
fTextTools= null;
}
if (fAsmTextTools != null) {
fAsmTextTools.dispose();
fAsmTextTools= null;
}
if (fImageDescriptorRegistry != null) {
fImageDescriptorRegistry.dispose();
fImageDescriptorRegistry= null;
@ -624,7 +638,10 @@ public class CUIPlugin extends AbstractUIPlugin {
manager.unregisterAdapters(fCElementAdapterFactory);
}
/** @deprecated Use {@link EditorsUI#getSharedTextColors()} instead. */
/**
* @deprecated Use {@link EditorsUI#getSharedTextColors()} instead.
* @noreference This method is not intended to be referenced by clients.
*/
@Deprecated
public ISharedTextColors getSharedTextColors() {
return EditorsUI.getSharedTextColors();

View file

@ -26,6 +26,8 @@ import org.eclipse.ui.texteditor.AbstractTextEditor;
/**
* This class implements the setting of the CUI initial preference store settings.
*
* @noextend This class is not intended to be subclassed by clients.
*/
public class CUIPreferenceInitializer extends AbstractPreferenceInitializer {

View file

@ -13,7 +13,8 @@ package org.eclipse.cdt.ui;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
/**
* Represents the C/C++ help provider
* Represents a C/C++ help provider. This interface need to be implemented by
* contributors to extension point "org.eclipse.cdt.ui.CHelpProvider".
* <p>
* Clients may implement this interface.
* </p>

View file

@ -12,9 +12,11 @@ package org.eclipse.cdt.ui;
/**
* A function summary provided by an {@link ICHelpProvider}.
* <p>
* Clients may implement this interface.
* </p>
* @see ICHelpProvider
*/
public interface IFunctionSummary {

View file

@ -11,15 +11,17 @@
package org.eclipse.cdt.ui;
/**
* Interface related to {@link IFunctionSummary} denoting an include required for a function.
* <p>
* Clients may implement this interface.
* </p>
* @see IFunctionSummary
*/
public interface IRequiredInclude {
/**
* Returns the name that has been imported.
* For an on-demand import, this includes the trailing <code>".*"</code>.
* For example, for the statement <code>"import java.util.*"</code>,
* this returns <code>"java.util.*"</code>.
* For the statement <code>"import java.util.Hashtable"</code>,
* this returns <code>"java.util.Hashtable"</code>.
* Get the include name.
*/
String getIncludeName();

View file

@ -31,10 +31,10 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.internal.ui.ICThemeConstants;
import org.eclipse.cdt.internal.ui.preferences.formatter.FormatterProfileManager;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
import org.eclipse.cdt.internal.ui.text.spelling.SpellCheckEngine;
/**

View file

@ -10,7 +10,7 @@
* QNX Software System
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
package org.eclipse.cdt.ui.text;
import java.util.ArrayList;
import java.util.Iterator;
@ -23,28 +23,43 @@ import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.cdt.ui.IPropertyChangeParticipant;
import org.eclipse.cdt.ui.text.ICTokenScanner;
import org.eclipse.cdt.ui.text.ITokenStore;
/**
* Convenience implementation.
* Convenience implementation for {@link ICTokenScanner}.
* Subclasses need to initialize scanner rules by calling {@link #setRules(IRule[])} or {@link #setRules(List)}.
* <p>
* Clients may instantiate and extend this class.
* </p>
*
* @since 5.1
*/
public abstract class AbstractCScanner extends BufferedRuleBasedScanner implements ICTokenScanner {
private List<IPropertyChangeParticipant> pcps;
private List<IPropertyChangeParticipant> fParticipants;
final protected ITokenStore fTokenStore;
/**
* Create a new scanner for the given token store with default buffer size.
*
* @param tokenStore
*/
public AbstractCScanner(ITokenStore tokenStore) {
fTokenStore= tokenStore;
fParticipants= new ArrayList<IPropertyChangeParticipant>();
}
/**
* Create a new scanner for the given token store and buffer size.
*
* @param tokenStore
* @param size
*/
public AbstractCScanner(ITokenStore tokenStore, int size) {
this(tokenStore);
setBufferSize(size);
}
public AbstractCScanner(ITokenStore tokenStore) {
fTokenStore= tokenStore;
pcps= new ArrayList<IPropertyChangeParticipant>();
}
protected void addPropertyChangeParticipant(IPropertyChangeParticipant participant) {
pcps.add(participant);
fParticipants.add(participant);
}
/**
@ -86,7 +101,7 @@ public abstract class AbstractCScanner extends BufferedRuleBasedScanner implemen
if(fTokenStore.affectsBehavior(event)) {
fTokenStore.adaptToPreferenceChange(event);
}
for (IPropertyChangeParticipant propertyChangeParticipant : pcps) {
for (IPropertyChangeParticipant propertyChangeParticipant : fParticipants) {
propertyChangeParticipant.adaptToPreferenceChange(event);
}
}
@ -96,9 +111,9 @@ public abstract class AbstractCScanner extends BufferedRuleBasedScanner implemen
*/
public boolean affectsBehavior(PropertyChangeEvent event) {
boolean result= fTokenStore.affectsBehavior(event);
for(Iterator<IPropertyChangeParticipant> i= pcps.iterator(); !result && i.hasNext(); ) {
for(Iterator<IPropertyChangeParticipant> i= fParticipants.iterator(); !result && i.hasNext(); ) {
result |= (i.next()).affectsBehavior(event);
}
return result;
}
}
}

View file

@ -9,7 +9,7 @@
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor.asm;
package org.eclipse.cdt.ui.text;
import org.eclipse.core.resources.IFile;
@ -43,20 +43,25 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ILanguageUI;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.ITokenStore;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
import org.eclipse.cdt.internal.ui.editor.asm.AsmCodeScanner;
import org.eclipse.cdt.internal.ui.editor.asm.AsmPreprocessorScanner;
import org.eclipse.cdt.internal.ui.editor.asm.AsmReconcilingStrategy;
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
import org.eclipse.cdt.internal.ui.text.TokenStore;
/**
* Configuration for a source viewer which shows Assembly code.
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @noextend This class is not intended to be subclassed by clients.
*
* @since 5.1
*/
public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration {
private ITextEditor fTextEditor;
@ -106,24 +111,6 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
initializeScanners();
}
/**
* Constructor for AsmSourceViewerConfiguration.
* @deprecated
*/
@Deprecated
public AsmSourceViewerConfiguration(AsmTextTools tools, IPreferenceStore store) {
this(tools.getColorManager(), store, null, ICPartitions.C_PARTITIONING);
}
/**
* Constructor for AsmSourceViewerConfiguration.
* @deprecated
*/
@Deprecated
public AsmSourceViewerConfiguration(ITextEditor editor, IPreferenceStore store) {
this(CUIPlugin.getDefault().getAsmTextTools().getColorManager(), store, editor, ICPartitions.C_PARTITIONING);
}
/**
* Initializes the scanners.
*/
@ -138,7 +125,7 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
*
* @return the ASM multiline comment scanner
*/
protected RuleBasedScanner getMultilineCommentScanner() {
public RuleBasedScanner getMultilineCommentScanner() {
return fMultilineCommentScanner;
}
@ -147,7 +134,7 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
*
* @return the ASM singleline comment scanner
*/
protected RuleBasedScanner getSinglelineCommentScanner() {
public RuleBasedScanner getSinglelineCommentScanner() {
return fSinglelineCommentScanner;
}
@ -156,7 +143,7 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
*
* @return the ASM string scanner
*/
protected RuleBasedScanner getStringScanner() {
public RuleBasedScanner getStringScanner() {
return fStringScanner;
}
@ -166,7 +153,7 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
*
* @return the assembly preprocessor scanner
*/
protected RuleBasedScanner getPreprocessorScanner(ILanguage language) {
public RuleBasedScanner getPreprocessorScanner(ILanguage language) {
if (fPreprocessorScanner != null) {
return fPreprocessorScanner;
}
@ -185,7 +172,7 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
* @param language
* @return the assembly code scanner for the given language
*/
protected RuleBasedScanner getCodeScanner(ILanguage language) {
public RuleBasedScanner getCodeScanner(ILanguage language) {
if (fCodeScanner != null) {
return fCodeScanner;
}
@ -334,11 +321,11 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
*
* @return the color manager
*/
protected IColorManager getColorManager() {
public IColorManager getColorManager() {
return fColorManager;
}
protected ILanguage getLanguage() {
public ILanguage getLanguage() {
if (fTextEditor == null) {
return AssemblyLanguage.getDefault();
}

View file

@ -12,7 +12,7 @@
* Sergey Prigogin (Google)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
package org.eclipse.cdt.ui.text;
import java.util.Arrays;
import java.util.Map;
@ -78,10 +78,6 @@ import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ILanguageUI;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.ICTokenScanner;
import org.eclipse.cdt.ui.text.ITokenStore;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
@ -90,6 +86,22 @@ import org.eclipse.cdt.internal.core.model.ProgressMonitorAndCanceler;
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
import org.eclipse.cdt.internal.ui.editor.CDocumentProvider;
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
import org.eclipse.cdt.internal.ui.text.CCodeScanner;
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
import org.eclipse.cdt.internal.ui.text.CCompositeReconcilingStrategy;
import org.eclipse.cdt.internal.ui.text.CDoubleClickSelector;
import org.eclipse.cdt.internal.ui.text.CFormattingStrategy;
import org.eclipse.cdt.internal.ui.text.COutlineInformationControl;
import org.eclipse.cdt.internal.ui.text.CPreprocessorScanner;
import org.eclipse.cdt.internal.ui.text.CPresentationReconciler;
import org.eclipse.cdt.internal.ui.text.CReconciler;
import org.eclipse.cdt.internal.ui.text.CStringAutoIndentStrategy;
import org.eclipse.cdt.internal.ui.text.CStringDoubleClickSelector;
import org.eclipse.cdt.internal.ui.text.HTMLAnnotationHover;
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
import org.eclipse.cdt.internal.ui.text.TokenStore;
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverProxy;
import org.eclipse.cdt.internal.ui.text.c.hover.CInformationProvider;
@ -104,7 +116,12 @@ import org.eclipse.cdt.internal.ui.typehierarchy.THInformationProvider;
/**
* Configuration for an <code>SourceViewer</code> which shows C/C++ code.
* Configuration for a <code>SourceViewer</code> which shows C/C++ code.
* <p>
* This class may be instantiated and subclassed by clients.
* </p>
*
* @since 5.1
*/
public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
@ -313,7 +330,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
*
* @return the C multi-line comment scanner
*/
private ICTokenScanner getMultilineCommentScanner() {
protected ICTokenScanner getMultilineCommentScanner() {
return fMultilineCommentScanner;
}
@ -322,7 +339,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
*
* @return the C single-line comment scanner
*/
private ICTokenScanner getSinglelineCommentScanner() {
protected ICTokenScanner getSinglelineCommentScanner() {
return fSinglelineCommentScanner;
}
@ -1011,12 +1028,12 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
* @return the IProject associated with this CSourceViewerConfiguration, or null if
* no IProject could be determined
*/
private IProject getProject() {
protected IProject getProject() {
ICProject cproject= getCProject();
return cproject!=null ? cproject.getProject() :null;
}
private ITokenStoreFactory getTokenStoreFactory() {
protected ITokenStoreFactory getTokenStoreFactory() {
return new ITokenStoreFactory() {
public ITokenStore createTokenStore(String[] propertyColorNames) {
return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -9,14 +9,25 @@
* QNX Software Systems - Initial API and implementation
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
package org.eclipse.cdt.ui.text;
/*
* Color constants that we use for the preferences
*/
/**
* Color keys used for syntax highlighting C/C++ and Assembly code
* A <code>IColorManager</code> is responsible for mapping
* concrete colors to these keys.
* <p>
* This interface declares static final fields only; it is not intended to be
* implemented.
* </p>
* @see org.eclipse.cdt.ui.text.IColorManager
*
* @since 5.1
*
* @noimplement This interface is not intended to be implemented by clients.
* @noextend This interface is not intended to be extended by clients.
*/
public interface ICColorConstants {
/** The color key for multi-line comments in C code. */
String C_MULTI_LINE_COMMENT= "c_multi_line_comment"; //$NON-NLS-1$

View file

@ -63,7 +63,7 @@ public interface ICPartitions {
String C_MULTI_LINE_DOC_COMMENT= "__c_multiline_doc_comment"; //$NON-NLS-1$
/**
* All defined CDT editor partitions
* All defined CDT editor partitions.
* @since 5.0
*/
String[] ALL_CPARTITIONS= {
@ -75,4 +75,17 @@ public interface ICPartitions {
ICPartitions.C_SINGLE_LINE_DOC_COMMENT,
ICPartitions.C_MULTI_LINE_DOC_COMMENT
};
/**
* Array of all assembly partitions.
* @since 5.1
*/
String[] ALL_ASM_PARTITIONS= new String[] {
ICPartitions.C_MULTI_LINE_COMMENT,
ICPartitions.C_SINGLE_LINE_COMMENT,
ICPartitions.C_STRING,
ICPartitions.C_CHARACTER,
ICPartitions.C_PREPROCESSOR
};
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -9,22 +9,26 @@
* IBM Corporation - initial API and implementation
* QNX Software System
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
package org.eclipse.cdt.ui.text;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
/**
* Manages SWT color objects for given color keys and
* given <code>RGB</code> objects. Until the <code>dispose</code>
* Manages SWT color objects for the given color keys and
* given <code>RGB</code> objects. Until the <code>dispose</code>
* method is called, the same color object is returned for
* equal keys and equal <code>RGB</code> values.
*
* <p>
* This interface may be implemented by clients.
* </p>
*
* @see ICColorConstants
* @see org.eclipse.cdt.ui.text.ICColorConstants
*
* @since 5.1
*/
public interface IColorManager {
@ -51,4 +55,21 @@ public interface IColorManager {
* Disposes all color objects remembered by this color manager.
*/
void dispose();
/**
* Remembers the given color specification under the given key.
*
* @param key the color key
* @param rgb the color specification
* @throws UnsupportedOperationException if there is already a
* color specification remembered under the given key
*/
void bindColor(String key, RGB rgb);
/**
* Forgets the color specification remembered under the given key.
* @param key the color key
*/
void unbindColor(String key);
}

View file

@ -15,13 +15,13 @@ import org.eclipse.jface.text.ITextHover;
import org.eclipse.ui.IEditorPart;
/**
* ICEditorTextHover
* Provides a hover popup which appears on top of an editor with relevant
* display information. If the text hover does not provide information no
* hover popup is shown.
* Interface to be implemented by contributors to extension point
* "org.eclipse.cdt.ui.textHovers". Provides a hover popup which appears on top
* of an editor with relevant display information. If the text hover does not
* provide information no hover popup is shown.
* <p>
* Clients may implement this interface.</p>
*
* Clients may implement this interface.
* </p>
*/
public interface ICEditorTextHover extends ITextHover {

View file

@ -13,43 +13,42 @@ package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.presentation;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IAsmLanguage;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.editor.CDocumentProvider;
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.SimpleCSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.TokenStore;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.AsmSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.ITokenStore;
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFileState;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IStorage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextPresentation;
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.information.IInformationPresenter;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* A presentation creator based on CDT syntax highlighting.
@ -60,11 +59,12 @@ public class CSourcePresentationCreator extends PresentationReconciler implement
/**
*
*/
private final static class CustomCSourceViewerConfiguration extends SimpleCSourceViewerConfiguration {
private final static class CustomCSourceViewerConfiguration extends CSourceViewerConfiguration {
/**
* Comment for <code>fLanguage</code>
*/
private final ILanguage fLanguage;
private AsmSourceViewerConfiguration fAsmConfig;
/**
* @param colorManager
@ -74,8 +74,11 @@ public class CSourcePresentationCreator extends PresentationReconciler implement
private CustomCSourceViewerConfiguration(
IColorManager colorManager, IPreferenceStore preferenceStore,
ILanguage language) {
super(colorManager, preferenceStore, null, ICPartitions.C_PARTITIONING, false);
super(colorManager, preferenceStore, null, ICPartitions.C_PARTITIONING);
fLanguage = language;
if (language instanceof IAsmLanguage) {
fAsmConfig= new AsmSourceViewerConfiguration(colorManager, preferenceStore, null, ICPartitions.C_PARTITIONING);
}
}
public void dispose() {
@ -114,63 +117,13 @@ public class CSourcePresentationCreator extends PresentationReconciler implement
return null;
}
private ITokenScanner getMultilineCommentScanner() {
return new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_SINGLE_LINE_COMMENT);
}
private ITokenScanner getSinglelineCommentScanner() {
return new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_MULTI_LINE_COMMENT);
}
/**
* Returns the ICProject associated with this CSourceViewerConfiguration, or null if
* no ICProject could be determined
* @return
*/
private ICProject internalGetCProject() {
ITextEditor editor= getEditor();
if (editor == null)
return null;
ICElement element= null;
IEditorInput input= editor.getEditorInput();
IDocumentProvider provider= editor.getDocumentProvider();
if (provider instanceof CDocumentProvider) {
CDocumentProvider cudp= (CDocumentProvider) provider;
element= cudp.getWorkingCopy(input);
}
if (element == null)
return null;
return element.getCProject();
}
/**
* @return the IProject associated with this CSourceViewerConfiguration, or null if
* no IProject could be determined
*/
private IProject getProject() {
ICProject cproject= internalGetCProject();
return cproject!=null ? cproject.getProject() :null;
}
private ITokenStoreFactory getTokenStoreFactory() {
return new ITokenStoreFactory() {
public ITokenStore createTokenStore(String[] propertyColorNames) {
return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
}
};
}
/*
* @see org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration#getCodeScanner(org.eclipse.cdt.core.model.ILanguage)
*/
@Override
protected RuleBasedScanner getCodeScanner(ILanguage language) {
if (language instanceof IAsmLanguage) {
return CUIPlugin.getDefault().getAsmTextTools().getCodeScanner();
return fAsmConfig.getCodeScanner(language);
}
return super.getCodeScanner(language);
}
@ -181,11 +134,99 @@ public class CSourcePresentationCreator extends PresentationReconciler implement
@Override
protected RuleBasedScanner getPreprocessorScanner(ILanguage language) {
if (language instanceof IAsmLanguage) {
return CUIPlugin.getDefault().getAsmTextTools().getPreprocessorScanner();
return fAsmConfig.getPreprocessorScanner(language);
}
return super.getPreprocessorScanner(language);
}
}
/*
* @see SourceViewerConfiguration#getAutoEditStrategies(ISourceViewer, String)
*/
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
return null;
}
/*
* @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
*/
@Override
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
return null;
}
/*
* @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
*/
@Override
public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
return null;
}
/*
* @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String)
*/
@Override
public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
return null;
}
/*
* @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
*/
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
return null;
}
/*
* @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
*/
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
return null;
}
/*
* @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
*/
@Override
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
return null;
}
/*
* @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
*/
@Override
public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
return null;
}
/*
* @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
*/
@Override
public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
return null;
}
/*
* @see SourceViewerConfiguration#getHyperlinkDetectors(ISourceViewer)
*/
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return null;
}
/*
* @see CSourceViewerConfiguration#getOutlinePresenter(ISourceViewer)
*/
@Override
public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer) {
return null;
}
}
private ITextViewer fViewer;
private ISourceTagProvider fSourceTagProvider;

View file

@ -18,10 +18,9 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightings;
import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.IColorManagerExtension;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.IDocument;
@ -99,9 +98,8 @@ public class SourceTagDamagerRepairer extends DefaultDamagerRepairer implements
private void removeTextAttribute(String key, String colorKey) {
if (fColorManager != null && colorKey != null) {
Color color= fColorManager.getColor(colorKey);
if (fColorManager instanceof IColorManagerExtension && color != null) {
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
ext.unbindColor(colorKey);
if (color != null) {
fColorManager.unbindColor(colorKey);
}
}
@ -109,13 +107,12 @@ public class SourceTagDamagerRepairer extends DefaultDamagerRepairer implements
}
private void addTextAttribute(String key, String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
if (fColorManager != null && colorKey != null && fColorManager instanceof IColorManagerExtension) {
if (fColorManager != null && colorKey != null) {
RGB rgb= PreferenceConverter.getColor(fPreferenceStore, colorKey);
Color color= fColorManager.getColor(colorKey);
if (color == null || !rgb.equals(color.getRGB())) {
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
ext.unbindColor(colorKey);
ext.bindColor(colorKey, rgb);
fColorManager.unbindColor(colorKey);
fColorManager.bindColor(colorKey, rgb);
}
}