public class MethodSigSearchTerm extends SimpleParamSigSearchTerm
Search term for methods.
MethodSigSearchTerm: Example import com.github.aliteralmind.codelet.simplesig.AllSimpleParamSignatures;
import com.github.aliteralmind.codelet.simplesig.MethodSigSearchTerm;
import com.github.aliteralmind.codelet.simplesig.MethodSimpleParamSig;
import com.github.aliteralmind.codelet.simplesig.CrashIfMoreThanOne;
import com.github.aliteralmind.codelet.simplesig.CrashIfZero;
import com.github.xbn.lang.reflect.Declared;
import java.util.List;
public class MethodSigSearchTermXmpl {
public static final String LINE_SEP = System.getProperty("line.separator", "\r\n");
public static final void main(String[] ignored) {
AllSimpleParamSignatures allInClass = new AllSimpleParamSignatures(
MethodSigSearchTermXmpl.class, Declared.NO);
test(allInClass, "nonExisting()");
test(allInClass, "doSomething()");
test(allInClass, "doSomething(*)");
test(allInClass, "doSomething(*,byte,*)");
}
private static void test(AllSimpleParamSignatures all_inClass, String param_searchTerm) {
MethodSigSearchTerm searchTerm = new MethodSigSearchTerm(param_searchTerm, null, null);
System.out.println("Searching for: \"" + param_searchTerm + "\"");
if(!searchTerm.doesMatchAny(all_inClass)) {
System.out.println(" Not found.");
System.out.println();
return;
}
MethodSimpleParamSig first = searchTerm.getFirstMatch(
all_inClass, CrashIfZero.NO, CrashIfMoreThanOne.NO);
List<MethodSimpleParamSig> allMatches = searchTerm.getAllMatches(
all_inClass, CrashIfZero.NO);
System.out.println(" - First match: " + first);
System.out.println(" - All matches:" + LINE_SEP +
AllSimpleParamSignatures.toStringForAllListsInList(" - ", allMatches, LINE_SEP));
System.out.println();
}
public String doSomething(String s, boolean b, int i, Object o) {
return null;
}
public String doSomething(String s, boolean b, int[] i, byte y, Object o) {
return null;
}
}
Output:
Searching for: "nonExisting()"
Not found.
Searching for: "doSomething()"
Not found.
Searching for: "doSomething(*)"
- First match: doSomething(String, boolean, int, Object)
- All matches:
- doSomething(String, boolean, int, Object)
- doSomething(String, boolean, int[], byte, Object)
Searching for: "doSomething(*,byte,*)"
- First match: doSomething(String, boolean, int[], byte, Object)
- All matches:
- doSomething(String, boolean, int[], byte, Object)
aliteralmind __DASH__ github __AT__ yahoo __DOT__ com), dual-licensed under the LGPL (version 3.0 or later) or the ASL (version 2.0). See source code for details. http://codelet.aliteralmind.com, https://github.com/aliteralmind/codelet| Constructor and Description |
|---|
MethodSigSearchTerm(String search_termSig,
Appendable debugBasics_ifNonNull,
Appendable dbgDoesMatch_ifNonNull)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
doesMatchAny(AllSimpleParamSignatures all_methods)
Does any match?.
|
boolean |
doesMatchOnlyOne(AllSimpleParamSignatures all_methods)
Does exactly one match?.
|
List<MethodSimpleParamSig> |
getAllMatches(AllSimpleParamSignatures all_methods,
CrashIfZero crashIf_zero)
Get a new list of all matches.
|
MethodSimpleParamSig |
getFirstMatch(AllSimpleParamSignatures all_methods,
CrashIfZero crashIf_zero,
CrashIfMoreThanOne crashIf_moreThanOne)
Get the first match.
|
static Method |
getMethodFromAllSigsAndSearchTerm(AllSimpleParamSignatures all_sigs,
String sig_searchTerm,
Appendable debugBasics_ifNonNull,
Appendable dbgDoesMatch_ifNonNull)
Get the single matching method from an all-signature object.
|
MethodSimpleParamSig |
getOnlyMatch(AllSimpleParamSignatures all_methods)
Get the first and only match.
|
appendToString, doesMatch, doesMatchAnyProt, doesMatchOnlyOneProt, getAllMatchesProt, getDebugAptrBasics, getDebugAptrDoesMatch, getFirstMatchProt, getMethodName, getNoParams, getOnlyMatchProt, getTermList, getWithParams, hasAStar, indexOfStar, lastIndexOfStar, setDebug, toStringpublic MethodSigSearchTerm(String search_termSig, Appendable debugBasics_ifNonNull, Appendable dbgDoesMatch_ifNonNull)
Create a new instance.
doSomething()
A function named "doSomething" with exactly zero parameters.
doSomething(*)
One or more parameters of any type.
doSomething(String, *)
A java.lang.String, followed by one or more parameters of any type.
doSomething(String, *, int...)
A java.lang.String and int-ellipsis, with one or more parameters of any type between.
This first calls
super(search_termSig)
search_termSig - The function name may not be empty.public boolean doesMatchAny(AllSimpleParamSignatures all_methods)
Does any match?.
all_methods - May not be null.all_methods.getMethodMap().get(getMethodName())
doesMatchAnyProt([the-list])*doesMatchOnlyOnepublic boolean doesMatchOnlyOne(AllSimpleParamSignatures all_methods)
Does exactly one match?.
all_methods - May not be null.all_methods.getMethodMap().get(getMethodName())
doesMatchOnlyOneProt([the-list])*doesMatchAnypublic List<MethodSimpleParamSig> getAllMatches(AllSimpleParamSignatures all_methods, CrashIfZero crashIf_zero)
Get a new list of all matches.
all_methods - May not be null.crashIf_zero - If com.github.xbn.lang.reflect.CrashIfZero#YES YES, then zero matches is unacceptable. May not be null.null if no matchesRTNoSuchMethodException - If zero matches and crashIf_zero is YES.public MethodSimpleParamSig getOnlyMatch(AllSimpleParamSignatures all_methods)
Get the first and only match.
getFirstMatch(all_methods, CrashIfZero.YES, CrashIfMoreThanOne.YES)doesMatchOnlyOne,
getFirstMatch,
getOnlyMatchpublic MethodSimpleParamSig getFirstMatch(AllSimpleParamSignatures all_methods, CrashIfZero crashIf_zero, CrashIfMoreThanOne crashIf_moreThanOne)
Get the first match.
all_methods - May not be null.crashIf_zero - If com.github.xbn.lang.reflect.CrashIfZero#YES YES, then zero matches is unacceptable. May not be null.null if no matches.RTNoSuchMethodException - If zero matches and crashIf_zero is YES.getOnlyMatchpublic static final Method getMethodFromAllSigsAndSearchTerm(AllSimpleParamSignatures all_sigs, String sig_searchTerm, Appendable debugBasics_ifNonNull, Appendable dbgDoesMatch_ifNonNull)
Get the single matching method from an all-signature object.
(new MethodSigSearchTerm(sig_searchTerm, debugBasics_ifNonNull, dbgDoesMatch_ifNonNull)).
getOnlyMatch(all_sigs).getMethod()Copyright 2014, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.
https://github.com/aliteralmind/codelet