@Test public void extract_A$String_StringIsEmpty() throws Exception { MethodMetaExtractor target = new MethodMetaExtractor(config); String sourceCodeString = ""; List<MethodMeta> actual = target.extract(sourceCodeString); assertThat(actual, notNullValue()); }
public List<MethodMeta> extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); List<MethodMeta> dest = new ArrayList<MethodMeta>(); TypeNameConverter typeNameConverter = new TypeNameConverter(config); sourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher mat = RegExp.PatternObject.MethodSignatureArea.matcher(sourceCodeString); while (mat.find()) { MethodMeta meta = new MethodMeta(); String methodSignatureArea = mat.group(0).replaceAll(StringValue.CarriageReturn, StringValue.Empty) .replaceAll(StringValue.LineFeed, StringValue.Space); if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + classMeta.name + "\\(" + RegExp.Anything_ZeroOrMore_Min + "\\)" + RegExp.Anything_ZeroOrMore_Min)) { continue; } String trimmedMethodSignatureArea = methodSignatureArea.replaceAll("\\s*,\\s*", ",").replaceAll( "\\s*<\\s*", "<").replaceAll("\\s*>", ">"); String methodSignatureAreaWithoutAccessModifier = trimAccessModifierFromMethodSignatureArea(trimmedMethodSignatureArea); Matcher matcherGrouping = RegExp.PatternObject.MethodSignatureWithoutAccessModifier_Group .matcher(StringValue.Space + methodSignatureAreaWithoutAccessModifier); if (!matcherGrouping.find()) { continue; } if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + "static" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + RegExp.Anything_ZeroOrMore_Min)) { meta.isStatic = true; } meta.accessModifier = getAccessModifier(methodSignatureArea); String grouped = matcherGrouping.group(1); String returnTypeFull = grouped.replaceAll("final ", StringValue.Empty).split("\\s+")[0].trim(); returnTypeFull = trimGenericsIfNested(returnTypeFull); Matcher toGenericsMatcherForReturn = Pattern.compile(RegExp.Generics_Group).matcher(returnTypeFull); while (toGenericsMatcherForReturn.find()) { String[] generics = toGenericsMatcherForReturn.group().replaceAll("<", StringValue.Empty).replaceAll( ">", StringValue.Empty).split(StringValue.Comma); for (String generic : generics) { generic = typeNameConverter .toCompilableType(generic, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.generics.add(generic); } } String returnTypeName = returnTypeFull.replace(RegExp.Generics, StringValue.Empty); if (!returnTypeName.equals("void")) { meta.returnType.name = typeNameConverter.toCompilableType(returnTypeName, meta.returnType.generics, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.nameInMethodName = typeNameConverter.toAvailableInMethodName(meta.returnType.name); } meta.name = matcherGrouping.group(2); String argsAreaString = matcherGrouping.group(3); ArgTypeMetaExtractor argTypeMetaExtractor = new ArgTypeMetaExtractor(config); argTypeMetaExtractor.initialize(classMeta).doExtract(argsAreaString); meta.argNames = argTypeMetaExtractor.getExtractedNameList(); meta.argTypes = argTypeMetaExtractor.getExtractedMetaList(); String fieldName = null; String fieldType = null; if (meta.name.matches("^set.+")) { fieldName = meta.name.substring(3); if (meta.argTypes.size() > 0) { fieldType = meta.argTypes.get(0).name; } } else if (meta.name.matches("^get.+")) { fieldName = meta.name.substring(3); fieldType = meta.returnType.name; } else if (meta.name.matches("^is.+")) { fieldName = meta.name.substring(2); fieldType = meta.returnType.name; } if (fieldName != null && fieldType != null) { meta.isAccessor = isPrivateFieldExists(fieldType, fieldName, sourceCodeString); } String throwsExceptions = matcherGrouping.group(4); if (throwsExceptions != null) { String[] exceptions = throwsExceptions.replaceAll( "throws" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max, StringValue.Empty).split( StringValue.Comma); for (String exception : exceptions) { exception = exception.trim(); ExceptionMeta exceptionMeta = new ExceptionMeta(); exceptionMeta.name = exception; exceptionMeta.nameInMethodName = typeNameConverter.toAvailableInMethodName(exception); meta.throwsExceptions.add(exceptionMeta); } } dest.add(meta); } return dest; }
MethodMetaExtractor { public List<MethodMeta> extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); List<MethodMeta> dest = new ArrayList<MethodMeta>(); TypeNameConverter typeNameConverter = new TypeNameConverter(config); sourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher mat = RegExp.PatternObject.MethodSignatureArea.matcher(sourceCodeString); while (mat.find()) { MethodMeta meta = new MethodMeta(); String methodSignatureArea = mat.group(0).replaceAll(StringValue.CarriageReturn, StringValue.Empty) .replaceAll(StringValue.LineFeed, StringValue.Space); if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + classMeta.name + "\\(" + RegExp.Anything_ZeroOrMore_Min + "\\)" + RegExp.Anything_ZeroOrMore_Min)) { continue; } String trimmedMethodSignatureArea = methodSignatureArea.replaceAll("\\s*,\\s*", ",").replaceAll( "\\s*<\\s*", "<").replaceAll("\\s*>", ">"); String methodSignatureAreaWithoutAccessModifier = trimAccessModifierFromMethodSignatureArea(trimmedMethodSignatureArea); Matcher matcherGrouping = RegExp.PatternObject.MethodSignatureWithoutAccessModifier_Group .matcher(StringValue.Space + methodSignatureAreaWithoutAccessModifier); if (!matcherGrouping.find()) { continue; } if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + "static" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + RegExp.Anything_ZeroOrMore_Min)) { meta.isStatic = true; } meta.accessModifier = getAccessModifier(methodSignatureArea); String grouped = matcherGrouping.group(1); String returnTypeFull = grouped.replaceAll("final ", StringValue.Empty).split("\\s+")[0].trim(); returnTypeFull = trimGenericsIfNested(returnTypeFull); Matcher toGenericsMatcherForReturn = Pattern.compile(RegExp.Generics_Group).matcher(returnTypeFull); while (toGenericsMatcherForReturn.find()) { String[] generics = toGenericsMatcherForReturn.group().replaceAll("<", StringValue.Empty).replaceAll( ">", StringValue.Empty).split(StringValue.Comma); for (String generic : generics) { generic = typeNameConverter .toCompilableType(generic, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.generics.add(generic); } } String returnTypeName = returnTypeFull.replace(RegExp.Generics, StringValue.Empty); if (!returnTypeName.equals("void")) { meta.returnType.name = typeNameConverter.toCompilableType(returnTypeName, meta.returnType.generics, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.nameInMethodName = typeNameConverter.toAvailableInMethodName(meta.returnType.name); } meta.name = matcherGrouping.group(2); String argsAreaString = matcherGrouping.group(3); ArgTypeMetaExtractor argTypeMetaExtractor = new ArgTypeMetaExtractor(config); argTypeMetaExtractor.initialize(classMeta).doExtract(argsAreaString); meta.argNames = argTypeMetaExtractor.getExtractedNameList(); meta.argTypes = argTypeMetaExtractor.getExtractedMetaList(); String fieldName = null; String fieldType = null; if (meta.name.matches("^set.+")) { fieldName = meta.name.substring(3); if (meta.argTypes.size() > 0) { fieldType = meta.argTypes.get(0).name; } } else if (meta.name.matches("^get.+")) { fieldName = meta.name.substring(3); fieldType = meta.returnType.name; } else if (meta.name.matches("^is.+")) { fieldName = meta.name.substring(2); fieldType = meta.returnType.name; } if (fieldName != null && fieldType != null) { meta.isAccessor = isPrivateFieldExists(fieldType, fieldName, sourceCodeString); } String throwsExceptions = matcherGrouping.group(4); if (throwsExceptions != null) { String[] exceptions = throwsExceptions.replaceAll( "throws" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max, StringValue.Empty).split( StringValue.Comma); for (String exception : exceptions) { exception = exception.trim(); ExceptionMeta exceptionMeta = new ExceptionMeta(); exceptionMeta.name = exception; exceptionMeta.nameInMethodName = typeNameConverter.toAvailableInMethodName(exception); meta.throwsExceptions.add(exceptionMeta); } } dest.add(meta); } return dest; } }
MethodMetaExtractor { public List<MethodMeta> extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); List<MethodMeta> dest = new ArrayList<MethodMeta>(); TypeNameConverter typeNameConverter = new TypeNameConverter(config); sourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher mat = RegExp.PatternObject.MethodSignatureArea.matcher(sourceCodeString); while (mat.find()) { MethodMeta meta = new MethodMeta(); String methodSignatureArea = mat.group(0).replaceAll(StringValue.CarriageReturn, StringValue.Empty) .replaceAll(StringValue.LineFeed, StringValue.Space); if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + classMeta.name + "\\(" + RegExp.Anything_ZeroOrMore_Min + "\\)" + RegExp.Anything_ZeroOrMore_Min)) { continue; } String trimmedMethodSignatureArea = methodSignatureArea.replaceAll("\\s*,\\s*", ",").replaceAll( "\\s*<\\s*", "<").replaceAll("\\s*>", ">"); String methodSignatureAreaWithoutAccessModifier = trimAccessModifierFromMethodSignatureArea(trimmedMethodSignatureArea); Matcher matcherGrouping = RegExp.PatternObject.MethodSignatureWithoutAccessModifier_Group .matcher(StringValue.Space + methodSignatureAreaWithoutAccessModifier); if (!matcherGrouping.find()) { continue; } if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + "static" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + RegExp.Anything_ZeroOrMore_Min)) { meta.isStatic = true; } meta.accessModifier = getAccessModifier(methodSignatureArea); String grouped = matcherGrouping.group(1); String returnTypeFull = grouped.replaceAll("final ", StringValue.Empty).split("\\s+")[0].trim(); returnTypeFull = trimGenericsIfNested(returnTypeFull); Matcher toGenericsMatcherForReturn = Pattern.compile(RegExp.Generics_Group).matcher(returnTypeFull); while (toGenericsMatcherForReturn.find()) { String[] generics = toGenericsMatcherForReturn.group().replaceAll("<", StringValue.Empty).replaceAll( ">", StringValue.Empty).split(StringValue.Comma); for (String generic : generics) { generic = typeNameConverter .toCompilableType(generic, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.generics.add(generic); } } String returnTypeName = returnTypeFull.replace(RegExp.Generics, StringValue.Empty); if (!returnTypeName.equals("void")) { meta.returnType.name = typeNameConverter.toCompilableType(returnTypeName, meta.returnType.generics, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.nameInMethodName = typeNameConverter.toAvailableInMethodName(meta.returnType.name); } meta.name = matcherGrouping.group(2); String argsAreaString = matcherGrouping.group(3); ArgTypeMetaExtractor argTypeMetaExtractor = new ArgTypeMetaExtractor(config); argTypeMetaExtractor.initialize(classMeta).doExtract(argsAreaString); meta.argNames = argTypeMetaExtractor.getExtractedNameList(); meta.argTypes = argTypeMetaExtractor.getExtractedMetaList(); String fieldName = null; String fieldType = null; if (meta.name.matches("^set.+")) { fieldName = meta.name.substring(3); if (meta.argTypes.size() > 0) { fieldType = meta.argTypes.get(0).name; } } else if (meta.name.matches("^get.+")) { fieldName = meta.name.substring(3); fieldType = meta.returnType.name; } else if (meta.name.matches("^is.+")) { fieldName = meta.name.substring(2); fieldType = meta.returnType.name; } if (fieldName != null && fieldType != null) { meta.isAccessor = isPrivateFieldExists(fieldType, fieldName, sourceCodeString); } String throwsExceptions = matcherGrouping.group(4); if (throwsExceptions != null) { String[] exceptions = throwsExceptions.replaceAll( "throws" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max, StringValue.Empty).split( StringValue.Comma); for (String exception : exceptions) { exception = exception.trim(); ExceptionMeta exceptionMeta = new ExceptionMeta(); exceptionMeta.name = exception; exceptionMeta.nameInMethodName = typeNameConverter.toAvailableInMethodName(exception); meta.throwsExceptions.add(exceptionMeta); } } dest.add(meta); } return dest; } MethodMetaExtractor(Configuration config); }
MethodMetaExtractor { public List<MethodMeta> extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); List<MethodMeta> dest = new ArrayList<MethodMeta>(); TypeNameConverter typeNameConverter = new TypeNameConverter(config); sourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher mat = RegExp.PatternObject.MethodSignatureArea.matcher(sourceCodeString); while (mat.find()) { MethodMeta meta = new MethodMeta(); String methodSignatureArea = mat.group(0).replaceAll(StringValue.CarriageReturn, StringValue.Empty) .replaceAll(StringValue.LineFeed, StringValue.Space); if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + classMeta.name + "\\(" + RegExp.Anything_ZeroOrMore_Min + "\\)" + RegExp.Anything_ZeroOrMore_Min)) { continue; } String trimmedMethodSignatureArea = methodSignatureArea.replaceAll("\\s*,\\s*", ",").replaceAll( "\\s*<\\s*", "<").replaceAll("\\s*>", ">"); String methodSignatureAreaWithoutAccessModifier = trimAccessModifierFromMethodSignatureArea(trimmedMethodSignatureArea); Matcher matcherGrouping = RegExp.PatternObject.MethodSignatureWithoutAccessModifier_Group .matcher(StringValue.Space + methodSignatureAreaWithoutAccessModifier); if (!matcherGrouping.find()) { continue; } if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + "static" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + RegExp.Anything_ZeroOrMore_Min)) { meta.isStatic = true; } meta.accessModifier = getAccessModifier(methodSignatureArea); String grouped = matcherGrouping.group(1); String returnTypeFull = grouped.replaceAll("final ", StringValue.Empty).split("\\s+")[0].trim(); returnTypeFull = trimGenericsIfNested(returnTypeFull); Matcher toGenericsMatcherForReturn = Pattern.compile(RegExp.Generics_Group).matcher(returnTypeFull); while (toGenericsMatcherForReturn.find()) { String[] generics = toGenericsMatcherForReturn.group().replaceAll("<", StringValue.Empty).replaceAll( ">", StringValue.Empty).split(StringValue.Comma); for (String generic : generics) { generic = typeNameConverter .toCompilableType(generic, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.generics.add(generic); } } String returnTypeName = returnTypeFull.replace(RegExp.Generics, StringValue.Empty); if (!returnTypeName.equals("void")) { meta.returnType.name = typeNameConverter.toCompilableType(returnTypeName, meta.returnType.generics, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.nameInMethodName = typeNameConverter.toAvailableInMethodName(meta.returnType.name); } meta.name = matcherGrouping.group(2); String argsAreaString = matcherGrouping.group(3); ArgTypeMetaExtractor argTypeMetaExtractor = new ArgTypeMetaExtractor(config); argTypeMetaExtractor.initialize(classMeta).doExtract(argsAreaString); meta.argNames = argTypeMetaExtractor.getExtractedNameList(); meta.argTypes = argTypeMetaExtractor.getExtractedMetaList(); String fieldName = null; String fieldType = null; if (meta.name.matches("^set.+")) { fieldName = meta.name.substring(3); if (meta.argTypes.size() > 0) { fieldType = meta.argTypes.get(0).name; } } else if (meta.name.matches("^get.+")) { fieldName = meta.name.substring(3); fieldType = meta.returnType.name; } else if (meta.name.matches("^is.+")) { fieldName = meta.name.substring(2); fieldType = meta.returnType.name; } if (fieldName != null && fieldType != null) { meta.isAccessor = isPrivateFieldExists(fieldType, fieldName, sourceCodeString); } String throwsExceptions = matcherGrouping.group(4); if (throwsExceptions != null) { String[] exceptions = throwsExceptions.replaceAll( "throws" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max, StringValue.Empty).split( StringValue.Comma); for (String exception : exceptions) { exception = exception.trim(); ExceptionMeta exceptionMeta = new ExceptionMeta(); exceptionMeta.name = exception; exceptionMeta.nameInMethodName = typeNameConverter.toAvailableInMethodName(exception); meta.throwsExceptions.add(exceptionMeta); } } dest.add(meta); } return dest; } MethodMetaExtractor(Configuration config); MethodMetaExtractor initialize(String sourceCodeString); MethodMetaExtractor initialize(ClassMeta classMeta); MethodMetaExtractor initialize(ClassMeta classMeta, String sourceCodeString); List<MethodMeta> extract(String sourceCodeString); }
MethodMetaExtractor { public List<MethodMeta> extract(String sourceCodeString) { Assertion.on("sourceCodeString").mustNotBeNull(sourceCodeString); List<MethodMeta> dest = new ArrayList<MethodMeta>(); TypeNameConverter typeNameConverter = new TypeNameConverter(config); sourceCodeString = TrimFilterUtil.doAllFilters(sourceCodeString); Matcher mat = RegExp.PatternObject.MethodSignatureArea.matcher(sourceCodeString); while (mat.find()) { MethodMeta meta = new MethodMeta(); String methodSignatureArea = mat.group(0).replaceAll(StringValue.CarriageReturn, StringValue.Empty) .replaceAll(StringValue.LineFeed, StringValue.Space); if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + classMeta.name + "\\(" + RegExp.Anything_ZeroOrMore_Min + "\\)" + RegExp.Anything_ZeroOrMore_Min)) { continue; } String trimmedMethodSignatureArea = methodSignatureArea.replaceAll("\\s*,\\s*", ",").replaceAll( "\\s*<\\s*", "<").replaceAll("\\s*>", ">"); String methodSignatureAreaWithoutAccessModifier = trimAccessModifierFromMethodSignatureArea(trimmedMethodSignatureArea); Matcher matcherGrouping = RegExp.PatternObject.MethodSignatureWithoutAccessModifier_Group .matcher(StringValue.Space + methodSignatureAreaWithoutAccessModifier); if (!matcherGrouping.find()) { continue; } if (methodSignatureArea.matches(RegExp.Anything_ZeroOrMore_Min + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + "static" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max + RegExp.Anything_ZeroOrMore_Min)) { meta.isStatic = true; } meta.accessModifier = getAccessModifier(methodSignatureArea); String grouped = matcherGrouping.group(1); String returnTypeFull = grouped.replaceAll("final ", StringValue.Empty).split("\\s+")[0].trim(); returnTypeFull = trimGenericsIfNested(returnTypeFull); Matcher toGenericsMatcherForReturn = Pattern.compile(RegExp.Generics_Group).matcher(returnTypeFull); while (toGenericsMatcherForReturn.find()) { String[] generics = toGenericsMatcherForReturn.group().replaceAll("<", StringValue.Empty).replaceAll( ">", StringValue.Empty).split(StringValue.Comma); for (String generic : generics) { generic = typeNameConverter .toCompilableType(generic, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.generics.add(generic); } } String returnTypeName = returnTypeFull.replace(RegExp.Generics, StringValue.Empty); if (!returnTypeName.equals("void")) { meta.returnType.name = typeNameConverter.toCompilableType(returnTypeName, meta.returnType.generics, classMeta.importedList, classMeta.packageName).trim(); meta.returnType.nameInMethodName = typeNameConverter.toAvailableInMethodName(meta.returnType.name); } meta.name = matcherGrouping.group(2); String argsAreaString = matcherGrouping.group(3); ArgTypeMetaExtractor argTypeMetaExtractor = new ArgTypeMetaExtractor(config); argTypeMetaExtractor.initialize(classMeta).doExtract(argsAreaString); meta.argNames = argTypeMetaExtractor.getExtractedNameList(); meta.argTypes = argTypeMetaExtractor.getExtractedMetaList(); String fieldName = null; String fieldType = null; if (meta.name.matches("^set.+")) { fieldName = meta.name.substring(3); if (meta.argTypes.size() > 0) { fieldType = meta.argTypes.get(0).name; } } else if (meta.name.matches("^get.+")) { fieldName = meta.name.substring(3); fieldType = meta.returnType.name; } else if (meta.name.matches("^is.+")) { fieldName = meta.name.substring(2); fieldType = meta.returnType.name; } if (fieldName != null && fieldType != null) { meta.isAccessor = isPrivateFieldExists(fieldType, fieldName, sourceCodeString); } String throwsExceptions = matcherGrouping.group(4); if (throwsExceptions != null) { String[] exceptions = throwsExceptions.replaceAll( "throws" + RegExp.WhiteSpace.Consecutive_OneOrMore_Max, StringValue.Empty).split( StringValue.Comma); for (String exception : exceptions) { exception = exception.trim(); ExceptionMeta exceptionMeta = new ExceptionMeta(); exceptionMeta.name = exception; exceptionMeta.nameInMethodName = typeNameConverter.toAvailableInMethodName(exception); meta.throwsExceptions.add(exceptionMeta); } } dest.add(meta); } return dest; } MethodMetaExtractor(Configuration config); MethodMetaExtractor initialize(String sourceCodeString); MethodMetaExtractor initialize(ClassMeta classMeta); MethodMetaExtractor initialize(ClassMeta classMeta, String sourceCodeString); List<MethodMeta> extract(String sourceCodeString);  }