Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Editor patch

Just commited the patch, it addresses the following:

- code assist for referenced projects should now work
- cleanup of assembly editor: syntax highlighting,
menus, follow color preferences

Sebastien

Index: src/org/eclipse/cdt/internal/ui/editor/CEditor.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEdito
r.java,v
retrieving revision 1.5
diff -c -r1.5 CEditor.java
*** src/org/eclipse/cdt/internal/ui/editor/CEditor.java	28 Aug 2002 22:42:29
-0000	1.5
--- src/org/eclipse/cdt/internal/ui/editor/CEditor.java	5 Sep 2002 14:52:29
-0000
***************
*** 1534,1540 ****
  		CTextTools textTools= CPlugin.getDefault().getTextTools();
  		affects |= textTools.affectsBehavior(event);
  									
! 		return affects; // ? affects :
super.affectsTextPresentation(event);
  	}
  
  	private ICEditorContextMenuAction[] getContextMenuActions()
--- 1534,1540 ----
  		CTextTools textTools= CPlugin.getDefault().getTextTools();
  		affects |= textTools.affectsBehavior(event);
  									
! 		return affects ? affects :
super.affectsTextPresentation(event);
  	}
  
  	private ICEditorContextMenuAction[] getContextMenuActions()
Index: src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/As
mCodeScanner.java,v
retrieving revision 1.2
diff -c -r1.2 AsmCodeScanner.java
*** src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.java	26
Jun 2002 21:53:41 -0000	1.2
--- src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.java	5
Sep 2002 14:52:30 -0000
***************
*** 9,14 ****
--- 9,16 ----
  import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
  import org.eclipse.cdt.internal.ui.text.ICColorConstants;
  import org.eclipse.cdt.internal.ui.text.IColorManager;
+ import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
+ 
  import java.util.ArrayList;
  import java.util.List;
  
***************
*** 20,25 ****
--- 22,28 ----
  import org.eclipse.jface.text.rules.IWordDetector;
  import org.eclipse.jface.text.rules.SingleLineRule;
  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;
***************
*** 30,83 ****
   */
  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= { 
  			".set", ".section",  
! 			".global", 
  			".extern", ".macro", ".endm", 
  			".if", ".ifdef", ".ifndef", ".else", ".endif",
  			".include", ".globl", 
  			".text",".data", ".rodata", ".common", ".debug",
".ctor", ".dtor", 
! 			".asciz", ".byte", ".long", ".size", ".align",
".type"
  	};
  
  
--- 33,46 ----
   */
  public final class AsmCodeScanner extends AbstractCScanner {
  	
  	private static String[] fgKeywords= { 
  			".set", ".section",  
! 			".global",".file", 
  			".extern", ".macro", ".endm", 
  			".if", ".ifdef", ".ifndef", ".else", ".endif",
  			".include", ".globl", 
  			".text",".data", ".rodata", ".common", ".debug",
".ctor", ".dtor", 
! 			".ascii", ".asciz", ".byte", ".long", ".size",
".align", ".type"
  	};
  
  
***************
*** 91,98 ****
  		ICColorConstants.C_DEFAULT
  	};
  	
- 	private VersionedWordRule fVersionedWordRule;
- 
  	/**
  	 * Creates a C code scanner
  	 */
--- 54,59 ----
***************
*** 117,124 ****
  		
  		// Add rule for strings
  		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.
  		rules.add(new EndOfLineRule("#", token));
--- 78,83 ----
***************
*** 126,137 ****
  		token= getToken(ICColorConstants.C_STRING);
  		// Add rule for strings and character constants.
  		rules.add(new SingleLineRule("'", "'", token, '\\'));
! 		rules.add(new SingleLineRule("\"", "\"", token, '\\'));
  				
  		Token other= getToken(ICColorConstants.C_DEFAULT);

  		
  		// Add generic whitespace rule.
