KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > JavaExpression


1 /*
2  * JavaExpression.java
3  *
4  * Copyright (C) 2002 Peter Graves
5  * $Id: JavaExpression.java,v 1.1.1.1 2002/09/24 16:08:44 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 /**
25  * A JavaExpression represents an instance of a method call in Java source.
26  */

27 public final class JavaExpression extends Expression implements Constants
28 {
29     private final int type; // TAG_METHOD etc.
30

31     public JavaExpression(String JavaDoc name, int arity)
32     {
33         super(name, arity);
34         type = TAG_METHOD;
35     }
36
37     public JavaExpression(String JavaDoc name, int arity, int type)
38     {
39         super(name, arity);
40         this.type = type;
41     }
42
43     public final int getType()
44     {
45         return type;
46     }
47
48     public boolean matches(LocalTag tag)
49     {
50         if (!name.equals(tag.getMethodName()))
51             return false;
52         if (type == TAG_METHOD && tag.getType() != TAG_METHOD)
53             return false;
54         if (type == TAG_UNKNOWN && tag.getType() == TAG_METHOD)
55             return false;
56         if (arity >= 0) {
57             int n = getArity(tag.getCanonicalSignature());
58             if (n < 0 || n == arity)
59                 return true;
60             else
61                 return false;
62         }
63         return true;
64     }
65
66     public boolean equals(Object JavaDoc obj)
67     {
68         if (this == obj)
69             return true;
70         if (obj instanceof JavaExpression) {
71             JavaExpression expr = (JavaExpression) obj;
72             if (arity != expr.arity)
73                 return false;
74             if (type != expr.type)
75                 return false;
76             if (name == expr.name || (name != null && name.equals(expr.name)))
77                 return true;
78         }
79         return false;
80     }
81
82     public String JavaDoc toString()
83     {
84         FastStringBuffer sb = new FastStringBuffer();
85         switch (type) {
86             case TAG_UNKNOWN:
87                 sb.append("TAG_UNKNOWN ");
88                 break;
89             case TAG_CLASS:
90                 sb.append("TAG_CLASS ");
91                 break;
92             case TAG_METHOD:
93                 sb.append("TAG_METHOD ");
94                 break;
95             default:
96                 sb.append(type);
97                 sb.append(' ');
98                 break;
99         }
100         sb.append(name);
101         if (type == TAG_METHOD) {
102             sb.append(' ');
103             sb.append(arity);
104         }
105         return sb.toString();
106     }
107 }
108
Popular Tags