KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > kawa > lang > Pattern


1 package kawa.lang;
2 import gnu.bytecode.*;
3 import gnu.expr.Compilation;
4 import gnu.text.Printable;
5
6 /**
7  * A Pattern is used to match against objects.
8  * E.g. it can be used to match against macro arguments.
9  * @author Per Bothner
10  */

11
12 abstract public class Pattern implements Printable
13 {
14   /**
15    * Match this Pattern against an object.
16    * @param obj object to match against this pattern
17    * @return null on failure, or an array of bound pattern variables.
18    */

19   public Object JavaDoc[] match (Object JavaDoc obj)
20   {
21     Object JavaDoc[] vars = new Object JavaDoc [varCount ()];
22     return match (obj, vars, 0) ? vars : null;
23   }
24
25   /** Match this Pattern against an Object.
26    * @param obj the Object to match against
27    * @param vars the "pattern variable" values extracted from obj go here
28    * @param start_vars where in vars to strt putting the varCount() values
29    * @return true iff the match succeeded.
30    */

31   abstract public boolean match (Object JavaDoc obj, Object JavaDoc[] vars, int start_vars);
32
33   abstract public int varCount ();
34
35   static public ClassType typePattern = ClassType.make("kawa.lang.Pattern");
36   private static Type[] matchArgs =
37   { Type.pointer_type, Compilation.objArrayType, Type.int_type };
38   static public final Method matchPatternMethod
39   = typePattern.addMethod("match", matchArgs, Type.boolean_type, Access.PUBLIC);
40 }
41
Popular Tags