! 		//rules.add(new WhitespaceRule(new CWhitespaceDetector()));
  
  		// Add word rule for labels
  		WordRule labelRule = new WordRule(new
AsmWordDetector(false), other) {
--- 85,96 ----
  		token= getToken(ICColorConstants.C_STRING);
  		// Add rule for strings and character constants.
  		rules.add(new SingleLineRule("'", "'", token, '\\'));
! 		//rules.add(new SingleLineRule("\"", "\"", token, '\\'));
  				
  		Token other= getToken(ICColorConstants.C_DEFAULT);

  		
  		// Add generic whitespace rule.
! 		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
  
  		// Add word rule for labels
  		WordRule labelRule = new WordRule(new
AsmWordDetector(false), other) {
***************
*** 212,225 ****
  	 * @see RuleBasedScanner#setRules(IRule[])
  	 */
  	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);	
  	}
--- 171,176 ----
Index: src/org/eclipse/cdt/internal/ui/editor/asm/AsmPartitionScanner.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/As
mPartitionScanner.java,v
retrieving revision 1.3
diff -c -r1.3 AsmPartitionScanner.java
*** src/org/eclipse/cdt/internal/ui/editor/asm/AsmPartitionScanner.java	26
Aug 2002 22:10:35 -0000	1.3
--- src/org/eclipse/cdt/internal/ui/editor/asm/AsmPartitionScanner.java	5
Sep 2002 14:52:30 -0000
***************
*** 8,13 ****
--- 8,16 ----
  import java.util.ArrayList;
  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.IPredicateRule;
  import org.eclipse.jface.text.rules.IRule;
***************
*** 16,21 ****
--- 19,25 ----
  import org.eclipse.jface.text.rules.MultiLineRule;
  import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
  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.WordRule;
  
***************
*** 29,35 ****
  	private final static String SKIP= "__skip";
  
  
! 	public final static String C_MULTILINE_COMMENT=
"__c_multiline_comment";
  
  
  	/**
--- 33,41 ----
  	private final static String SKIP= "__skip";
  
  
! 	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,98 ****
  	public AsmPartitionScanner() {
  		super();
  		
! 		IToken comment= new Token(C_MULTILINE_COMMENT);
  
  
  		List rules= new ArrayList();
--- 98,108 ----
  	public AsmPartitionScanner() {
  		super();
  		
! 		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();
***************
*** 103,114 ****
  
  
  		// Add rule for single line comments.
! 		//rules.add(new EndOfLineRule("//", Token.UNDEFINED));
! 
  
  		// Add rule for strings and character constants.
! 		//rules.add(new SingleLineRule("\"", "\"", Token.UNDEFINED,
'\\'));
! 		//rules.add(new SingleLineRule("'", "'", Token.UNDEFINED,
'\\'));
  		
  		EmptyCommentRule wordRule= new EmptyCommentRule(comment);
  		rules.add(wordRule);
--- 113,123 ----
  
  
  		// Add rule for single line comments.
! 		rules.add(new EndOfLineRule("//", single_comment));
  
  		// Add rule for strings and character constants.
! 		rules.add(new SingleLineRule("\"", "\"", string, '\\'));
! 		rules.add(new SingleLineRule("'", "'", string, '\\'));
  		
  		EmptyCommentRule wordRule= new EmptyCommentRule(comment);
  		rules.add(wordRule);
Index:
src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/As
mSourceViewerConfiguration.java,v
retrieving revision 1.2
diff -c -r1.2 AsmSourceViewerConfiguration.java
***
src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
9 Aug 2002 02:31:39 -0000	1.2
---
src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
5 Sep 2002 14:52:31 -0000
***************
*** 13,18 ****
--- 13,19 ----
  import org.eclipse.jface.text.presentation.IPresentationReconciler;
  import org.eclipse.jface.text.presentation.PresentationReconciler;
  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.SourceViewerConfiguration;
  import org.eclipse.swt.custom.StyleRange;
***************
*** 25,30 ****
--- 26,58 ----
  	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
  	 */
  	public AsmSourceViewerConfiguration(AsmTextTools tools,
AsmTextEditor editor) {
***************
*** 51,65 ****
  
  
  
! 		dr= new DefaultDamagerRepairer(fTextTools.getCodeScanner());

! 		reconciler.setDamager(dr,
AsmPartitionScanner.C_MULTILINE_COMMENT);
! 		reconciler.setRepairer(dr,
AsmPartitionScanner.C_MULTILINE_COMMENT);
! 
  
  
  		return reconciler;
  	}
  	
  
  
  }
