001/*-------------------------------------------------------------------------+ 002| | 003| Copyright 2005-2011 the ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016+-------------------------------------------------------------------------*/ 017package eu.cqse.check.framework.shallowparser.languages.cs; 018 019import java.util.List; 020 021import eu.cqse.check.framework.scanner.ETokenType; 022import eu.cqse.check.framework.scanner.IToken; 023import eu.cqse.check.framework.shallowparser.framework.ParserState; 024import eu.cqse.check.framework.shallowparser.framework.RecognizerBase; 025import eu.cqse.check.framework.shallowparser.languages.base.EGenericParserStates; 026 027/** 028 * Recognizer for array brackets as part of types, also dealing with multi-dim 029 * arrays, e.g. [], [,,] etc. 030 */ 031public class ArrayBracketsRecognizer extends RecognizerBase<EGenericParserStates> { 032 /** {@inheritDoc} */ 033 @Override 034 protected int matchesLocally(ParserState<EGenericParserStates> parserState, List<IToken> tokens, int startOffset) { 035 if (startOffset >= tokens.size() || tokens.get(startOffset).getType() != ETokenType.LBRACK) { 036 return NO_MATCH; 037 } 038 for (int i = startOffset + 1; i < tokens.size(); i++) { 039 ETokenType tokenType = tokens.get(i).getType(); 040 if (tokenType == ETokenType.RBRACK) { 041 return i + 1; 042 } else if (tokenType != ETokenType.COMMA) { 043 return NO_MATCH; 044 } 045 } 046 return NO_MATCH; 047 } 048}