All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nutz.aop.matcher.RegexMethodMatcher Maven / Gradle / Ivy

Go to download

Nutz, which is a collections of lightweight frameworks, each of them can be used independently

There is a newer version: 1.r.72
Show newest version
package org.nutz.aop.matcher;

import static java.lang.reflect.Modifier.TRANSIENT;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.regex.Pattern;

import org.nutz.aop.MethodMatcher;
import org.nutz.lang.Maths;

public class RegexMethodMatcher implements MethodMatcher {

	private Pattern active;
	private Pattern ignore;
	private int mods;

	public RegexMethodMatcher(String active) {
		this(active, null);
	}

	public RegexMethodMatcher(String active, String ignore) {
		this(active, ignore, Modifier.PUBLIC | Modifier.PROTECTED);
	}

	public RegexMethodMatcher(String active, String ignore, int mods) {
		if (active != null)
		this.active = Pattern.compile(active);
		if (ignore != null)
			this.ignore = Pattern.compile(ignore);
		this.mods = mods;
	}

	public boolean match(Method method) {
		int mod = method.getModifiers();
		String name = method.getName();
		if (null != ignore)
			if (ignore.matcher(name).find())
				return false;
		if (null != active)
			if (!active.matcher(name).find())
				return false;
		if (mods <= 0)
			return true;

		if (mod == 0)
			mod |= TRANSIENT;

		return Maths.isMask(mod, mods);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy