FileDocCategorySizeDatePackage
Rule.javaAPI DocGlassfish v2 API4173Wed Aug 30 15:34:16 BST 2006persistence.antlr.preprocessor

Rule

public class Rule extends Object

Fields Summary
protected String
name
protected String
block
protected String
args
protected String
returnValue
protected String
throwsSpec
protected String
initAction
protected IndexedVector
options
protected String
visibility
protected Grammar
enclosingGrammar
protected boolean
bang
Constructors Summary
public Rule(String n, String b, IndexedVector options, Grammar gr)


             
        name = n;
        block = b;
        this.options = options;
        setEnclosingGrammar(gr);
    
Methods Summary
public java.lang.StringgetArgs()

        return args;
    
public booleangetBang()

        return bang;
    
public java.lang.StringgetName()

        return name;
    
public java.lang.StringgetReturnValue()

        return returnValue;
    
public java.lang.StringgetVisibility()

        return visibility;
    
public booleannarrowerVisibility(persistence.antlr.preprocessor.Rule rule)
If 'rule' narrows the visible of 'this', return true; For example, 'this' is public and 'rule' is private, true is returned. You cannot narrow the vis. of a rule.

        if (visibility.equals("public")) {
            if (!rule.equals("public")) {
                return true;	// everything narrower than public
            }
            return false;
        }
        else if (visibility.equals("protected")) {
            if (rule.equals("private")) {
                return true;	// private narrower than protected
            }
            return false;
        }
        else if (visibility.equals("private")) {
            return false;	// nothing is narrower than private
        }
        return false;
    
public booleansameSignature(persistence.antlr.preprocessor.Rule rule)
Two rules have the same signature if they have: same name same return value same args I do a simple string compare now, but later the type could be pulled out so it is insensitive to names of args etc...

        boolean nSame = true;
        boolean aSame = true;
        boolean rSame = true;

        nSame = name.equals(rule.getName());
        if (args != null) {
            aSame = args.equals(rule.getArgs());
        }
        if (returnValue != null) {
            rSame = returnValue.equals(rule.getReturnValue());
        }
        return nSame && aSame && rSame;
    
public voidsetArgs(java.lang.String a)

        args = a;
    
public voidsetBang()

        bang = true;
    
public voidsetEnclosingGrammar(persistence.antlr.preprocessor.Grammar g)

        enclosingGrammar = g;
    
public voidsetInitAction(java.lang.String a)

        initAction = a;
    
public voidsetOptions(persistence.antlr.collections.impl.IndexedVector options)

        this.options = options;
    
public voidsetReturnValue(java.lang.String ret)

        returnValue = ret;
    
public voidsetThrowsSpec(java.lang.String t)

        throwsSpec = t;
    
public voidsetVisibility(java.lang.String v)

        visibility = v;
    
public java.lang.StringtoString()

        String s = "";
        String retString = returnValue == null ? "" : "returns " + returnValue;
        String argString = args == null ? "" : args;
        String bang = getBang() ? "!" : "";

        s += visibility == null ? "" : visibility + " ";
        s += name + bang + argString + " " + retString + throwsSpec;
        if (options != null) {
            s += System.getProperty("line.separator") +
                "options {" +
                System.getProperty("line.separator");
            for (Enumeration e = options.elements(); e.hasMoreElements();) {
                s += (Option)e.nextElement() + System.getProperty("line.separator");
            }
            s += "}" + System.getProperty("line.separator");
        }
        if (initAction != null) {
            s += initAction + System.getProperty("line.separator");
        }
        s += block;
        return s;