All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.harmonysoft.oss.traute.javac.text.ParameterCheckExceptionTextGeneratorSpi Maven / Gradle / Ivy

There is a newer version: 1.1.10
Show newest version
package tech.harmonysoft.oss.traute.javac.text;

import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.common.util.TrauteConstants;
import tech.harmonysoft.oss.traute.javac.instrumentation.parameter.ParameterToInstrumentInfo;

import java.util.HashSet;
import java.util.Set;

import static java.util.Collections.singletonList;

public class ParameterCheckExceptionTextGeneratorSpi implements ExceptionTextGeneratorSpi {

    private final Set supportedVariables = new HashSet<>(singletonList(
            TrauteConstants.VARIABLE_PARAMETER_NAME
    ));

    @NotNull
    @Override
    public Set getSupportedVariables() {
        return supportedVariables;
    }

    @NotNull
    @Override
    public String getVariableValue(@NotNull String variableName, @NotNull ParameterToInstrumentInfo context) {
        switch (variableName) {
            case TrauteConstants.VARIABLE_PARAMETER_NAME:
                return context.getMethodParameter().getName().toString();
            default:
                throw new IllegalArgumentException(String.format(
                        "Can't map variable with name '%s' to data from the %s. Make sure to use only supported "
                        + "variables: %s", variableName, context.getClass().getName(), getSupportedVariables()
                ));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy