1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Reworked syntax highlighting of preprocessor directives

This commit is contained in:
Anton Leherbauer 2006-09-29 15:36:10 +00:00
parent a13418d58f
commit 7412f600a8
27 changed files with 1364 additions and 480 deletions

View file

@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
* QNX Software System
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
package org.eclipse.cdt.ui.tests.text;
import java.util.ArrayList;
import java.util.List;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* Copyright (c) 2000, 2006 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
@ -251,6 +252,34 @@ public class CPartitionerTest extends TestCase {
assertTrue(false);
}
}
public void testInsertPreprocessorPartition() {
try {
fDocument.replace(4, 0, " # include <x.h>\n");
// "xxx\n/*xxx*/\nxxx\n/**xxx*/\nxxx\n/**/\nx\"yyy\"x\n/***/\nxxx");
// "xxx\n # include <x.h>\n/*xxx*/\nxxx\n/**xxx*/\nxxx\n/**/\nx\"yyy\"x\n/***/\nxxx");
assertTrue(fDocumentPartitioningChanged);
ITypedRegion[] result= fDocument.computePartitioning(0, fDocument.getLength());
TypedRegion[] expectation= {
new TypedRegion(0, 4, IDocument.DEFAULT_CONTENT_TYPE),
new TypedRegion(4, 17, ICPartitions.C_PREPROCESSOR),
new TypedRegion(21, 7, ICPartitions.C_MULTI_LINE_COMMENT),
new TypedRegion(28, 5, IDocument.DEFAULT_CONTENT_TYPE),
new TypedRegion(33, 8, ICPartitions.C_MULTI_LINE_COMMENT),
new TypedRegion(41, 5, IDocument.DEFAULT_CONTENT_TYPE),
new TypedRegion(46, 4, ICPartitions.C_MULTI_LINE_COMMENT),
new TypedRegion(50, 5, IDocument.DEFAULT_CONTENT_TYPE),
new TypedRegion(55, 5, ICPartitions.C_MULTI_LINE_COMMENT),
new TypedRegion(60, 4, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
} catch (BadLocationException x) {
assertTrue(false);
}
}
public void testRemovePartition1() {
try {
@ -950,4 +979,93 @@ public class CPartitionerTest extends TestCase {
}
}
public void testEditingPreprocessor() {
try {
fDocument.replace(0, fDocument.getLength(), "");
ITypedRegion[] result= fDocument.computePartitioning(0, fDocument.getLength());
TypedRegion[] expectation= {
new TypedRegion(0, 0, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
fDocument.replace(fDocument.getLength(), 0, "#");
fDocument.replace(fDocument.getLength(), 0, " ");
fDocument.replace(fDocument.getLength(), 0, "\t");
fDocument.replace(fDocument.getLength(), 0, "include <float.h> /* */");
result= fDocument.computePartitioning(0, fDocument.getLength());
expectation= new TypedRegion[] {
new TypedRegion(0, fDocument.getLength(), ICPartitions.C_PREPROCESSOR)
};
checkPartitioning(expectation, result);
fDocument.replace(fDocument.getLength(), 0, "\nz");
result= fDocument.computePartitioning(0, fDocument.getLength());
expectation= new TypedRegion[] {
new TypedRegion(0, 27, ICPartitions.C_PREPROCESSOR),
new TypedRegion(27, 1, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
// insert escaped backslash
fDocument.replace(2, 0, "\\\\");
result= fDocument.computePartitioning(0, fDocument.getLength());
expectation= new TypedRegion[] {
new TypedRegion(0, 29, ICPartitions.C_PREPROCESSOR),
new TypedRegion(29, 1, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
// replace one backslash with a newline
fDocument.replace(3, 1, "\n");
result= fDocument.computePartitioning(0, fDocument.getLength());
expectation= new TypedRegion[] {
new TypedRegion(0, 29, ICPartitions.C_PREPROCESSOR),
new TypedRegion(29, 1, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
// insert backslash and newline inside multiline comment
fDocument.replace(26, 0, "\\\r\n");
result= fDocument.computePartitioning(0, fDocument.getLength());
expectation= new TypedRegion[] {
new TypedRegion(0, 32, ICPartitions.C_PREPROCESSOR),
new TypedRegion(32, 1, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
// delete NL leaving only CR
fDocument.replace(28, 1, "");
result= fDocument.computePartitioning(0, fDocument.getLength());
expectation= new TypedRegion[] {
new TypedRegion(0, 31, ICPartitions.C_PREPROCESSOR),
new TypedRegion(31, 1, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
// delete backslash
fDocument.replace(26, 1, "");
result= fDocument.computePartitioning(0, fDocument.getLength());
expectation= new TypedRegion[] {
new TypedRegion(0, 30, ICPartitions.C_PREPROCESSOR),
new TypedRegion(30, 1, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
// insert white space before #
fDocument.replace(0, 0, " \t");
result= fDocument.computePartitioning(0, fDocument.getLength());
expectation= new TypedRegion[] {
new TypedRegion(0, 33, ICPartitions.C_PREPROCESSOR),
new TypedRegion(33, 1, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
} catch (BadLocationException x) {
assertTrue(false);
}
}
}

View file

@ -19,7 +19,6 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.internal.ui.text.CPartitionScanner;
import org.eclipse.cdt.internal.ui.text.FastCPartitionScanner;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
@ -42,10 +41,10 @@ public class PartitionTokenScannerTest extends TestCase {
protected void setUp() {
fReference= new CPartitionScanner();
fTestee= new FastCPartitionScanner();
fTestee= new FastCPartitionScanner(true);
}
// read sample java file
// read sample C file
private IDocument getDocument(String name, String lineDelimiter) {
try {
InputStream stream= getClass().getResourceAsStream(name);

View file

@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.ui.editor.SemanticHighlightings;
*/
public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
private static final boolean PRINT_POSITIONS= true;
private static final boolean PRINT_POSITIONS= false;
private static final Class THIS= SemanticHighlightingTest.class;

View file

@ -22,7 +22,7 @@ public class TextTestSuite extends TestSuite {
public TextTestSuite() {
super("Tests in package org.eclipse.cdt.ui.tests.text");
//addTest(PartitionTokenScannerTest.suite());
addTest(PartitionTokenScannerTest.suite());
addTest(NumberRuleTest.suite());
addTest(CAutoIndentTest.suite());
addTest(CPartitionerTest.suite());

View file

@ -576,7 +576,7 @@
name="%ColoringPreferencePage.name"
category="org.eclipse.cdt.ui.preferences.CEditorPreferencePage"
class="org.eclipse.cdt.internal.ui.preferences.CEditorColoringPreferencePage"
id="org.eclipse.cdt.ui.preferences.CEditorColoringPreferencePage"/>
id="org.eclipse.cdt.ui.preferences.CodeColoringPreferencePage"/>
<page
name="%CPluginTemplatePreferencePage.name"
category="org.eclipse.cdt.ui.preferences.CEditorPreferencePage"

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
@ -159,7 +160,8 @@ public class AddBlockCommentAction extends BlockCommentAction {
private boolean isSpecialPartition(String partType) {
return partType == ICPartitions.C_CHARACTER
|| partType == ICPartitions.C_STRING
|| partType == ICPartitions.C_SINGLE_LINE_COMMENT;
|| partType == ICPartitions.C_SINGLE_LINE_COMMENT
|| partType == ICPartitions.C_PREPROCESSOR;
}
/*

View file

@ -22,7 +22,9 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextPresentationListener;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.information.IInformationPresenter;
@ -32,6 +34,7 @@ import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
@ -445,4 +448,24 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
fTextPresentationListeners.remove(listener);
fTextPresentationListeners.add(0, listener);
}
/**
* {@inheritDoc}
* <p>
* Performance optimization: since we know at this place
* that none of the clients expects the given range to be
* untouched we reuse the given range as return value.
* </p>
*/
protected StyleRange modelStyleRange2WidgetStyleRange(StyleRange range) {
IRegion region= modelRange2WidgetRange(new Region(range.start, range.length));
if (region != null) {
// don't clone the style range, but simply reuse it.
range.start= region.getOffset();
range.length= region.getLength();
return range;
}
return null;
}
}

View file

@ -0,0 +1,117 @@
/*******************************************************************************
* Copyright (c) 2006 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:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor.asm;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
import org.eclipse.cdt.internal.ui.text.CHeaderRule;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
import org.eclipse.cdt.internal.ui.text.PreprocessorRule;
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
/**
* A preprocessor directive scanner for Asm source.
*
* @since 4.0
*/
public class AsmPreprocessorScanner extends AbstractCScanner {
/** Properties for tokens. */
private static String[] fgTokenProperties= {
ICColorConstants.C_SINGLE_LINE_COMMENT,
ICColorConstants.C_MULTI_LINE_COMMENT,
ICColorConstants.PP_DIRECTIVE,
ICColorConstants.C_STRING,
ICColorConstants.PP_HEADER,
ICColorConstants.PP_DEFAULT,
};
/**
* Create a preprocessor directive scanner.
*
* @param colorManager
* @param store
*/
public AsmPreprocessorScanner(CColorManager colorManager, IPreferenceStore store) {
super(colorManager, store);
initialize();
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#createRules()
*/
protected List createRules() {
Token defaultToken= getToken(ICColorConstants.PP_DEFAULT);
List rules= new ArrayList();
Token token;
// Add generic white space rule.
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
token= getToken(ICColorConstants.PP_DIRECTIVE);
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), defaultToken, getToken(ICColorConstants.C_SINGLE_LINE_COMMENT));
Iterator iter;
iter = ParserFactory.getKeywordSet( KeywordSetKey.PP_DIRECTIVE, ParserLanguage.C ).iterator();
while( iter.hasNext() ) {
String ppKeyword= (String) iter.next();
if (ppKeyword.length() > 1) {
preprocessorRule.addWord(ppKeyword, token);
}
}
// add ## operator
preprocessorRule.addWord("##", token); //$NON-NLS-1$
rules.add(preprocessorRule);
token = getToken(ICColorConstants.PP_HEADER);
CHeaderRule headerRule = new CHeaderRule(token);
rules.add(headerRule);
token = getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
IRule lineCommentRule = new EndOfLineRule("//", token, '\\', true); //$NON-NLS-1$
rules.add(lineCommentRule);
lineCommentRule = new EndOfLineRule("#", token); //$NON-NLS-1$
rules.add(lineCommentRule);
token = getToken(ICColorConstants.C_MULTI_LINE_COMMENT);
IRule blockCommentRule = new MultiLineRule("/*", "*/", token, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(blockCommentRule);
setDefaultReturnToken(defaultToken);
return rules;
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#getTokenProperties()
*/
protected String[] getTokenProperties() {
return fgTokenProperties;
}
}

View file

@ -22,6 +22,8 @@ import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration {
@ -62,6 +64,14 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
return fAsmTextTools.getStringScanner();
}
/**
* Returns the ASM preprocessor scanner for this configuration.
*
* @return the ASM preprocessor scanner
*/
protected RuleBasedScanner getPreprocessorScanner() {
return fAsmTextTools.getPreprocessorScanner();
}
/*
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
@ -98,6 +108,10 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
reconciler.setDamager(dr, ICPartitions.C_CHARACTER);
reconciler.setRepairer(dr, ICPartitions.C_CHARACTER);
dr= new DefaultDamagerRepairer(getPreprocessorScanner());
reconciler.setDamager(new PartitionDamager(), ICPartitions.C_PREPROCESSOR);
reconciler.setRepairer(dr, ICPartitions.C_PREPROCESSOR);
reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
return reconciler;
}
@ -111,7 +125,8 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
ICPartitions.C_MULTI_LINE_COMMENT,
ICPartitions.C_SINGLE_LINE_COMMENT,
ICPartitions.C_STRING,
ICPartitions.C_CHARACTER };
ICPartitions.C_CHARACTER,
ICPartitions.C_PREPROCESSOR};
}

View file

@ -51,7 +51,8 @@ public class AsmTextTools {
private CCommentScanner fSinglelineCommentScanner;
/** The ASM string scanner */
private SingleTokenCScanner fStringScanner;
/** The ASM preprocessor scanner */
private AsmPreprocessorScanner fPreprocessorScanner;
/** The preference store */
private IPreferenceStore fPreferenceStore;
@ -80,6 +81,7 @@ public class AsmTextTools {
fColorManager= new CColorManager();
fCodeScanner= new AsmCodeScanner(fColorManager, store);
fPreprocessorScanner= new AsmPreprocessorScanner(fColorManager, store);
fMultilineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
fSinglelineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
@ -145,32 +147,40 @@ public class AsmTextTools {
}
/**
* Returns a scanner which is configured to scan Java multiline comments.
* Returns a scanner which is configured to scan multiline comments.
*
* @return a Java multiline comment scanner
* @return a multiline comment scanner
*/
public RuleBasedScanner getMultilineCommentScanner() {
return fMultilineCommentScanner;
}
/**
* Returns a scanner which is configured to scan Java singleline comments.
* Returns a scanner which is configured to scan singleline comments.
*
* @return a Java singleline comment scanner
* @return a singleline comment scanner
*/
public RuleBasedScanner getSinglelineCommentScanner() {
return fSinglelineCommentScanner;
}
/**
* Returns a scanner which is configured to scan Java strings.
* Returns a scanner which is configured to scan strings.
*
* @return a Java string scanner
* @return a string scanner
*/
public RuleBasedScanner getStringScanner() {
return fStringScanner;
}
/**
* Returns a scanner which is configured to scan Asm preprocessor directives.
*
* @return an Asm preprocessor directives scanner
*/
public RuleBasedScanner getPreprocessorScanner() {
return fPreprocessorScanner;
}
/**
* Determines whether the preference change encoded by the given event
@ -183,7 +193,8 @@ public class AsmTextTools {
return fCodeScanner.affectsBehavior(event) ||
fMultilineCommentScanner.affectsBehavior(event) ||
fSinglelineCommentScanner.affectsBehavior(event) ||
fStringScanner.affectsBehavior(event);
fStringScanner.affectsBehavior(event) ||
fPreprocessorScanner.affectsBehavior(event);
}
/**
@ -201,6 +212,8 @@ public class AsmTextTools {
fSinglelineCommentScanner.adaptToPreferenceChange(event);
if (fStringScanner.affectsBehavior(event))
fStringScanner.adaptToPreferenceChange(event);
if (fPreprocessorScanner.affectsBehavior(event))
fPreprocessorScanner.adaptToPreferenceChange(event);
}
}

View file

@ -210,7 +210,7 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
return new String[] {fCodeCategory, fCommentsCategory};
return new String[] {fCodeCategory, fCommentsCategory, fPreprocessorCategory};
}
/*
@ -229,9 +229,11 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
if (parentElement instanceof String) {
String entry= (String) parentElement;
if (fCodeCategory.equals(entry))
return fListModel.subList(3, fListModel.size()).toArray();
return fListModel.subList(6, fListModel.size()).toArray();
if (fCommentsCategory.equals(entry))
return fListModel.subList(0, 3).toArray();
if (fPreprocessorCategory.equals(entry))
return fListModel.subList(3, 6).toArray();
}
return new Object[0];
}
@ -240,8 +242,10 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
if (element instanceof String)
return null;
int index= fListModel.indexOf(element);
if (index >= 3)
if (index >= 6)
return fCodeCategory;
if (index >= 3)
return fPreprocessorCategory;
return fCommentsCategory;
}
@ -274,6 +278,9 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
{ PreferencesMessages.CEditorColoringConfigurationBlock_MultiLine, PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_singleLine, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_cCommentTaskTags, PreferenceConstants.EDITOR_TASK_TAG_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_ppDirectives, PreferenceConstants.EDITOR_PP_DIRECTIVE_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_ppOthers, PreferenceConstants.EDITOR_PP_DEFAULT_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_ppHeaders, PreferenceConstants.EDITOR_PP_HEADER_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_keywords, PreferenceConstants.EDITOR_C_KEYWORD_COLOR },
// { PreferencesMessages.CEditorColoringConfigurationBlock_returnKeyword, PreferenceConstants.EDITOR_C_KEYWORD_RETURN_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_builtInTypes, PreferenceConstants.EDITOR_C_BUILTIN_TYPE_COLOR },
@ -281,12 +288,12 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
{ PreferencesMessages.CEditorColoringConfigurationBlock_strings, PreferenceConstants.EDITOR_C_STRING_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_braces, PreferenceConstants.EDITOR_C_BRACES_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_numbers, PreferenceConstants.EDITOR_C_NUMBER_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_headers, PreferenceConstants.EDITOR_C_HEADER_COLOR },
{ PreferencesMessages.CEditorColoringConfigurationBlock_others, PreferenceConstants.EDITOR_C_DEFAULT_COLOR },
};
private final String fCodeCategory= PreferencesMessages.CEditorColoringConfigurationBlock_coloring_category_code;
private final String fCommentsCategory= PreferencesMessages.CEditorColoringConfigurationBlock_coloring_category_comments;
private final String fPreprocessorCategory= PreferencesMessages.CEditorColoringConfigurationBlock_coloring_category_preprocessor;
private ColorSelector fSyntaxForegroundColorEditor;
private Label fColorEditorLabel;
@ -560,6 +567,8 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
return 0;
if (fCommentsCategory.equals(element))
return 2;
if (fPreprocessorCategory.equals(element))
return 3;
// to sort semantic settings after partition based ones:
// if (element instanceof SemanticHighlightingColorListItem)
// return 1;

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences;
@ -88,11 +89,14 @@ public final class PreferencesMessages extends NLS {
public static String CEditorColoringConfigurationBlock_operators;
public static String CEditorColoringConfigurationBlock_braces;
public static String CEditorColoringConfigurationBlock_numbers;
public static String CEditorColoringConfigurationBlock_headers;
public static String CEditorColoringConfigurationBlock_others;
public static String CEditorColoringConfigurationBlock_ppDirectives;
public static String CEditorColoringConfigurationBlock_ppOthers;
public static String CEditorColoringConfigurationBlock_ppHeaders;
public static String CEditorColoringConfigurationBlock_cCommentTaskTags;
public static String CEditorColoringConfigurationBlock_coloring_category_code;
public static String CEditorColoringConfigurationBlock_coloring_category_comments;
public static String CEditorColoringConfigurationBlock_coloring_category_preprocessor;
public static String CEditorColoringConfigurationBlock_coloring_element;
public static String CEditorColoringConfigurationBlock_link;
public static String CEditorColoringConfigurationBlock_enable;

View file

@ -7,6 +7,7 @@
#
# Contributors:
# IBM Corporation - initial API and implementation
# Anton Leherbauer (Wind River Systems)
###############################################################################
OptionsConfigurationBlock_builderror_title=Preference Changes
@ -90,11 +91,14 @@ CEditorColoringConfigurationBlock_strings=Strings
CEditorColoringConfigurationBlock_operators=Operators
CEditorColoringConfigurationBlock_braces=Braces
CEditorColoringConfigurationBlock_numbers=Numbers
CEditorColoringConfigurationBlock_headers=Headers
CEditorColoringConfigurationBlock_others=Others
CEditorColoringConfigurationBlock_ppDirectives=Directives
CEditorColoringConfigurationBlock_ppHeaders=Headers
CEditorColoringConfigurationBlock_ppOthers=Others
CEditorColoringConfigurationBlock_cCommentTaskTags=Task Tags
CEditorColoringConfigurationBlock_coloring_category_code=Code
CEditorColoringConfigurationBlock_coloring_category_comments=Comments
CEditorColoringConfigurationBlock_coloring_category_preprocessor=Preprocessor
CEditorColoringConfigurationBlock_coloring_element=Element:
# DO NOT TRANSLATE "org.eclipse.ui.preferencePages.GeneralTextEditor" and "org.eclipse.ui.preferencePages.ColorsAndFonts"
CEditorColoringConfigurationBlock_link=Default colors and font can be configured on the <a href=\"org.eclipse.ui.preferencePages.GeneralTextEditor\">Text Editors</a> and on the <a href=\"org.eclipse.ui.preferencePages.ColorsAndFonts\">Colors and Fonts</a> preference page.

View file

@ -19,6 +19,7 @@ import java.util.List;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.jface.util.PropertyChangeEvent;
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
@ -43,11 +45,9 @@ public final class CCodeScanner extends AbstractCScanner {
private static String[] fgTokenProperties= {
ICColorConstants.C_KEYWORD,
ICColorConstants.C_TYPE,
ICColorConstants.C_STRING,
ICColorConstants.C_OPERATOR,
ICColorConstants.C_BRACES,
ICColorConstants.C_NUMBER,
ICColorConstants.C_HEADER,
ICColorConstants.C_DEFAULT,
};
@ -78,7 +78,7 @@ public final class CCodeScanner extends AbstractCScanner {
Token token;
// Add generic white space rule.
//rules.add(new WhitespaceRule(new CWhitespaceDetector()));
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
// Add word rule for keywords, types, and constants.
token= getToken(ICColorConstants.C_DEFAULT);
@ -102,10 +102,6 @@ public final class CCodeScanner extends AbstractCScanner {
NumberRule numberRule = new NumberRule(token);
rules.add(numberRule);
token = getToken(ICColorConstants.C_HEADER);
CHeaderRule headerRule = new CHeaderRule(token);
rules.add(headerRule);
token = getToken(ICColorConstants.C_OPERATOR);
COperatorRule opRule = new COperatorRule(token);
rules.add(opRule);
@ -114,15 +110,6 @@ public final class CCodeScanner extends AbstractCScanner {
CBraceRule braceRule = new CBraceRule(token);
rules.add(braceRule);
token = getToken(ICColorConstants.C_TYPE);
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), token);
i = ParserFactory.getKeywordSet( KeywordSetKey.PP_DIRECTIVE, ParserLanguage.C ).iterator();
while( i.hasNext() )
preprocessorRule.addWord((String) i.next(), token);
rules.add(preprocessorRule);
setDefaultReturnToken(getToken(ICColorConstants.C_DEFAULT));
return rules;
}

View file

@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
@ -43,11 +44,12 @@ public class CHeaderRule implements IRule {
int lookAhead = 1;
int contentLength = 0;
if (current == '<') {
if (current == '<' || current == '"') {
int expected = current == '<' ? '>' : current;
do {
current = scanner.read();
lookAhead++;
if (current == '>') {
if (current == expected) {
if (contentLength < 1) {
break;
}
@ -113,8 +115,8 @@ public class CHeaderRule implements IRule {
lookBehind++;
} while (Character.isWhitespace((char) current));
scanner.read();
if (searchBackwards(scanner, "#include")) { //$NON-NLS-1$
--lookBehind;
if (searchBackwards(scanner, "include")) { //$NON-NLS-1$
result = true;
}
}

View file

@ -0,0 +1,145 @@
/*******************************************************************************
* Copyright (c) 2006 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:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.PatternRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
/**
* A scanner for preprocessor directives.
*
* @since 4.0
*/
public class CPreprocessorScanner extends AbstractCScanner {
/** Properties for tokens. */
private static String[] fgTokenProperties= {
ICColorConstants.C_SINGLE_LINE_COMMENT,
ICColorConstants.C_MULTI_LINE_COMMENT,
ICColorConstants.C_KEYWORD,
ICColorConstants.PP_DIRECTIVE,
ICColorConstants.PP_DEFAULT,
ICColorConstants.C_TYPE,
ICColorConstants.C_STRING,
ICColorConstants.PP_HEADER
};
private boolean fIsCpp;
/**
* Creates a C/C++ preprocessor scanner.
*
* @param manager the color manager.
* @param store the preference store.
* @param isCpp if <code>true</code> C++ keywords are used, else C keywords
*/
public CPreprocessorScanner(IColorManager manager, IPreferenceStore store, boolean isCpp) {
super(manager, store);
fIsCpp= isCpp;
initialize();
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#createRules()
*/
protected List createRules() {
Token defaultToken= getToken(ICColorConstants.PP_DEFAULT);
List rules= new ArrayList();
Token token;
// Add generic white space rule.
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
token= getToken(ICColorConstants.PP_DIRECTIVE);
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), token);
Iterator iter;
if (fIsCpp) {
iter = ParserFactory.getKeywordSet( KeywordSetKey.PP_DIRECTIVE, ParserLanguage.CPP ).iterator();
} else {
iter = ParserFactory.getKeywordSet( KeywordSetKey.PP_DIRECTIVE, ParserLanguage.C ).iterator();
}
while( iter.hasNext() )
preprocessorRule.addWord((String) iter.next(), token);
// add ## operator
preprocessorRule.addWord("##", token); //$NON-NLS-1$
rules.add(preprocessorRule);
// Add word rule for keywords, types, and constants.
WordRule wordRule= new WordRule(new CWordDetector(), defaultToken);
token= getToken(ICColorConstants.C_KEYWORD);
if (fIsCpp) {
iter = ParserFactory.getKeywordSet( KeywordSetKey.KEYWORDS, ParserLanguage.CPP ).iterator();
} else {
iter = ParserFactory.getKeywordSet( KeywordSetKey.KEYWORDS, ParserLanguage.C ).iterator();
}
while( iter.hasNext() )
wordRule.addWord((String) iter.next(), token);
token= getToken(ICColorConstants.C_TYPE);
iter = ParserFactory.getKeywordSet( KeywordSetKey.TYPES, ParserLanguage.C ).iterator();
while( iter.hasNext() )
wordRule.addWord((String) iter.next(), token);
rules.add(wordRule);
token = getToken(ICColorConstants.PP_HEADER);
CHeaderRule headerRule = new CHeaderRule(token);
rules.add(headerRule);
token = getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
IRule lineCommentRule = new EndOfLineRule("//", token, '\\', true); //$NON-NLS-1$
rules.add(lineCommentRule);
token = getToken(ICColorConstants.C_MULTI_LINE_COMMENT);
IRule blockCommentRule = new MultiLineRule("/*", "*/", token, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(blockCommentRule);
token = getToken(ICColorConstants.C_STRING);
IRule stringRule = new PatternRule("\"", "\"", token, '\\', true, true, true); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(stringRule);
token = getToken(ICColorConstants.C_STRING);
IRule charRule = new PatternRule("'", "'", token, '\\', true, true, true); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(charRule);
setDefaultReturnToken(defaultToken);
return rules;
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#getTokenProperties()
*/
protected String[] getTokenProperties() {
return fgTokenProperties;
}
}

View file

@ -118,6 +118,24 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
return fTextTools.getStringScanner();
}
/**
* Returns the C preprocessor scanner for this configuration.
*
* @return the C preprocessor scanner
*/
protected RuleBasedScanner getCPreprocessorScanner() {
return fTextTools.getCPreprocessorScanner();
}
/**
* Returns the C++ preprocessor scanner for this configuration.
*
* @return the C++ preprocessor scanner
*/
protected RuleBasedScanner getCppPreprocessorScanner() {
return fTextTools.getCppPreprocessorScanner();
}
/**
* Returns the color manager for this configuration.
*
@ -153,6 +171,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
presenter.setInformationProvider(provider, ICPartitions.C_SINGLE_LINE_COMMENT);
presenter.setInformationProvider(provider, ICPartitions.C_STRING);
presenter.setInformationProvider(provider, ICPartitions.C_CHARACTER);
presenter.setInformationProvider(provider, ICPartitions.C_PREPROCESSOR);
presenter.setSizeConstraints(20, 20, true, false);
presenter.setRestoreInformationControlBounds(getSettings("outline_presenter_bounds"), true, true); //$NON-NLS-1$
return presenter;
@ -167,8 +186,9 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
RuleBasedScanner scanner = null;
ILanguage language= null;
if(sourceViewer instanceof CSourceViewer) {
ILanguage language = ((CSourceViewer)sourceViewer).getLanguage();
language = ((CSourceViewer)sourceViewer).getLanguage();
if (language instanceof GPPLanguage) {
scanner = fTextTools.getCppCodeScanner();
} else if (language instanceof GCCLanguage) {
@ -206,6 +226,18 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
reconciler.setDamager(dr, ICPartitions.C_CHARACTER);
reconciler.setRepairer(dr, ICPartitions.C_CHARACTER);
if (language instanceof GPPLanguage) {
dr= new DefaultDamagerRepairer(getCppPreprocessorScanner());
} else if (language instanceof GCCLanguage) {
dr= new DefaultDamagerRepairer(getCPreprocessorScanner());
} else {
dr= null;
}
if (dr != null) {
reconciler.setDamager(new PartitionDamager(), ICPartitions.C_PREPROCESSOR);
reconciler.setRepairer(dr, ICPartitions.C_PREPROCESSOR);
}
return reconciler;
}
@ -400,7 +432,8 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
ICPartitions.C_MULTI_LINE_COMMENT,
ICPartitions.C_SINGLE_LINE_COMMENT,
ICPartitions.C_STRING,
ICPartitions.C_CHARACTER};
ICPartitions.C_CHARACTER,
ICPartitions.C_PREPROCESSOR};
}
/**

View file

@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* QNX Software System
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
@ -51,12 +52,16 @@ public class CTextTools {
private CppCodeScanner fCppCodeScanner;
/** The C partitions scanner */
private FastCPartitionScanner fPartitionScanner;
/** The Java multiline comment scanner */
/** The C multiline comment scanner */
private CCommentScanner fMultilineCommentScanner;
/** The Java singleline comment scanner */
/** The C singleline comment scanner */
private CCommentScanner fSinglelineCommentScanner;
/** The Java string scanner */
/** 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;
@ -99,6 +104,8 @@ public class CTextTools {
fMultilineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
fSinglelineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
fStringScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_STRING);
fCPreprocessorScanner= new CPreprocessorScanner(fColorManager, store, false);
fCppPreprocessorScanner= new CPreprocessorScanner(fColorManager, store, true);
fPreferenceStore = store;
fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
@ -190,7 +197,8 @@ public class CTextTools {
ICPartitions.C_MULTI_LINE_COMMENT,
ICPartitions.C_SINGLE_LINE_COMMENT,
ICPartitions.C_STRING,
ICPartitions.C_CHARACTER
ICPartitions.C_CHARACTER,
ICPartitions.C_PREPROCESSOR
};
return new FastPartitioner(getPartitionScanner(), types);
@ -215,14 +223,31 @@ public class CTextTools {
}
/**
* Returns a scanner which is configured to scan Java strings.
* Returns a scanner which is configured to scan C strings.
*
* @return a Java string scanner
* @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
@ -236,7 +261,8 @@ public class CTextTools {
fCppCodeScanner.affectsBehavior(event) ||
fMultilineCommentScanner.affectsBehavior(event) ||
fSinglelineCommentScanner.affectsBehavior(event) ||
fStringScanner.affectsBehavior(event);
fStringScanner.affectsBehavior(event) ||
fCPreprocessorScanner.affectsBehavior(event);
}
/**
@ -256,6 +282,10 @@ public class CTextTools {
fSinglelineCommentScanner.adaptToPreferenceChange(event);
if (fStringScanner.affectsBehavior(event))
fStringScanner.adaptToPreferenceChange(event);
if (fCPreprocessorScanner.affectsBehavior(event)) {
fCPreprocessorScanner.adaptToPreferenceChange(event);
fCppPreprocessorScanner.adaptToPreferenceChange(event);
}
}
/**

View file

@ -19,6 +19,7 @@ import java.util.List;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.jface.util.PropertyChangeEvent;
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
@ -41,11 +43,9 @@ public final class CppCodeScanner extends AbstractCScanner {
private static String[] fgTokenProperties= {
ICColorConstants.C_KEYWORD,
ICColorConstants.C_TYPE,
ICColorConstants.C_STRING,
ICColorConstants.C_OPERATOR,
ICColorConstants.C_BRACES,
ICColorConstants.C_NUMBER,
ICColorConstants.C_HEADER,
ICColorConstants.C_DEFAULT
};
@ -74,8 +74,7 @@ public final class CppCodeScanner extends AbstractCScanner {
Token token;
// Add generic whitespace rule.
//rules.add(new WhitespaceRule(new CWhitespaceDetector()));
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
// Add word rule for keywords, types, and constants.
token= getToken(ICColorConstants.C_DEFAULT);
@ -93,23 +92,10 @@ public final class CppCodeScanner extends AbstractCScanner {
wordRule.addWord(fgConstants[i], token);
rules.add(wordRule);
token = getToken(ICColorConstants.C_TYPE);
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), token);
iter = ParserFactory.getKeywordSet( KeywordSetKey.PP_DIRECTIVE, ParserLanguage.CPP ).iterator();
while( iter.hasNext() )
preprocessorRule.addWord((String) iter.next(), token);
rules.add(preprocessorRule);
token = getToken(ICColorConstants.C_NUMBER);
NumberRule numberRule = new NumberRule(token);
rules.add(numberRule);
token = getToken(ICColorConstants.C_HEADER);
CHeaderRule headerRule = new CHeaderRule(token);
rules.add(headerRule);
token = getToken(ICColorConstants.C_OPERATOR);
COperatorRule opRule = new COperatorRule(token);
rules.add(opRule);

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.ui.text;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
@ -24,9 +25,9 @@ import org.eclipse.cdt.ui.text.ICPartitions;
/**
* This scanner recognizes the C multi line comments, C single line comments,
* C strings and C characters.
* C strings, C characters and C preprocessor directives.
*/
public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitions {
public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitions {
// states
private static final int CCODE= 0;
@ -34,17 +35,19 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
private static final int MULTI_LINE_COMMENT= 2;
private static final int CHARACTER= 3;
private static final int STRING= 4;
private static final int PREPROCESSOR= 5;
private static final int PREPROCESSOR_MULTI_LINE_COMMENT= 6;
// beginning of prefixes and postfixes
private static final int NONE= 0;
private static final int BACKSLASH= 1; // postfix for STRING and CHARACTER
private static final int BACKSLASH= 1; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
private static final int SLASH= 2; // prefix for SINGLE_LINE or MULTI_LINE
private static final int SLASH_STAR= 3; // prefix for MULTI_LINE_COMMENT
private static final int STAR= 4; // postfix for MULTI_LINE_COMMENT
private static final int CARRIAGE_RETURN=5; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
private static final int BACKSLASH_CR= 6; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
/** The scanner. */
// private final BufferedRuleBasedScanner fScanner= new BufferedRuleBasedScanner(1000);
private final BufferedDocumentScanner fScanner= new BufferedDocumentScanner(1000); // faster implementation
/** The offset of the last returned token. */
@ -58,62 +61,213 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
private int fLast;
/** The amount of characters already read on first call to nextToken(). */
private int fPrefixLength;
/** Indicate whether current char is first non-whitespace char on the line*/
private boolean fFirstCharOnLine= true;
// emulate CPartitionScanner
private boolean fEmulate= false;
private int fCCodeOffset;
private int fCCodeLength;
private final IToken[] fTokens= new IToken[] {
new Token(null),
new Token(C_SINGLE_LINE_COMMENT),
new Token(C_MULTI_LINE_COMMENT),
new Token(C_CHARACTER),
new Token(C_STRING)
new Token(C_STRING),
new Token(C_PREPROCESSOR),
new Token(C_PREPROCESSOR)
};
public FastCPartitionScanner(boolean emulate) {
fEmulate= emulate;
}
public FastCPartitionScanner() {
this(false);
}
/*
* @see org.eclipse.jface.text.rules.ITokenScanner#nextToken()
*/
public IToken nextToken() {
// emulate CPartitionScanner
if (fEmulate) {
if (fCCodeOffset != -1 && fTokenOffset + fTokenLength != fCCodeOffset + fCCodeLength) {
fTokenOffset += fTokenLength;
return fTokens[CCODE];
} else {
fCCodeOffset= -1;
fCCodeLength= 0;
}
}
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
final char[][] delimiters = fScanner.getLegalLineDelimiters();
while (true) {
final int ch= fScanner.read();
if (ch == ICharacterScanner.EOF) {
final boolean isFirstCharOnLine= fFirstCharOnLine;
if (fFirstCharOnLine && ch != ' ' && ch != '\t') {
fFirstCharOnLine= false;
}
// characters
switch (ch) {
case ICharacterScanner.EOF:
if (fTokenLength > 0) {
fLast= NONE; // ignore last
return preFix(fState, CCODE, NONE, 0);
} else {
fLast= NONE;
fPrefixLength= 0;
return Token.EOF;
}
fLast= NONE;
fPrefixLength= 0;
return Token.EOF;
}
// detect if we're at the end of the line
final int delim = detectLineDelimiter(ch, fScanner, delimiters);
if (delim != -1) {
final int len = delimiters[delim].length;
if (len > 1) {
// adjust the token length if the delimiter was 2 or more chars
fTokenLength += (len - 1);
}
case '\r':
fFirstCharOnLine= true;
if (!fEmulate && fLast == BACKSLASH) {
fLast= BACKSLASH_CR;
fTokenLength++;
continue;
} else if (!fEmulate && fLast != CARRIAGE_RETURN) {
fLast= CARRIAGE_RETURN;
fTokenLength++;
continue;
} else {
// fEmulate || fLast == CARRIAGE_RETURN
switch (fState) {
case SINGLE_LINE_COMMENT:
case CHARACTER:
case STRING:
case PREPROCESSOR:
if (fTokenLength > 0) {
IToken token= fTokens[fState];
// emulate CPartitionScanner
if (fEmulate) {
fTokenLength++;
fLast= NONE;
fPrefixLength= 0;
} else {
fLast= CARRIAGE_RETURN;
fPrefixLength= 1;
}
fState= CCODE;
return token;
} else {
consume();
continue;
}
default:
consume();
continue;
}
}
case '\\':
if (fLast == BACKSLASH) {
consume();
continue;
}
break;
case '\n':
fFirstCharOnLine= true;
switch (fState) {
case SINGLE_LINE_COMMENT:
case CHARACTER:
case STRING:
case PREPROCESSOR:
// assert(fTokenLength > 0);
// if last char was a backslash then we have an escaped line
if (fLast != BACKSLASH) {
if (fLast != BACKSLASH && fLast != BACKSLASH_CR) {
return postFix(fState);
}
// FALLTHROUGH
default:
consume();
continue;
}
default:
if (!fEmulate && fLast == CARRIAGE_RETURN) {
switch (fState) {
case SINGLE_LINE_COMMENT:
case CHARACTER:
case STRING:
int last;
int newState;
switch (ch) {
case '/':
last= SLASH;
newState= CCODE;
break;
case '*':
last= STAR;
newState= CCODE;
break;
case '\'':
last= NONE;
newState= CHARACTER;
break;
case '"':
last= NONE;
newState= STRING;
break;
case '\r':
last= CARRIAGE_RETURN;
newState= CCODE;
break;
case '\\':
last= BACKSLASH;
newState= CCODE;
break;
default:
last= NONE;
newState= CCODE;
break;
}
fLast= NONE; // ignore fLast
return preFix(fState, newState, last, 1);
case CCODE:
if (ch == '#' && isFirstCharOnLine) {
fLast= NONE; // ignore fLast
int column= fScanner.getColumn() - 1;
fTokenLength -= column;
if (fTokenLength > 0) {
return preFix(fState, PREPROCESSOR, NONE, column + 1);
} else {
preFix(fState, PREPROCESSOR, NONE, column + 1);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
}
}
break;
case PREPROCESSOR:
fLast= NONE; // ignore fLast
return preFix(fState, CCODE, NONE, 1);
default:
break;
}
}
}
// states
@ -124,51 +278,71 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
if (fLast == SLASH) {
if (fTokenLength - getLastLength(fLast) > 0) {
return preFix(CCODE, SINGLE_LINE_COMMENT, NONE, 2);
} else {
preFix(CCODE, SINGLE_LINE_COMMENT, NONE, 2);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
}
preFix(CCODE, SINGLE_LINE_COMMENT, NONE, 2);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
} else {
fTokenLength++;
fLast= SLASH;
break;
}
fTokenLength++;
fLast= SLASH;
break;
case '*':
if (fLast == SLASH) {
if (fTokenLength - getLastLength(fLast) > 0)
if (fTokenLength - getLastLength(fLast) > 0) {
return preFix(CCODE, MULTI_LINE_COMMENT, SLASH_STAR, 2);
} else {
preFix(CCODE, MULTI_LINE_COMMENT, SLASH_STAR, 2);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
}
preFix(CCODE, MULTI_LINE_COMMENT, SLASH_STAR, 2);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
} else {
consume();
break;
}
consume();
break;
case '\'':
fLast= NONE; // ignore fLast
if (fTokenLength > 0) {
return preFix(CCODE, CHARACTER, NONE, 1);
} else {
preFix(CCODE, CHARACTER, NONE, 1);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
}
preFix(CCODE, CHARACTER, NONE, 1);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
case '"':
fLast= NONE; // ignore fLast
if (fTokenLength > 0 ) {
return preFix(CCODE, STRING, NONE, 1);
} else {
preFix(CCODE, STRING, NONE, 1);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
}
preFix(CCODE, STRING, NONE, 1);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
case '#':
if (!fEmulate && isFirstCharOnLine) {
int column= fScanner.getColumn() - 1;
fTokenLength -= column;
if (fTokenLength > 0) {
return preFix(fState, PREPROCESSOR, NONE, column + 1);
} else {
preFix(fState, PREPROCESSOR, NONE, column + 1);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
}
}
// fallthrough
default:
consume();
break;
@ -176,11 +350,65 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
break;
case SINGLE_LINE_COMMENT:
switch (ch) {
case '\\':
switch (ch) {
case '\\':
fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH;
fTokenLength++;
break;
default:
consume();
break;
}
break;
case PREPROCESSOR:
switch (ch) {
case '\\':
fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH;
fTokenLength++;
break;
case '/':
if (fLast == SLASH) {
consume();
break;
} else {
fTokenLength++;
fLast= SLASH;
break;
}
case '*':
if (fLast == SLASH) {
fState= PREPROCESSOR_MULTI_LINE_COMMENT;
consume();
break;
} else {
consume();
break;
}
default:
consume();
break;
}
break;
case PREPROCESSOR_MULTI_LINE_COMMENT:
switch (ch) {
case '*':
fTokenLength++;
fLast= STAR;
break;
case '/':
if (fLast == STAR) {
fState= PREPROCESSOR;
consume();
}
break;
default:
consume();
break;
@ -197,9 +425,10 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
case '/':
if (fLast == STAR) {
return postFix(MULTI_LINE_COMMENT);
} else {
consume();
break;
}
consume();
break;
default:
consume();
@ -218,9 +447,10 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
if (fLast != BACKSLASH) {
return postFix(STRING);
} else {
consume();
break;
}
consume();
break;
default:
consume();
@ -239,9 +469,10 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
if (fLast != BACKSLASH) {
return postFix(CHARACTER);
} else {
consume();
break;
}
consume();
break;
default:
consume();
@ -252,46 +483,6 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
}
}
/**
* returns index of longest matching element in delimiters
*/
private static final int detectLineDelimiter(final int ch, final ICharacterScanner scanner, final char[][] delimiters) {
int longestDelimiter = -1;
int maxLen = 0;
for (int i = 0; i < delimiters.length; i++) {
final char[] delim = delimiters[i];
if (ch == delim[0]) {
final int len = delim.length;
if (len > maxLen && (len == 1 || sequenceDetected(scanner, delim, 1, len))) {
maxLen = len;
longestDelimiter = i;
}
}
}
return longestDelimiter;
}
/**
* <code>true</code> if sequence matches between beginIndex (inclusive) and endIndex (exclusive)
*/
private static final boolean sequenceDetected(final ICharacterScanner scanner, final char[] sequence, final int beginIndex, final int endIndex) {
int charsRead = 0;
for (int i = beginIndex; i < endIndex; ++i) {
final int c = scanner.read();
if (c != ICharacterScanner.EOF) {
++charsRead;
}
if (c != sequence[i]) {
// Non-matching character detected, rewind the scanner back to the start.
for (; charsRead > 0; --charsRead) {
scanner.unread();
}
return false;
}
}
return true;
}
private static final int getLastLength(int last) {
switch (last) {
default:
@ -307,6 +498,7 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
return 1;
case SLASH_STAR:
case BACKSLASH_CR:
return 2;
}
@ -326,12 +518,25 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
}
private final IToken preFix(int state, int newState, int last, int prefixLength) {
fTokenLength -= getLastLength(fLast);
fLast= last;
fPrefixLength= prefixLength;
IToken token= fTokens[state];
fState= newState;
return token;
// emulate CPartitionScanner
if (fEmulate && state == CCODE && (fTokenLength - getLastLength(fLast) > 0)) {
fTokenLength -= getLastLength(fLast);
fCCodeOffset= fTokenOffset;
fCCodeLength= fTokenLength;
fTokenLength= 1;
fState= newState;
fPrefixLength= prefixLength;
fLast= last;
return fTokens[state];
} else {
fTokenLength -= getLastLength(fLast);
fLast= last;
fPrefixLength= prefixLength;
IToken token= fTokens[state];
fState= newState;
return token;
}
}
private static int getState(String contentType) {
@ -351,6 +556,9 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
else if (contentType.equals(C_CHARACTER))
return CHARACTER;
else if (contentType.equals(C_PREPROCESSOR))
return PREPROCESSOR;
else
return CCODE;
}
@ -373,6 +581,18 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
fState= getState(contentType);
}
try {
int column= fScanner.getColumn();
fFirstCharOnLine= column == 0 || document.get(offset-column, column).trim().length() == 0;
} catch (BadLocationException exc) {
fFirstCharOnLine= true;
}
// emulate CPartitionScanner
if (fEmulate) {
fCCodeOffset= -1;
fCCodeLength= 0;
}
}
/*
@ -387,6 +607,18 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
fLast= NONE;
fState= CCODE;
try {
int column= fScanner.getColumn();
fFirstCharOnLine= column == 0 || document.get(offset-column, column).trim().length() == 0;
} catch (BadLocationException exc) {
fFirstCharOnLine= true;
}
// emulate CPartitionScanner
if (fEmulate) {
fCCodeOffset= -1;
fCCodeLength= 0;
}
}
/*

View file

@ -18,30 +18,32 @@ package org.eclipse.cdt.internal.ui.text;
*/
public interface ICColorConstants {
/* The prefix all color constants start with */
String PREFIX= "c_"; //$NON-NLS-1$
/* The color key for multi-line comments in C code. */
/** The color key for multi-line comments in C code. */
String C_MULTI_LINE_COMMENT= "c_multi_line_comment"; //$NON-NLS-1$
/* The color key for single-line comments in C code. */
/** The color key for single-line comments in C code. */
String C_SINGLE_LINE_COMMENT= "c_single_line_comment"; //$NON-NLS-1$
/* The color key for keywords in C code. */
/** The color key for keywords in C code. */
String C_KEYWORD= "c_keyword"; //$NON-NLS-1$
/* The color key for builtin types in C code. */
/** The color key for builtin types in C code. */
String C_TYPE= "c_type"; //$NON-NLS-1$
/* The color key for string and character literals in C code. */
/** The color key for string and character literals in C code. */
String C_STRING= "c_string"; //$NON-NLS-1$
/** The color key for operators. */
String C_OPERATOR = "c_operators"; //$NON-NLS-1$
String C_OPERATOR= "c_operators"; //$NON-NLS-1$
/** The color key for braces. */
String C_BRACES = "c_braces"; //$NON-NLS-1$
String C_BRACES= "c_braces"; //$NON-NLS-1$
/** The color key for numbers. */
String C_NUMBER = "c_numbers"; //$NON-NLS-1$
/** The color key for headers. */
String C_HEADER = "c_header"; //$NON-NLS-1$
/* The color key for everthing in C code for which no other color is specified. */
String C_NUMBER= "c_numbers"; //$NON-NLS-1$
/** The color key for everthing in C code for which no other color is specified. */
String C_DEFAULT= "c_default"; //$NON-NLS-1$
/** The color key for preprocessor directives. */
String PP_DIRECTIVE= "pp_directive"; //$NON-NLS-1$
/** The color key for preprocessor text not colored otherwise. */
String PP_DEFAULT= "pp_default"; //$NON-NLS-1$
/** The color key for preprocessor include files. */
String PP_HEADER= "pp_header"; //$NON-NLS-1$
/**
* The color key for task tags in C comments
* (value <code>"c_comment_task_tag"</code>).

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2006 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:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.presentation.IPresentationDamager;
/**
* A simple presentation damager always damaging the whole partition.
* This is necessary if the partition contains multiline highlight regions.
*
* @since 4.0
*/
public class PartitionDamager implements IPresentationDamager {
/*
* @see org.eclipse.jface.text.presentation.IPresentationDamager#getDamageRegion(org.eclipse.jface.text.ITypedRegion, org.eclipse.jface.text.DocumentEvent, boolean)
*/
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event,
boolean documentPartitioningChanged) {
return partition;
}
/*
* @see org.eclipse.jface.text.presentation.IPresentationDamager#setDocument(org.eclipse.jface.text.IDocument)
*/
public void setDocument(IDocument document) {
}
}

View file

@ -7,15 +7,15 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WordRule;
/**
* Implementation of <code>IRule</code> for C/C++ preprocessor scanning.
@ -23,9 +23,10 @@ import org.eclipse.jface.text.rules.Token;
* at the beginning of the string, then '#' sign, then 0 or more whitespaces
* again, and then directive itself.
*/
public class PreprocessorRule extends WordRule implements IRule {
public class PreprocessorRule extends WordRule {
private StringBuffer fBuffer = new StringBuffer();
private IToken fMalformedToken;
/**
* Creates a rule which, with the help of a word detector, will return the token
@ -56,6 +57,33 @@ public class PreprocessorRule extends WordRule implements IRule {
super(detector, defaultToken);
}
/**
* Creates a rule which, with the help of an word detector, will return the token
* associated with the detected word. If no token has been associated, the
* specified default token will be returned.
*
* @param detector the word detector to be used by this rule, may not be <code>null</code>
* @param defaultToken the default token to be returned on success
* if nothing else is specified, may not be <code>null</code>
* @param malformedToken the token to be returned if the directive is malformed
*
* @see WordRule#addWord
*/
public PreprocessorRule(IWordDetector detector, IToken defaultToken, IToken malformedToken) {
super(detector, defaultToken);
fMalformedToken= malformedToken;
}
/*
* @see org.eclipse.jface.text.rules.WordRule#addWord(java.lang.String, org.eclipse.jface.text.rules.IToken)
*/
public void addWord(String word, IToken token) {
if (word.charAt(0) == '#') {
word= word.substring(1);
}
super.addWord(word, token);
}
/*
* @see IRule#evaluate
*/
@ -64,14 +92,10 @@ public class PreprocessorRule extends WordRule implements IRule {
int nCharsToRollback = 0;
boolean hashSignDetected = false;
if (scanner.getColumn() > 0)
return Token.UNDEFINED;
do {
c = scanner.read();
nCharsToRollback++;
} while (Character.isWhitespace((char) c));
} while (c == ' ' || c == '\t');
// Di- and trigraph support
if (c == '#') {
@ -98,21 +122,30 @@ public class PreprocessorRule extends WordRule implements IRule {
do {
c = scanner.read();
} while (Character.isWhitespace((char) c));
} while (c == ' ' || c == '\t');
fBuffer.setLength(0);
do {
fBuffer.append((char) c);
c = scanner.read();
} while (Character.isJavaIdentifierPart((char) c));
scanner.unread();
IToken token = (IToken) fWords.get("#" + fBuffer.toString()); //$NON-NLS-1$
if (c != '#') {
if (fDetector.isWordStart((char) c)) {
do {
fBuffer.append((char) c);
c = scanner.read();
} while (fDetector.isWordPart((char) c));
}
scanner.unread();
}
IToken token = (IToken) fWords.get(fBuffer.toString());
if (token != null)
return token;
if (fMalformedToken != null) {
do {
c = scanner.read();
} while (c != ICharacterScanner.EOF);
return fMalformedToken;
}
return fDefaultToken;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000 2005 IBM Corporation and others.
* Copyright (c) 2000, 2006 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
@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* QNX Software System
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.util;
@ -15,14 +16,22 @@ import org.eclipse.jface.text.rules.IWhitespaceDetector;
/**
* A C aware white space detector.
* A simple white space detector.
*/
public class CWhitespaceDetector implements IWhitespaceDetector {
/**
* @see IWhitespaceDetector#isWhitespace
/*
* @see IWhitespaceDetector#isWhitespace(char)
*/
public boolean isWhitespace(char c) {
return Character.isWhitespace(c);
switch (c) {
case ' ':
case '\t':
case '\r':
case '\n':
return true;
default:
return Character.isWhitespace(c);
}
}
}

View file

@ -164,6 +164,105 @@ public class PreferenceConstants {
*/
public final static String EDITOR_C_KEYWORD_ITALIC= ICColorConstants.C_KEYWORD + EDITOR_ITALIC_SUFFIX;
/**
* A named preference that holds the color used to render preprocessor directives.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 4.0
*/
public final static String EDITOR_PP_DIRECTIVE_COLOR= ICColorConstants.PP_DIRECTIVE;
/**
* A named preference that controls whether preprocessor directives are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 4.0
*/
public final static String EDITOR_PP_DIRECTIVE_BOLD= ICColorConstants.PP_DIRECTIVE + EDITOR_BOLD_SUFFIX;
/**
* A named preference that controls whether preprocessor directives are rendered in italic.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 4.0
*/
public final static String EDITOR_PP_DIRECTIVE_ITALIC= ICColorConstants.PP_DIRECTIVE + EDITOR_ITALIC_SUFFIX;
/**
* A named preference that holds the color used to render headers.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 4.0
*/
public final static String EDITOR_PP_HEADER_COLOR= ICColorConstants.PP_HEADER;
/**
* A named preference that controls whether headers are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 4.0
*/
public final static String EDITOR_PP_HEADER_BOLD= ICColorConstants.PP_HEADER + EDITOR_BOLD_SUFFIX;
/**
* A named preference that controls whether number are rendered in italic.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 4.0
*/
public final static String EDITOR_PP_HEADER_ITALIC= ICColorConstants.PP_HEADER + EDITOR_ITALIC_SUFFIX;
/**
* A named preference that holds the color used to render preprocessor text.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 4.0
*/
public final static String EDITOR_PP_DEFAULT_COLOR= ICColorConstants.PP_DEFAULT;
/**
* A named preference that controls whether preprocessor text is rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 4.0
*/
public final static String EDITOR_PP_DEFAULT_BOLD= ICColorConstants.PP_DEFAULT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that controls whether preprocessor text is rendered in italic.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 4.0
*/
public final static String EDITOR_PP_DEFAULT_ITALIC= ICColorConstants.PP_DEFAULT + EDITOR_ITALIC_SUFFIX;
/**
* A named preference that holds the color used to render builtin types.
* <p>
@ -296,39 +395,6 @@ public class PreferenceConstants {
*/
public final static String EDITOR_C_NUMBER_ITALIC= ICColorConstants.C_NUMBER + EDITOR_ITALIC_SUFFIX;
/**
* A named preference that holds the color used to render headers.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 4.0
*/
public final static String EDITOR_C_HEADER_COLOR= ICColorConstants.C_HEADER;
/**
* A named preference that controls whether headers are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 4.0
*/
public final static String EDITOR_C_HEADER_BOLD= ICColorConstants.C_HEADER + EDITOR_BOLD_SUFFIX;
/**
* A named preference that controls whether number are rendered in italic.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 4.0
*/
public final static String EDITOR_C_HEADER_ITALIC= ICColorConstants.C_HEADER + EDITOR_ITALIC_SUFFIX;
/**
* A named preference that holds the color used to render braces.
* <p>
@ -956,9 +1022,17 @@ public class PreferenceConstants {
store.setDefault(EDITOR_C_NUMBER_BOLD, false);
store.setDefault(EDITOR_C_NUMBER_ITALIC, false);
PreferenceConverter.setDefault(store, EDITOR_C_HEADER_COLOR, new RGB(42, 0, 255));
store.setDefault(EDITOR_C_HEADER_BOLD, false);
store.setDefault(EDITOR_C_HEADER_ITALIC, false);
PreferenceConverter.setDefault(store, EDITOR_PP_DIRECTIVE_COLOR, new RGB(127, 0, 85));
store.setDefault(EDITOR_PP_DIRECTIVE_BOLD, true);
store.setDefault(EDITOR_PP_DIRECTIVE_ITALIC, false);
PreferenceConverter.setDefault(store, EDITOR_PP_HEADER_COLOR, new RGB(42, 0, 255));
store.setDefault(EDITOR_PP_HEADER_BOLD, false);
store.setDefault(EDITOR_PP_HEADER_ITALIC, false);
PreferenceConverter.setDefault(store, EDITOR_PP_DEFAULT_COLOR, new RGB(0, 0, 0));
store.setDefault(EDITOR_PP_DEFAULT_BOLD, false);
store.setDefault(EDITOR_PP_DEFAULT_ITALIC, false);
// folding
store.setDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED, false);

View file

@ -41,4 +41,9 @@ public interface ICPartitions {
* The identifier of the C character partition content type.
*/
String C_CHARACTER= "__c_character"; //$NON-NLS-1$
/**
* The identifier of the C preprocessor partition content type.
*/
String C_PREPROCESSOR= "__c_preprocessor"; //$NON-NLS-1$
}