/** * Create object from one of Checkstyle module names. * @param name name of module. * @return instance of module. * @throws CheckstyleException if the class fails to instantiate or there are ambiguous classes. */ private Object createFromStandardCheckSet(String name) throws CheckstyleException { final String fullModuleName = NAME_TO_FULL_MODULE_NAME.get(name); Object instance = null; if (fullModuleName == null) { final String fullCheckModuleName = NAME_TO_FULL_MODULE_NAME.get(name + CHECK_SUFFIX); if (fullCheckModuleName != null) { instance = createObject(fullCheckModuleName); } } else { instance = createObject(fullModuleName); } return instance; }
instance = createObject(name);
instance = createObject(name);
/** * Searching to class with given name (or name concatenated with "Check") in existing * packages. Returns instance if class found or, otherwise, null. * @param name the name of a class. * @return the {@code Object} created by loader. * @throws CheckstyleException if an error occurs. */ private Object createModuleByTryInEachPackage(String name) throws CheckstyleException { final List<String> possibleNames = packages.stream() .map(packageName -> packageName + PACKAGE_SEPARATOR + name) .flatMap(className -> Stream.of(className, className + CHECK_SUFFIX)) .collect(Collectors.toList()); Object instance = null; for (String possibleName : possibleNames) { instance = createObject(possibleName); if (instance != null) { break; } } return instance; }
/** * Create Object from optional full module names. * In most case, there should be only one element in {@code fullModuleName}, otherwise * an exception would be thrown. * @param name name of module * @param fullModuleNames the supplied full module names set * @return instance of module if there is only one element in {@code fullModuleName} * @throws CheckstyleException if the class fails to instantiate or there are more than one * element in {@code fullModuleName} */ private Object createObjectFromFullModuleNames(String name, Set<String> fullModuleNames) throws CheckstyleException { final Object returnValue; if (fullModuleNames.size() == 1) { returnValue = createObject(fullModuleNames.iterator().next()); } else { final String optionalNames = fullModuleNames.stream() .sorted() .collect(Collectors.joining(STRING_SEPARATOR)); final LocalizedMessage exceptionMessage = new LocalizedMessage(1, Definitions.CHECKSTYLE_BUNDLE, AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE, new String[] {name, optionalNames}, null, getClass(), null); throw new CheckstyleException(exceptionMessage.getMessage()); } return returnValue; }
/** * Create object from one of Checkstyle module names. * @param name name of module. * @return instance of module. * @throws CheckstyleException if the class fails to instantiate or there are ambiguous classes. */ private Object createFromStandardCheckSet(String name) throws CheckstyleException { final String fullModuleName = NAME_TO_FULL_MODULE_NAME.get(name); Object instance = null; if (fullModuleName == null) { final String fullCheckModuleName = NAME_TO_FULL_MODULE_NAME.get(name + CHECK_SUFFIX); if (fullCheckModuleName != null) { instance = createObject(fullCheckModuleName); } } else { instance = createObject(fullModuleName); } return instance; }
/** * Searching to class with given name (or name concatenated with "Check") in existing * packages. Returns instance if class found or, otherwise, null. * @param name the name of a class. * @return the {@code Object} created by loader. * @throws CheckstyleException if an error occurs. */ private Object createModuleByTryInEachPackage(String name) throws CheckstyleException { final List<String> possibleNames = packages.stream() .map(packageName -> packageName + PACKAGE_SEPARATOR + name) .flatMap(className -> Stream.of(className, className + CHECK_SUFFIX)) .collect(Collectors.toList()); Object instance = null; for (String possibleName : possibleNames) { instance = createObject(possibleName); if (instance != null) { break; } } return instance; }
/** * Create Object from optional full module names. * In most case, there should be only one element in {@code fullModuleName}, otherwise * an exception would be thrown. * @param name name of module * @param fullModuleNames the supplied full module names set * @return instance of module if there is only one element in {@code fullModuleName} * @throws CheckstyleException if the class fails to instantiate or there are more than one * element in {@code fullModuleName} */ private Object createObjectFromFullModuleNames(String name, Set<String> fullModuleNames) throws CheckstyleException { final Object returnValue; if (fullModuleNames.size() == 1) { returnValue = createObject(fullModuleNames.iterator().next()); } else { final String optionalNames = fullModuleNames.stream() .sorted() .collect(Collectors.joining(STRING_SEPARATOR)); final LocalizedMessage exceptionMessage = new LocalizedMessage(1, Definitions.CHECKSTYLE_BUNDLE, AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE, new String[] {name, optionalNames}, null, getClass(), null); throw new CheckstyleException(exceptionMessage.getMessage()); } return returnValue; }