diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AssemblyLanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AssemblyLanguage.java new file mode 100644 index 00000000000..a413edb2123 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AssemblyLanguage.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2007 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.core.model; + +import java.util.Set; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.dom.ast.IASTCompletionNode; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.IScannerInfo; +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.core.model.AsmModelBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; + +/** + * Built-in language for assembly files. + * + * @since 4.0 + */ +public class AssemblyLanguage extends AbstractLanguage implements IAsmLanguage, IExecutableExtension { + + private static final String[] DIRECTIVE_KEYWORDS= { + ".set", ".section", //$NON-NLS-1$ //$NON-NLS-2$ + ".global", ".globl", ".extern", ".type", ".file", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + ".if", ".ifdef", ".ifndef", ".else", ".endif", ".include", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + ".macro", ".endm", //$NON-NLS-1$ //$NON-NLS-2$ + ".func", ".endfunc", //$NON-NLS-1$//$NON-NLS-2$ + ".text", ".data", ".rodata", ".common", ".debug", ".ctor", ".dtor", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + ".ascii", ".asciz", ".byte", ".long", ".size", ".align", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + ".short", ".word", ".float", ".single", ".double" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + }; + + private static final String DEFAULT_ID= "org.eclipse.cdt.core.assembly"; //$NON-NLS-1$ + + public static final AssemblyLanguage DEFAULT_INSTANCE= new AssemblyLanguage(); + + private String fId= DEFAULT_ID; + private char[] fLineCommentCharacters= {}; + + /** + * @return the default language instance + */ + public static AssemblyLanguage getDefault() { + return DEFAULT_INSTANCE; + } + + /* + * @see org.eclipse.cdt.core.model.ILanguage#createModelBuilder(org.eclipse.cdt.core.model.ITranslationUnit) + */ + public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) { + IContributedModelBuilder modelBuilder= null; + IContributedModelBuilder.Factory modelBuilderFactory= (IContributedModelBuilder.Factory)getAdapter(IContributedModelBuilder.Factory.class); + if (modelBuilderFactory != null) { + modelBuilder= modelBuilderFactory.create(tu); + } + if (modelBuilder == null) { + // use default + AsmModelBuilder defaultModelBuilder= new AsmModelBuilder(tu); + defaultModelBuilder.setLineSeparatorCharacter(getLineSeparatorCharacter()); + modelBuilder= defaultModelBuilder; + } + return modelBuilder; + } + + /* + * @see org.eclipse.cdt.core.model.ILanguage#getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader, org.eclipse.cdt.core.parser.IScannerInfo, org.eclipse.cdt.core.dom.ICodeReaderFactory, org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.parser.IParserLogService) + */ + public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException { + return null; + } + + /* + * @see org.eclipse.cdt.core.model.ILanguage#getCompletionNode(org.eclipse.cdt.core.parser.CodeReader, org.eclipse.cdt.core.parser.IScannerInfo, org.eclipse.cdt.core.dom.ICodeReaderFactory, org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.parser.IParserLogService, int) + */ + public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException { + return null; + } + + /* + * @see org.eclipse.cdt.core.model.ILanguage#getId() + */ + public String getId() { + return fId; + } + + /* + * @see org.eclipse.cdt.core.model.ILanguage#getSelectedNames(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit, int, int) + */ + public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) { + return null; + } + + // IAsmLanguage + + /* + * @see org.eclipse.cdt.core.model.IAsmLanguage#getLineCommentCharacters() + */ + public char[] getLineCommentCharacters() { + return fLineCommentCharacters; + } + + /* + * @see org.eclipse.cdt.core.model.IAsmLanguage#getLineSeparatorCharacter() + */ + public char getLineSeparatorCharacter() { + return '\0'; + } + + /* + * @see org.eclipse.cdt.core.model.IAsmLanguage#getDirectiveKeywords() + */ + public String[] getDirectiveKeywords() { + return DIRECTIVE_KEYWORDS; + } + + /* + * @see org.eclipse.cdt.core.model.IAsmLanguage#getPreprocessorKeywords() + */ + public String[] getPreprocessorKeywords() { + Set ppDirectives= ParserFactory.getKeywordSet(KeywordSetKey.PP_DIRECTIVE, ParserLanguage.C); + String[] result= (String[]) ppDirectives.toArray(new String[ppDirectives.size()]); + return result; + } + + /* + * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) + */ + public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { + if (data instanceof String) { + fLineCommentCharacters= ((String)data).toCharArray(); + } + fId= CCorePlugin.PLUGIN_ID + '.' + config.getAttribute("id"); //$NON-NLS-1$ + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IAsmLanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IAsmLanguage.java new file mode 100644 index 00000000000..1573192f720 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IAsmLanguage.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2007 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.core.model; + + +/** + * This is an optional extension interface to {@link ILanguage} which allows + * an assembly language variant to expose certain syntax characteristics. + * + *
+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *
+ * + * @since 5.0 + */ +public interface IAsmLanguage { + + /** + * Get the set of valid line comment characters defined for this assembly variant. + * + * @return an array line comment characters + */ + char[] getLineCommentCharacters(); + + /** + * Get the line separator character defined for this assembly variant. + * The line separator character is used to split physical lines into logical lines. + *'\0'
means that no line separator character is defined.
+ *
+ * @return the line separator character or '\0'
+ */
+ char getLineSeparatorCharacter();
+
+ /**
+ * Get the set of assembler directives defined for this variant.
+ *
+ * @return an array of keywords
+ */
+ String[] getDirectiveKeywords();
+
+ /**
+ * Get the preprocessor keywords (directives) defined for this variant.
+ *
+ * @return an array of keywords
+ */
+ String[] getPreprocessorKeywords();
+
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AsmModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AsmModelBuilder.java
index f7b05c517fa..b2feb967d29 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AsmModelBuilder.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AsmModelBuilder.java
@@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.model;
import java.util.HashMap;
+import org.eclipse.cdt.core.model.AssemblyLanguage;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
@@ -70,7 +71,7 @@ public class AsmModelBuilder implements IContributedModelBuilder {
*
* @param lineSeparatorChar
*/
- public void setLineSeparatorChar(char lineSeparatorChar) {
+ public void setLineSeparatorCharacter(char lineSeparatorChar) {
fLineSeparatorChar= lineSeparatorChar;
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AssemblyLanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AssemblyLanguage.java
deleted file mode 100644
index 8b73ecf865a..00000000000
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AssemblyLanguage.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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.core.model;
-
-import org.eclipse.cdt.core.dom.ICodeReaderFactory;
-import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
-import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.index.IIndex;
-import org.eclipse.cdt.core.model.AbstractLanguage;
-import org.eclipse.cdt.core.model.IContributedModelBuilder;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.core.parser.CodeReader;
-import org.eclipse.cdt.core.parser.IParserLogService;
-import org.eclipse.cdt.core.parser.IScannerInfo;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Built-in language for assembly files.
- *
- * @since 4.0
- */
-public class AssemblyLanguage extends AbstractLanguage {
-
- private static final String ID= "org.eclipse.cdt.core.assembly"; //$NON-NLS-1$
-
- /*
- * @see org.eclipse.cdt.core.model.ILanguage#createModelBuilder(org.eclipse.cdt.core.model.ITranslationUnit)
- */
- public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) {
- IContributedModelBuilder modelBuilder= null;
- IContributedModelBuilder.Factory modelBuilderFactory= (IContributedModelBuilder.Factory)getAdapter(IContributedModelBuilder.Factory.class);
- if (modelBuilderFactory != null) {
- modelBuilder= modelBuilderFactory.create(tu);
- }
- if (modelBuilder == null) {
- // use default
- modelBuilder= new AsmModelBuilder(tu);
- }
- return modelBuilder;
- }
-
- /*
- * @see org.eclipse.cdt.core.model.ILanguage#getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader, org.eclipse.cdt.core.parser.IScannerInfo, org.eclipse.cdt.core.dom.ICodeReaderFactory, org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.parser.IParserLogService)
- */
- public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
- ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException {
- return null;
- }
-
- /*
- * @see org.eclipse.cdt.core.model.ILanguage#getCompletionNode(org.eclipse.cdt.core.parser.CodeReader, org.eclipse.cdt.core.parser.IScannerInfo, org.eclipse.cdt.core.dom.ICodeReaderFactory, org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.parser.IParserLogService, int)
- */
- public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
- ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
- return null;
- }
-
- /*
- * @see org.eclipse.cdt.core.model.ILanguage#getId()
- */
- public String getId() {
- return ID;
- }
-
- /*
- * @see org.eclipse.cdt.core.model.ILanguage#getSelectedNames(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit, int, int)
- */
- public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
- return null;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index ec68e966950..099702a5a8a 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -593,12 +593,10 @@
class="org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory"
id="C++"/>
null
- */
- public void addWord(String word, IToken token) {
-
- fWords.put(word, token);
- }
- /**
- * Returns the characters in the buffer to the scanner.
- *
- * @param scanner the scanner to be used
- */
- protected void unreadBuffer(ICharacterScanner scanner) {
- for (int i= fBuffer.length() - 1; i >= 0; i--)
- scanner.unread();
- }
- };
-
- token= getToken(ICColorConstants.C_TYPE);
- labelRule.addWord(":", token); //$NON-NLS-1$
- //wordRule.setColumnConstraint(0);
+ final Token other= getToken(ICColorConstants.C_DEFAULT);
+
+ // Add rule for labels
+ token= getToken(ICColorConstants.ASM_LABEL);
+ IRule labelRule= new AsmLabelRule(new AsmWordDetector(false), token, other);
rules.add(labelRule);
- // Add word rule for keywords and types
+ // Add word rule for keywords
+ token= getToken(ICColorConstants.ASM_DIRECTIVE);
+ String[] keywords= fAsmLanguage.getDirectiveKeywords();
WordRule wordRule= new WordRule(new AsmWordDetector('.'), other);
- for (int i=0; inull
if none
+ * @param partitioning the document partitioning for this configuration, or null
for the default partitioning
*/
- public AsmSourceViewerConfiguration(AsmTextTools tools, IPreferenceStore store) {
- super(store);
- fTextEditor= null;
- fAsmTextTools = tools;
+ public AsmSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
+ super(preferenceStore);
+ fColorManager= colorManager;
+ fTextEditor= editor;
+ fDocumentPartitioning= partitioning;
+ initializeScanners();
}
/**
- * Constructor for AsmSourceViewerConfiguration
+ * Constructor for AsmSourceViewerConfiguration.
+ * @deprecated
+ */
+ public AsmSourceViewerConfiguration(AsmTextTools tools, IPreferenceStore store) {
+ this(tools.getColorManager(), store, null, ICPartitions.C_PARTITIONING);
+ }
+
+ /**
+ * Constructor for AsmSourceViewerConfiguration.
+ * @deprecated
*/
public AsmSourceViewerConfiguration(ITextEditor editor, IPreferenceStore store) {
- super(store);
- fTextEditor= editor;
- fAsmTextTools= CUIPlugin.getDefault().getAsmTextTools();
+ this(CUIPlugin.getDefault().getAsmTextTools().getColorManager(), store, editor, ICPartitions.C_PARTITIONING);
+ }
+
+ /**
+ * Initializes the scanners.
+ */
+ private void initializeScanners() {
+ fMultilineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_MULTI_LINE_COMMENT);
+ fSinglelineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
+ fStringScanner= new SingleTokenCScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_STRING);
}
/**
@@ -60,7 +134,7 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
* @return the ASM multiline comment scanner
*/
protected RuleBasedScanner getMultilineCommentScanner() {
- return fAsmTextTools.getMultilineCommentScanner();
+ return fMultilineCommentScanner;
}
/**
@@ -69,7 +143,7 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
* @return the ASM singleline comment scanner
*/
protected RuleBasedScanner getSinglelineCommentScanner() {
- return fAsmTextTools.getSinglelineCommentScanner();
+ return fSinglelineCommentScanner;
}
/**
@@ -78,24 +152,63 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
* @return the ASM string scanner
*/
protected RuleBasedScanner getStringScanner() {
- return fAsmTextTools.getStringScanner();
+ return fStringScanner;
}
/**
- * Returns the ASM preprocessor scanner for this configuration.
+ * Returns the assembly preprocessor scanner for this configuration.
+ * @param language
*
- * @return the ASM preprocessor scanner
+ * @return the assembly preprocessor scanner
*/
- protected RuleBasedScanner getPreprocessorScanner() {
- return fAsmTextTools.getPreprocessorScanner();
+ protected RuleBasedScanner getPreprocessorScanner(ILanguage language) {
+ if (fPreprocessorScanner != null) {
+ return fPreprocessorScanner;
+ }
+ AbstractCScanner scanner= null;
+ if (language instanceof IAsmLanguage) {
+ scanner= new AsmPreprocessorScanner(getColorManager(), fPreferenceStore, (IAsmLanguage)language);
+ }
+ if (scanner == null) {
+ scanner= new AsmPreprocessorScanner(getColorManager(), fPreferenceStore, AssemblyLanguage.getDefault());
+ }
+ fPreprocessorScanner= scanner;
+ return fPreprocessorScanner;
+ }
+
+ /**
+ * @param language
+ * @return the assembly code scanner for the given language
+ */
+ protected RuleBasedScanner getCodeScanner(ILanguage language) {
+ if (fCodeScanner != null) {
+ return fCodeScanner;
+ }
+ RuleBasedScanner scanner= null;
+ if (language instanceof IAsmLanguage) {
+ IAsmLanguage asmLang= (IAsmLanguage)language;
+ scanner = new AsmCodeScanner(getColorManager(), fPreferenceStore, asmLang);
+ } else if (language != null) {
+ ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class);
+ if (languageUI != null)
+ scanner = languageUI.getCodeScanner();
+ }
+ if (scanner == null) {
+ scanner = new AsmCodeScanner(getColorManager(), fPreferenceStore, AssemblyLanguage.getDefault());
+ }
+ if (scanner instanceof AbstractCScanner) {
+ fCodeScanner= (AbstractCScanner)scanner;
+ }
+ return scanner;
}
/*
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
*/
public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
- // the ASM editor also uses the CDocumentPartitioner
- return ICPartitions.C_PARTITIONING;
+ if (fDocumentPartitioning != null)
+ return fDocumentPartitioning;
+ return super.getConfiguredDocumentPartitioning(sourceViewer);
}
/*
@@ -105,7 +218,8 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
PresentationReconciler reconciler= new PresentationReconciler();
- DefaultDamagerRepairer dr= new DefaultDamagerRepairer(fAsmTextTools.getCodeScanner());
+ ILanguage language= getLanguage();
+ DefaultDamagerRepairer dr= new DefaultDamagerRepairer(getCodeScanner(language));
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
@@ -125,7 +239,7 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
reconciler.setDamager(dr, ICPartitions.C_CHARACTER);
reconciler.setRepairer(dr, ICPartitions.C_CHARACTER);
- dr= new DefaultDamagerRepairer(getPreprocessorScanner());
+ dr= new DefaultDamagerRepairer(getPreprocessorScanner(language));
reconciler.setDamager(new PartitionDamager(), ICPartitions.C_PREPROCESSOR);
reconciler.setRepairer(dr, ICPartitions.C_PREPROCESSOR);
@@ -159,6 +273,106 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
}
return super.getReconciler(sourceViewer);
}
+
+ /**
+ * Determines whether the preference change encoded by the given event
+ * changes the behavior of one of its contained components.
+ *
+ * @param event the event to be investigated
+ * @return true
if event causes a behavioral change
+ */
+ public boolean affectsTextPresentation(PropertyChangeEvent event) {
+ if (fMultilineCommentScanner.affectsBehavior(event)
+ || fSinglelineCommentScanner.affectsBehavior(event)
+ || fStringScanner.affectsBehavior(event)) {
+ return true;
+ }
+ if (fCodeScanner != null && fCodeScanner.affectsBehavior(event)) {
+ return true;
+ }
+ if (fPreprocessorScanner != null && fPreprocessorScanner.affectsBehavior(event)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Adapts the behavior of the contained components to the change
+ * encoded in the given event.
+ * + * Clients are not allowed to call this method if the old setup with + * text tools is in use. + *
+ * + * @param event the event to which to adapt + * @see CSourceViewerConfiguration#CSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String) + */ + public void handlePropertyChangeEvent(PropertyChangeEvent event) { + if (fCodeScanner != null && fCodeScanner.affectsBehavior(event)) + fCodeScanner.adaptToPreferenceChange(event); + if (fMultilineCommentScanner.affectsBehavior(event)) + fMultilineCommentScanner.adaptToPreferenceChange(event); + if (fSinglelineCommentScanner.affectsBehavior(event)) + fSinglelineCommentScanner.adaptToPreferenceChange(event); + if (fStringScanner.affectsBehavior(event)) + fStringScanner.adaptToPreferenceChange(event); + if (fPreprocessorScanner != null && fPreprocessorScanner.affectsBehavior(event)) + fPreprocessorScanner.adaptToPreferenceChange(event); + } + + /** + * Returns the color manager for this configuration. + * + * @return the color manager + */ + protected IColorManager getColorManager() { + return fColorManager; + } + + protected ILanguage getLanguage() { + if (fTextEditor == null) { + return AssemblyLanguage.getDefault(); + } + ICElement element = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fTextEditor.getEditorInput()); + if (element instanceof ITranslationUnit) { + try { + return ((ITranslationUnit)element).getLanguage(); + } catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } + } else { + // compute the language from the plain editor input + IContentType contentType = null; + IEditorInput input = fTextEditor.getEditorInput(); + IFile file = ResourceUtil.getFile(input); + if (file != null) { + contentType = CCorePlugin.getContentType(file.getProject(), file.getName()); + } else if (input instanceof IPathEditorInput) { + IPath path = ((IPathEditorInput)input).getPath(); + contentType = CCorePlugin.getContentType(path.lastSegment()); + } else { + ILocationProvider locationProvider = (ILocationProvider)input.getAdapter(ILocationProvider.class); + if (locationProvider != null) { + IPath path = locationProvider.getPath(input); + contentType = CCorePlugin.getContentType(path.lastSegment()); + } + } + if (contentType != null) { + return LanguageManager.getInstance().getLanguage(contentType); + } + } + // fallback + return AssemblyLanguage.getDefault(); + } + + /** + * Reset cached language dependent scanners. + */ + public void resetScanners() { + fCodeScanner= null; + fPreprocessorScanner= null; + } + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java index 9e096ddfd7b..ae216c2cfa6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java @@ -27,6 +27,7 @@ import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -52,6 +53,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.IWorkingCopyManager; +import org.eclipse.cdt.ui.text.ICPartitions; import org.eclipse.cdt.internal.ui.IContextMenuConstants; import org.eclipse.cdt.internal.ui.editor.AbstractCModelOutlinePage; @@ -85,20 +87,34 @@ public class AsmTextEditor extends TextEditor implements ISelectionChangedListen public AsmTextEditor() { super(); } + /** * Initializes this editor. */ protected void initializeEditor() { IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore(); - setSourceViewerConfiguration(new AsmSourceViewerConfiguration(this, store)); - setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider()); // FIXME: Should this editor have a different preference store ? // 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)); + setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider()); setEditorContextMenuId("#ASMEditorContext"); //$NON-NLS-1$ setRulerContextMenuId("#ASMEditorRulerContext"); //$NON-NLS-1$ - //setOutlinerContextMenuId("#ASMEditorOutlinerContext"); //$NON-NLS-1$ + } + + /* + * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#collectContextMenuPreferencePages() + */ + protected String[] collectContextMenuPreferencePages() { + // Add Assembly Editor relevant pages + String[] parentPrefPageIds = super.collectContextMenuPreferencePages(); + String[] prefPageIds = new String[parentPrefPageIds.length + 1]; + int nIds = 0; + prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeColoringPreferencePage"; //$NON-NLS-1$ + System.arraycopy(parentPrefPageIds, 0, prefPageIds, nIds, parentPrefPageIds.length); + return prefPageIds; } /* @@ -143,11 +159,22 @@ public class AsmTextEditor extends TextEditor implements ISelectionChangedListen * Pulled in from 2.0 */ protected boolean affectsTextPresentation(PropertyChangeEvent event) { - boolean affects= false; - AsmTextTools textTools= CUIPlugin.getDefault().getAsmTextTools(); - affects= textTools.affectsBehavior(event); - - return affects || super.affectsTextPresentation(event); + SourceViewerConfiguration configuration = getSourceViewerConfiguration(); + if (configuration instanceof AsmSourceViewerConfiguration) { + return ((AsmSourceViewerConfiguration)configuration).affectsTextPresentation(event); + } + return false; + } + + /* + * @see org.eclipse.ui.editors.text.TextEditor#handlePreferenceStoreChanged(org.eclipse.jface.util.PropertyChangeEvent) + */ + protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { + SourceViewerConfiguration configuration = getSourceViewerConfiguration(); + if (configuration instanceof AsmSourceViewerConfiguration) { + ((AsmSourceViewerConfiguration)configuration).handlePropertyChangeEvent(event); + } + super.handlePreferenceStoreChanged(event); } /* diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java index ef0a8fee656..a7163810f86 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -18,8 +18,10 @@ import org.eclipse.jface.text.rules.RuleBasedScanner; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.cdt.core.model.AssemblyLanguage; import org.eclipse.cdt.ui.CUIPlugin; + import org.eclipse.cdt.internal.ui.text.CCommentScanner; import org.eclipse.cdt.internal.ui.text.ICColorConstants; import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner; @@ -80,8 +82,8 @@ public class AsmTextTools { } fColorManager= new CColorManager(); - fCodeScanner= new AsmCodeScanner(fColorManager, store); - fPreprocessorScanner= new AsmPreprocessorScanner(fColorManager, store); + fCodeScanner= new AsmCodeScanner(fColorManager, store, AssemblyLanguage.getDefault()); + fPreprocessorScanner= new AsmPreprocessorScanner(fColorManager, store, AssemblyLanguage.getDefault()); fMultilineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT); fSinglelineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorColoringConfigurationBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorColoringConfigurationBlock.java index fba6e3084ad..8060e85a0bb 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorColoringConfigurationBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorColoringConfigurationBlock.java @@ -229,7 +229,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, fPreprocessorCategory}; + return new String[] {fCodeCategory, fAssemblyCategory, fCommentsCategory, fPreprocessorCategory}; } /* @@ -248,7 +248,9 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock { if (parentElement instanceof String) { String entry= (String) parentElement; if (fCodeCategory.equals(entry)) - return fListModel.subList(6, fListModel.size()).toArray(); + return fListModel.subList(8, fListModel.size()).toArray(); + if (fAssemblyCategory.equals(entry)) + return fListModel.subList(6, 8).toArray(); if (fCommentsCategory.equals(entry)) return fListModel.subList(0, 3).toArray(); if (fPreprocessorCategory.equals(entry)) @@ -261,8 +263,10 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock { if (element instanceof String) return null; int index= fListModel.indexOf(element); - if (index >= 6) + if (index >= 8) return fCodeCategory; + if (index >= 6) + return fAssemblyCategory; if (index >= 3) return fPreprocessorCategory; return fCommentsCategory; @@ -300,6 +304,8 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock { { 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_asmLabels, PreferenceConstants.EDITOR_ASM_LABEL_COLOR }, + { PreferencesMessages.CEditorColoringConfigurationBlock_asmDirectives, PreferenceConstants.EDITOR_ASM_DIRECTIVE_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 }, @@ -313,6 +319,7 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock { 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 final String fAssemblyCategory= PreferencesMessages.CEditorColoringConfigurationBlock_coloring_category_assembly; private ColorSelector fSyntaxForegroundColorEditor; private Label fColorEditorLabel; @@ -587,13 +594,12 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock { // don't sort the top level categories if (fCodeCategory.equals(element)) return 0; + if (fAssemblyCategory.equals(element)) + return 1; 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; return 0; } }); @@ -759,7 +765,7 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock { public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item= getHighlightingColorListItem(); if (item instanceof SemanticHighlightingColorListItem) { - fListViewer.refresh(); + fListViewer.refresh(true); handleSyntaxColorListSelection(); uninstallSemanticHighlighting(); installSemanticHighlighting(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java index efba4f028eb..188e179d1c1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java @@ -65,6 +65,8 @@ 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_asmLabels; + public static String CEditorColoringConfigurationBlock_asmDirectives; public static String CEditorColoringConfigurationBlock_others; public static String CEditorColoringConfigurationBlock_ppDirectives; public static String CEditorColoringConfigurationBlock_ppOthers; @@ -73,6 +75,7 @@ public final class PreferencesMessages extends NLS { 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_category_assembly; public static String CEditorColoringConfigurationBlock_coloring_element; public static String CEditorColoringConfigurationBlock_link; public static String CEditorColoringConfigurationBlock_enable_semantic_highlighting; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties index b835eae6425..0412c738fca 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties @@ -62,6 +62,8 @@ CEditorColoringConfigurationBlock_operators=Operators CEditorColoringConfigurationBlock_braces=Braces CEditorColoringConfigurationBlock_numbers=Numbers CEditorColoringConfigurationBlock_others=Others +CEditorColoringConfigurationBlock_asmLabels=Labels +CEditorColoringConfigurationBlock_asmDirectives=Directives CEditorColoringConfigurationBlock_ppDirectives=Directives CEditorColoringConfigurationBlock_ppHeaders=Headers CEditorColoringConfigurationBlock_ppOthers=Others @@ -69,6 +71,7 @@ CEditorColoringConfigurationBlock_cCommentTaskTags=Task Tags CEditorColoringConfigurationBlock_coloring_category_code=Code CEditorColoringConfigurationBlock_coloring_category_comments=Comments CEditorColoringConfigurationBlock_coloring_category_preprocessor=Preprocessor +CEditorColoringConfigurationBlock_coloring_category_assembly=Assembly 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 Text Editors and on the Colors and Fonts preference page. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java index 047dfbe92c0..2ecaabfb23c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java @@ -14,10 +14,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.text; -import java.util.Vector; +import java.util.Arrays; import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; @@ -95,7 +94,6 @@ import org.eclipse.cdt.internal.ui.typehierarchy.THInformationProvider; */ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration { - private CTextTools fTextTools; private ITextEditor fTextEditor; /** * The document partitioning. @@ -129,12 +127,6 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration { /** * Creates a new C source viewer configuration for viewers in the given editor * using the given preference store, the color manager and the specified document partitioning. - *- * Creates a C source viewer configuration in the new setup without text tools. Clients are - * allowed to call {@link CSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)} - * and disallowed to call {@link CSourceViewerConfiguration#getPreferenceStore()} on the resulting - * C source viewer configuration. - *
* * @param colorManager the color manager * @param preferenceStore the preference store, can be read-only @@ -185,22 +177,14 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration { if (fPreprocessorScanner != null) { return fPreprocessorScanner; } - if (isNewSetup()) { - AbstractCScanner scanner= null; - if (language instanceof ICLanguageKeywords) { - scanner= new CPreprocessorScanner(getColorManager(), fPreferenceStore, (ICLanguageKeywords)language); - } - if (scanner == null) { - scanner= new CPreprocessorScanner(getColorManager(), fPreferenceStore, GPPLanguage.getDefault()); - } - fPreprocessorScanner= scanner; - } else { - if (language instanceof ICLanguageKeywords) { - return fTextTools.getCPreprocessorScanner(); - } else { - return fTextTools.getCppPreprocessorScanner(); - } + AbstractCScanner scanner= null; + if (language instanceof ICLanguageKeywords) { + scanner= new CPreprocessorScanner(getColorManager(), fPreferenceStore, (ICLanguageKeywords)language); } + if (scanner == null) { + scanner= new CPreprocessorScanner(getColorManager(), fPreferenceStore, GPPLanguage.getDefault()); + } + fPreprocessorScanner= scanner; return fPreprocessorScanner; } @@ -266,7 +250,6 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration { * Initializes the scanners. */ private void initializeScanners() { - Assert.isTrue(isNewSetup()); fMultilineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_MULTI_LINE_COMMENT); fSinglelineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_SINGLE_LINE_COMMENT); fStringScanner= new SingleTokenCScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_STRING); @@ -319,30 +302,22 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration { if (fCodeScanner != null) { return fCodeScanner; } - if (isNewSetup()) { - RuleBasedScanner scanner= null; - if (language instanceof ICLanguageKeywords) { - ICLanguageKeywords cLang= (ICLanguageKeywords)language; - scanner = new CCodeScanner(getColorManager(), fPreferenceStore, cLang); - } else if (language != null) { - ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class); - if (languageUI != null) - scanner = languageUI.getCodeScanner(); - } - if (scanner == null) { - scanner = new CCodeScanner(getColorManager(), fPreferenceStore, GPPLanguage.getDefault()); - } - if (scanner instanceof AbstractCScanner) { - fCodeScanner= (AbstractCScanner)scanner; - } - return scanner; - } else { - if (language instanceof ICLanguageKeywords) { - return fTextTools.getCCodeScanner(); - } else { - return fTextTools.getCppCodeScanner(); - } + RuleBasedScanner scanner= null; + if (language instanceof ICLanguageKeywords) { + ICLanguageKeywords cLang= (ICLanguageKeywords)language; + scanner = new CCodeScanner(getColorManager(), fPreferenceStore, cLang); + } else if (language != null) { + ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class); + if (languageUI != null) + scanner = languageUI.getCodeScanner(); } + if (scanner == null) { + scanner = new CCodeScanner(getColorManager(), fPreferenceStore, GPPLanguage.getDefault()); + } + if (scanner instanceof AbstractCScanner) { + fCodeScanner= (AbstractCScanner)scanner; + } + return scanner; } /* @@ -452,44 +427,64 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration { * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String) */ public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { - - Vector vector= new Vector(); - - // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces - ICProject project= getProject(); final int tabWidth= CodeFormatterUtil.getTabWidth(project); final int indentWidth= CodeFormatterUtil.getIndentWidth(project); - int spaceEquivalents= Math.min(tabWidth, indentWidth); - boolean useSpaces; + boolean allowTabs= tabWidth <= indentWidth; + + String indentMode; if (project == null) - useSpaces= CCorePlugin.SPACE.equals(CCorePlugin.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)) || tabWidth > indentWidth; + indentMode= CCorePlugin.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); else - useSpaces= CCorePlugin.SPACE.equals(project.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true)) || tabWidth > indentWidth; + indentMode= project.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true); - for (int i= 0; i <= spaceEquivalents; i++) { - StringBuffer prefix= new StringBuffer(); + boolean useSpaces= CCorePlugin.SPACE.equals(indentMode) || DefaultCodeFormatterConstants.MIXED.equals(indentMode); + + // assert allowTabs || useSpaces; + + if (!allowTabs) + return new String[] { getStringWithSpaces(indentWidth), "" }; //$NON-NLS-1$ + else if (!useSpaces) + return getIndentPrefixesForTab(tabWidth); + else + return getIndentPrefixesForSpaces(tabWidth); + } - if (useSpaces) { - for (int j= 0; j + i < spaceEquivalents; j++) - prefix.append(' '); - - if (i != 0) - prefix.append('\t'); - } else { - for (int j= 0; j < i; j++) - prefix.append(' '); - - if (i != spaceEquivalents) - prefix.append('\t'); - } - - vector.add(prefix.toString()); + /** + * Computes and returns the indent prefixes for space indentation + * and the giventabWidth
.
+ *
+ * @param tabWidth the display tab width
+ * @return the indent prefixes
+ * @see #getIndentPrefixes(ISourceViewer, String)
+ */
+ private String[] getIndentPrefixesForSpaces(int tabWidth) {
+ String[] indentPrefixes= new String[tabWidth + 2];
+ indentPrefixes[0]= getStringWithSpaces(tabWidth);
+
+ for (int i= 0; i < tabWidth; i++) {
+ String spaces= getStringWithSpaces(i);
+ if (i < tabWidth)
+ indentPrefixes[i+1]= spaces + '\t';
+ else
+ indentPrefixes[i+1]= new String(spaces);
}
+
+ indentPrefixes[tabWidth + 1]= ""; //$NON-NLS-1$
- vector.add(""); //$NON-NLS-1$
+ return indentPrefixes;
+ }
- return (String[]) vector.toArray(new String[vector.size()]);
+ /**
+ * Creates and returns a String with count
spaces.
+ *
+ * @param count the space count
+ * @return the string with the spaces
+ */
+ private static String getStringWithSpaces(int count) {
+ char[] spaceChars= new char[count];
+ Arrays.fill(spaceChars, ' ');
+ return new String(spaceChars);
}
private ICProject getProject() {
@@ -622,29 +617,6 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
return false;
}
- /**
- * 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) {
- Assert.isTrue(!isNewSetup());
- fTextTools.adaptToPreferenceChange(event);
- }
-
- protected IPreferenceStore getPreferenceStore() {
- Assert.isTrue(!isNewSetup());
- return fPreferenceStore;
- }
-
- /**
- * @return true
iff the new setup without text tools is in use.
- */
- private boolean isNewSetup() {
- return fTextTools == null;
- }
-
/*
* @see SourceViewerConfiguration#getHoverControlCreator(ISourceViewer)
* @since 2.0
@@ -694,7 +666,6 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
* @see CSourceViewerConfiguration#CSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
*/
public void handlePropertyChangeEvent(PropertyChangeEvent event) {
- Assert.isTrue(isNewSetup());
if (fCodeScanner != null && fCodeScanner.affectsBehavior(event))
fCodeScanner.adaptToPreferenceChange(event);
if (fMultilineCommentScanner.affectsBehavior(event))
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java
index 7a6ec0768fa..dc17ac69fac 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java
@@ -36,7 +36,7 @@ public interface ICColorConstants {
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. */
@@ -44,6 +44,11 @@ public interface ICColorConstants {
/** The color key for preprocessor include files. */
String PP_HEADER= "pp_header"; //$NON-NLS-1$
+ /** The color key for keywords in assembly code. */
+ String ASM_DIRECTIVE= "asm_directive"; //$NON-NLS-1$
+ /** The color key for assembly labels. */
+ String ASM_LABEL= "asm_label"; //$NON-NLS-1$
+
/**
* The color key for task tags in C comments
* (value "c_comment_task_tag"
).
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/PreprocessorRule.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/PreprocessorRule.java
index e6e66eb87cb..52f207f5199 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/PreprocessorRule.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/PreprocessorRule.java
@@ -120,13 +120,15 @@ public class PreprocessorRule extends WordRule {
if (hashSignDetected) {
- do {
- c = scanner.read();
- } while (c == ' ' || c == '\t');
-
fBuffer.setLength(0);
-
- if (c != '#') {
+ c = scanner.read();
+ if (c == '#') {
+ // ## operator
+ fBuffer.append((char) c);
+ } else {
+ while (c == ' ' || c == '\t') {
+ c = scanner.read();
+ }
if (fDetector.isWordStart((char) c)) {
do {
fBuffer.append((char) c);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
index 5bc44f820d8..35529728b61 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
@@ -461,6 +461,72 @@ public class PreferenceConstants {
*/
public final static String EDITOR_C_DEFAULT_ITALIC= ICColorConstants.C_DEFAULT + EDITOR_ITALIC_SUFFIX;
+ /**
+ * A named preference that holds the color used to render assembly labels.
+ *
+ * Value is of type String
. A RGB color value encoded as a string
+ * using class PreferenceConverter
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type String
. A RGB color value encoded as a string
+ * using class PreferenceConverter
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type Boolean
.
+ *
"org.eclipse.cdt.ui.editors.textfont"
).
@@ -987,6 +1053,14 @@ public class PreferenceConstants {
store.setDefault(EDITOR_PP_DEFAULT_BOLD, false);
store.setDefault(EDITOR_PP_DEFAULT_ITALIC, false);
+ PreferenceConverter.setDefault(store, EDITOR_ASM_LABEL_COLOR, new RGB(127, 0, 85));
+ store.setDefault(EDITOR_ASM_LABEL_BOLD, true);
+ store.setDefault(EDITOR_ASM_LABEL_ITALIC, false);
+
+ PreferenceConverter.setDefault(store, EDITOR_ASM_DIRECTIVE_COLOR, new RGB(127, 0, 85));
+ store.setDefault(EDITOR_ASM_DIRECTIVE_BOLD, true);
+ store.setDefault(EDITOR_ASM_DIRECTIVE_ITALIC, false);
+
// folding
store.setDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED, false);
store.setDefault(PreferenceConstants.EDITOR_FOLDING_PROVIDER, "org.eclipse.cdt.ui.text.defaultFoldingProvider"); //$NON-NLS-1$