This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 216362 - LexerInput.readText(start, end) does not respect start index
Summary: LexerInput.readText(start, end) does not respect start index
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Lexer (show other bugs)
Version: 7.2
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-03 12:01 UTC by fvogler
Modified: 2012-09-20 02:24 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Path for lexer module - http://hg.netbeans.org/main at revision 227659 (6.25 KB, application/octet-stream)
2012-08-03 12:01 UTC, fvogler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description fvogler 2012-08-03 12:01:56 UTC
Created attachment 122713 [details]
Path for lexer module - http://hg.netbeans.org/main at revision 227659

Hi,

LexerInput.readText(start, end) returns always 
a CharSequence starting at position 0.

The returned LexerInput.ReadText does not use 
start index as offset in its charAt(index) method.

Regards
Florian
Comment 1 Miloslav Metelka 2012-08-03 15:56:57 UTC
It should work as described in the javadoc. Let's say that during a recogntion of a current token lexerInput.read() is invoked 6 times reading chars "abcdef". If you now call lexerInput.readText(2, 5) the returned CharSequence (let's name it txt) should contain text "cde" i.e. txt.length() == 3 and txt.charAt(0) == 'c' till txt.charAt(2) == 'e'. Once a token is returned by TokenFactory.createToken() the lexerInput.readText() is no longer able to reference characters "abcdef" (if they all were part of just returned token).
 If it does not work in this way please reopen the issue.
Comment 2 fvogler 2012-08-05 21:12:04 UTC
Hi,
did you check my attachment (fix + unit test)?
The following code did not work.

@Override
public Token<TokenIdImpl> nextToken() {
 ...
  String text = String.valueOf(input.readText()); // text="abcdefg"
  String subText = text.substring(2, 4);          // subText ="cd"
  CharSequence readText = input.readText(2, 4);   // readText="ab" (length=2, ok)
  subText.contentEquals(readText);                // -> false !!! Should be true?
 ...
}

The var readText should be "cd" (but was "ab")?
Take a look at LexerInput.ReadText class.
There is an unused var containing the start index.

If I am wrong please close again.

Regards
Florian
Comment 3 Miloslav Metelka 2012-09-18 20:45:24 UTC
I see, I'm sorry. Thank you for the patch.
http://hg.netbeans.org/jet-main/rev/69dc8e287dbf
Comment 4 Quality Engineering 2012-09-20 02:24:08 UTC
Integrated into 'main-golden', will be available in build *201209200001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/69dc8e287dbf
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #216362 - LexerInput.readText(start, end) does not respect start index.