4 package com
.intellij
.lexer
;
6 import com
.intellij
.psi
.tree
.IElementType
;
7 import com
.intellij
.util
.text
.CharArrayUtil
;
8 import com
.intellij
.util
.text
.CharArrayCharSequence
;
10 public class PrefixSuffixStripperLexer
extends LexerBase
{
11 private CharSequence myBuffer
;
12 private char[] myBufferArray
;
13 private int myTokenStart
;
14 private int myTokenEnd
;
15 private IElementType myTokenType
;
17 private int myBufferEnd
;
18 private String myPrefix
;
19 private IElementType myPrefixType
;
20 private String mySuffix
;
21 private IElementType myMiddleTokenType
;
22 private IElementType mySuffixType
;
24 public PrefixSuffixStripperLexer(final String prefix
,
25 final IElementType prefixType
,
27 final IElementType suffixType
,
28 final IElementType middleTokenType
) {
29 mySuffixType
= suffixType
;
30 myMiddleTokenType
= middleTokenType
;
32 myPrefixType
= prefixType
;
36 public void start(char[] buffer
, int startOffset
, int endOffset
, int initialState
) {
37 start(new CharArrayCharSequence(buffer
),startOffset
, endOffset
, initialState
);
40 public void start(CharSequence buffer
, int startOffset
, int endOffset
, int initialState
) {
42 myBufferArray
= CharArrayUtil
.fromSequenceWithoutCopying(buffer
);
43 myTokenStart
= startOffset
;
44 myTokenEnd
= startOffset
;
46 myState
= initialState
;
47 myBufferEnd
= endOffset
;
50 public IElementType
getTokenType() {
55 public int getTokenStart() {
60 public int getTokenEnd() {
65 public int getState() {
69 public int getBufferEnd() {
73 public char[] getBuffer() {
74 return CharArrayUtil
.fromSequence(myBuffer
);
77 public CharSequence
getBufferSequence() {
81 public void advance() {
85 private void locateToken() {
86 if (myTokenType
!= null || myState
== 3) return;
89 myTokenEnd
= myTokenStart
+ myPrefix
.length();
90 myTokenType
= myPrefixType
;
91 myState
= myTokenEnd
< myBufferEnd ?
1 : 3;
96 myTokenStart
= myTokenEnd
;
97 final int suffixStart
= myBufferEnd
- mySuffix
.length();
98 myTokenType
= myMiddleTokenType
;
99 if ( (myBufferArray
!= null && CharArrayUtil
.regionMatches(myBufferArray
, suffixStart
, myBufferEnd
, mySuffix
)) ||
100 (myBufferArray
== null && CharArrayUtil
.regionMatches(myBuffer
, suffixStart
, myBufferEnd
, mySuffix
))
102 myTokenEnd
= suffixStart
;
103 if (myTokenStart
< myTokenEnd
) {
108 myTokenType
= mySuffixType
;
109 myTokenEnd
= myBufferEnd
;
113 myTokenEnd
= myBufferEnd
;
121 myTokenStart
= myTokenEnd
;
122 myTokenEnd
= myBufferEnd
;
123 myTokenType
= mySuffixType
;