use of com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver in project cobigen by devonfw.
the class TriggerExpressionResolverTest method testEvaluateExpression_isAbstract_invalid.
/**
* Test for {@link TriggerExpressionResolver#evaluateExpression(String)}
*/
@Test
public void testEvaluateExpression_isAbstract_invalid() {
TriggerExpressionResolver target = new TriggerExpressionResolver(getClass());
assertThat(target.evaluateExpression("isAbstract")).isFalse();
}
use of com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver in project cobigen by devonfw.
the class TriggerExpressionResolverTest method testEvaluateExpression_instanceof.
/**
* Test for {@link TriggerExpressionResolver#evaluateExpression(String)}
*/
@Test
public void testEvaluateExpression_instanceof() {
TriggerExpressionResolver target = new TriggerExpressionResolver(TriggerExpressionResolver.class);
assertThat(target.evaluateExpression("instanceof java.lang.String")).isFalse();
assertThat(target.evaluateExpression("instanceof java.lang.Object")).isTrue();
}
use of com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver in project cobigen by devonfw.
the class TriggerExpressionResolverTest method testEvaluateExpression_isAbstract_valid.
/**
* Test for {@link TriggerExpressionResolver#evaluateExpression(String)}
*/
@Test
public void testEvaluateExpression_isAbstract_valid() {
TriggerExpressionResolver target = new TriggerExpressionResolver(AbstractIntegrationTest.class);
assertThat(target.evaluateExpression("isAbstract")).isTrue();
}
use of com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver in project cobigen by devonfw.
the class JavaMatcher method matches.
@Override
public boolean matches(MatcherTo matcher) {
try {
MatcherType matcherType = Enum.valueOf(MatcherType.class, matcher.getType().toUpperCase());
switch(matcherType) {
case FQN:
String fqn = getFqn(matcher);
LOG.debug("Matching input FQN {} against regex '{}'", fqn, matcher.getValue());
return fqn != null && fqn.matches(matcher.getValue());
case PACKAGE:
return matcher.getTarget() instanceof PackageFolder && ((PackageFolder) matcher.getTarget()).getPackageName().matches(matcher.getValue());
case EXPRESSION:
Object target = matcher.getTarget();
if (target instanceof Object[]) {
// expression
if (((Object[]) target)[0] instanceof Class<?>) {
target = ((Object[]) target)[0];
} else {
target = ((Object[]) target)[1];
}
}
if (target instanceof Class<?>) {
TriggerExpressionResolver resolver = new TriggerExpressionResolver((Class<?>) target);
return resolver.evaluateExpression(matcher.getValue());
}
if (target instanceof JavaClass) {
TriggerExpressionResolver resolver = new TriggerExpressionResolver((JavaClass) target);
return resolver.evaluateExpression(matcher.getValue());
}
}
} catch (IllegalArgumentException e) {
LOG.info("Matcher type '{}' not registered --> no match!", matcher.getType());
}
return false;
}
Aggregations