Search in sources :

Example 1 with TriggerExpressionResolver

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();
}
Also used : TriggerExpressionResolver(com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver) AbstractIntegrationTest(com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with TriggerExpressionResolver

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();
}
Also used : TriggerExpressionResolver(com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver) AbstractIntegrationTest(com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with TriggerExpressionResolver

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();
}
Also used : TriggerExpressionResolver(com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver) AbstractIntegrationTest(com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with TriggerExpressionResolver

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;
}
Also used : TriggerExpressionResolver(com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver) JavaClass(com.thoughtworks.qdox.model.JavaClass) PackageFolder(com.devonfw.cobigen.javaplugin.inputreader.to.PackageFolder) JavaClass(com.thoughtworks.qdox.model.JavaClass)

Aggregations

TriggerExpressionResolver (com.devonfw.cobigen.javaplugin.matcher.resolver.TriggerExpressionResolver)4 AbstractIntegrationTest (com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest)3 Test (org.junit.Test)3 PackageFolder (com.devonfw.cobigen.javaplugin.inputreader.to.PackageFolder)1 JavaClass (com.thoughtworks.qdox.model.JavaClass)1