ConstructorMetaExtractor { public List<ConstructorMeta> extract(String sourceCodeString) { List<ConstructorMeta> dest = new ArrayList<ConstructorMeta>(); TypeNameConverter typeNameConverter = new TypeNameConverter(config); sourceCodeString = sourceCodeString.replaceAll("\\s+?" + StringValue.Comma, StringValue.Comma).replaceAll( StringValue.Comma + "\\s+?", StringValue.Comma).replaceAll("<\\s+?", "<").replaceAll("\\s+?>", ">"); Matcher matcherGrouping = RegExp.PatternObject.MethodSignatureArea.matcher(sourceCodeString); while (matcherGrouping.find()) { ConstructorMeta meta = new ConstructorMeta(); String methodSignatureArea = matcherGrouping.group(0).replaceAll(StringValue.CarriageReturn, StringValue.Empty).replaceAll(StringValue.LineFeed, StringValue.Space); meta.accessModifier = getAccessModifier(methodSignatureArea); String methodSignatureAreaWithoutAccessModifier = trimAccessModifierFromMethodSignatureArea(methodSignatureArea); String matchesConstructors = RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + classMeta.name + "\\(" + RegExp.Anything_ZeroOrMore_Min + "\\)" + RegExp.Anything_ZeroOrMore_Min; if (!methodSignatureAreaWithoutAccessModifier.matches(matchesConstructors)) { continue; } String constructorString = StringValue.Space + methodSignatureAreaWithoutAccessModifier; String groupConstructor = RegExp.WhiteSpace.Consecutive_ZeroOrMore_Max + classMeta.name + "\\(([^\\)]*?)\\)" + RegExp.WhiteSpace.Consecutive_ZeroOrMore_Max + "(throws .+)*.*?" + RegExp.WhiteSpace.Consecutive_ZeroOrMore_Max + "\\{.*"; Matcher constructorMatcher = Pattern.compile(groupConstructor).matcher(constructorString); if (!constructorMatcher.find()) { continue; } String argsDefAreaString = constructorMatcher.group(1); List<String> argArr = ArgExtractorHelper.getArgListFromArgsDefAreaString(argsDefAreaString); int argArrLen = argArr.size(); for (int i = 0; i < argArrLen; i++) { ArgTypeMeta argTypeMeta = new ArgTypeMeta(); String argTypeFull = argArr.get(i); Matcher toGenericsMatcher = Pattern.compile(RegExp.Generics_Group).matcher(argTypeFull); while (toGenericsMatcher.find()) { String[] generics = toGenericsMatcher.group().replaceAll("<", StringValue.Empty).replaceAll(">", StringValue.Empty).split(StringValue.Comma); for (String generic : generics) { generic = typeNameConverter.toCompilableType(generic, classMeta.importedList, classMeta.packageName); argTypeMeta.generics.add(generic); } } String argTypeName = argTypeFull.replaceAll(RegExp.Generics, StringValue.Empty).replaceAll("final ", StringValue.Empty).split("\\s+")[0].trim(); if (argTypeName != null && !argTypeName.equals("")) { argTypeMeta.name = typeNameConverter.toCompilableType(argTypeName, argTypeMeta.generics, classMeta.importedList, classMeta.packageName); argTypeMeta.nameInMethodName = typeNameConverter.toAvailableInMethodName(argTypeMeta.name); meta.argTypes.add(argTypeMeta); Matcher nameMatcher = RegExp.PatternObject.MethodArg_Group.matcher(argTypeFull); if (nameMatcher.find()) { String argName = nameMatcher.group(1); if (argName.matches(".+\\[\\s*\\]")) { String arrayPart = ""; Matcher mat = Pattern.compile("\\[\\s*\\]").matcher(argName); while (mat.find()) { arrayPart += "[]"; } argName = argName.replaceAll("\\[\\s*\\]", StringValue.Empty); argTypeMeta.name = argTypeMeta.name + arrayPart; argTypeMeta.nameInMethodName = typeNameConverter.toAvailableInMethodName(argTypeMeta.name); } meta.argNames.add(argName); } else { meta.argNames.add("constructorArg" + i); } } } dest.add(meta); } if (dest.size() == 0) { ConstructorMeta defaultConstructorMeta = new ConstructorMeta(); dest.add(defaultConstructorMeta); } return dest; } ConstructorMetaExtractor(Configuration config); ConstructorMetaExtractor initialize(String sourceCodeString); ConstructorMetaExtractor initialize(ClassMeta classMeta, String sourceCodeString); List<ConstructorMeta> extract(String sourceCodeString);  }
@Test public void extract_A$String_StringIsEmpty() throws Exception { ConstructorMetaExtractor target = new ConstructorMetaExtractor(config); String sourceCodeString = ""; List<ConstructorMeta> actual = target.extract(sourceCodeString); assertThat(actual, notNullValue()); }
@Test public void extract_A$String_StringIsNull() throws Exception { ConstructorMetaExtractor target = new ConstructorMetaExtractor(config); String sourceCodeString = "public class Sample {}"; List<ConstructorMeta> actual = target.extract(sourceCodeString); assertThat(actual, notNullValue()); }