--- 79,109 ----
  
  
  
! 		dr= new
DefaultDamagerRepairer(getMultilineCommentScanner());		
! 		reconciler.setDamager(dr,
AsmPartitionScanner.ASM_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;
  	}
  	
+ 	/**
+ 	 * @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 };
+ 	}
  
  
  }
Index: src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/As
mTextEditor.java,v
retrieving revision 1.1
diff -c -r1.1 AsmTextEditor.java
*** src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java	26
Jun 2002 20:55:44 -0000	1.1
--- src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java	5
Sep 2002 14:52:30 -0000
***************
*** 22,29 ****
--- 22,31 ----
  import org.eclipse.core.runtime.IProgressMonitor;
  
  
+ import org.eclipse.jface.action.IMenuManager;
  import org.eclipse.jface.dialogs.MessageDialog;
  import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+ import org.eclipse.jface.util.PropertyChangeEvent;
  
  
  import org.eclipse.ui.IEditorInput;
***************
*** 31,37 ****
--- 33,45 ----
  import org.eclipse.ui.dialogs.SaveAsDialog;
  import org.eclipse.ui.part.FileEditorInput;
  import org.eclipse.ui.texteditor.AbstractTextEditor;
+ import org.eclipse.ui.texteditor.ConvertLineDelimitersAction;
  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,46 ****
  /**
   * Assembly text editor
   */
