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

com.exasol.errorcodecrawlermavenplugin.crawler.AbstractTextWithParametersStepReader Maven / Gradle / Ivy

package com.exasol.errorcodecrawlermavenplugin.crawler;

import java.nio.file.Path;
import java.util.List;
import java.util.Set;

import com.exasol.errorreporting.ErrorMessageBuilder;
import com.exsol.errorcodemodel.ErrorMessageDeclaration;

import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtInvocation;

/**
 * Abstract basis for step readers that read from method that have one String parameter with placeholders followed by
 * inline parameters values.
 */
abstract class AbstractTextWithParametersStepReader implements MessageBuilderStepReader {
    private final Set supportedSignatures;

    /**
     * Create a new instance of {@link AbstractTextWithParametersStepReader}.
     * 
     * @param supportedSignatures set of supported signatures
     */
    AbstractTextWithParametersStepReader(final Set supportedSignatures) {
        this.supportedSignatures = supportedSignatures;
    }

    /**
     * Add the text of message / mitigation to the error code builder.
     * 
     * @param text             text to add
     * @param errorCodeBuilder error code builder to add the text to
     */
    abstract void addTextToBuilder(final String text, final ErrorMessageDeclaration.Builder errorCodeBuilder);

    @Override
    public void read(final CtInvocation builderCall, final ErrorMessageDeclaration.Builder errorCodeBuilder,
            final Path projectDirectory) throws InvalidSyntaxException {
        final List> arguments = builderCall.getArguments();
        assert !arguments.isEmpty();
        final CtExpression messageArgument = arguments.get(0);
        final var text = new ArgumentReader(builderCall.getExecutable().getSignature())
                .readStringArgumentValue(messageArgument);
        addTextToBuilder(text, errorCodeBuilder);
        new DirectParameterReader().readInlineParameters(arguments.size() - 1, text, errorCodeBuilder);
    }

    @Override
    public boolean canRead(final String className, final String methodSignature) {
        return className.equals(ErrorMessageBuilder.class.getSimpleName())
                && this.supportedSignatures.contains(methodSignature);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy