Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2007-10-31 10:40:38 -0400
committerAnton Leherbauer2007-10-31 10:40:38 -0400
commit8b8971f1a3fae2ae08a8bdb9186d956014c89e97 (patch)
treea841c8c69995111e442afa643bee69f30c4438c1
parentb11692f3de2d387d6fda22f0ac25eda64bf399df (diff)
downloadorg.eclipse.cdt-8b8971f1a3fae2ae08a8bdb9186d956014c89e97.tar.gz
org.eclipse.cdt-8b8971f1a3fae2ae08a8bdb9186d956014c89e97.tar.xz
org.eclipse.cdt-8b8971f1a3fae2ae08a8bdb9186d956014c89e97.zip
Fix for 201983: [Editor] Inflexible assembler highlighling
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AssemblyLanguage.java154
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IAsmLanguage.java59
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AsmModelBuilder.java3
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/AssemblyLanguage.java81
-rw-r--r--core/org.eclipse.cdt.core/plugin.xml6
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java13
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.java143
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmLabelRule.java74
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmPreprocessorScanner.java41
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java254
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java43
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java8
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorColoringConfigurationBlock.java20
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java171
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java7
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/PreprocessorRule.java14
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java74
19 files changed, 802 insertions, 369 deletions
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.
+ *
+ * <p>
+ * <strong>EXPERIMENTAL</strong>. 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.
+ * </p>
+ *
+ * @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.
+ * <code>'\0'</code> means that no line separator character is defined.
+ *
+ * @return the line separator character or <code>'\0'</code>
+ */
+ 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++"/>
<language
- class="org.eclipse.cdt.internal.core.model.AssemblyLanguage"
+ class="org.eclipse.cdt.core.model.AssemblyLanguage"
id="assembly"
name="%language.name.asm">
- <contentType
- id="org.eclipse.cdt.core.asmSource">
- </contentType>
+ <contentType id="org.eclipse.cdt.core.asmSource"/>
</language>
</extension>
<extension
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java
index 6a907690f11..d0a1696e1bf 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/AsmMergeViewer.java
@@ -18,6 +18,7 @@ import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.editor.asm.AsmSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
@@ -48,8 +49,8 @@ public class AsmMergeViewer extends AbstractMergeViewer {
protected SourceViewerConfiguration getSourceViewerConfiguration() {
if (fSourceViewerConfiguration == null) {
AsmTextTools tools= CUIPlugin.getDefault().getAsmTextTools();
- IPreferenceStore store = getPreferenceStore();
- fSourceViewerConfiguration = new AsmSourceViewerConfiguration(tools, store);
+ IPreferenceStore store= getPreferenceStore();
+ fSourceViewerConfiguration= new AsmSourceViewerConfiguration(tools.getColorManager(), store, null, ICPartitions.C_PARTITIONING);
}
return fSourceViewerConfiguration;
}
@@ -67,11 +68,9 @@ public class AsmMergeViewer extends AbstractMergeViewer {
protected void handlePropertyChange(PropertyChangeEvent event) {
super.handlePropertyChange(event);
- if (fSourceViewerConfiguration != null) {
- AsmTextTools tools= CUIPlugin.getDefault().getAsmTextTools();
- if (tools.affectsBehavior(event)) {
- invalidateTextPresentation();
- }
+ if (fSourceViewerConfiguration != null && fSourceViewerConfiguration.affectsTextPresentation(event)) {
+ fSourceViewerConfiguration.handlePropertyChangeEvent(event);
+ invalidateTextPresentation();
}
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.java
index 88fc5653086..23738f42cdd 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.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
@@ -17,15 +17,15 @@ import java.util.List;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.EndOfLineRule;
-import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IRule;
-import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordPatternRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.cdt.core.model.IAsmLanguage;
+
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
import org.eclipse.cdt.internal.ui.text.IColorManager;
@@ -33,36 +33,26 @@ import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
/**
- * A C code scanner.
+ * An assembly code scanner.
*/
public final class AsmCodeScanner extends AbstractCScanner {
- private static String[] fgKeywords= {
- ".set", ".section", //$NON-NLS-1$ //$NON-NLS-2$
- ".global",".file", //$NON-NLS-1$ //$NON-NLS-2$
- ".extern", ".macro", ".endm", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ".if", ".ifdef", ".ifndef", ".else", ".endif", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- ".include", ".globl", //$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", ".type" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- };
-
-
- private static String[] fgTypes= { "char", "double", "float", "int", "long", "short", "signed", "unsigned", "void"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
-
private static String[] fgTokenProperties= {
+ ICColorConstants.ASM_DIRECTIVE,
+ ICColorConstants.ASM_LABEL,
ICColorConstants.C_KEYWORD,
- ICColorConstants.C_TYPE,
- ICColorConstants.C_STRING,
ICColorConstants.C_SINGLE_LINE_COMMENT,
ICColorConstants.C_DEFAULT
};
+
+ private IAsmLanguage fAsmLanguage;
/**
- * Creates a C code scanner
+ * Creates an assembly code scanner.
*/
- public AsmCodeScanner(IColorManager manager, IPreferenceStore store) {
+ public AsmCodeScanner(IColorManager manager, IPreferenceStore store, IAsmLanguage asmLanguage) {
super(manager, store);
+ fAsmLanguage= asmLanguage;
initialize();
}
@@ -80,110 +70,45 @@ public final class AsmCodeScanner extends AbstractCScanner {
List rules= new ArrayList();
- Token token= getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
-
- // Add rule for single line comments.
- rules.add(new EndOfLineRule("#", token)); //$NON-NLS-1$
-
- Token other= getToken(ICColorConstants.C_DEFAULT);
-
+ Token token;
+
+ // Add rule(s) for single line comments
+ token= getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
+ char[] lineCommentChars= fAsmLanguage.getLineCommentCharacters();
+ for (int i= 0; i < lineCommentChars.length; i++) {
+ rules.add(new EndOfLineRule(new String(new char [] {lineCommentChars[i]}), token));
+ }
+
// Add generic whitespace rule.
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
- // Add word rule for labels
- WordRule labelRule = new WordRule(new AsmWordDetector(false), other) {
- private StringBuffer fBuffer= new StringBuffer();
- /*
- * @see IRule#evaluate
- */
- public IToken evaluate(ICharacterScanner scanner) {
- int c= scanner.read();
- if (fDetector.isWordStart((char) c)) {
- if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
-
- fBuffer.setLength(0);
- do {
- fBuffer.append((char) c);
- c= scanner.read();
- } while (fDetector.isWordPart((char) c));
- if(c != ':') {
- unreadBuffer(scanner);
- return fDefaultToken;
- }
- fBuffer.append((char) c);
- IToken token= (IToken) fWords.get(":"); //$NON-NLS-1$
- if (token != null)
- return token;
-
- return fDefaultToken;
- }
- }
-
- scanner.unread();
- return Token.UNDEFINED;
- }
- /**
- * Adds a word and the token to be returned if it is detected.
- *
- * @param word the word this rule will search for, may not be <code>null</code>
- * @param token the token to be returned if the word has been found, may not be <code>null</code>
- */
- 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; i<fgKeywords.length; i++)
- wordRule.addWord(fgKeywords[i], token);
- for (int i=0; i<fgTypes.length; i++)
- wordRule.addWord(fgTypes[i], token);
- rules.add(wordRule);
-
+ for (int i=0; i<keywords.length; i++)
+ wordRule.addWord(keywords[i], token);
+
+ // TODO use extra color?
token= getToken(ICColorConstants.C_KEYWORD);
- WordPatternRule regPattern = new WordPatternRule(new AsmWordDetector('%', (char)0), "%", null, token); //$NON-NLS-1$
+ WordPatternRule regPattern= new WordPatternRule(new AsmWordDetector('%', (char)0), "%", null, token); //$NON-NLS-1$
rules.add(regPattern);
- setDefaultReturnToken(getToken(ICColorConstants.C_DEFAULT));
+ setDefaultReturnToken(other);
return rules;
}
/*
- * @see RuleBasedScanner#setRules(IRule[])
- */
- public void setRules(IRule[] rules) {
-
- super.setRules(rules);
- }
-
- /*
- * @see AbstractCScanner#affectsBehavior(PropertyChangeEvent)
- */
- public boolean affectsBehavior(PropertyChangeEvent event) {
- return super.affectsBehavior(event);
- }
-
- /*
* @see AbstractCScanner#adaptToPreferenceChange(PropertyChangeEvent)
*/
public void adaptToPreferenceChange(PropertyChangeEvent event) {
-
if (super.affectsBehavior(event)) {
super.adaptToPreferenceChange(event);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmLabelRule.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmLabelRule.java
new file mode 100644
index 00000000000..8881b86c14b
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmLabelRule.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.ui.editor.asm;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.rules.ICharacterScanner;
+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;
+
+/**
+ * A word rule matching assembly labels.
+ *
+ * @since 5.0
+ */
+final class AsmLabelRule implements IRule {
+
+ /** The word detector used by this rule. */
+ protected IWordDetector fDetector;
+ /** The token to be returned when a label has been matched. */
+ protected IToken fLabelToken;
+ /** The default token to be returned when no label could be matched. */
+ protected IToken fDefaultToken;
+
+ /**
+ * @param detector
+ * @param defaultToken
+ */
+ AsmLabelRule(IWordDetector detector, IToken labelToken, IToken defaultToken) {
+ Assert.isNotNull(detector);
+ Assert.isNotNull(labelToken);
+ Assert.isNotNull(defaultToken);
+
+ fDetector= detector;
+ fLabelToken= labelToken;
+ fDefaultToken= defaultToken;
+ }
+
+ /*
+ * @see IRule#evaluate
+ */
+ public IToken evaluate(ICharacterScanner scanner) {
+ int c= scanner.read();
+ if (fDetector.isWordStart((char) c)) {
+ int count= 1;
+ do {
+ c= scanner.read();
+ ++count;
+ } while (fDetector.isWordPart((char) c));
+ if(c == ':') {
+ return fLabelToken;
+ }
+ if (fDefaultToken.isUndefined()) {
+ while (count-- > 0) {
+ scanner.unread();
+ }
+ }
+ return fDefaultToken;
+ }
+
+ scanner.unread();
+ return Token.UNDEFINED;
+ }
+
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmPreprocessorScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmPreprocessorScanner.java
index 775cb5c9a49..a961b821d6e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmPreprocessorScanner.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmPreprocessorScanner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 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
@@ -8,29 +8,25 @@
* 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.core.runtime.Assert;
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.core.model.IAsmLanguage;
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.IColorManager;
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;
@@ -42,23 +38,27 @@ import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
public class AsmPreprocessorScanner extends AbstractCScanner {
/** Properties for tokens. */
- private static String[] fgTokenProperties= {
+ private static final String[] fgTokenProperties= {
ICColorConstants.C_SINGLE_LINE_COMMENT,
- ICColorConstants.C_MULTI_LINE_COMMENT,
ICColorConstants.PP_DIRECTIVE,
ICColorConstants.C_STRING,
ICColorConstants.PP_HEADER,
ICColorConstants.PP_DEFAULT,
};
+ private IAsmLanguage fAsmLanguage;
+
/**
* Create a preprocessor directive scanner.
*
* @param colorManager
* @param store
+ * @param asmLanguage
*/
- public AsmPreprocessorScanner(CColorManager colorManager, IPreferenceStore store) {
+ public AsmPreprocessorScanner(IColorManager colorManager, IPreferenceStore store, IAsmLanguage asmLanguage) {
super(colorManager, store);
+ Assert.isNotNull(asmLanguage);
+ fAsmLanguage= asmLanguage;
initialize();
}
@@ -76,11 +76,10 @@ public class AsmPreprocessorScanner extends AbstractCScanner {
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();
+ PreprocessorRule preprocessorRule= new PreprocessorRule(new CWordDetector(), defaultToken, getToken(ICColorConstants.C_SINGLE_LINE_COMMENT));
+ String[] ppKeywords= fAsmLanguage.getPreprocessorKeywords();
+ for (int i= 0; i < ppKeywords.length; i++) {
+ String ppKeyword= ppKeywords[i];
if (ppKeyword.length() > 1) {
preprocessorRule.addWord(ppKeyword, token);
}
@@ -94,14 +93,12 @@ public class AsmPreprocessorScanner extends AbstractCScanner {
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$
+ IRule 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);
+// 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;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
index 4ec5ce466a0..138b31b4dc4 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
@@ -12,7 +12,11 @@
package org.eclipse.cdt.internal.ui.editor.asm;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
@@ -22,36 +26,106 @@ import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPathEditorInput;
+import org.eclipse.ui.editors.text.ILocationProvider;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+import org.eclipse.ui.ide.ResourceUtil;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.AssemblyLanguage;
+import org.eclipse.cdt.core.model.IAsmLanguage;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.ILanguageUI;
import org.eclipse.cdt.ui.text.ICPartitions;
+import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
+import org.eclipse.cdt.internal.ui.text.CCommentScanner;
+import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
+import org.eclipse.cdt.internal.ui.text.ICColorConstants;
+import org.eclipse.cdt.internal.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
+import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration {
- private AsmTextTools fAsmTextTools;
private ITextEditor fTextEditor;
+ /**
+ * The code scanner.
+ */
+ private AbstractCScanner fCodeScanner;
+ /**
+ * The C multi-line comment scanner.
+ */
+ private AbstractCScanner fMultilineCommentScanner;
+ /**
+ * The C single-line comment scanner.
+ */
+ private AbstractCScanner fSinglelineCommentScanner;
+ /**
+ * The C string scanner.
+ */
+ private AbstractCScanner fStringScanner;
+ /**
+ * The preprocessor scanner.
+ */
+ private AbstractCScanner fPreprocessorScanner;
+ /**
+ * The color manager.
+ */
+ private IColorManager fColorManager;
+ /**
+ * The document partitioning.
+ */
+ private String fDocumentPartitioning;
/**
- * Constructor for AsmSourceViewerConfiguration
+ * Creates a new assembly source viewer configuration for viewers in the given editor
+ * using the given preference store, the color manager and the specified document partitioning.
+ *
+ * @param colorManager the color manager
+ * @param preferenceStore the preference store, can be read-only
+ * @param editor the editor in which the configured viewer(s) will reside, or <code>null</code> if none
+ * @param partitioning the document partitioning for this configuration, or <code>null</code> for the default partitioning
+ */
+ public AsmSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
+ super(preferenceStore);
+ fColorManager= colorManager;
+ fTextEditor= editor;
+ fDocumentPartitioning= partitioning;
+ initializeScanners();
+ }
+
+ /**
+ * Constructor for AsmSourceViewerConfiguration.
+ * @deprecated
*/
public AsmSourceViewerConfiguration(AsmTextTools tools, IPreferenceStore store) {
- super(store);
- fTextEditor= null;
- fAsmTextTools = tools;
+ this(tools.getColorManager(), store, null, ICPartitions.C_PARTITIONING);
}
/**
- * Constructor for AsmSourceViewerConfiguration
+ * 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(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 getPreprocessorScanner() {
- return fAsmTextTools.getPreprocessorScanner();
+ 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 <code>true</code> 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.
+ * <p>
+ * Clients are not allowed to call this method if the old setup with
+ * text tools is in use.
+ * </p>
+ *
+ * @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 <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.
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.
- * <p>
- * 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.
- * </p>
*
* @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();
-
- 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');
- }
+ 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);
+ }
- vector.add(prefix.toString());
+ /**
+ * Computes and returns the indent prefixes for space indentation
+ * and the given <code>tabWidth</code>.
+ *
+ * @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 <code>count</code> 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 <code>true</code> 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 <code>"c_comment_task_tag"</code>).
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
@@ -462,6 +462,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.
+ * <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 5.0
+ */
+ public final static String EDITOR_ASM_LABEL_COLOR= ICColorConstants.ASM_LABEL;
+
+ /**
+ * A named preference that controls whether assembly labels are rendered in bold.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 5.0
+ */
+ public final static String EDITOR_ASM_LABEL_BOLD= ICColorConstants.ASM_LABEL + EDITOR_BOLD_SUFFIX;
+
+ /**
+ * A named preference that controls whether assembly labels are rendered in italic.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 5.0
+ */
+ public final static String EDITOR_ASM_LABEL_ITALIC= ICColorConstants.ASM_LABEL + EDITOR_ITALIC_SUFFIX;
+
+ /**
+ * A named preference that holds the color used to render assembly 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 5.0
+ */
+ public final static String EDITOR_ASM_DIRECTIVE_COLOR= ICColorConstants.ASM_DIRECTIVE;
+
+ /**
+ * A named preference that controls whether assembly directives are rendered in bold.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 5.0
+ */
+ public final static String EDITOR_ASM_DIRECTIVE_BOLD= ICColorConstants.ASM_DIRECTIVE + EDITOR_BOLD_SUFFIX;
+
+ /**
+ * A named preference that controls whether assembly directives are rendered in italic.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ *
+ * @since 5.0
+ */
+ public final static String EDITOR_ASM_DIRECTIVE_ITALIC= ICColorConstants.ASM_DIRECTIVE + EDITOR_ITALIC_SUFFIX;
+
+ /**
* The symbolic font name for the C/C++ editor text font
* (value <code>"org.eclipse.cdt.ui.editors.textfont"</code>).
*
@@ -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$

Back to the top