<commit_before>/*
 * Copyright 2004-2005 the original author or authors.
 * 
 * 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 org.codehaus.groovy.grails.commons.metaclass;

import groovy.lang.Interceptor;
/**
 * Implements an the Interceptor interface to add support for using ProxyMetaClass to define 
 * dynamic methods
 * 
 * @author <NAME>
 * @since Oct 24, 2005
 */
public abstract class AbstractDynamicMethodsInterceptor extends AbstractDynamicMethods
		implements Interceptor,PropertyAccessInterceptor {

	protected boolean doInvoke = true;
	protected boolean doGet = true;
	protected boolean doSet = true;
	private Object returnValue;
	

	public Object beforeInvoke(Object target, String methodName,
			Object[] arguments) {
		InvocationCallback callback = new InvocationCallback();
		this.returnValue = super.invokeMethod(target, methodName, arguments, callback);
		// if the method was invoked as dynamic 
		// don't invoke true target
		if (callback.isInvoked()) {
			doInvoke = false;
			return returnValue;
		} else {
			doInvoke = true;
			return null;
		}
	}

	public Object afterInvoke(Object object, String methodName,
			Object[] arguments, Object result) {
		return this.returnValue;
	}

	public boolean doInvoke() {
		return doInvoke;
	}

	public Object beforeGet(Object object, String property) {
		InvocationCallback callback = new InvocationCallback();
		Object returnValue = super.getProperty(object,property,callback);
		// if the method was invoked as dynamic 
		// don't invoke true target
		if (callback.isInvoked()) {
			doGet = false;
			return returnValue;
		} else {
			doGet = true;
			return null;
		}
	}

	public void beforeSet(Object object, String property, Object newValue) {
		InvocationCallback callback = new InvocationCallback();
		super.setProperty(object,property,newValue,callback);
		// if the method was invoked as dynamic 
		// don't invoke true target
		if (callback.isInvoked()) {
			doSet = false;
		} else {
			doSet = true;
		}
	}

	public boolean doGet() {
		return doGet;
	}

	public boolean doSet() {
		return doSet;<commit_msg>updated to not call super to that methods are overridable by subclass<commit_after>/*
 * Copyright 2004-2005 the original author or authors.
 * 
 * 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 org.codehaus.groovy.grails.commons.metaclass;

import groovy.lang.Interceptor;
/**
 * Implements an the Interceptor interface to add support for using ProxyMetaClass to define 
 * dynamic methods
 * 
 * @author <NAME>
 * @since Oct 24, 2005
 */
public abstract class AbstractDynamicMethodsInterceptor extends AbstractDynamicMethods
		implements Interceptor,PropertyAccessInterceptor {

	protected boolean doInvoke = true;
	protected boolean doGet = true;
	protected boolean doSet = true;
	private Object returnValue;
	

	public Object beforeInvoke(Object target, String methodName,
			Object[] arguments) {
		InvocationCallback callback = new InvocationCallback();
		this.returnValue = invokeMethod(target, methodName, arguments, callback);
		// if the method was invoked as dynamic 
		// don't invoke true target
		if (callback.isInvoked()) {
			doInvoke = false;
			return returnValue;
		} else {
			doInvoke = true;
			return null;
		}
	}

	public Object afterInvoke(Object object, String methodName,
			Object[] arguments, Object result) {
		return this.returnValue;
	}

	public boolean doInvoke() {
		return doInvoke;
	}

	public Object beforeGet(Object object, String property) {
		InvocationCallback callback = new InvocationCallback();
		Object returnValue = getProperty(object,property,callback);
		// if the method was invoked as dynamic 
		// don't invoke true target
		if (callback.isInvoked()) {
			doGet = false;
			return returnValue;
		} else {
			doGet = true;
			return null;
		}
	}

	public void beforeSet(Object object, String property, Object newValue) {
		InvocationCallback callback = new InvocationCallback();
		setProperty(object,property,newValue,callback);
		// if the method was invoked as dynamic 
		// don't invoke true target
		if (callback.isInvoked()) {
			doSet = false;
		} else {
			doSet = true;
		}
	}

	public boolean doGet() {
		return doGet;
	}

	public boolean doSet() {
		return doSet;
{'fraction_non_alphanumeric': 0.08174542682926829, 'fraction_numerical': 0.006859756097560976, 'mean_word_length': 3.947219604147031, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '6966159', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1404, 'n_words': 542}