001/*-------------------------------------------------------------------------+
002|                                                                          |
003| Copyright (c) 2009-2018 CQSE GmbH                                        |
004|                                                                          |
005+-------------------------------------------------------------------------*/
006package eu.cqse.check.framework.core.phase;
007
008import java.io.Serializable;
009import java.util.EnumSet;
010import java.util.List;
011
012import eu.cqse.check.framework.core.CheckException;
013import eu.cqse.check.framework.core.ECheckParameter;
014import eu.cqse.check.framework.scanner.ELanguage;
015
016/**
017 * A global extraction phase allows to provide global information to a custom
018 * check. The phase is executed before the first run of the check.
019 */
020public interface IGlobalExtractionPhase<T extends IExtractedValue<D>, D extends Serializable> {
021
022        /** Extracts the values from a single file described by the context. */
023        List<T> extract(ITokenElementContext fileContext) throws CheckException;
024
025        /** Factory method for creating a value from the given parts. */
026        T createValue(String uniformPath, String value, D additionalInformation);
027
028        /**
029         * If this returns true, an inverted index that allows access by extracted value
030         * will be constructed as well.
031         */
032        default boolean needsAccessUniformPathByValue() {
033                return false;
034        }
035
036        /** The languages for which the phase is applicable. */
037        EnumSet<ELanguage> getLanguages();
038
039        /**
040         * The context parameters required by this check phase.
041         * 
042         * This is used to determine which context elements need to be initialized, not
043         * to filter elements. That means if you specify
044         * {@link ECheckParameter#ABSTRACT_SYNTAX_TREE} here and {@link #getLanguages()}
045         * returns a language for which we don't have a shallow parser (e.g.,
046         * {@link ELanguage#XML}), this will result in errors.
047         */
048        EnumSet<ECheckParameter> getRequiredContextParameters();
049}