KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > script > Rule


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.source.script;
21
22 import com.sun.tools.javac.tree.*;
23 import com.sun.tools.javac.tree.JCTree.JCErroneous;
24 import com.sun.tools.javac.util.List;
25 import com.sun.tools.javac.util.Position;
26
27 public class Rule {
28     Rule next;
29     JCTree pattern;
30     JCTree replacement;
31     JCTree suchthat;
32     JCTree code;
33     int startLine;
34     Rule(JCTree p, JCTree r, JCTree s, JCTree c, int line) {
35     pattern = p;
36     replacement = r;
37     suchthat = s;
38     code = c;
39         this.startLine = line;
40     }
41     boolean isValid() { return this != invalidRule; }
42     public String JavaDoc toString() {
43     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
44     sb.append(pattern);
45     if(replacement!=null) {
46         sb.append("=>");
47         sb.append(replacement);
48     }
49     if(suchthat!=null) {
50         sb.append("::");
51         sb.append(suchthat);
52     }
53     if(code!=null) {
54         sb.append(" ");
55         sb.append(code);
56     }
57     return sb.toString().replace('\n',' ')/*replaceAll("\\n| +"," ")*/;
58     }
59     
60     private static class ErroneousRule extends JCTree.JCErroneous {
61         ErroneousRule() {
62             super(List.<JCTree>nil());
63         }
64     }
65     public static final Rule invalidRule =
66         new Rule(new ErroneousRule(), null, null, null, -1);
67 }
68
Popular Tags