KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > neu > ccs > jmk > Pattern


1 // $Id: Pattern.java,v 1.2 2001/12/07 11:41:24 ramsdell Exp $
2

3 // Pattern rules defined by a makefile.
4

5 /*
6  * Copyright 1997 by John D. Ramsdell
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 package edu.neu.ccs.jmk;
24
25 /**
26  * Pattern rules defined by a makefile.
27  * A pattern rule defines commands that can be used by a rule defined
28  * without commands as long as the rule's target matches the target
29  * of the pattern rule.
30  * @version November 1997
31  * @author John D. Ramsdell
32  */

33 final class Pattern
34 {
35   private Matcher matcher;
36   private String JavaDoc[] prerequisites;
37   private Command[] commands;
38   private int lineNumber;
39
40   /**
41    * Create a pattern rule.
42    */

43   Pattern(String JavaDoc target, String JavaDoc[] prerequisites,
44       Command[] commands, int lineNumber) {
45     matcher = new Matcher(target);
46     this.prerequisites = prerequisites;
47     this.commands = commands;
48     this.lineNumber = lineNumber;
49   }
50
51   /**
52    * Merge a pattern into a rule.
53    * @return true if the targets match and the rule uses the pattern.
54    */

55   boolean merge(Rule rule) {
56     String JavaDoc target = rule.getTarget();
57     String JavaDoc match = matcher.match(target);
58     if (match == null)
59       return false;
60     String JavaDoc[] dependencies = new String JavaDoc[prerequisites.length];
61     for (int i = 0; i < prerequisites.length; i++)
62       dependencies[i] = Matcher.subst(match, prerequisites[i]);
63     return rule.tryPattern(match, dependencies, commands, lineNumber);
64   }
65 }
66
Popular Tags