@Test public void testSubstituteArguments() throws Exception { String newPropertyId = AbstractPropertyProvider.substituteArgument("category/name1/$1/name2/$2", "$1", "foo"); Assert.assertEquals("category/name1/foo/name2/$2", newPropertyId); newPropertyId = AbstractPropertyProvider.substituteArgument("category/name1/$1/name2/$2", "$2", "bar"); Assert.assertEquals("category/name1/$1/name2/bar", newPropertyId); newPropertyId = AbstractPropertyProvider.substituteArgument( "category/name1/$1.toLowerCase()/name2/$2.toUpperCase()", "$1", "FOO"); Assert.assertEquals("category/name1/foo/name2/$2.toUpperCase()", newPropertyId); newPropertyId = AbstractPropertyProvider.substituteArgument( "category/name1/$1.toLowerCase()/name2/$2.toUpperCase()", "$2", "bar"); Assert.assertEquals("category/name1/$1.toLowerCase()/name2/BAR", newPropertyId); newPropertyId = AbstractPropertyProvider.substituteArgument( "category/name1/$1.toLowerCase().substring(1)/name2", "$1", "FOO"); Assert.assertEquals("category/name1/oo/name2", newPropertyId); newPropertyId = AbstractPropertyProvider.substituteArgument( "category/name1/$1.toLowerCase().substring(1).concat(\"_post\")/name2/$2.concat(\"_post\")", "$1", "FOO"); newPropertyId = AbstractPropertyProvider.substituteArgument(newPropertyId, "$2", "bar"); Assert.assertEquals("category/name1/oo_post/name2/bar_post", newPropertyId); }
protected static String substituteArgument(String propertyId, String argName, String val) { int argStart = propertyId.indexOf(argName); String value = val == null ? "" : val; if (argStart > -1) { String argSegment = propertyId.substring(argStart); Matcher matcher = CHECK_FOR_METRIC_ARGUMENT_METHODS_REGEX.matcher(argSegment); if (matcher.find()) { argName = argSegment.substring(matcher.start(), matcher.end()); matcher = FIND_ARGUMENT_METHOD_REGEX.matcher(argName); while (matcher.find()) { int openParenIndex = argName.indexOf('(', matcher.start()); int closeParenIndex = indexOfClosingParenthesis(argName, openParenIndex); String methodName = argName.substring(matcher.start() + 1, openParenIndex); String args = argName.substring(openParenIndex + 1, closeParenIndex); List<Object> argList = new LinkedList<Object>(); List<Class<?>> paramTypes = new LinkedList<Class<?>>(); Matcher argMatcher = FIND_ARGUMENT_METHOD_ARGUMENTS_REGEX.matcher(args); while (argMatcher.find()) { addArgument(args, argMatcher.start(), argMatcher.end(), argList, paramTypes); } try { value = invokeArgumentMethod(value, methodName, argList, paramTypes); } catch (Exception e) { throw new IllegalArgumentException("Can't apply method " + methodName + " for argument " + argName + " in " + propertyId, e); } } if (value.equals(val)) { return propertyId; } } return propertyId.replace(argName, value); } throw new IllegalArgumentException("Can't substitute " + val + " for argument " + argName + " in " + propertyId); }
AbstractPropertyProvider extends BaseProvider implements PropertyProvider { protected static String substituteArgument(String propertyId, String argName, String val) { int argStart = propertyId.indexOf(argName); String value = val == null ? "" : val; if (argStart > -1) { String argSegment = propertyId.substring(argStart); Matcher matcher = CHECK_FOR_METRIC_ARGUMENT_METHODS_REGEX.matcher(argSegment); if (matcher.find()) { argName = argSegment.substring(matcher.start(), matcher.end()); matcher = FIND_ARGUMENT_METHOD_REGEX.matcher(argName); while (matcher.find()) { int openParenIndex = argName.indexOf('(', matcher.start()); int closeParenIndex = indexOfClosingParenthesis(argName, openParenIndex); String methodName = argName.substring(matcher.start() + 1, openParenIndex); String args = argName.substring(openParenIndex + 1, closeParenIndex); List<Object> argList = new LinkedList<Object>(); List<Class<?>> paramTypes = new LinkedList<Class<?>>(); Matcher argMatcher = FIND_ARGUMENT_METHOD_ARGUMENTS_REGEX.matcher(args); while (argMatcher.find()) { addArgument(args, argMatcher.start(), argMatcher.end(), argList, paramTypes); } try { value = invokeArgumentMethod(value, methodName, argList, paramTypes); } catch (Exception e) { throw new IllegalArgumentException("Can't apply method " + methodName + " for argument " + argName + " in " + propertyId, e); } } if (value.equals(val)) { return propertyId; } } return propertyId.replace(argName, value); } throw new IllegalArgumentException("Can't substitute " + val + " for argument " + argName + " in " + propertyId); } }
AbstractPropertyProvider extends BaseProvider implements PropertyProvider { protected static String substituteArgument(String propertyId, String argName, String val) { int argStart = propertyId.indexOf(argName); String value = val == null ? "" : val; if (argStart > -1) { String argSegment = propertyId.substring(argStart); Matcher matcher = CHECK_FOR_METRIC_ARGUMENT_METHODS_REGEX.matcher(argSegment); if (matcher.find()) { argName = argSegment.substring(matcher.start(), matcher.end()); matcher = FIND_ARGUMENT_METHOD_REGEX.matcher(argName); while (matcher.find()) { int openParenIndex = argName.indexOf('(', matcher.start()); int closeParenIndex = indexOfClosingParenthesis(argName, openParenIndex); String methodName = argName.substring(matcher.start() + 1, openParenIndex); String args = argName.substring(openParenIndex + 1, closeParenIndex); List<Object> argList = new LinkedList<Object>(); List<Class<?>> paramTypes = new LinkedList<Class<?>>(); Matcher argMatcher = FIND_ARGUMENT_METHOD_ARGUMENTS_REGEX.matcher(args); while (argMatcher.find()) { addArgument(args, argMatcher.start(), argMatcher.end(), argList, paramTypes); } try { value = invokeArgumentMethod(value, methodName, argList, paramTypes); } catch (Exception e) { throw new IllegalArgumentException("Can't apply method " + methodName + " for argument " + argName + " in " + propertyId, e); } } if (value.equals(val)) { return propertyId; } } return propertyId.replace(argName, value); } throw new IllegalArgumentException("Can't substitute " + val + " for argument " + argName + " in " + propertyId); } AbstractPropertyProvider(Map<String, Map<String, PropertyInfo>> componentMetrics); }
AbstractPropertyProvider extends BaseProvider implements PropertyProvider { protected static String substituteArgument(String propertyId, String argName, String val) { int argStart = propertyId.indexOf(argName); String value = val == null ? "" : val; if (argStart > -1) { String argSegment = propertyId.substring(argStart); Matcher matcher = CHECK_FOR_METRIC_ARGUMENT_METHODS_REGEX.matcher(argSegment); if (matcher.find()) { argName = argSegment.substring(matcher.start(), matcher.end()); matcher = FIND_ARGUMENT_METHOD_REGEX.matcher(argName); while (matcher.find()) { int openParenIndex = argName.indexOf('(', matcher.start()); int closeParenIndex = indexOfClosingParenthesis(argName, openParenIndex); String methodName = argName.substring(matcher.start() + 1, openParenIndex); String args = argName.substring(openParenIndex + 1, closeParenIndex); List<Object> argList = new LinkedList<Object>(); List<Class<?>> paramTypes = new LinkedList<Class<?>>(); Matcher argMatcher = FIND_ARGUMENT_METHOD_ARGUMENTS_REGEX.matcher(args); while (argMatcher.find()) { addArgument(args, argMatcher.start(), argMatcher.end(), argList, paramTypes); } try { value = invokeArgumentMethod(value, methodName, argList, paramTypes); } catch (Exception e) { throw new IllegalArgumentException("Can't apply method " + methodName + " for argument " + argName + " in " + propertyId, e); } } if (value.equals(val)) { return propertyId; } } return propertyId.replace(argName, value); } throw new IllegalArgumentException("Can't substitute " + val + " for argument " + argName + " in " + propertyId); } AbstractPropertyProvider(Map<String, Map<String, PropertyInfo>> componentMetrics); Map<String, Map<String, PropertyInfo>> getComponentMetrics(); }
AbstractPropertyProvider extends BaseProvider implements PropertyProvider { protected static String substituteArgument(String propertyId, String argName, String val) { int argStart = propertyId.indexOf(argName); String value = val == null ? "" : val; if (argStart > -1) { String argSegment = propertyId.substring(argStart); Matcher matcher = CHECK_FOR_METRIC_ARGUMENT_METHODS_REGEX.matcher(argSegment); if (matcher.find()) { argName = argSegment.substring(matcher.start(), matcher.end()); matcher = FIND_ARGUMENT_METHOD_REGEX.matcher(argName); while (matcher.find()) { int openParenIndex = argName.indexOf('(', matcher.start()); int closeParenIndex = indexOfClosingParenthesis(argName, openParenIndex); String methodName = argName.substring(matcher.start() + 1, openParenIndex); String args = argName.substring(openParenIndex + 1, closeParenIndex); List<Object> argList = new LinkedList<Object>(); List<Class<?>> paramTypes = new LinkedList<Class<?>>(); Matcher argMatcher = FIND_ARGUMENT_METHOD_ARGUMENTS_REGEX.matcher(args); while (argMatcher.find()) { addArgument(args, argMatcher.start(), argMatcher.end(), argList, paramTypes); } try { value = invokeArgumentMethod(value, methodName, argList, paramTypes); } catch (Exception e) { throw new IllegalArgumentException("Can't apply method " + methodName + " for argument " + argName + " in " + propertyId, e); } } if (value.equals(val)) { return propertyId; } } return propertyId.replace(argName, value); } throw new IllegalArgumentException("Can't substitute " + val + " for argument " + argName + " in " + propertyId); } AbstractPropertyProvider(Map<String, Map<String, PropertyInfo>> componentMetrics); Map<String, Map<String, PropertyInfo>> getComponentMetrics();  }