Search in sources :

Example 16 with CtNamedElement

use of spoon.reflect.declaration.CtNamedElement in project spoon by INRIA.

the class TemplateMatcher method invokeCallBack.

/**
 * invokes {@link ParameterMatcher} associated to the `template` (= template parameter)
 * @param target a potentially matching element
 * @param template a matching parameter, which may define extra {@link ParameterMatcher}
 * @return true if {@link ParameterMatcher} of `template` matches on `target`
 */
private boolean invokeCallBack(Object target, Object template) {
    try {
        if (template instanceof CtInvocation) {
            CtFieldAccess<?> param = (CtFieldAccess<?>) ((CtInvocation<?>) template).getTarget();
            ParameterMatcher instance = getParameterInstance(param.getVariable());
            return instance.match(this, (CtInvocation<?>) template, (CtElement) target);
        } else if (template instanceof CtReference) {
            // Get parameter
            CtReference ref = (CtReference) template;
            ParameterMatcher instance;
            if (ref.getDeclaration() == null || ref.getDeclaration().getAnnotation(Parameter.class) == null) {
                instance = new DefaultParameterMatcher();
            } else {
                Parameter param = ref.getDeclaration().getAnnotation(Parameter.class);
                instance = param.match().newInstance();
            }
            return instance.match(this, (CtReference) template, (CtReference) target);
        } else if (template instanceof CtNamedElement) {
            CtNamedElement named = (CtNamedElement) template;
            ParameterMatcher instance = findParameterMatcher(named);
            return instance.match(this, (CtElement) template, (CtElement) target);
        } else {
            // Should not happen
            throw new RuntimeException();
        }
    } catch (InstantiationException e) {
        Launcher.LOGGER.error(e.getMessage(), e);
        return true;
    } catch (IllegalAccessException e) {
        Launcher.LOGGER.error(e.getMessage(), e);
        return true;
    }
}
Also used : CtFieldAccess(spoon.reflect.code.CtFieldAccess) CtInvocation(spoon.reflect.code.CtInvocation) DefaultParameterMatcher(spoon.support.template.DefaultParameterMatcher) CtReference(spoon.reflect.reference.CtReference) CtParameter(spoon.reflect.declaration.CtParameter) DefaultParameterMatcher(spoon.support.template.DefaultParameterMatcher) ParameterMatcher(spoon.support.template.ParameterMatcher) CtNamedElement(spoon.reflect.declaration.CtNamedElement)

Aggregations

CtNamedElement (spoon.reflect.declaration.CtNamedElement)16 Test (org.junit.Test)5 File (java.io.File)4 Map (java.util.Map)4 CtType (spoon.reflect.declaration.CtType)4 FileReader (java.io.FileReader)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CtElement (spoon.reflect.declaration.CtElement)3 CtReference (spoon.reflect.reference.CtReference)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 AutomaticBuilderFactory (fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory)2 TestCaseJSON (fr.inria.diversify.dspot.selector.json.coverage.TestCaseJSON)2 TestClassJSON (fr.inria.diversify.dspot.selector.json.coverage.TestClassJSON)2 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)2 Counter (fr.inria.diversify.utils.Counter)2 DSpotUtils (fr.inria.diversify.utils.DSpotUtils)2 DSpotCompiler (fr.inria.diversify.utils.compilation.DSpotCompiler)2 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)2