2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.psi
.impl
.source
.parsing
;
18 import com
.intellij
.lang
.ASTFactory
;
19 import com
.intellij
.lexer
.Lexer
;
20 import com
.intellij
.lexer
.LexerPosition
;
21 import com
.intellij
.openapi
.diagnostic
.Logger
;
22 import com
.intellij
.psi
.JavaTokenType
;
23 import com
.intellij
.psi
.impl
.source
.tree
.TreeElement
;
24 import com
.intellij
.psi
.tree
.IElementType
;
25 import com
.intellij
.util
.CharTable
;
30 class GTTokens
implements JavaTokenType
{
31 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.source.parsing.GTTokens");
32 static IElementType
getTokenType(Lexer lexer
) {
33 if (lexer
.getTokenType() != GT
) return lexer
.getTokenType();
34 final LexerPosition originalPosition
= lexer
.getCurrentPosition();
35 final int prevTokenEnd
= lexer
.getTokenEnd();
37 if (lexer
.getTokenStart() != prevTokenEnd
) {
38 lexer
.restore(originalPosition
);
41 final IElementType resultType
;
42 IElementType i1
= lexer
.getTokenType();
48 final int prevTokenEnd2
= lexer
.getTokenEnd();
50 if (lexer
.getTokenStart() != prevTokenEnd2
) {
54 IElementType i
= lexer
.getTokenType();
56 final int prevTokenEnd3
= lexer
.getTokenEnd();
58 if (lexer
.getTokenStart() != prevTokenEnd3
|| lexer
.getTokenType() != EQ
) {
62 resultType
= GTGTGTEQ
;
77 lexer
.restore(originalPosition
);
81 static TreeElement
createTokenElementAndAdvance(IElementType tokenType
, Lexer lexer
, CharTable table
) {
82 final TreeElement result
;
83 if (tokenType
== GTGT
|| tokenType
== GE
) {
84 result
= mergeTokens(1, lexer
, tokenType
, table
);
86 else if (tokenType
== GTGTEQ
|| tokenType
== GTGTGT
) {
87 result
= mergeTokens(2, lexer
, tokenType
, table
);
89 else if (tokenType
== GTGTGTEQ
) {
90 result
= mergeTokens(3, lexer
, tokenType
, table
);
93 LOG
.assertTrue(tokenType
== lexer
.getTokenType());
94 result
= ParseUtil
.createTokenElement(lexer
, table
);
100 static void advance(IElementType tokenType
, Lexer lexer
) {
101 if(lexer
.getTokenType() != GT
){
105 if (tokenType
== GTGTGTEQ
) {
110 else if (tokenType
== GTGTEQ
|| tokenType
== GTGTGT
) {
114 else if (tokenType
== GTGT
|| tokenType
== GE
) {
121 private static TreeElement
mergeTokens(int nTokens
, Lexer lexer
, IElementType tokenType
, CharTable table
) {
122 final int tokenStart
= lexer
.getTokenStart();
123 for (int i
= 0; i
< nTokens
; i
++) {
126 final int tokenEnd
= lexer
.getTokenEnd();
127 return ASTFactory
.leaf(tokenType
, table
.intern(lexer
.getBufferSequence(), tokenStart
, tokenEnd
));