001/*-------------------------------------------------------------------------+
002|                                                                          |
003| Copyright (c) 2009-2018 CQSE GmbH                                        |
004|                                                                          |
005+-------------------------------------------------------------------------*/
006package eu.cqse.check.framework.util.variable;
007
008import java.util.ArrayList;
009import java.util.EnumSet;
010import java.util.List;
011
012import eu.cqse.check.framework.scanner.ETokenType;
013import eu.cqse.check.framework.scanner.IToken;
014import eu.cqse.check.framework.util.cs.CsCheckUtils;
015
016/**
017 * A variable use extractor that considers string interpolation, feature that is
018 * specific for C#.
019 */
020public class CSVariableUseExtractor extends CLikeVariableUseExtractor {
021
022        /** Constructor. */
023        public CSVariableUseExtractor(ETokenType accessOperator, EnumSet<ETokenType> noVariableSuccessorTypes) {
024                super(EnumSet.of(accessOperator), noVariableSuccessorTypes);
025        }
026
027        /** {@inheritDoc} */
028        @Override
029        public List<Integer> extractVariableReads(List<IToken> tokens, String variableName, boolean isField,
030                        boolean isShadowed) {
031                List<Integer> uses = super.extractVariableReads(tokens, variableName, isField, isShadowed);
032                List<Integer> usesWithInterpolation = new ArrayList<>();
033
034                usesWithInterpolation.addAll(CsCheckUtils.checkForVariableUseInStringInterpolation(tokens, variableName));
035                usesWithInterpolation.addAll(uses);
036                return usesWithInterpolation;
037        }
038
039}