001: // ============================================================================
002: // $Id: FunctorRef.java,v 1.6 2005/12/17 04:16:18 davidahall Exp $
003: // Copyright (c) 2004-2005 David A. Hall
004: // ============================================================================
005: // The contents of this file are subject to the Common Development and
006: // Distribution License (CDDL), Version 1.0 (the License); you may not use this
007: // file except in compliance with the License. You should have received a copy
008: // of the the License along with this file: if not, a copy of the License is
009: // available from Sun Microsystems, Inc.
010: //
011: // http://www.sun.com/cddl/cddl.html
012: //
013: // From time to time, the license steward (initially Sun Microsystems, Inc.) may
014: // publish revised and/or new versions of the License. You may not use,
015: // distribute, or otherwise make this file available under subsequent versions
016: // of the License.
017: //
018: // Alternatively, the contents of this file may be used under the terms of the
019: // GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
020: // case the provisions of the LGPL are applicable instead of those above. If you
021: // wish to allow use of your version of this file only under the terms of the
022: // LGPL, and not to allow others to use your version of this file under the
023: // terms of the CDDL, indicate your decision by deleting the provisions above
024: // and replace them with the notice and other provisions required by the LGPL.
025: // If you do not delete the provisions above, a recipient may use your version
026: // of this file under the terms of either the CDDL or the LGPL.
027: //
028: // This library is distributed in the hope that it will be useful,
029: // but WITHOUT ANY WARRANTY; without even the implied warranty of
030: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
031: // ============================================================================
032:
033: package net.sf.jga.parser;
034:
035: /**
036: * Contains and describes a functor being built by the functor parser. Many of the
037: * parsing methods return and/or accept instances of this interface that describe a
038: * functor, describe its broad type, the number, names, and types of its arguments,
039: * and the type returned.
040: * <p>
041: * Copyright © 2004-2005 David A. Hall
042: * @author <a href="mailto:davidahall@users.sf.net">David A. Hall</a>
043: */
044:
045: public interface FunctorRef<T> {
046:
047: /**
048: * Returns the functor to which this refers.
049: */
050: public T getFunctor();
051:
052: /**
053: * value returned by <tt>getReferenceType()</tt> for constants. A constant is
054: * by definition a Generator, and many constant expressions can be evaluated at
055: * parse time.
056: */
057:
058: static public final int CONSTANT = -2;
059:
060: /**
061: * value returned by <tt>getReferenceType()</tt> when it refers to an Identity.
062: * An Identity is by definition a UnaryFunctor, and in many cases, binding an
063: * Identity is unnecessary. Singling out this special case reduces the complexity
064: * of many functors that are produced.
065: */
066:
067: static public final int IDENTITY = -1;
068:
069: /**
070: * value returned by <tt>getReferenceType()</tt> when it refers to a generator.
071: */
072:
073: static public final int GENERATOR = 0;
074:
075: /**
076: * value returned by <tt>getReferenceType()</tt> when it refers to a unary functor.
077: */
078:
079: static public final int UNARY_FN = 1;
080:
081: /**
082: * value returned by <tt>getReferenceType()</tt> when it refers to a binary functor.
083: */
084:
085: static public final int BINARY_FN = 2;
086:
087: /**
088: * returns the type of objects that the current functor returns.
089: */
090: public Class getReturnType();
091:
092: /**
093: * returns the number of arguments that the current functor requires. Currently,
094: * the implementations tend to be hard coded.
095: */
096: public int getNumberArgs();
097:
098: /**
099: * returns the type of the i'th argument to the current functor.
100: * @throws IllegalArgumentException if the current functor takes fewer than i
101: * arguments (or if i is < 0)
102: */
103: public Class getArgType(int i);
104:
105: /**
106: * returns the name of the i'th argument to the current functor, as described
107: * in the expression being parsed.
108: * @throws IllegalArgumentException if the current functor takes fewer than i
109: * arguments (or if i is < 0)
110: */
111: public String getArgName(int i);
112:
113: /**
114: * returns a value that classifies the functor by the number of arguments that
115: * it requires.
116: */
117: public int getReferenceType();
118:
119: }
|