@Test public void works_with_escaped_parenthesis() { String expr = "Across the line\\(s\\)"; String step = "Across the line(s)"; List<?> match = match(compile(expr), step); assertEquals(emptyList(), match); }
@Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } final ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); final List<ParameterType<?>> parameterTypes = new ArrayList<>(); int typeHintIndex = 0; for (GroupBuilder groupBuilder : treeRegexp.getGroupBuilder().getChildren()) { final String parameterTypeRegexp = groupBuilder.getSource(); boolean hasTypeHint = typeHintIndex < typeHints.length; final Type typeHint = hasTypeHint ? typeHints[typeHintIndex++] : String.class; ParameterType<?> parameterType = parameterTypeRegistry.lookupByRegexp(parameterTypeRegexp, expressionRegexp, text); if (parameterType != null && hasTypeHint && !parameterType.useRegexpMatchAsStrongTypeHint()) { if (!parameterType.getType().equals(typeHint)) { parameterType = null; } } if (parameterType == null) { parameterType = createAnonymousParameterType(parameterTypeRegexp); } if (parameterType.isAnonymous()) { parameterType = parameterType.deAnonymize(typeHint, arg -> defaultTransformer.transform(arg, typeHint)); } parameterTypes.add(parameterType); } return Argument.build(group, treeRegexp, parameterTypes); }
RegularExpression implements Expression { @Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } final ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); final List<ParameterType<?>> parameterTypes = new ArrayList<>(); int typeHintIndex = 0; for (GroupBuilder groupBuilder : treeRegexp.getGroupBuilder().getChildren()) { final String parameterTypeRegexp = groupBuilder.getSource(); boolean hasTypeHint = typeHintIndex < typeHints.length; final Type typeHint = hasTypeHint ? typeHints[typeHintIndex++] : String.class; ParameterType<?> parameterType = parameterTypeRegistry.lookupByRegexp(parameterTypeRegexp, expressionRegexp, text); if (parameterType != null && hasTypeHint && !parameterType.useRegexpMatchAsStrongTypeHint()) { if (!parameterType.getType().equals(typeHint)) { parameterType = null; } } if (parameterType == null) { parameterType = createAnonymousParameterType(parameterTypeRegexp); } if (parameterType.isAnonymous()) { parameterType = parameterType.deAnonymize(typeHint, arg -> defaultTransformer.transform(arg, typeHint)); } parameterTypes.add(parameterType); } return Argument.build(group, treeRegexp, parameterTypes); } }
RegularExpression implements Expression { @Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } final ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); final List<ParameterType<?>> parameterTypes = new ArrayList<>(); int typeHintIndex = 0; for (GroupBuilder groupBuilder : treeRegexp.getGroupBuilder().getChildren()) { final String parameterTypeRegexp = groupBuilder.getSource(); boolean hasTypeHint = typeHintIndex < typeHints.length; final Type typeHint = hasTypeHint ? typeHints[typeHintIndex++] : String.class; ParameterType<?> parameterType = parameterTypeRegistry.lookupByRegexp(parameterTypeRegexp, expressionRegexp, text); if (parameterType != null && hasTypeHint && !parameterType.useRegexpMatchAsStrongTypeHint()) { if (!parameterType.getType().equals(typeHint)) { parameterType = null; } } if (parameterType == null) { parameterType = createAnonymousParameterType(parameterTypeRegexp); } if (parameterType.isAnonymous()) { parameterType = parameterType.deAnonymize(typeHint, arg -> defaultTransformer.transform(arg, typeHint)); } parameterTypes.add(parameterType); } return Argument.build(group, treeRegexp, parameterTypes); } RegularExpression(Pattern expressionRegexp, ParameterTypeRegistry parameterTypeRegistry); }
RegularExpression implements Expression { @Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } final ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); final List<ParameterType<?>> parameterTypes = new ArrayList<>(); int typeHintIndex = 0; for (GroupBuilder groupBuilder : treeRegexp.getGroupBuilder().getChildren()) { final String parameterTypeRegexp = groupBuilder.getSource(); boolean hasTypeHint = typeHintIndex < typeHints.length; final Type typeHint = hasTypeHint ? typeHints[typeHintIndex++] : String.class; ParameterType<?> parameterType = parameterTypeRegistry.lookupByRegexp(parameterTypeRegexp, expressionRegexp, text); if (parameterType != null && hasTypeHint && !parameterType.useRegexpMatchAsStrongTypeHint()) { if (!parameterType.getType().equals(typeHint)) { parameterType = null; } } if (parameterType == null) { parameterType = createAnonymousParameterType(parameterTypeRegexp); } if (parameterType.isAnonymous()) { parameterType = parameterType.deAnonymize(typeHint, arg -> defaultTransformer.transform(arg, typeHint)); } parameterTypes.add(parameterType); } return Argument.build(group, treeRegexp, parameterTypes); } RegularExpression(Pattern expressionRegexp, ParameterTypeRegistry parameterTypeRegistry); @Override List<Argument<?>> match(String text, Type... typeHints); @Override Pattern getRegexp(); @Override String getSource(); }
RegularExpression implements Expression { @Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } final ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); final List<ParameterType<?>> parameterTypes = new ArrayList<>(); int typeHintIndex = 0; for (GroupBuilder groupBuilder : treeRegexp.getGroupBuilder().getChildren()) { final String parameterTypeRegexp = groupBuilder.getSource(); boolean hasTypeHint = typeHintIndex < typeHints.length; final Type typeHint = hasTypeHint ? typeHints[typeHintIndex++] : String.class; ParameterType<?> parameterType = parameterTypeRegistry.lookupByRegexp(parameterTypeRegexp, expressionRegexp, text); if (parameterType != null && hasTypeHint && !parameterType.useRegexpMatchAsStrongTypeHint()) { if (!parameterType.getType().equals(typeHint)) { parameterType = null; } } if (parameterType == null) { parameterType = createAnonymousParameterType(parameterTypeRegexp); } if (parameterType.isAnonymous()) { parameterType = parameterType.deAnonymize(typeHint, arg -> defaultTransformer.transform(arg, typeHint)); } parameterTypes.add(parameterType); } return Argument.build(group, treeRegexp, parameterTypes); } RegularExpression(Pattern expressionRegexp, ParameterTypeRegistry parameterTypeRegistry); @Override List<Argument<?>> match(String text, Type... typeHints); @Override Pattern getRegexp(); @Override String getSource();  }