001: /*
002: * JavaExpression.java
003: *
004: * Copyright (C) 2002 Peter Graves
005: * $Id: JavaExpression.java,v 1.1.1.1 2002/09/24 16:08:44 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: /**
025: * A JavaExpression represents an instance of a method call in Java source.
026: */
027: public final class JavaExpression extends Expression implements
028: Constants {
029: private final int type; // TAG_METHOD etc.
030:
031: public JavaExpression(String name, int arity) {
032: super (name, arity);
033: type = TAG_METHOD;
034: }
035:
036: public JavaExpression(String name, int arity, int type) {
037: super (name, arity);
038: this .type = type;
039: }
040:
041: public final int getType() {
042: return type;
043: }
044:
045: public boolean matches(LocalTag tag) {
046: if (!name.equals(tag.getMethodName()))
047: return false;
048: if (type == TAG_METHOD && tag.getType() != TAG_METHOD)
049: return false;
050: if (type == TAG_UNKNOWN && tag.getType() == TAG_METHOD)
051: return false;
052: if (arity >= 0) {
053: int n = getArity(tag.getCanonicalSignature());
054: if (n < 0 || n == arity)
055: return true;
056: else
057: return false;
058: }
059: return true;
060: }
061:
062: public boolean equals(Object obj) {
063: if (this == obj)
064: return true;
065: if (obj instanceof JavaExpression) {
066: JavaExpression expr = (JavaExpression) obj;
067: if (arity != expr.arity)
068: return false;
069: if (type != expr.type)
070: return false;
071: if (name == expr.name
072: || (name != null && name.equals(expr.name)))
073: return true;
074: }
075: return false;
076: }
077:
078: public String toString() {
079: FastStringBuffer sb = new FastStringBuffer();
080: switch (type) {
081: case TAG_UNKNOWN:
082: sb.append("TAG_UNKNOWN ");
083: break;
084: case TAG_CLASS:
085: sb.append("TAG_CLASS ");
086: break;
087: case TAG_METHOD:
088: sb.append("TAG_METHOD ");
089: break;
090: default:
091: sb.append(type);
092: sb.append(' ');
093: break;
094: }
095: sb.append(name);
096: if (type == TAG_METHOD) {
097: sb.append(' ');
098: sb.append(arity);
099: }
100: return sb.toString();
101: }
102: }
|