Search in sources :

Example 11 with Pattern

use of org.apache.oro.text.regex.Pattern in project tdi-studio-se by Talend.

the class MapperComponent method hasOrRenameData.

/**
     * 
     * DOC amaumont Comment method "hasOrRenameData".
     * 
     * @param oldName
     * @param newName can be null if <code>renameAction</code> is false
     * @param renameAction true to rename in all expressions, false to get boolean if present in one of the expressions
     * @return
     */
@Override
protected boolean hasOrRenameData(String oldName, String newName, boolean renameAction) {
    if (oldName == null || newName == null && renameAction) {
        throw new NullPointerException();
    }
    if (externalData != null) {
        List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
        tables.addAll(externalData.getOutputTables());
        if (externalData.getVarsTables() != null) {
            tables.addAll(externalData.getVarsTables());
        }
        for (ExternalMapperTable table : tables) {
            if (table.getExpressionFilter() != null) {
                Pattern pattern = getRenamePattern(oldName);
                if (pattern != null) {
                    PatternMatcher matcher = new Perl5Matcher();
                    ((Perl5Matcher) matcher).setMultiline(true);
                    if (renameAction) {
                        Perl5Substitution substitution = getRenameSubstitution(newName);
                        String expression = renameDataIntoExpression(pattern, matcher, substitution, table.getExpressionFilter());
                        table.setExpressionFilter(expression);
                    } else {
                        if (hasDataIntoExpression(pattern, matcher, table.getExpressionFilter())) {
                            return true;
                        }
                    }
                }
            }
            List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
            if (metadataTableEntries != null) {
                // loop on all entries of current table
                for (ExternalMapperTableEntry entry : metadataTableEntries) {
                    if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
                        // existed
                        return true;
                    }
                }
            // for (ExternalMapperTableEntry entry : metadataTableEntries) {
            }
            if (table.getConstraintTableEntries() != null) {
                for (ExternalMapperTableEntry entry : table.getConstraintTableEntries()) {
                    if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
                        // existed
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ArrayList(java.util.ArrayList) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 12 with Pattern

use of org.apache.oro.text.regex.Pattern in project tdi-studio-se by Talend.

the class MapDataDelegateHelper method matchExpression.

private boolean matchExpression(String regex, String expression) {
    PatternCompiler compiler = new Perl5Compiler();
    try {
        //$NON-NLS-1$ //$NON-NLS-2$
        Pattern pattern = compiler.compile("\\b(" + UpdateContextVariablesHelper.replaceSpecialChar(regex) + ")(\\b|\\_)");
        PatternMatcher matcher = new Perl5Matcher();
        ((Perl5Matcher) matcher).setMultiline(true);
        if (matcher.contains(expression, pattern)) {
            return true;
        }
    } catch (MalformedPatternException e) {
    //
    }
    return false;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 13 with Pattern

use of org.apache.oro.text.regex.Pattern in project intellij-plugins by JetBrains.

the class CucumberStepsIndex method findStepDefinitions.

/**
   * Searches for ALL step definitions, groups it by step definition class and sorts by pattern size.
   * For each step definition class it finds the largest pattern.
   *
   * @param featureFile file with steps
   * @param step        step itself
   * @return definitions
   */
@NotNull
public Collection<AbstractStepDefinition> findStepDefinitions(@NotNull final PsiFile featureFile, @NotNull final GherkinStep step) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(featureFile);
    if (module == null) {
        return Collections.emptyList();
    }
    Map<Class<? extends AbstractStepDefinition>, AbstractStepDefinition> definitionsByClass = new java.util.HashMap<>();
    List<AbstractStepDefinition> allSteps = loadStepsFor(featureFile, module);
    for (AbstractStepDefinition stepDefinition : allSteps) {
        if (stepDefinition.matches(step.getSubstitutedName()) && stepDefinition.supportsStep(step)) {
            final Pattern currentLongestPattern = getPatternByDefinition(definitionsByClass.get(stepDefinition.getClass()));
            final Pattern newPattern = getPatternByDefinition(stepDefinition);
            final int newPatternLength = ((newPattern != null) ? newPattern.getPattern().length() : -1);
            if ((currentLongestPattern == null) || (currentLongestPattern.getPattern().length() < newPatternLength)) {
                definitionsByClass.put(stepDefinition.getClass(), stepDefinition);
            }
        }
    }
    return definitionsByClass.values();
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) HashMap(com.intellij.util.containers.HashMap) Module(com.intellij.openapi.module.Module) CucumberJvmExtensionPoint(org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint) OptionalStepDefinitionExtensionPoint(org.jetbrains.plugins.cucumber.OptionalStepDefinitionExtensionPoint) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with Pattern

use of org.apache.oro.text.regex.Pattern in project intellij-plugins by JetBrains.

the class JavaStepDefinition method matches.

@Override
public boolean matches(String stepName) {
    Pattern perlPattern = getPattern();
    if (perlPattern != null) {
        final java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(perlPattern.getPattern());
        Matcher m = pattern.matcher(stepName);
        return m.matches();
    }
    return false;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 15 with Pattern

use of org.apache.oro.text.regex.Pattern in project Lucee by lucee.

the class Perl5Util method match.

public static Array match(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
    Perl5Matcher matcher = new Perl5Matcher();
    PatternMatcherInput input = new PatternMatcherInput(strInput);
    int compileOptions = caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
    compileOptions += Perl5Compiler.MULTILINE_MASK;
    if (offset < 1)
        offset = 1;
    Pattern pattern = getPattern(strPattern, compileOptions);
    Array rtn = new ArrayImpl();
    MatchResult result;
    while (matcher.contains(input, pattern)) {
        result = matcher.getMatch();
        rtn.appendEL(result.toString());
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) ArrayImpl(lucee.runtime.type.ArrayImpl) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult)

Aggregations

Pattern (org.apache.oro.text.regex.Pattern)70 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)48 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)27 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)24 MatchResult (org.apache.oro.text.regex.MatchResult)17 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)14 ArrayList (java.util.ArrayList)12 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)9 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)7 IOException (java.io.IOException)6 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)6 MalformedURLException (java.net.MalformedURLException)4 BufferedReader (java.io.BufferedReader)3 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)3 EOFException (java.io.EOFException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2