eu.cqse.check.framework.shallowparser.languages.objectivec.ObjectiveCBlockRules Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of teamscale-check-api Show documentation
Show all versions of teamscale-check-api Show documentation
The Teamscale Custom Check API allows users to extend Teamscale by writing custom analyses that create findings.
package eu.cqse.check.framework.shallowparser.languages.objectivec;
import static eu.cqse.check.framework.scanner.ETokenType.BOOL;
import static eu.cqse.check.framework.scanner.ETokenType.CHAR;
import static eu.cqse.check.framework.scanner.ETokenType.CONST;
import static eu.cqse.check.framework.scanner.ETokenType.DOUBLE;
import static eu.cqse.check.framework.scanner.ETokenType.EQ;
import static eu.cqse.check.framework.scanner.ETokenType.FLOAT;
import static eu.cqse.check.framework.scanner.ETokenType.ID;
import static eu.cqse.check.framework.scanner.ETokenType.IDENTIFIER;
import static eu.cqse.check.framework.scanner.ETokenType.INLINE;
import static eu.cqse.check.framework.scanner.ETokenType.INT;
import static eu.cqse.check.framework.scanner.ETokenType.LBRACE;
import static eu.cqse.check.framework.scanner.ETokenType.LONG;
import static eu.cqse.check.framework.scanner.ETokenType.LPAREN;
import static eu.cqse.check.framework.scanner.ETokenType.RBRACE;
import static eu.cqse.check.framework.scanner.ETokenType.RPAREN;
import static eu.cqse.check.framework.scanner.ETokenType.SEMICOLON;
import static eu.cqse.check.framework.scanner.ETokenType.SHORT;
import static eu.cqse.check.framework.scanner.ETokenType.SIGNED;
import static eu.cqse.check.framework.scanner.ETokenType.STATIC;
import static eu.cqse.check.framework.scanner.ETokenType.UNSIGNED;
import static eu.cqse.check.framework.scanner.ETokenType.VOID;
import static eu.cqse.check.framework.scanner.ETokenType.XOR;
import static eu.cqse.check.framework.shallowparser.framework.EShallowEntityType.METHOD;
import static eu.cqse.check.framework.shallowparser.languages.base.EGenericParserStates.IN_METHOD;
import static eu.cqse.check.framework.shallowparser.languages.base.EGenericParserStates.IN_TYPE;
import static eu.cqse.check.framework.shallowparser.languages.base.EGenericParserStates.TOP_LEVEL;
import java.util.EnumSet;
import java.util.Set;
import eu.cqse.check.framework.scanner.ETokenType;
import eu.cqse.check.framework.shallowparser.SubTypeNames;
import eu.cqse.check.framework.shallowparser.framework.RecognizerBase;
import eu.cqse.check.framework.shallowparser.languages.base.CStyleShallowParserBase;
import eu.cqse.check.framework.shallowparser.languages.base.CStyleShallowParserRuleProviderBase;
import eu.cqse.check.framework.shallowparser.languages.base.EGenericParserStates;
/**
* Creates rules for matching Objective-C blocks objects, which are very similar to lambdas and
* methods. Read more about Objective-C
* blocks
*/
public class ObjectiveCBlockRules extends CStyleShallowParserRuleProviderBase {
/** Reserved and user-defined Objective-C types. */
private static final Set TYPE_NAMES = EnumSet.of(IDENTIFIER, VOID, INT, FLOAT, DOUBLE, CHAR, BOOL, ID);
/** Modifiers followed by an Objective-C primitive type. */
private static final Set MODIFIER_KEYWORDS = EnumSet.of(STATIC, LONG, SHORT, UNSIGNED, SIGNED);
/** Specifiers followed by an Objective-C function. */
private static final Set FUNCTION_SPECIFIER_KEYWORDS = EnumSet.of(STATIC, INLINE, CONST);
public ObjectiveCBlockRules(CStyleShallowParserBase parser) {
super(parser);
}
@Override
public void contributeRules() {
createRulesForObjectiveCBlocks();
}
private void createRulesForObjectiveCBlocks() {
typeAndModifierPattern(inState(TOP_LEVEL, IN_METHOD, IN_TYPE)).sequence(LPAREN, XOR).sequence(IDENTIFIER)
.createNode(METHOD, SubTypeNames.BLOCK, 0).sequence(RPAREN, LPAREN)
.skipToWithNesting(RPAREN, LPAREN, RPAREN).sequence(EQ, XOR).optional(TYPE_NAMES).skipTo(LBRACE)
.parseUntil(IN_METHOD).sequence(RBRACE).optional(SEMICOLON).endNode();
}
/**
* Pattern matching optional modifiers followed by an Objective-C method or primitive type.
*/
public static RecognizerBase typeAndModifierPattern(
RecognizerBase currentState) {
Set allKeywords = EnumSet.noneOf(ETokenType.class);
allKeywords.addAll(MODIFIER_KEYWORDS);
allKeywords.addAll(FUNCTION_SPECIFIER_KEYWORDS);
return currentState.repeated(allKeywords).sequence(TYPE_NAMES);
}
}