本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.MessageDispatcher类的典型用法代码示例。如果您正苦于以下问题:Java MessageDispatcher类的具体用法?Java MessageDispatcher怎么用?Java MessageDispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageDispatcher类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了MessageDispatcher类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkFilesForConsistencyRegardingTheirKeys
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; //导入依赖的package包/类
/**
* Compares th the specified key set with the key sets of the given translation files (arranged
* in a map). All missing keys are reported.
* @param fileKeys a Map from translation files to their key sets.
* @param keysThatMustExist the set of keys to compare with.
*/
private void checkFilesForConsistencyRegardingTheirKeys(SetMultimap<File, String> fileKeys,
Set<String> keysThatMustExist) {
for (File currentFile : fileKeys.keySet()) {
final MessageDispatcher dispatcher = getMessageDispatcher();
final String path = currentFile.getPath();
dispatcher.fireFileStarted(path);
final Set<String> currentFileKeys = fileKeys.get(currentFile);
final Set<String> missingKeys = new HashSet<String>();
for (String e : keysThatMustExist) {
if (!currentFileKeys.contains(e)) {
missingKeys.add(e);
}
}
if (!missingKeys.isEmpty()) {
for (Object key : missingKeys) {
log(0, MSG_KEY, key);
}
}
fireErrors(path);
dispatcher.fireFileFinished(path);
}
}
示例2: testLogIoException
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; //导入依赖的package包/类
@Test
public void testLogIoException() throws Exception {
//I can't put wrong file here. Checkstyle fails before check started.
//I saw some usage of file or handling of wrong file in Checker, or somewhere
//in checks running part. So I had to do it with reflection to improve coverage.
final TranslationCheck check = new TranslationCheck();
final DefaultConfiguration checkConfig = createModuleConfig(TranslationCheck.class);
final MessageDispatcher dispatcher = mock(MessageDispatcher.class);
check.configure(checkConfig);
check.setMessageDispatcher(dispatcher);
final Method logIoException = check.getClass().getDeclaredMethod("logIoException",
IOException.class,
File.class);
logIoException.setAccessible(true);
final File file = new File("");
logIoException.invoke(check, new IOException("test exception"), file);
Mockito.verify(dispatcher, times(1)).fireErrors(any(String.class), captor.capture());
final String actual = captor.getValue().first().getMessage();
assertThat("Invalid message: " + actual, actual, endsWith("test exception"));
}
示例3: checkFilesForConsistencyRegardingTheirKeys
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; //导入依赖的package包/类
/**
* Compares th the specified key set with the key sets of the given translation files (arranged
* in a map). All missing keys are reported.
* @param fileKeys a Map from translation files to their key sets.
* @param keysThatMustExist the set of keys to compare with.
*/
private void checkFilesForConsistencyRegardingTheirKeys(SetMultimap<File, String> fileKeys,
Set<String> keysThatMustExist) {
for (File currentFile : fileKeys.keySet()) {
final MessageDispatcher dispatcher = getMessageDispatcher();
final String path = currentFile.getPath();
dispatcher.fireFileStarted(path);
final Set<String> currentFileKeys = fileKeys.get(currentFile);
final Set<String> missingKeys = keysThatMustExist.stream()
.filter(e -> !currentFileKeys.contains(e)).collect(Collectors.toSet());
if (!missingKeys.isEmpty()) {
for (Object key : missingKeys) {
log(0, MSG_KEY, key);
}
}
fireErrors(path);
dispatcher.fireFileFinished(path);
}
}
示例4: logMissingTranslation
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; //导入依赖的package包/类
/**
* Logs that translation file is missing.
* @param filePath file path.
* @param fileName file name.
*/
private void logMissingTranslation(String filePath, String fileName) {
final MessageDispatcher dispatcher = getMessageDispatcher();
dispatcher.fireFileStarted(filePath);
log(0, MSG_KEY_MISSING_TRANSLATION_FILE, fileName);
fireErrors(filePath);
dispatcher.fireFileFinished(filePath);
}
示例5: getInternalMessageDispatcher
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; //导入依赖的package包/类
public MessageDispatcher getInternalMessageDispatcher() {
return getMessageDispatcher();
}
示例6: setMessageDispatcher
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; //导入依赖的package包/类
public void setMessageDispatcher(MessageDispatcher dispatcher) {
check.setMessageDispatcher(dispatcher);
}