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}