<commit_before>/*
 * Copyright 2008-2017 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aspectran.core.context.rule.parser.xml;

import com.aspectran.core.context.rule.AspectAdviceRule;
import com.aspectran.core.context.rule.AspectRule;
import com.aspectran.core.context.rule.ExceptionThrownRule;
import com.aspectran.core.context.rule.assistant.ContextRuleAssistant;
import com.aspectran.core.context.rule.type.AspectAdviceType;
import com.aspectran.core.util.StringUtils;
import com.aspectran.core.util.xml.NodeletAdder;
import com.aspectran.core.util.xml.NodeletParser;

/**
 * The Class AspectAdviceInnerNodeletAdder.
 *
 * @since 2013. 8. 11.
 */
class AspectAdviceInnerNodeletAdder implements NodeletAdder {

    protected final ContextRuleAssistant assistant;

    /**
     * Instantiates a new AspectAdviceNodeletAdder.
     *
     * @param assistant the assistant for Context Builder
     */
    AspectAdviceInnerNodeletAdder(ContextRuleAssistant assistant) {
        this.assistant = assistant;
    }

    @Override
    public void process(String xpath, NodeletParser parser) {
        parser.addNodelet(xpath, "/before", (node, attributes, text) -> {
            AspectRule aspectRule = assistant.peekObject();
            AspectAdviceRule aspectAdviceRule = aspectRule.newAspectAdviceRule(AspectAdviceType.BEFORE);
            assistant.pushObject(aspectAdviceRule);
        });
        parser.addNodelet(xpath, "/before", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/before/end()", (node, attributes, text) -> assistant.popObject());
        parser.addNodelet(xpath, "/after", (node, attributes, text) -> {
            AspectRule aspectRule = assistant.peekObject();
            AspectAdviceRule aspectAdviceRule = aspectRule.newAspectAdviceRule(AspectAdviceType.AFTER);
            assistant.pushObject(aspectAdviceRule);
        });
        parser.addNodelet(xpath, "/after", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/after/end()", (node, attributes, text) -> assistant.popObject());
        parser.addNodelet(xpath, "/around", (node, attributes, text) -> {
            AspectRule aspectRule = assistant.peekObject();
            AspectAdviceRule aspectAdviceRule = aspectRule.newAspectAdviceRule(AspectAdviceType.AROUND);
            assistant.pushObject(aspectAdviceRule);
        });
        parser.addNodelet(xpath, "/around", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/around/end()", (node, attributes, text) -> assistant.popObject());
        parser.addNodelet(xpath, "/finally", (node, attributes, text) -> {
            AspectRule aspectRule = assistant.peekObject();
            AspectAdviceRule aspectAdviceRule = aspectRule.newAspectAdviceRule(AspectAdviceType.FINALLY);
            assistant.pushObject(aspectAdviceRule);
        });
        parser.addNodelet(xpath, "/finally/thrown", (node, attributes, text) -> {
            String exceptionType = attributes.get("type");

            ExceptionThrownRule etr = new ExceptionThrownRule();
            if (exceptionType != null) {
                String[] exceptionTypes = StringUtils.splitCommaDelimitedString(exceptionType);
                etr.setExceptionTypes(exceptionTypes);
            }

            assistant.pushObject(etr);
        });
        parser.addNodelet(xpath, "/finally/thrown", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/finally/thrown", new ResponseInnerNodeletAdder(assistant));
        parser.addNodelet(xpath, "/finally/thrown/end()", (node, attributes, text) -> {
            ExceptionThrownRule etr = assistant.popObject();
            AspectAdviceRule aspectAdviceRule = assistant.peekObject();
            aspectAdviceRule.setExceptionThrownRule(etr);
        });
        parser.addNodelet(xpath, "/finally", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/finally/end()", (node, attributes, text) -> assistant.popObject());<commit_msg>Bug fixes that could not execute action of the finally advice<commit_after>/*
 * Copyright 2008-2017 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aspectran.core.context.rule.parser.xml;

import com.aspectran.core.context.rule.AspectAdviceRule;
import com.aspectran.core.context.rule.AspectRule;
import com.aspectran.core.context.rule.ExceptionThrownRule;
import com.aspectran.core.context.rule.assistant.ContextRuleAssistant;
import com.aspectran.core.context.rule.type.AspectAdviceType;
import com.aspectran.core.util.StringUtils;
import com.aspectran.core.util.xml.NodeletAdder;
import com.aspectran.core.util.xml.NodeletParser;

/**
 * The Class AspectAdviceInnerNodeletAdder.
 *
 * @since 2013. 8. 11.
 */
class AspectAdviceInnerNodeletAdder implements NodeletAdder {

    protected final ContextRuleAssistant assistant;

    /**
     * Instantiates a new AspectAdviceNodeletAdder.
     *
     * @param assistant the assistant for Context Builder
     */
    AspectAdviceInnerNodeletAdder(ContextRuleAssistant assistant) {
        this.assistant = assistant;
    }

    @Override
    public void process(String xpath, NodeletParser parser) {
        parser.addNodelet(xpath, "/before", (node, attributes, text) -> {
            AspectRule aspectRule = assistant.peekObject();
            AspectAdviceRule aspectAdviceRule = aspectRule.newAspectAdviceRule(AspectAdviceType.BEFORE);
            assistant.pushObject(aspectAdviceRule);
        });
        parser.addNodelet(xpath, "/before", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/before/end()", (node, attributes, text) -> assistant.popObject());
        parser.addNodelet(xpath, "/after", (node, attributes, text) -> {
            AspectRule aspectRule = assistant.peekObject();
            AspectAdviceRule aspectAdviceRule = aspectRule.newAspectAdviceRule(AspectAdviceType.AFTER);
            assistant.pushObject(aspectAdviceRule);
        });
        parser.addNodelet(xpath, "/after", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/after/end()", (node, attributes, text) -> assistant.popObject());
        parser.addNodelet(xpath, "/around", (node, attributes, text) -> {
            AspectRule aspectRule = assistant.peekObject();
            AspectAdviceRule aspectAdviceRule = aspectRule.newAspectAdviceRule(AspectAdviceType.AROUND);
            assistant.pushObject(aspectAdviceRule);
        });
        parser.addNodelet(xpath, "/around", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/around/end()", (node, attributes, text) -> assistant.popObject());
        parser.addNodelet(xpath, "/finally", (node, attributes, text) -> {
            AspectRule aspectRule = assistant.peekObject();
            AspectAdviceRule aspectAdviceRule = aspectRule.newAspectAdviceRule(AspectAdviceType.FINALLY);
            assistant.pushObject(aspectAdviceRule);
        });
        parser.addNodelet(xpath, "/finally/thrown", (node, attributes, text) -> {
            String exceptionType = attributes.get("type");

            AspectAdviceRule aspectAdviceRule = assistant.peekObject();
            ExceptionThrownRule etr = new ExceptionThrownRule(aspectAdviceRule);
            if (exceptionType != null) {
                String[] exceptionTypes = StringUtils.splitCommaDelimitedString(exceptionType);
                etr.setExceptionTypes(exceptionTypes);
            }
            assistant.pushObject(etr);
        });
        parser.addNodelet(xpath, "/finally/thrown", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/finally/thrown", new ResponseInnerNodeletAdder(assistant));
        parser.addNodelet(xpath, "/finally/thrown/end()", (node, attributes, text) -> {
            ExceptionThrownRule etr = assistant.popObject();
            AspectAdviceRule aspectAdviceRule = assistant.peekObject();
            aspectAdviceRule.setExceptionThrownRule(etr);
        });
        parser.addNodelet(xpath, "/finally", new ActionNodeletAdder(assistant));
        parser.addNodelet(xpath, "/finally/end()", (node, attributes, text) -> assistant.popObject());
{'fraction_non_alphanumeric': 0.11081995851075445, 'fraction_numerical': 0.004148924555082432, 'mean_word_length': 3.4748412310698584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2503528', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2588, 'n_words': 542}