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;
}
}
Aggregations