You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RegexpFactory.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Common Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/cpl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. // todo: non-distribution license?
  14. package org.aspectj.testing.compare;
  15. // currently in aspectj-external-lib/regexp
  16. import org.apache.regexp.RE;
  17. import java.util.Vector;
  18. /** Factory for our Regexp. */
  19. public class RegexpFactory {
  20. public static Regexp makeRegexp() {
  21. return new RegExpDelegate();
  22. }
  23. }
  24. /** Implement Regexp by delegating to org.apache.regexp.RE */
  25. final class RegExpDelegate implements Regexp {
  26. String pattern;
  27. RE regexp;
  28. public RegExpDelegate() { }
  29. public Vector getGroups(String arg) {
  30. String label = "getGroups(\"" + arg + "\") ";
  31. D.log(label);
  32. Vector result = null;
  33. if ((null != arg) && (matches(arg))) {
  34. int size = regexp.getParenCount();
  35. D.log(label + " size " + size);
  36. result = new Vector(size);
  37. for (int i = 0; i < size; i++) {
  38. Object item = regexp.getParen(i);
  39. result.addElement(item);
  40. D.log(label + i + ": " + item);
  41. }
  42. }
  43. return result;
  44. }
  45. public boolean matches(String arg) {
  46. return ((null != regexp) && regexp.match(arg));
  47. }
  48. public void setPattern(String pattern) throws Exception {
  49. this.pattern = pattern;
  50. regexp = new RE(this.pattern);
  51. D.log("RE: " + regexp + " pattern: /" + pattern + "/");
  52. }
  53. public String getPattern() {
  54. return pattern;
  55. }
  56. }