|
From: <caw...@us...> - 2007-08-07 13:58:17
|
Revision: 2927
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=2927&view=rev
Author: cawilliams
Date: 2007-08-07 06:58:13 -0700 (Tue, 07 Aug 2007)
Log Message:
-----------
add test and fix for #5448 - Error when opening authenticated_generator.rb file (restful_athentication plugin)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/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-08-02 18:59:27 UTC (rev 2926)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java 2007-08-07 13:58:13 UTC (rev 2927)
@@ -14,6 +14,7 @@
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.jruby.ast.CommentNode;
+import org.jruby.ast.Node;
import org.jruby.common.NullWarnings;
import org.jruby.lexer.yacc.LexState;
import org.jruby.lexer.yacc.LexerSource;
@@ -159,8 +160,8 @@
addClosingBraceToken();
setLexerPastDynamicSectionOfString();
return popTokenOffQueue();
- } else if (lexerToken == Tokens.tSTRING_BEG) {
- String opening = fContents.substring(fOffset - origOffset, lexerSource.getOffset());
+ } else if (lexerToken == Tokens.tSTRING_BEG) {
+ String opening = getOpeningString();
int index = indexOf(opening, ", +");
if (opening.trim().startsWith("<<") && index != -1) {
addHereDocStartToken(index);
@@ -194,6 +195,7 @@
// end of parsing
else
fLength = getOffset() - fOffset;
+ Assert.isTrue(fLength >= 0);
return new Token(RUBY_DEFAULT);
} catch (IOException e) {
RubyPlugin.log(e);
@@ -360,7 +362,7 @@
case Tokens.tSTRING_CONTENT:
return new Token(fContentType);
case Tokens.tSTRING_BEG:
- fOpeningString = fContents.substring(fOffset - origOffset, lexerSource.getOffset()).trim();
+ fOpeningString = getOpeningString();
if (fOpeningString.equals("'") || fOpeningString.startsWith("%q")) {
inSingleQuote = true;
} else if (fOpeningString.startsWith("<<")) { // here-doc
@@ -369,11 +371,11 @@
fContentType = RUBY_STRING;
return new Token(RUBY_STRING);
case Tokens.tXSTRING_BEG:
- fOpeningString = fContents.substring(fOffset - origOffset, lexerSource.getOffset()).trim();
+ fOpeningString = getOpeningString();
fContentType = RUBY_COMMAND;
return new Token(RUBY_COMMAND);
case Tokens.tQWORDS_BEG:
- fOpeningString = fContents.substring(fOffset - origOffset, lexerSource.getOffset()).trim();
+ fOpeningString = getOpeningString();
fContentType = RUBY_STRING;
return new Token(RUBY_STRING);
case Tokens.tSTRING_END:
@@ -382,7 +384,7 @@
inSingleQuote = false;
return new Token(oldContentType);
case Tokens.tREGEXP_BEG:
- fOpeningString = fContents.substring(fOffset - origOffset, lexerSource.getOffset()).trim();
+ fOpeningString = getOpeningString();
fContentType = RUBY_REGULAR_EXPRESSION;
return new Token(RUBY_REGULAR_EXPRESSION);
case Tokens.tREGEXP_END:
@@ -393,6 +395,17 @@
}
}
+ private String getOpeningString() {
+ int start = fOffset - origOffset;
+ List comments = result.getCommentNodes();
+ if (comments != null && !comments.isEmpty()) {
+ Node comment = (Node) comments.get(comments.size() - 1);
+ int end = comment.getPosition().getEndOffset();
+ start = end;
+ }
+ return fContents.substring(start, lexerSource.getOffset()).trim();
+ }
+
/**
* correct start offset, since when a line with nothing but spaces on it appears before comment,
* we get messed up positions
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|