|
From: <caw...@us...> - 2007-06-21 16:45:37
|
Revision: 2660
http://svn.sourceforge.net/rubyeclipse/?rev=2660&view=rev
Author: cawilliams
Date: 2007-06-21 09:45:35 -0700 (Thu, 21 Jun 2007)
Log Message:
-----------
add proper support for regex partitions
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/text/TC_RubyPartitionScanner.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java 2007-06-21 16:44:58 UTC (rev 2659)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java 2007-06-21 16:45:35 UTC (rev 2660)
@@ -243,7 +243,7 @@
}
private void addStringToken(int length) {
- push(new QueuedToken(new Token(RUBY_STRING), fOffset, length));
+ push(new QueuedToken(new Token(fContentType), fOffset, length));
setOffset(fOffset + length); // move past token
}
@@ -258,7 +258,11 @@
for (int i = 0; i < start; i++) {
fakeContents.append(" ");
}
- fakeContents.append('"');
+ if (fContentType.equals(RUBY_REGULAR_EXPRESSION)) {
+ fakeContents.append('/');
+ } else {
+ fakeContents.append('"');
+ }
if ((fOffset - origOffset) < origLength) {
fakeContents.append(new String(fContents.substring((fOffset - origOffset)))); // BLAH removed + 1 from end here
}
@@ -297,12 +301,13 @@
}
switch (i) {
case Tokens.tSTRING_CONTENT:
- return new Token(RUBY_STRING);
+ return new Token(fContentType);
case Tokens.tSTRING_BEG:
- String token = fContents.substring(fOffset, getOffset());
+ String token = fContents.substring(fOffset - origOffset, lexerSource.getOffset());
if (token.trim().equals("'")) {
inSingleQuote = true;
}
+ fContentType = RUBY_STRING;
return new Token(RUBY_STRING);
case Tokens.tQWORDS_BEG:
fContentType = RUBY_STRING;
@@ -312,8 +317,10 @@
inSingleQuote = false;
return new Token(RUBY_STRING);
case Tokens.tREGEXP_BEG:
+ fContentType = RUBY_REGULAR_EXPRESSION;
return new Token(RUBY_REGULAR_EXPRESSION);
case Tokens.tREGEXP_END:
+ fContentType = RUBY_DEFAULT;
return new Token(RUBY_REGULAR_EXPRESSION);
default:
return new Token(RUBY_DEFAULT);
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-06-21 16:44:58 UTC (rev 2659)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-06-21 16:45:35 UTC (rev 2660)
@@ -90,7 +90,7 @@
protected AbstractRubyTokenScanner fCodeScanner;
- protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner, fStringScanner;
+ protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner, fStringScanner, fRegexScanner;
private RubyDoubleClickSelector fRubyDoubleClickSelector;
private RubyCompletionProcessor fRubyCp;
@@ -169,7 +169,8 @@
*/
public boolean affectsTextPresentation(PropertyChangeEvent event) {
return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
- || fSinglelineCommentScanner.affectsBehavior(event) || fStringScanner.affectsBehavior(event);
+ || fSinglelineCommentScanner.affectsBehavior(event) || fStringScanner.affectsBehavior(event)
+ || fRegexScanner.affectsBehavior(event);
}
/**
@@ -196,6 +197,8 @@
fSinglelineCommentScanner.adaptToPreferenceChange(event);
if (fStringScanner.affectsBehavior(event))
fStringScanner.adaptToPreferenceChange(event);
+ if (fRegexScanner.affectsBehavior(event))
+ fRegexScanner.adaptToPreferenceChange(event);
}
/**
@@ -209,6 +212,7 @@
fMultilineCommentScanner = new RubyCommentScanner(getColorManager(), fPreferenceStore, IRubyColorConstants.RUBY_MULTI_LINE_COMMENT);
fSinglelineCommentScanner = new RubyCommentScanner(getColorManager(), fPreferenceStore, IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT);
fStringScanner = new SingleTokenRubyScanner(getColorManager(), fPreferenceStore, IRubyColorConstants.RUBY_STRING);
+ fRegexScanner = new SingleTokenRubyScanner(getColorManager(), fPreferenceStore, IRubyColorConstants.RUBY_REGEXP);
}
/**
@@ -249,6 +253,10 @@
dr = new DefaultDamagerRepairer(getStringScanner());
reconciler.setDamager(dr, RubyPartitionScanner.RUBY_STRING);
reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_STRING);
+
+ dr = new DefaultDamagerRepairer(getRegexScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
+ reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
return reconciler;
}
@@ -267,9 +275,13 @@
protected ITokenScanner getStringScanner() {
return fStringScanner;
}
+
+ protected ITokenScanner getRegexScanner() {
+ return fRegexScanner;
+ }
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return new String[] { IDocument.DEFAULT_CONTENT_TYPE, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT, RubyPartitionScanner.RUBY_STRING };
+ return new String[] { IDocument.DEFAULT_CONTENT_TYPE, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT, RubyPartitionScanner.RUBY_STRING, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION };
}
/*
@@ -305,7 +317,7 @@
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
if (IRubyPartitions.RUBY_SINGLE_LINE_COMMENT.equals(contentType)) {
- return new IAutoEditStrategy[] { new RubyCommentAutoIndentStrategy(partitioning) };
+ return new IAutoEditStrategy[] { new RubyCommentAutoIndentStrategy(fTextEditor, partitioning) };
} else if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) {
return new IAutoEditStrategy[] { new RubyAutoIndentStrategy(partitioning, getProject()) };
} else {
Modified: trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/text/TC_RubyPartitionScanner.java
===================================================================
--- trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/text/TC_RubyPartitionScanner.java 2007-06-21 16:44:58 UTC (rev 2659)
+++ trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/text/TC_RubyPartitionScanner.java 2007-06-21 16:45:35 UTC (rev 2660)
@@ -229,4 +229,20 @@
assertEquals(RubyPartitionScanner.RUBY_STRING, this.getContentType(code, 42)); // 1'}' t
assertEquals(RubyPartitionScanner.RUBY_STRING, this.getContentType(code, 44)); // 't'here
}
+
+ public void testRegex() {
+ String code = "regex = /hi there/";
+ assertEquals(RubyPartitionScanner.RUBY_DEFAULT, this.getContentType(code, 2)); // re'g'ex
+ assertEquals(RubyPartitionScanner.RUBY_REGULAR_EXPRESSION, this.getContentType(code, 9)); // '/'hi the
+ assertEquals(RubyPartitionScanner.RUBY_REGULAR_EXPRESSION, this.getContentType(code, 11)); // /h'i' the
+ }
+
+ public void testRegexWithDynamicCode() {
+ String code = "/\\.#{Regexp.escape(extension.to_s)}$/ # comment";
+ assertEquals(RubyPartitionScanner.RUBY_REGULAR_EXPRESSION, this.getContentType(code, 3));
+ assertEquals(RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT, this.getContentType(code, 38)); // '#' co
+ assertEquals(RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT, this.getContentType(code, 40)); // # 'c'ommen
+ }
+
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|