//# 0 errors, 111 messages
//#
/*
    //#ConditionRuleValidator.java:1:1: class: com.dmdirc.config.prefs.validator.ConditionRuleValidator
    //#ConditionRuleValidator.java:1:1: method: com.dmdirc.config.prefs.validator.ConditionRuleValidator.com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.config.prefs.validator;

import com.dmdirc.actions.ConditionTree;

/**
 * Validates a condition tree.
 */
public class ConditionRuleValidator implements Validator<String> {
    //#ConditionRuleValidator.java:30: method: ValidationResponse com.dmdirc.config.prefs.validator.ConditionRuleValidator.validate(Object)
    //#input(ValidationResponse validate(Object)): " does not exist"._tainted
    //#input(ValidationResponse validate(Object)): "Condition "._tainted
    //#input(ValidationResponse validate(Object)): __Descendant_Table[com/dmdirc/config/prefs/validator/ConditionRuleValidator]
    //#input(ValidationResponse validate(Object)): __Descendant_Table[others]
    //#input(ValidationResponse validate(Object)): __Dispatch_Table.validate(Ljava/lang/String;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): this
    //#input(ValidationResponse validate(Object)): this.__Tag
    //#input(ValidationResponse validate(Object)): this.args
    //#input(ValidationResponse validate(Object)): x0
    //#output(ValidationResponse validate(Object)): java.lang.StringBuilder:toString(...)._tainted
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1*).failure
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#2*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#2*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#2*).failure
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#4*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#4*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#4*).failure
    //#output(ValidationResponse validate(Object)): return_value
    //#new obj(ValidationResponse validate(Object)): java.lang.StringBuilder:toString(...)
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#1*)
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#2*)
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#4*)
    //#pre[2] (ValidationResponse validate(Object)): this.__Tag == com/dmdirc/config/prefs/validator/ConditionRuleValidator
    //#pre[3] (ValidationResponse validate(Object)): (soft) init'ed(this.args)
    //#post(ValidationResponse validate(Object)): java.lang.StringBuilder:toString(...)._tainted == 0
    //#post(ValidationResponse validate(Object)): return_value == One-of{&new ValidationResponse(validate#1*), &new ValidationResponse(validate#2*), &new ValidationResponse(validate#4*)}
    //#post(ValidationResponse validate(Object)): return_value in Addr_Set{&new ValidationResponse(validate#1*),&new ValidationResponse(validate#2*),&new ValidationResponse(validate#4*)}
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1*).failure == &"Invalid rule."
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#2*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#2*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#2*).failure == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#4*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#4*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#4*).failure == null
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:com.dmdirc.actions.ConditionTree:parseString
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:com.dmdirc.actions.ConditionTree:getMaximumArgument
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.StringBuilder:toString
    //#ConditionRuleValidator.java:30: end of method: ValidationResponse com.dmdirc.config.prefs.validator.ConditionRuleValidator.validate(Object)

    /** The number of arguments to the tree. */
    private int args = 0;

    /**
     * Creates a new ConditionRuleValidator.
     *
     * @param args The number of arguments allowed in the ConditionTree (i.e.,
     * the number of ActionConditions)
     */
    public ConditionRuleValidator(final int args) {
    //#ConditionRuleValidator.java:41: method: void com.dmdirc.config.prefs.validator.ConditionRuleValidator.com.dmdirc.config.prefs.validator.ConditionRuleValidator(int)
    //#input(void com.dmdirc.config.prefs.validator.ConditionRuleValidator(int)): args
    //#input(void com.dmdirc.config.prefs.validator.ConditionRuleValidator(int)): this
    //#output(void com.dmdirc.config.prefs.validator.ConditionRuleValidator(int)): this.args
    //#post(void com.dmdirc.config.prefs.validator.ConditionRuleValidator(int)): this.args == args
    //#post(void com.dmdirc.config.prefs.validator.ConditionRuleValidator(int)): init'ed(this.args)
        this.args = args;
    }
    //#ConditionRuleValidator.java:43: end of method: void com.dmdirc.config.prefs.validator.ConditionRuleValidator.com.dmdirc.config.prefs.validator.ConditionRuleValidator(int)
    
    /**
     * Updates the number of arguments used to validate the condition tree.
     * 
     * @param args New number of arguments
     */
    public void setArgs(final int args) {
        this.args = args;
    //#ConditionRuleValidator.java:51: method: void com.dmdirc.config.prefs.validator.ConditionRuleValidator.setArgs(int)
    //#input(void setArgs(int)): args
    //#input(void setArgs(int)): this
    //#output(void setArgs(int)): this.args
    //#post(void setArgs(int)): this.args == args
    //#post(void setArgs(int)): init'ed(this.args)
    }
    //#ConditionRuleValidator.java:52: end of method: void com.dmdirc.config.prefs.validator.ConditionRuleValidator.setArgs(int)

    /** {@inheritDoc} */
    @Override
    public ValidationResponse validate(final String object) {
        final ConditionTree tree = ConditionTree.parseString(object);
    //#ConditionRuleValidator.java:57: method: ValidationResponse com.dmdirc.config.prefs.validator.ConditionRuleValidator.validate(String)
    //#ConditionRuleValidator.java:57: Warning: method not available - call not analyzed
    //#    call on ConditionTree com.dmdirc.actions.ConditionTree:parseString(String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.config.prefs.validator.ConditionRuleValidator
    //#    method: ValidationResponse validate(String)
    //#    unanalyzed callee: ConditionTree com.dmdirc.actions.ConditionTree:parseString(String)
    //#input(ValidationResponse validate(String)): " does not exist"._tainted
    //#input(ValidationResponse validate(String)): "Condition "._tainted
    //#input(ValidationResponse validate(String)): object
    //#input(ValidationResponse validate(String)): this
    //#input(ValidationResponse validate(String)): this.args
    //#output(ValidationResponse validate(String)): java.lang.StringBuilder:toString(...)._tainted
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#1) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#1).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#1).failure
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#2) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#2).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#2).failure
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#4) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#4).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#4).failure
    //#output(ValidationResponse validate(String)): return_value
    //#new obj(ValidationResponse validate(String)): java.lang.StringBuilder:toString(...)
    //#new obj(ValidationResponse validate(String)): new ValidationResponse(validate#1)
    //#new obj(ValidationResponse validate(String)): new ValidationResponse(validate#2)
    //#new obj(ValidationResponse validate(String)): new ValidationResponse(validate#4)
    //#pre[3] (ValidationResponse validate(String)): (soft) init'ed(this.args)
    //#post(ValidationResponse validate(String)): java.lang.StringBuilder:toString(...)._tainted == 0
    //#post(ValidationResponse validate(String)): return_value in Addr_Set{&new ValidationResponse(validate#4),&new ValidationResponse(validate#2),&new ValidationResponse(validate#1)}
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#1) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#1).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#1).failure == &"Invalid rule."
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#2) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#2).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#2).failure == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#4) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#4).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#4).failure == null
    //#test_vector(ValidationResponse validate(String)): com.dmdirc.actions.ConditionTree:parseString(...)@57: Inverse{null}, Addr_Set{null}

        if (tree == null) {
            return new ValidationResponse("Invalid rule.");
        } else if (tree.getMaximumArgument() >= args) {
    //#ConditionRuleValidator.java:61: Warning: method not available - call not analyzed
    //#    call on int com.dmdirc.actions.ConditionTree:getMaximumArgument()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.config.prefs.validator.ConditionRuleValidator
    //#    method: ValidationResponse validate(String)
    //#    unanalyzed callee: int com.dmdirc.actions.ConditionTree:getMaximumArgument()
            return new ValidationResponse("Condition "
    //#ConditionRuleValidator.java:62: Warning: method not available - call not analyzed
    //#    call on int com.dmdirc.actions.ConditionTree:getMaximumArgument()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.config.prefs.validator.ConditionRuleValidator
    //#    method: ValidationResponse validate(String)
    //#    unanalyzed callee: int com.dmdirc.actions.ConditionTree:getMaximumArgument()
                    + tree.getMaximumArgument() + " does not exist");
        } else {
            return new ValidationResponse();
    //#ConditionRuleValidator.java:65: end of method: ValidationResponse com.dmdirc.config.prefs.validator.ConditionRuleValidator.validate(String)
        }
    }

}
    //#output(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): __Descendant_Table[com/dmdirc/config/prefs/validator/ConditionRuleValidator]
    //#output(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): __Dispatch_Table.setArgs(I)V
    //#output(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): __Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#output(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): __Dispatch_Table.validate(Ljava/lang/String;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#output(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/ConditionRuleValidator]
    //#post(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): __Descendant_Table[com/dmdirc/config/prefs/validator/ConditionRuleValidator] == &__Dispatch_Table
    //#post(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/ConditionRuleValidator] == &__Dispatch_Table
    //#post(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): __Dispatch_Table.setArgs(I)V == &setArgs
    //#post(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): __Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse; == &validate
    //#post(com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init): __Dispatch_Table.validate(Ljava/lang/String;)Lcom/dmdirc/config/prefs/validator/ValidationResponse; == &validate
    //#ConditionRuleValidator.java:: end of method: com.dmdirc.config.prefs.validator.ConditionRuleValidator.com.dmdirc.config.prefs.validator.ConditionRuleValidator__static_init
    //#ConditionRuleValidator.java:: end of class: com.dmdirc.config.prefs.validator.ConditionRuleValidator
