mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 11:36:51 +01:00
Add getters and setters for each of the fuzzy contracts.
This commit is contained in:
parent
d583f7ccc3
commit
58969b26f6
@ -164,6 +164,38 @@ public abstract class AbstractFuzzyMember<T extends Member> extends AbstractFuzz
|
||||
this.sealed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a bit field of every {@link java.lang.reflect.Modifier Modifier} that is required for the member to match.
|
||||
* @return A required modifier bit field.
|
||||
*/
|
||||
public int getModifiersRequired() {
|
||||
return modifiersRequired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a bit field of every {@link java.lang.reflect.Modifier Modifier} that must not be present for the member to match.
|
||||
* @return A banned modifier bit field.
|
||||
*/
|
||||
public int getModifiersBanned() {
|
||||
return modifiersBanned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the regular expression pattern that is used to match the name of a member.
|
||||
* @return The regex matching a name, or NULL if everything matches.
|
||||
*/
|
||||
public Pattern getNameRegex() {
|
||||
return nameRegex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a class matcher for the declaring class of the member.
|
||||
* @return An object matching the declaring class.
|
||||
*/
|
||||
public AbstractFuzzyMatcher<Class<?>> getDeclaringMatcher() {
|
||||
return declaringMatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(T value, Object parent) {
|
||||
int mods = value.getModifiers();
|
||||
|
@ -118,6 +118,14 @@ public class FuzzyFieldContract extends AbstractFuzzyMember<Field> {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the class matcher that matches the type of a field.
|
||||
* @return The class matcher.
|
||||
*/
|
||||
public AbstractFuzzyMatcher<Class<?>> getTypeMatcher() {
|
||||
return typeMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new field contract from the given contract.
|
||||
* @param other - the contract to clone.
|
||||
|
@ -9,6 +9,7 @@ import javax.annotation.Nonnull;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
|
||||
import com.comphenix.protocol.reflect.MethodInfo;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
@ -80,8 +81,8 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
|
||||
private AbstractFuzzyMatcher<Class<?>> returnMatcher = ExactClassMatcher.MATCH_ALL;
|
||||
|
||||
// Handle parameters and exceptions
|
||||
private List<ParameterClassMatcher> paramMatchers = Lists.newArrayList();
|
||||
private List<ParameterClassMatcher> exceptionMatchers = Lists.newArrayList();
|
||||
private List<ParameterClassMatcher> paramMatchers;
|
||||
private List<ParameterClassMatcher> exceptionMatchers;
|
||||
|
||||
// Expected parameter count
|
||||
private Integer paramCount;
|
||||
@ -326,13 +327,14 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
|
||||
@Override
|
||||
@Nonnull
|
||||
protected FuzzyMethodContract initialMember() {
|
||||
// With mutable lists
|
||||
return new FuzzyMethodContract();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMethodContract build() {
|
||||
member.prepareBuild();
|
||||
return new FuzzyMethodContract(member);
|
||||
return immutableCopy(member);
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,8 +348,10 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
|
||||
|
||||
private FuzzyMethodContract() {
|
||||
// Only allow construction from the builder
|
||||
paramMatchers = Lists.newArrayList();
|
||||
exceptionMatchers = Lists.newArrayList();
|
||||
}
|
||||
|
||||
|
||||
private FuzzyMethodContract(FuzzyMethodContract other) {
|
||||
super(other);
|
||||
this.returnMatcher = other.returnMatcher;
|
||||
@ -356,6 +360,58 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
|
||||
this.paramCount = other.paramCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new immutable copy of the given method contract.
|
||||
* @param other - the contract to clone.
|
||||
* @return A immutable copy of the given contract.
|
||||
*/
|
||||
private static FuzzyMethodContract immutableCopy(FuzzyMethodContract other) {
|
||||
FuzzyMethodContract copy = new FuzzyMethodContract(other);
|
||||
|
||||
// Ensure that the lists are immutable
|
||||
copy.paramMatchers = ImmutableList.copyOf(copy.paramMatchers);
|
||||
copy.exceptionMatchers = ImmutableList.copyOf(copy.exceptionMatchers);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the class matcher for the return type.
|
||||
* @return Class matcher for the return type.
|
||||
*/
|
||||
public AbstractFuzzyMatcher<Class<?>> getReturnMatcher() {
|
||||
return returnMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an immutable list of every parameter matcher for this method.
|
||||
* @return Immutable list of every parameter matcher.
|
||||
*/
|
||||
public ImmutableList<ParameterClassMatcher> getParamMatchers() {
|
||||
if (paramMatchers instanceof ImmutableList)
|
||||
return (ImmutableList<ParameterClassMatcher>) paramMatchers;
|
||||
else
|
||||
throw new IllegalStateException("Lists haven't been sealed yet.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an immutable list of every exception matcher for this method.
|
||||
* @return Immutable list of every exception matcher.
|
||||
*/
|
||||
public List<ParameterClassMatcher> getExceptionMatchers() {
|
||||
if (exceptionMatchers instanceof ImmutableList)
|
||||
return exceptionMatchers;
|
||||
else
|
||||
throw new IllegalStateException("Lists haven't been sealed yet.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the expected parameter count for this method.
|
||||
* @return Expected parameter count, or NULL if anyting goes.
|
||||
*/
|
||||
public Integer getParamCount() {
|
||||
return paramCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareBuild() {
|
||||
super.prepareBuild();
|
||||
|
Loading…
Reference in New Issue
Block a user