001/*-------------------------------------------------------------------------+
002|                                                                          |
003| Copyright (c) 2009-2019 CQSE GmbH                                        |
004|                                                                          |
005+-------------------------------------------------------------------------*/
006package eu.cqse.check.framework.util;
007
008import static eu.cqse.check.framework.shallowparser.SubTypeNames.ANONYMOUS_BLOCK;
009import static eu.cqse.check.framework.shallowparser.SubTypeNames.CASE;
010import static eu.cqse.check.framework.shallowparser.SubTypeNames.DEFAULT;
011import static eu.cqse.check.framework.shallowparser.SubTypeNames.SWITCH;
012import static eu.cqse.check.framework.shallowparser.framework.EShallowEntityType.META;
013import static eu.cqse.check.framework.shallowparser.framework.EShallowEntityType.STATEMENT;
014
015import eu.cqse.check.framework.shallowparser.framework.ShallowEntity;
016
017/**
018 * Provides utility methods for handling switch, case and label statements
019 */
020public class SwitchStatementUtils {
021
022        /** Returns whether given statement is a switch or not. */
023        public static boolean isSwitch(ShallowEntity entity) {
024                return entity.getType() == STATEMENT && entity.getSubtype().equals(SWITCH);
025        }
026
027        /** Returns whether given statement is a case or not. */
028        public static boolean isCase(ShallowEntity entity) {
029                return entity.getType() == META && entity.getSubtype().equals(CASE);
030        }
031
032        /** Returns whether given statement is a default or not. */
033        public static boolean isDefault(ShallowEntity entity) {
034                return entity.getType() == META && entity.getSubtype().equals(DEFAULT);
035        }
036
037        /** Returns whether given statement is an anonymous block. */
038        public static boolean isAnonymousBlock(ShallowEntity entity) {
039                return entity.getType() == STATEMENT && entity.getSubtype().equals(ANONYMOUS_BLOCK);
040        }
041
042        /** Returns true if statement entity is a META one and its a case or default. */
043        public static boolean isCaseOrDefault(ShallowEntity entity) {
044                return entity.getType().equals(META)
045                                && (entity.getSubtype().equals(CASE) || entity.getSubtype().equals(DEFAULT));
046        }
047}