! public class AsmTextEditor extends AbstractTextEditor {
  		
  	/**
  	 * Creates a new text editor.
--- 48,54 ----
  /**
   * Assembly text editor
   */
! public class AsmTextEditor extends StatusTextEditor {
  		
  	/**
  	 * Creates a new text editor.
***************
*** 125,129 ****
--- 133,172 ----
  		
  		if (progressMonitor != null)
  			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);
  	}
  }
Index: src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/As
mTextTools.java,v
retrieving revision 1.2
diff -c -r1.2 AsmTextTools.java
*** src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java	21
Aug 2002 00:44:37 -0000	1.2
--- src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java	5
Sep 2002 14:52:31 -0000
***************
*** 6,11 ****
--- 6,13 ----
   */
   
  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.jface.preference.IPreferenceStore;
***************
*** 35,41 ****
  	private AsmCodeScanner fCodeScanner;
  	/** The Asm partitions scanner */
  	private AsmPartitionScanner fPartitionScanner;
! 		
  	/** The preference change listener */
  	private PreferenceListener fPreferenceListener= new
PreferenceListener();
  	
--- 37,52 ----
  	private AsmCodeScanner fCodeScanner;
  	/** The Asm partitions scanner */
  	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 */
  	private PreferenceListener fPreferenceListener= new
PreferenceListener();
  	
***************
*** 49,57 ****
--- 60,73 ----
  			store = CPlugin.getDefault().getPreferenceStore();
  		}
  		store.addPropertyChangeListener(fPreferenceListener);
+ 		fPreferenceStore = store;
  		fColorManager= new CColorManager();
  		fCodeScanner= new AsmCodeScanner(fColorManager, store);
  		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,76 ****
  		fCodeScanner= null;
  		fPartitionScanner= null;
  		
! 		fColorManager.dispose();
! 		fColorManager= null;
  	}
  	
  	/**
--- 85,104 ----
  		fCodeScanner= null;
  		fPartitionScanner= null;
  		
! 		fMultilineCommentScanner= null;
! 		fSinglelineCommentScanner= null;
! 		fStringScanner= null;
! 		
! 		if (fColorManager != null) {
! 			fColorManager.dispose();
! 			fColorManager= null;
! 		}
! 		
! 		if (fPreferenceStore != null) {
!
fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
! 			fPreferenceStore= null;
! 			fPreferenceListener= null;
! 		}
  	}
  	
  	/**
***************
*** 100,113 ****
  	public IDocumentPartitioner createDocumentPartitioner() {
  		
  		String[] types= new String[] {
! 			AsmPartitionScanner.C_MULTILINE_COMMENT
  		};
  		
  		//return new RuleBasedPartitioner(getPartitionScanner(),
types);
  		return new DefaultPartitioner(getPartitionScanner(), types);
  	}
  	
! 		
  	/**
  	 * Determines whether the preference change encoded by the given
event
  	 * changes the behavior of one its contained components.
--- 128,170 ----
  	public IDocumentPartitioner createDocumentPartitioner() {
  		
  		String[] types= new String[] {
! 			AsmPartitionScanner.ASM_MULTILINE_COMMENT,
! 			AsmPartitionScanner.ASM_SINGLE_LINE_COMMENT,
! 			AsmPartitionScanner.ASM_STRING
  		};
  		
  		//return new RuleBasedPartitioner(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
  	 * changes the behavior of one its contained components.
***************
*** 116,122 ****
  	 * @return <code>true</code> if event causes a behavioral change
  	 */
  	public boolean affectsBehavior(PropertyChangeEvent event) {
! 		return  fCodeScanner.affectsBehavior(event);
  	}
  	
  	/**
--- 173,182 ----
  	 * @return <code>true</code> if event causes a behavioral change
  	 */
  	public boolean affectsBehavior(PropertyChangeEvent event) {
! 		return  fCodeScanner.affectsBehavior(event) ||
!
fMultilineCommentScanner.affectsBehavior(event) ||
!
fSinglelineCommentScanner.affectsBehavior(event) ||
!
fStringScanner.affectsBehavior(event);
  	}
  	
  	/**
***************
*** 128,132 ****
--- 188,199 ----
  	protected void adaptToPreferenceChange(PropertyChangeEvent event) {
  		if (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);
  	}
+ 		
  }
Index: src/org/eclipse/cdt/internal/ui/text/CCodeScanner.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCodeSca
nner.java,v
retrieving revision 1.2
diff -c -r1.2 CCodeScanner.java
*** src/org/eclipse/cdt/internal/ui/text/CCodeScanner.java	26 Jun 2002
21:53:41 -0000	1.2
--- src/org/eclipse/cdt/internal/ui/text/CCodeScanner.java	5 Sep 2002
14:52:27 -0000
***************
*** 20,25 ****
--- 20,26 ----
  import org.eclipse.jface.text.rules.PatternRule;
  import org.eclipse.jface.text.rules.SingleLineRule;
  import org.eclipse.jface.text.rules.Token;
+ import org.eclipse.jface.text.rules.WordRule;
  import org.eclipse.jface.util.Assert;
  import org.eclipse.jface.util.PropertyChangeEvent;
  
***************
*** 29,143 ****
   */
  public final class CCodeScanner extends AbstractCScanner {
  	
- 	private class CWordRule implements IRule {
- 		
- 		protected static final int UNDEFINED= -1;
- 		
- 		/** The word detector used by this rule */
- 		protected IWordDetector fDetector;
- 		/** The default token to be returned on success and if
nothing else has been specified. */
- 		protected IToken fDefaultToken;
- 		/** The column constraint */
- 		protected int fColumn= UNDEFINED;
- 		/** The table of predefined words and token for this rule */
- 		protected Map fWords= new HashMap();
- 		
- 		private StringBuffer fBuffer= new StringBuffer();
- 	
- 		/**
- 		 * Creates a rule which, with the help of an word detector,
will return the token
- 		 * associated with the detected word. If no token has been
associated, the scanner 
- 		 * will be rolled back and an undefined token will be
returned in order to allow 
- 		 * any subsequent rules to analyze the characters.
- 		 *
- 		 * @param detector the word detector to be used by this
rule, may not be <code>null</code>
- 		 *
- 		 * @see #addWord
- 		 */
- 		public CWordRule(IWordDetector detector) {
- 			this(detector, Token.UNDEFINED);
- 		}
- 		/**
- 		 * Creates a rule which, with the help of an word detector,
will return the token
- 		 * associated with the detected word. If no token has been
associated, the
- 		 * specified default token will be returned.
- 		 *
- 		 * @param detector the word detector to be used by this
rule, may not be <code>null</code>
- 		 * @param defaultToken the default token to be returned on
success 
- 		 *		if nothing else is specified, may not be
<code>null</code>
- 		 *
- 		 * @see #addWord
- 		 */
- 		public CWordRule(IWordDetector detector, IToken
defaultToken) {
- 			
- 			Assert.isNotNull(detector);
- 			Assert.isNotNull(defaultToken);
- 			
- 			fDetector= detector;
- 			fDefaultToken= defaultToken;
- 		}
- 		/**
- 		 * 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) {
- 			Assert.isNotNull(word);
- 			Assert.isNotNull(token);		
- 		
- 			fWords.put(word, token);
- 		}
- 		/*
- 		 * @see IRule#evaluate
- 		 */
- 		public IToken evaluate(ICharacterScanner scanner) {
- 			
- 			int c= scanner.read();
- 			if (Character.isJavaIdentifierStart((char) c) || (c
== '#' && scanner.getColumn() == 1)) {	
- 				fBuffer.setLength(0);
- 				do {
- 					fBuffer.append((char) c);
- 					c= scanner.read();
- 				} while
(Character.isJavaIdentifierPart((char) c));
- 				scanner.unread();
- 				
- 				IToken token= (IToken)
fWords.get(fBuffer.toString());
- 				if (token != null)
- 					return token;
- 					
- 				//if (fDefaultToken.isUndefined())
- 				//	unreadBuffer(scanner);
- 					
- 				return fDefaultToken;
- 			}
- 			
- 			scanner.unread();
- 			return Token.UNDEFINED; 
- 		}
- 		/**
- 		 * Sets a column constraint for this rule. If set, the
rule's token
- 		 * will only be returned if the pattern is detected starting
at the 
- 		 * specified column. If the column is smaller then 0, the
column
- 		 * constraint is considered removed.
- 		 *
- 		 * @param column the column in which the pattern starts
- 		 */
- 		public void setColumnConstraint(int column) {
- 			if (column < 0)
- 				column= UNDEFINED;
- 			fColumn= column;
- 		}
- 		/**
- 		 * 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();
- 		}
- 	};
  
  	private static String[] fgKeywords= { 
  			"asm", "auto",
--- 30,35 ----
***************
*** 198,204 ****
  		// Add rule for strings and character constants.
  		rules.add(new SingleLineRule("'", "'", token, '\\'));
  				
- 				
  		
  		// Add generic whitespace rule.
  		//rules.add(new WhitespaceRule(new CWhitespaceDetector()));
--- 90,95 ----
***************
*** 206,212 ****
  		
  		// Add word rule for keywords, types, and constants.
  		token= getToken(ICColorConstants.C_DEFAULT);
! 		CWordRule wordRule= new CWordRule(new CWordDetector(),
token);
  		
  		token= getToken(ICColorConstants.C_KEYWORD);
  		for (int i=0; i<fgKeywords.length; i++)
--- 97,103 ----
  		
  		// Add word rule for keywords, types, and constants.
  		token= getToken(ICColorConstants.C_DEFAULT);
! 		WordRule wordRule= new WordRule(new CWordDetector(), token);
  		
  		token= getToken(ICColorConstants.C_KEYWORD);
  		for (int i=0; i<fgKeywords.length; i++)
Index: src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CComplet
ionProcessor.java,v
retrieving revision 1.1
diff -c -r1.1 CCompletionProcessor.java
*** src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java	26
Jun 2002 20:55:44 -0000	1.1
--- src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java	5
Sep 2002 14:52:26 -0000
***************
*** 24,29 ****
--- 24,30 ----
  import org.eclipse.swt.graphics.Point;
  
  import org.eclipse.core.resources.IProject;
+ import org.eclipse.core.runtime.CoreException;
  import org.eclipse.jface.text.BadLocationException;
  import org.eclipse.jface.text.IDocument;
  import org.eclipse.jface.text.IRegion;
***************
*** 217,222 ****
--- 218,257 ----
  		return proposals;	
  	}
  	
+ 	private void addProjectCompletions(IProject project, IRegion region,
String frag, ArrayList completions) {
+ 		IndexModel model = IndexModel.getDefault();
+ 		
+ 		ITagEntry[] tags= model.query(project, frag+"*", false,
false);
+ 		if(tags != null && tags.length > 0) {
+ 			// We have some matches!
+ 			for(int i = 0; i < tags.length; i++) {
+ 
+ 				String fname = tags[i].getTagName();
+ 
+ 				int kind = tags[i].getKind();
+ 
+ 				if(kind == TagFlags.T_FUNCTION || kind ==
TagFlags.T_PROTOTYPE) {
+ 					fname = fname + "()";
+ 				}
+ 				String proto = fname + " - " +
tags[i].getPattern();
+ 				//System.out.println("tagmatch " + fname + "
proto " + proto + " type" + tags[i].getKind());
+ 				if(tags[i].getKind() != TagFlags.T_MEMBER) {
+ 					completions.add(
+ 						new CCompletionProposal(
+ 						fname,
+ 						region.getOffset(),
+ 						region.getLength(),
+ 						//fname.length() + 1,
+ 						getTagImage(kind),
+ 						proto.equals("") ? (fname +
"()") : proto,
+ 						//null,
+ 						//null));
+ 						3));
+ 				}
+ 			}
+ 		}
+ 	}
+ 	
  	/**
  	 * Evaluate the actual proposals for C
  	 */
***************
*** 269,275 ****
  		ArrayList completions = new ArrayList();
  
  		// Look in index manager
- 		IndexModel model = IndexModel.getDefault();
  		IProject project = null;
  		IEditorInput input = fEditor.getEditorInput();
  		if(input instanceof IFileEditorInput) {
--- 304,309 ----
***************
*** 281,315 ****
  			}
  		}
  		if(project != null) {
! 			ITagEntry[] tags= model.query(project, frag+"*",
false, false);
! 			if(tags != null && tags.length > 0) {
! 				// We have some matches!
! 				for(int i = 0; i < tags.length; i++) {
! 
! 					String fname = tags[i].getTagName();
! 
! 					int kind = tags[i].getKind();
! 
! 					if(kind == TagFlags.T_FUNCTION ||
kind == TagFlags.T_PROTOTYPE) {
! 						fname = fname + "()";
! 					}
! 					String proto = fname + " - " +
tags[i].getPattern();
! 					//System.out.println("tagmatch " +
fname + " proto " + proto + " type" + tags[i].getKind());
! 					if(tags[i].getKind() !=
TagFlags.T_MEMBER) {
! 						completions.add(
! 							new
CCompletionProposal(
! 							fname,
! 							region.getOffset(),
! 							region.getLength(),
! 							//fname.length() +
1,
! 							getTagImage(kind),
! 							proto.equals("") ?
(fname + "()") : proto,
! 							//null,
! 							//null));
! 							3));
  					}
  				}
  			}
  		}
  				
  		
--- 315,333 ----
  			}
  		}
  		if(project != null) {
! 			addProjectCompletions(project, region, frag,
completions);
! 			// Now query referenced projects
! 			IProject referenced[];
! 			try {
! 				referenced =
project.getReferencedProjects();
! 				if(referenced.length > 0) {
! 					for (int i = 0; i <
referenced.length; i++) {
!
addProjectCompletions(referenced[i], region, frag, completions);
  					}
  				}
+ 			} catch (CoreException e) {
  			}
+ 
  		}
  				
  		


Back to the top