private boolean shouldBeSkippedByAnnotationPattern(ClassReader reader) { if (myClassFilterAnnotationRegexpList.isEmpty()) { return false; } final boolean[] result = new boolean[]{false}; reader.accept(new ClassVisitor(Opcodes.ASM5) { public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (!result[0]) { String internalName = Type.getType(desc).getInternalName(); for (Regexp regexp : myClassFilterAnnotationRegexpList) { if (regexp.matches(internalName)) { result[0] = true; break; } } } return null; } }, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); return result[0]; }
protected String doReplace() throws BuildException { if (replace == null) throw new BuildException("No replace expression specified."); int options = 0; if (!caseSensitive) options |= Regexp.MATCH_CASE_INSENSITIVE; if (global) options |= Regexp.REPLACE_ALL; Regexp sregex = regexp.getRegexp(project); String output = null; if (sregex.matches(input, options)) { String expression = replace.getExpression(project); output = sregex.substitute(input, expression, options); } if (output == null) output = defaultValue; return output; }
protected String doSelect() throws BuildException { int options = 0; if (!caseSensitive) options |= Regexp.MATCH_CASE_INSENSITIVE; Regexp sregex = regexp.getRegexp(project); String output = select; Vector groups = sregex.getGroups(input, options); if (groups != null && groups.size() > 0) { output = RegexUtil.select(select, groups); } else { output = null; } if (output == null) output = defaultValue; return output; }
/** * Invoke a regular expression (r) on a string (input) using * substitutions (s) for a matching regex. * * @param r a regular expression * @param s a Substitution * @param input the string to do the replacement on * @param options The options for the regular expression * @return the replacement result */ protected String doReplace(RegularExpression r, Substitution s, String input, int options) { String res = input; Regexp regexp = r.getRegexp(getProject()); if (regexp.matches(input, options)) { log("Found match; substituting", Project.MSG_DEBUG); res = regexp.substitute(input, s.getExpression(getProject()), options); } return res; }
/** * provides a reference to the Regexp contained in this * @param p project * @return Regexp instance associated with this RegularExpression instance */ public Regexp getRegexp(Project p) { init(p); if (isReference()) { return getRef(p).getRegexp(p); } setPattern(); return this.regexp; }
/** * @return true if the string matches the regular expression pattern * @exception BuildException if the attributes are not set correctly */ public boolean eval() throws BuildException { if (string == null) { throw new BuildException( "Parameter string is required in matches."); } if (regularExpression == null) { throw new BuildException("Missing pattern in matches."); } int options = RegexpUtil.asOptions(caseSensitive, multiLine, singleLine); Regexp regexp = regularExpression.getRegexp(getProject()); return regexp.matches(string, options); }
/** * Returns the next character in the filtered stream, only including * lines from the original stream which match all of the specified * regular expressions. * * @return the next character in the resulting stream, or -1 * if the end of the resulting stream has been reached * * @exception IOException if the underlying stream throws an IOException * during reading */ public int read() throws IOException { if (!getInitialized()) { initialize(); setInitialized(true); } int ch = -1; if (line != null) { ch = line.charAt(0); if (line.length() == 1) { line = null; } else { line = line.substring(1); } } else { final int regexpsSize = regexps.size(); for (line = readLine(); line != null; line = readLine()) { boolean matches = true; for (int i = 0; matches && i < regexpsSize; i++) { RegularExpression regexp = (RegularExpression) regexps.elementAt(i); Regexp re = regexp.getRegexp(getProject()); matches = re.matches(line, regexpOptions); } if (matches ^ isNegated()) { break; } } if (line != null) { return read(); } } return ch; }
/** * Creates a new LineContainsRegExp using the passed in * Reader for instantiation. * * @param rdr A Reader object providing the underlying stream. * Must not be <code>null</code>. * * @return a new filter based on this configuration, but filtering * the specified reader */ public Reader chain(final Reader rdr) { LineContainsRegExp newFilter = new LineContainsRegExp(rdr); newFilter.setRegexps(getRegexps()); newFilter.setNegate(isNegated()); newFilter .setCaseSensitive(!RegexpUtil.hasFlag(regexpOptions, Regexp.MATCH_CASE_INSENSITIVE) ); return newFilter; }
private String performMatching(final String input) { final Regexp regexp = this.pattern.getRegexp(getProject()); final Vector groups = regexp.getGroups(input, 0); if (groups != null && !groups.isEmpty()) { String output = select; final int count = groups.size(); for (int i = 0; i < count; i++) { final String group = (String) groups.get(i); output = output.replace("\\" + i, group); } return output; } return null; }
private boolean lineMatches(final String line, final Regexp[] regexps) { for (Regexp regexp : regexps) { if (regexp.matches(line)) { return true; } } return false; }
/** Default Constructor */ public SelectRegExp() { super(); this.file = null; this.filesets = new Vector<FileSet>(); this.regexList = new Vector<Regexp>(); this.flags = ""; }
/** * Adds a set of files to count. */ @SuppressWarnings("deprecation") public void addConfiguredRegexp(RegularExpression regex) { Regexp regexp = regex.getRegexp(project); regexList.add(regexp); }