001/*license*\ 002 Codelet: Copyright (C) 2014, Jeff Epstein (aliteralmind __DASH__ github __AT__ yahoo __DOT__ com) 003 004 This software is dual-licensed under the: 005 - Lesser General Public License (LGPL) version 3.0 or, at your option, any later version; 006 - Apache Software License (ASL) version 2.0. 007 008 Either license may be applied at your discretion. More information may be found at 009 - http://en.wikipedia.org/wiki/Multi-licensing. 010 011 The text of both licenses is available in the root directory of this project, under the names "LICENSE_lgpl-3.0.txt" and "LICENSE_asl-2.0.txt". The latest copies may be downloaded at: 012 - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt 013 - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt 014\*license*/ 015package com.github.aliteralmind.codelet.simplesig; 016 import java.lang.reflect.Constructor; 017 import com.github.xbn.lang.CrashIfObject; 018 import com.github.xbn.lang.reflect.RTNoSuchMethodException; 019 import java.util.List; 020/** 021 <P>For matching one or more {@code ConstructorSimpleParamSig}.</P> 022 023 <A NAME="xmpl_cnstr"></A><H3>{@link com.github.aliteralmind.codelet.simplesig.ConstructorParamSearchTerm}: Example</H3> 024 025{@.codelet.and.out com.github.aliteralmind.codelet.examples.simplesig.ConstructorParamSearchTermXmpl%()} 026 027 @since 0.1.0 028 @author Copyright (C) 2014, Jeff Epstein ({@code 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. <A HREF="http://codelet.aliteralmind.com">{@code http://codelet.aliteralmind.com}</A>, <A HREF="https://github.com/aliteralmind/codelet">{@code https://github.com/aliteralmind/codelet}</A> 029 **/ 030public class ConstructorParamSearchTerm extends SimpleParamSigSearchTerm { 031 /** 032 <P>Create a new instance.</P> 033 034 <H4>Examples</H4> 035 036<BLOCKQUOTE><PRE>()</PRE></BLOCKQUOTE> 037 038 <P>A constructor with exactly zero parameters.</P> 039 040<BLOCKQUOTE><PRE>(*)</PRE></BLOCKQUOTE> 041 042 <P>One or more parameters of any type.</P> 043 044<BLOCKQUOTE><PRE>(String, *)</PRE></BLOCKQUOTE> 045 046 <P>A {@code java.lang.String}, followed by one or more parameters of any type.</P> 047 048<BLOCKQUOTE><PRE>(String, *, int[])</PRE></BLOCKQUOTE> 049 050 <P>A {@code java.lang.String} and {@code int} array, with one or more parameters of any type between.</P> 051 052 <P>This first calls 053 <BR> <CODE>{@link SimpleParamSigSearchTerm#SimpleParamSigSearchTerm(String, Appendable, Appendable) super}(param_searchTerm)</CODE></P> 054 055 @param param_searchTerm There may not be any text before the open parenthesis ({@code '('}). 056 **/ 057 public ConstructorParamSearchTerm(String param_searchTerm, Appendable debugBasics_ifNonNull, Appendable dbgDoesMatch_ifNonNull) { 058 super(param_searchTerm, debugBasics_ifNonNull, dbgDoesMatch_ifNonNull); 059 if(getMethodName().length() != 0) { 060 throw new SimpleParamSigSearchTermFormatException(param_searchTerm, "Constructor shortcut has text before the open-parenthesis ('('): \"" + param_searchTerm + "\""); 061 } 062 } 063 /** 064 <P>Does any constructor match?.</P> 065 066 @return {@link com.github.aliteralmind.codelet.simplesig.SimpleParamSigSearchTerm#doesMatchAnyProt(List) doesMatchAnyProt}{@code (to_searchList)}* 067 @see #getFirstMatch(List, CrashIfZero, CrashIfMoreThanOne) 068 **/ 069 public boolean doesMatchAny(List<ConstructorSimpleParamSig> to_searchList) { 070 return doesMatchAnyProt(to_searchList); 071 } 072 /** 073 <P>Get a new list of all matches.</P> 074 075 @return {@link com.github.aliteralmind.codelet.simplesig.SimpleParamSigSearchTerm#getAllMatchesProt(List, CrashIfZero) getAllMatchesProt}{@code (to_searchList, crashIf_zero)}* 076 @see #getFirstMatch(List, CrashIfZero, CrashIfMoreThanOne) 077 **/ 078 public List<ConstructorSimpleParamSig> getAllMatches(List<ConstructorSimpleParamSig> to_searchList, CrashIfZero crashIf_zero) { 079 @SuppressWarnings("unchecked") 080 List<ConstructorSimpleParamSig> matches = (List<ConstructorSimpleParamSig>)getAllMatchesProt(to_searchList, crashIf_zero); 081 return matches; 082 } 083 /** 084 <P>Get the first and only match.</P> 085 086 @return <CODE>(ConstructorSimpleParamSig){@link SimpleParamSigSearchTerm#getOnlyMatchProt(List) getOnlyMatchProt}(to_searchList)</CODE> 087 @see SimpleParamSigSearchTerm#doesMatchOnlyOneProt(List) doesMatchOnlyOneProt* 088 @see #getFirstMatch(List, CrashIfZero, CrashIfMoreThanOne) getFirstMatch 089 @see #getAllMatches(List, CrashIfZero) getAllMatches 090 **/ 091 public ConstructorSimpleParamSig getOnlyMatch(List<ConstructorSimpleParamSig> to_searchList) { 092 return (ConstructorSimpleParamSig)getOnlyMatchProt(to_searchList); 093 } 094 /** 095 <P>Get the first match.</P> 096 097 @return <CODE>(ConstructorSimpleParamSig){@link SimpleParamSigSearchTerm#getFirstMatchProt(List, CrashIfZero, CrashIfMoreThanOne) getFirstMatchProt}(to_searchList, crashIf_zero, crashIf_moreThanOne)</CODE> 098 @see #doesMatchAny(List) 099 @see #getAllMatches(List, CrashIfZero) 100 @see #getFirstMatch(List, CrashIfZero, CrashIfMoreThanOne) 101 **/ 102 public ConstructorSimpleParamSig getFirstMatch(List<ConstructorSimpleParamSig> to_searchList, CrashIfZero crashIf_zero, CrashIfMoreThanOne crashIf_moreThanOne) { 103 return (ConstructorSimpleParamSig)getFirstMatchProt(to_searchList, crashIf_zero, crashIf_moreThanOne); 104 } 105 106 107 /** 108 <P>Get the single matching constructor from an all-signature object.</P> 109 110 @return <CODE>(new {@link ConstructorParamSearchTerm#ConstructorParamSearchTerm(String, Appendable, Appendable) ConstructorParamSearchTerm}(param_searchTerm, debugBasics_ifNonNull, dbgDoesMatch_ifNonNull)). 111 <BR> {@link ConstructorParamSearchTerm#getOnlyMatch(List) getOnlyMatch}(all_sigs.{@link AllSimpleParamSignatures#getConstructorList() getConstructorList}).{@link ConstructorSimpleParamSig#getConstructor() getConstructor}()</CODE> 112 **/ 113 public static final Constructor<?> getConstructorFromAllSigsAndSearchTerm(AllSimpleParamSignatures all_sigs, String param_searchTerm, Appendable debugBasics_ifNonNull, Appendable dbgDoesMatch_ifNonNull) { 114 try { 115 return (new ConstructorParamSearchTerm(param_searchTerm, debugBasics_ifNonNull, dbgDoesMatch_ifNonNull)). 116 getOnlyMatch(all_sigs.getConstructorList()).getConstructor(); 117 } catch(RTNoSuchMethodException nsmx) { 118 throw new RTNoSuchMethodException("Attempting to get java.lang.reflect.Constructor object for JavaDoc link. target_class:" + all_sigs.getContainingClass().getName(), nsmx); 119 } catch(RuntimeException rx) { 120 throw CrashIfObject.nullOrReturnCause(all_sigs, "all_sigs", null, rx); 121 } 122 } 123}