mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 13:55:39 +02:00
Cleanups to asm editor to fix highlighting, follow color
preferences and add keyworks
This commit is contained in:
parent
9de625f710
commit
3b2d390a93
5 changed files with 186 additions and 72 deletions
|
@ -9,6 +9,8 @@ package org.eclipse.cdt.internal.ui.editor.asm;
|
||||||
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
||||||
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||||
import org.eclipse.cdt.internal.ui.text.IColorManager;
|
import org.eclipse.cdt.internal.ui.text.IColorManager;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -20,6 +22,7 @@ import org.eclipse.jface.text.rules.IToken;
|
||||||
import org.eclipse.jface.text.rules.IWordDetector;
|
import org.eclipse.jface.text.rules.IWordDetector;
|
||||||
import org.eclipse.jface.text.rules.SingleLineRule;
|
import org.eclipse.jface.text.rules.SingleLineRule;
|
||||||
import org.eclipse.jface.text.rules.Token;
|
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.WordPatternRule;
|
||||||
import org.eclipse.jface.text.rules.WordRule;
|
import org.eclipse.jface.text.rules.WordRule;
|
||||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||||
|
@ -30,54 +33,14 @@ import org.eclipse.jface.util.PropertyChangeEvent;
|
||||||
*/
|
*/
|
||||||
public final class AsmCodeScanner extends AbstractCScanner {
|
public final class AsmCodeScanner extends AbstractCScanner {
|
||||||
|
|
||||||
private static class VersionedWordRule extends WordRule {
|
|
||||||
|
|
||||||
private final String fVersion;
|
|
||||||
private final boolean fEnable;
|
|
||||||
|
|
||||||
private String fCurrentVersion;
|
|
||||||
|
|
||||||
public VersionedWordRule(IWordDetector detector, String version, boolean enable, String currentVersion) {
|
|
||||||
super(detector);
|
|
||||||
|
|
||||||
fVersion= version;
|
|
||||||
fEnable= enable;
|
|
||||||
fCurrentVersion= currentVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentVersion(String version) {
|
|
||||||
fCurrentVersion= version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @see IRule#evaluate
|
|
||||||
*/
|
|
||||||
public IToken evaluate(ICharacterScanner scanner) {
|
|
||||||
IToken token= super.evaluate(scanner);
|
|
||||||
|
|
||||||
if (fEnable) {
|
|
||||||
if (fCurrentVersion.equals(fVersion))
|
|
||||||
return token;
|
|
||||||
|
|
||||||
return Token.UNDEFINED;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (fCurrentVersion.equals(fVersion))
|
|
||||||
return Token.UNDEFINED;
|
|
||||||
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String[] fgKeywords= {
|
private static String[] fgKeywords= {
|
||||||
".set", ".section",
|
".set", ".section",
|
||||||
".global",
|
".global",".file",
|
||||||
".extern", ".macro", ".endm",
|
".extern", ".macro", ".endm",
|
||||||
".if", ".ifdef", ".ifndef", ".else", ".endif",
|
".if", ".ifdef", ".ifndef", ".else", ".endif",
|
||||||
".include", ".globl",
|
".include", ".globl",
|
||||||
".text",".data", ".rodata", ".common", ".debug", ".ctor", ".dtor",
|
".text",".data", ".rodata", ".common", ".debug", ".ctor", ".dtor",
|
||||||
".asciz", ".byte", ".long", ".size", ".align", ".type"
|
".ascii", ".asciz", ".byte", ".long", ".size", ".align", ".type"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,8 +54,6 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
||||||
ICColorConstants.C_DEFAULT
|
ICColorConstants.C_DEFAULT
|
||||||
};
|
};
|
||||||
|
|
||||||
private VersionedWordRule fVersionedWordRule;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a C code scanner
|
* Creates a C code scanner
|
||||||
*/
|
*/
|
||||||
|
@ -117,8 +78,6 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
||||||
|
|
||||||
// Add rule for strings
|
// Add rule for strings
|
||||||
Token token= getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
|
Token token= getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||||
// Add rule for single line comments.
|
|
||||||
rules.add(new EndOfLineRule("//", token));
|
|
||||||
|
|
||||||
// Add rule for single line comments.
|
// Add rule for single line comments.
|
||||||
rules.add(new EndOfLineRule("#", token));
|
rules.add(new EndOfLineRule("#", token));
|
||||||
|
@ -126,12 +85,12 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
||||||
token= getToken(ICColorConstants.C_STRING);
|
token= getToken(ICColorConstants.C_STRING);
|
||||||
// Add rule for strings and character constants.
|
// Add rule for strings and character constants.
|
||||||
rules.add(new SingleLineRule("'", "'", token, '\\'));
|
rules.add(new SingleLineRule("'", "'", token, '\\'));
|
||||||
rules.add(new SingleLineRule("\"", "\"", token, '\\'));
|
//rules.add(new SingleLineRule("\"", "\"", token, '\\'));
|
||||||
|
|
||||||
Token other= getToken(ICColorConstants.C_DEFAULT);
|
Token other= getToken(ICColorConstants.C_DEFAULT);
|
||||||
|
|
||||||
// Add generic whitespace rule.
|
// Add generic whitespace rule.
|
||||||
//rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
||||||
|
|
||||||
// Add word rule for labels
|
// Add word rule for labels
|
||||||
WordRule labelRule = new WordRule(new AsmWordDetector(false), other) {
|
WordRule labelRule = new WordRule(new AsmWordDetector(false), other) {
|
||||||
|
@ -212,14 +171,6 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
||||||
* @see RuleBasedScanner#setRules(IRule[])
|
* @see RuleBasedScanner#setRules(IRule[])
|
||||||
*/
|
*/
|
||||||
public void setRules(IRule[] rules) {
|
public void setRules(IRule[] rules) {
|
||||||
int i;
|
|
||||||
for (i= 0; i < rules.length; i++)
|
|
||||||
if (rules[i].equals(fVersionedWordRule))
|
|
||||||
break;
|
|
||||||
|
|
||||||
// not found - invalidate fVersionedWordRule
|
|
||||||
if (i == rules.length)
|
|
||||||
fVersionedWordRule= null;
|
|
||||||
|
|
||||||
super.setRules(rules);
|
super.setRules(rules);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,9 @@ package org.eclipse.cdt.internal.ui.editor.asm;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.text.CPartitionScanner;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||||
|
import org.eclipse.jface.text.rules.EndOfLineRule;
|
||||||
import org.eclipse.jface.text.rules.ICharacterScanner;
|
import org.eclipse.jface.text.rules.ICharacterScanner;
|
||||||
import org.eclipse.jface.text.rules.IPredicateRule;
|
import org.eclipse.jface.text.rules.IPredicateRule;
|
||||||
import org.eclipse.jface.text.rules.IRule;
|
import org.eclipse.jface.text.rules.IRule;
|
||||||
|
@ -16,6 +19,7 @@ import org.eclipse.jface.text.rules.IWordDetector;
|
||||||
import org.eclipse.jface.text.rules.MultiLineRule;
|
import org.eclipse.jface.text.rules.MultiLineRule;
|
||||||
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
|
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
|
||||||
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||||
|
import org.eclipse.jface.text.rules.SingleLineRule;
|
||||||
import org.eclipse.jface.text.rules.Token;
|
import org.eclipse.jface.text.rules.Token;
|
||||||
import org.eclipse.jface.text.rules.WordRule;
|
import org.eclipse.jface.text.rules.WordRule;
|
||||||
|
|
||||||
|
@ -29,7 +33,9 @@ public class AsmPartitionScanner extends RuleBasedPartitionScanner {
|
||||||
private final static String SKIP= "__skip";
|
private final static String SKIP= "__skip";
|
||||||
|
|
||||||
|
|
||||||
public final static String C_MULTILINE_COMMENT= "__c_multiline_comment";
|
public final static String ASM_MULTILINE_COMMENT= ICColorConstants.C_MULTI_LINE_COMMENT;
|
||||||
|
public final static String ASM_SINGLE_LINE_COMMENT= ICColorConstants.C_SINGLE_LINE_COMMENT;
|
||||||
|
public final static String ASM_STRING= ICColorConstants.C_STRING;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,7 +98,11 @@ public class AsmPartitionScanner extends RuleBasedPartitionScanner {
|
||||||
public AsmPartitionScanner() {
|
public AsmPartitionScanner() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
IToken comment= new Token(C_MULTILINE_COMMENT);
|
IToken comment= new Token(CPartitionScanner.C_MULTILINE_COMMENT);
|
||||||
|
IToken single_comment= new Token(CPartitionScanner.C_SINGLE_LINE_COMMENT);
|
||||||
|
IToken string= new Token(CPartitionScanner.C_STRING);
|
||||||
|
IToken skip= new Token(SKIP);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List rules= new ArrayList();
|
List rules= new ArrayList();
|
||||||
|
@ -103,12 +113,11 @@ public class AsmPartitionScanner extends RuleBasedPartitionScanner {
|
||||||
|
|
||||||
|
|
||||||
// Add rule for single line comments.
|
// Add rule for single line comments.
|
||||||
//rules.add(new EndOfLineRule("//", Token.UNDEFINED));
|
rules.add(new EndOfLineRule("//", single_comment));
|
||||||
|
|
||||||
|
|
||||||
// Add rule for strings and character constants.
|
// Add rule for strings and character constants.
|
||||||
//rules.add(new SingleLineRule("\"", "\"", Token.UNDEFINED, '\\'));
|
rules.add(new SingleLineRule("\"", "\"", string, '\\'));
|
||||||
//rules.add(new SingleLineRule("'", "'", Token.UNDEFINED, '\\'));
|
rules.add(new SingleLineRule("'", "'", string, '\\'));
|
||||||
|
|
||||||
EmptyCommentRule wordRule= new EmptyCommentRule(comment);
|
EmptyCommentRule wordRule= new EmptyCommentRule(comment);
|
||||||
rules.add(wordRule);
|
rules.add(wordRule);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.eclipse.jface.text.TextPresentation;
|
||||||
import org.eclipse.jface.text.presentation.IPresentationReconciler;
|
import org.eclipse.jface.text.presentation.IPresentationReconciler;
|
||||||
import org.eclipse.jface.text.presentation.PresentationReconciler;
|
import org.eclipse.jface.text.presentation.PresentationReconciler;
|
||||||
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
|
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.text.source.ISourceViewer;
|
||||||
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
||||||
import org.eclipse.swt.custom.StyleRange;
|
import org.eclipse.swt.custom.StyleRange;
|
||||||
|
@ -24,6 +25,33 @@ public class AsmSourceViewerConfiguration extends SourceViewerConfiguration {
|
||||||
private AsmTextEditor fEditor;
|
private AsmTextEditor fEditor;
|
||||||
private AsmTextTools fTextTools;
|
private AsmTextTools fTextTools;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ASM multiline comment scanner for this configuration.
|
||||||
|
*
|
||||||
|
* @return the ASM multiline comment scanner
|
||||||
|
*/
|
||||||
|
protected RuleBasedScanner getMultilineCommentScanner() {
|
||||||
|
return fTextTools.getMultilineCommentScanner();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ASM singleline comment scanner for this configuration.
|
||||||
|
*
|
||||||
|
* @return the ASM singleline comment scanner
|
||||||
|
*/
|
||||||
|
protected RuleBasedScanner getSinglelineCommentScanner() {
|
||||||
|
return fTextTools.getSinglelineCommentScanner();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ASM string scanner for this configuration.
|
||||||
|
*
|
||||||
|
* @return the ASM string scanner
|
||||||
|
*/
|
||||||
|
protected RuleBasedScanner getStringScanner() {
|
||||||
|
return fTextTools.getStringScanner();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for AsmSourceViewerConfiguration
|
* Constructor for AsmSourceViewerConfiguration
|
||||||
*/
|
*/
|
||||||
|
@ -51,15 +79,31 @@ public class AsmSourceViewerConfiguration extends SourceViewerConfiguration {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dr= new DefaultDamagerRepairer(fTextTools.getCodeScanner());
|
dr= new DefaultDamagerRepairer(getMultilineCommentScanner());
|
||||||
reconciler.setDamager(dr, AsmPartitionScanner.C_MULTILINE_COMMENT);
|
reconciler.setDamager(dr, AsmPartitionScanner.ASM_MULTILINE_COMMENT);
|
||||||
reconciler.setRepairer(dr, AsmPartitionScanner.C_MULTILINE_COMMENT);
|
reconciler.setRepairer(dr, AsmPartitionScanner.ASM_MULTILINE_COMMENT);
|
||||||
|
|
||||||
|
dr= new DefaultDamagerRepairer(getSinglelineCommentScanner());
|
||||||
|
reconciler.setDamager(dr, AsmPartitionScanner.ASM_SINGLE_LINE_COMMENT);
|
||||||
|
reconciler.setRepairer(dr, AsmPartitionScanner.ASM_SINGLE_LINE_COMMENT);
|
||||||
|
|
||||||
|
dr= new DefaultDamagerRepairer(getStringScanner());
|
||||||
|
reconciler.setDamager(dr, AsmPartitionScanner.ASM_STRING);
|
||||||
|
reconciler.setRepairer(dr, AsmPartitionScanner.ASM_STRING);
|
||||||
|
|
||||||
|
|
||||||
return reconciler;
|
return reconciler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SourceViewerConfiguration#getConfiguredContentTypes(ISourceViewer)
|
||||||
|
*/
|
||||||
|
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
|
||||||
|
return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
|
||||||
|
AsmPartitionScanner.ASM_MULTILINE_COMMENT,
|
||||||
|
AsmPartitionScanner.ASM_SINGLE_LINE_COMMENT,
|
||||||
|
AsmPartitionScanner.ASM_STRING };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,10 @@ import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
|
|
||||||
|
import org.eclipse.jface.action.IMenuManager;
|
||||||
import org.eclipse.jface.dialogs.MessageDialog;
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||||
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||||
|
|
||||||
|
|
||||||
import org.eclipse.ui.IEditorInput;
|
import org.eclipse.ui.IEditorInput;
|
||||||
|
@ -31,7 +33,13 @@ import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
||||||
import org.eclipse.ui.dialogs.SaveAsDialog;
|
import org.eclipse.ui.dialogs.SaveAsDialog;
|
||||||
import org.eclipse.ui.part.FileEditorInput;
|
import org.eclipse.ui.part.FileEditorInput;
|
||||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||||
|
import org.eclipse.ui.texteditor.ConvertLineDelimitersAction;
|
||||||
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
|
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
|
||||||
|
import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
||||||
|
import org.eclipse.ui.texteditor.ResourceAction;
|
||||||
|
import org.eclipse.ui.texteditor.StatusTextEditor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +48,7 @@ import org.eclipse.ui.texteditor.DefaultRangeIndicator;
|
||||||
/**
|
/**
|
||||||
* Assembly text editor
|
* Assembly text editor
|
||||||
*/
|
*/
|
||||||
public class AsmTextEditor extends AbstractTextEditor {
|
public class AsmTextEditor extends StatusTextEditor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new text editor.
|
* Creates a new text editor.
|
||||||
|
@ -126,4 +134,39 @@ public class AsmTextEditor extends AbstractTextEditor {
|
||||||
if (progressMonitor != null)
|
if (progressMonitor != null)
|
||||||
progressMonitor.setCanceled(!success);
|
progressMonitor.setCanceled(!success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
|
||||||
|
* Pulled in from 2.0
|
||||||
|
*/
|
||||||
|
protected boolean affectsTextPresentation(PropertyChangeEvent event) {
|
||||||
|
String p= event.getProperty();
|
||||||
|
|
||||||
|
boolean affects= false;
|
||||||
|
AsmTextTools textTools= CPlugin.getDefault().getAsmTextTools();
|
||||||
|
affects |= textTools.affectsBehavior(event);
|
||||||
|
|
||||||
|
return affects ? affects : super.affectsTextPresentation(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see AbstractTextEditor#createActions()
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
protected void createActions() {
|
||||||
|
super.createActions();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager)
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
protected void editorContextMenuAboutToShow(IMenuManager menu) {
|
||||||
|
super.editorContextMenuAboutToShow(menu);
|
||||||
|
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, ITextEditorActionConstants.SHIFT_RIGHT);
|
||||||
|
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, ITextEditorActionConstants.SHIFT_LEFT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ package org.eclipse.cdt.internal.ui.editor.asm;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.CPlugin;
|
import org.eclipse.cdt.internal.ui.CPlugin;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
|
||||||
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
|
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
|
||||||
|
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
|
@ -35,7 +37,16 @@ public class AsmTextTools {
|
||||||
private AsmCodeScanner fCodeScanner;
|
private AsmCodeScanner fCodeScanner;
|
||||||
/** The Asm partitions scanner */
|
/** The Asm partitions scanner */
|
||||||
private AsmPartitionScanner fPartitionScanner;
|
private AsmPartitionScanner fPartitionScanner;
|
||||||
|
/** The ASM multiline comment scanner */
|
||||||
|
private SingleTokenCScanner fMultilineCommentScanner;
|
||||||
|
/** The ASM singleline comment scanner */
|
||||||
|
private SingleTokenCScanner fSinglelineCommentScanner;
|
||||||
|
/** The ASM string scanner */
|
||||||
|
private SingleTokenCScanner fStringScanner;
|
||||||
|
|
||||||
|
|
||||||
|
/** The preference store */
|
||||||
|
private IPreferenceStore fPreferenceStore;
|
||||||
/** The preference change listener */
|
/** The preference change listener */
|
||||||
private PreferenceListener fPreferenceListener= new PreferenceListener();
|
private PreferenceListener fPreferenceListener= new PreferenceListener();
|
||||||
|
|
||||||
|
@ -49,9 +60,14 @@ public class AsmTextTools {
|
||||||
store = CPlugin.getDefault().getPreferenceStore();
|
store = CPlugin.getDefault().getPreferenceStore();
|
||||||
}
|
}
|
||||||
store.addPropertyChangeListener(fPreferenceListener);
|
store.addPropertyChangeListener(fPreferenceListener);
|
||||||
|
fPreferenceStore = store;
|
||||||
fColorManager= new CColorManager();
|
fColorManager= new CColorManager();
|
||||||
fCodeScanner= new AsmCodeScanner(fColorManager, store);
|
fCodeScanner= new AsmCodeScanner(fColorManager, store);
|
||||||
fPartitionScanner= new AsmPartitionScanner();
|
fPartitionScanner= new AsmPartitionScanner();
|
||||||
|
|
||||||
|
fMultilineCommentScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||||
|
fSinglelineCommentScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||||
|
fStringScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,10 +85,22 @@ public class AsmTextTools {
|
||||||
fCodeScanner= null;
|
fCodeScanner= null;
|
||||||
fPartitionScanner= null;
|
fPartitionScanner= null;
|
||||||
|
|
||||||
|
fMultilineCommentScanner= null;
|
||||||
|
fSinglelineCommentScanner= null;
|
||||||
|
fStringScanner= null;
|
||||||
|
|
||||||
|
if (fColorManager != null) {
|
||||||
fColorManager.dispose();
|
fColorManager.dispose();
|
||||||
fColorManager= null;
|
fColorManager= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fPreferenceStore != null) {
|
||||||
|
fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
|
||||||
|
fPreferenceStore= null;
|
||||||
|
fPreferenceListener= null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the color manager.
|
* Gets the color manager.
|
||||||
*/
|
*/
|
||||||
|
@ -100,13 +128,42 @@ public class AsmTextTools {
|
||||||
public IDocumentPartitioner createDocumentPartitioner() {
|
public IDocumentPartitioner createDocumentPartitioner() {
|
||||||
|
|
||||||
String[] types= new String[] {
|
String[] types= new String[] {
|
||||||
AsmPartitionScanner.C_MULTILINE_COMMENT
|
AsmPartitionScanner.ASM_MULTILINE_COMMENT,
|
||||||
|
AsmPartitionScanner.ASM_SINGLE_LINE_COMMENT,
|
||||||
|
AsmPartitionScanner.ASM_STRING
|
||||||
};
|
};
|
||||||
|
|
||||||
//return new RuleBasedPartitioner(getPartitionScanner(), types);
|
//return new RuleBasedPartitioner(getPartitionScanner(), types);
|
||||||
return new DefaultPartitioner(getPartitionScanner(), types);
|
return new DefaultPartitioner(getPartitionScanner(), types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a scanner which is configured to scan Java multiline comments.
|
||||||
|
*
|
||||||
|
* @return a Java multiline comment scanner
|
||||||
|
*/
|
||||||
|
public RuleBasedScanner getMultilineCommentScanner() {
|
||||||
|
return fMultilineCommentScanner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a scanner which is configured to scan Java singleline comments.
|
||||||
|
*
|
||||||
|
* @return a Java singleline comment scanner
|
||||||
|
*/
|
||||||
|
public RuleBasedScanner getSinglelineCommentScanner() {
|
||||||
|
return fSinglelineCommentScanner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a scanner which is configured to scan Java strings.
|
||||||
|
*
|
||||||
|
* @return a Java string scanner
|
||||||
|
*/
|
||||||
|
public RuleBasedScanner getStringScanner() {
|
||||||
|
return fStringScanner;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the preference change encoded by the given event
|
* Determines whether the preference change encoded by the given event
|
||||||
|
@ -116,7 +173,10 @@ public class AsmTextTools {
|
||||||
* @return <code>true</code> if event causes a behavioral change
|
* @return <code>true</code> if event causes a behavioral change
|
||||||
*/
|
*/
|
||||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||||
return fCodeScanner.affectsBehavior(event);
|
return fCodeScanner.affectsBehavior(event) ||
|
||||||
|
fMultilineCommentScanner.affectsBehavior(event) ||
|
||||||
|
fSinglelineCommentScanner.affectsBehavior(event) ||
|
||||||
|
fStringScanner.affectsBehavior(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,5 +188,12 @@ public class AsmTextTools {
|
||||||
protected void adaptToPreferenceChange(PropertyChangeEvent event) {
|
protected void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||||
if (fCodeScanner.affectsBehavior(event))
|
if (fCodeScanner.affectsBehavior(event))
|
||||||
fCodeScanner.adaptToPreferenceChange(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue