001: /*****************************************************************************
002: * *
003: * This file is part of the BeanShell Java Scripting distribution. *
004: * Documentation and updates may be found at http://www.beanshell.org/ *
005: * *
006: * Sun Public License Notice: *
007: * *
008: * The contents of this file are subject to the Sun Public License Version *
009: * 1.0 (the "License"); you may not use this file except in compliance with *
010: * the License. A copy of the License is available at http://www.sun.com *
011: * *
012: * The Original Code is BeanShell. The Initial Developer of the Original *
013: * Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright *
014: * (C) 2000. All Rights Reserved. *
015: * *
016: * GNU Public License Notice: *
017: * *
018: * Alternatively, the contents of this file may be used under the terms of *
019: * the GNU Lesser General Public License (the "LGPL"), in which case the *
020: * provisions of LGPL are applicable instead of those above. If you wish to *
021: * allow use of your version of this file only under the terms of the LGPL *
022: * and not to allow others to use your version of this file under the SPL, *
023: * indicate your decision by deleting the provisions above and replace *
024: * them with the notice and other provisions required by the LGPL. If you *
025: * do not delete the provisions above, a recipient may use your version of *
026: * this file under either the SPL or the LGPL. *
027: * *
028: * Patrick Niemeyer (pat@pat.net) *
029: * Author of Learning Java, O'Reilly & Associates *
030: * http://www.pat.net/~pat/ *
031: * *
032: *****************************************************************************/package org.gjt.sp.jedit.bsh;
033:
034: /**
035: */
036: class BSHClassDeclaration extends SimpleNode {
037: /**
038: The class instance initializer method name.
039: A BshMethod by this name is installed by the class delcaration into
040: the static class body namespace.
041: It is called once to initialize the static members of the class space
042: and each time an instances is created to initialize the instance
043: members.
044: */
045: static final String CLASSINITNAME = "_bshClassInit";
046:
047: String name;
048: Modifiers modifiers;
049: int numInterfaces;
050: boolean extend;
051: boolean isInterface;
052:
053: BSHClassDeclaration(int id) {
054: super (id);
055: }
056:
057: /**
058: */
059: public Object eval(CallStack callstack, Interpreter interpreter)
060: throws EvalError {
061: int child = 0;
062:
063: // resolve superclass if any
064: Class super Class = null;
065: if (extend) {
066: BSHAmbiguousName super Node = (BSHAmbiguousName) jjtGetChild(child++);
067: super Class = super Node.toClass(callstack, interpreter);
068: }
069:
070: // Get interfaces
071: Class[] interfaces = new Class[numInterfaces];
072: for (int i = 0; i < numInterfaces; i++) {
073: BSHAmbiguousName node = (BSHAmbiguousName) jjtGetChild(child++);
074: interfaces[i] = node.toClass(callstack, interpreter);
075: if (!interfaces[i].isInterface())
076: throw new EvalError("Type: " + node.text
077: + " is not an interface!", this , callstack);
078: }
079:
080: BSHBlock block;
081: // Get the class body BSHBlock
082: if (child < jjtGetNumChildren())
083: block = (BSHBlock) jjtGetChild(child);
084: else
085: block = new BSHBlock(ParserTreeConstants.JJTBLOCK);
086:
087: try {
088: return ClassGenerator.getClassGenerator().generateClass(
089: name, modifiers, interfaces, super Class, block,
090: isInterface, callstack, interpreter);
091: } catch (UtilEvalError e) {
092: throw e.toEvalError(this , callstack);
093: }
094:
095: }
096:
097: public String toString() {
098: return "ClassDeclaration: " + name;
099: }
100: }
|