本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.LocalizedMessage类的典型用法代码示例。如果您正苦于以下问题:Java LocalizedMessage类的具体用法?Java LocalizedMessage怎么用?Java LocalizedMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalizedMessage类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了LocalizedMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logIoException
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
/**
* Helper method to log an io exception.
* @param exception the exception that occurred
* @param file the file that could not be processed
*/
private void logIoException(IOException exception, File file) {
String[] args = null;
String key = "general.fileNotFound";
if (!(exception instanceof FileNotFoundException)) {
args = new String[] {exception.getMessage()};
key = "general.exception";
}
final LocalizedMessage message =
new LocalizedMessage(
0,
Definitions.CHECKSTYLE_BUNDLE,
key,
args,
getId(),
getClass(), null);
final SortedSet<LocalizedMessage> messages = new TreeSet<LocalizedMessage>();
messages.add(message);
getMessageDispatcher().fireErrors(file.getPath(), messages);
log.debug("IOException occurred.", exception);
}
示例2: logLoadErrorImpl
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
/**
* Common implementation for logLoadError() method.
* @param lineNo line number of the problem.
* @param columnNo column number of the problem.
* @param msgKey message key to use.
* @param values values to fill the message out.
*/
protected final void logLoadErrorImpl(int lineNo, int columnNo,
String msgKey, Object... values) {
if (!logLoadErrors) {
final LocalizedMessage msg = new LocalizedMessage(lineNo,
columnNo,
getMessageBundle(),
msgKey,
values,
getSeverityLevel(),
getId(),
getClass(),
null);
throw new IllegalStateException(msg.getMessage());
}
if (!suppressLoadErrors) {
log(lineNo, columnNo, msgKey, values);
}
}
示例3: loadProperties
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
/**
* Loads properties from a File.
* @param file
* the properties file
* @return the properties in file
* @throws CheckstyleException
* when could not load properties file
*/
private static Properties loadProperties(File file)
throws CheckstyleException {
final Properties properties = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
properties.load(fis);
}
catch (final IOException ex) {
final LocalizedMessage loadPropertiesExceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, LOAD_PROPERTIES_EXCEPTION,
new String[] {file.getAbsolutePath()}, null, Main.class, null);
throw new CheckstyleException(loadPropertiesExceptionMessage.getMessage(), ex);
}
finally {
Closeables.closeQuietly(fis);
}
return properties;
}
示例4: createObjectFromFullModuleNames
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
/**
* 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 {
String optionalNames = "";
for (String fullModuleName : new TreeSet<String>(fullModuleNames)) {
if (optionalNames.length() != 0) {
optionalNames += STRING_SEPARATOR;
}
optionalNames += fullModuleName;
}
final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE,
new String[] {name, optionalNames}, null, getClass(), null);
throw new CheckstyleException(exceptionMessage.getMessage());
}
return returnValue;
}
示例5: fireErrors
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
/**
* Notify all listeners about the errors in a file.
*
* @param fileName the audited file
* @param errors the audit errors from the file
*/
@Override
public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
boolean hasNonFilteredViolations = false;
for (final LocalizedMessage element : errors) {
final AuditEvent event = new AuditEvent(this, stripped, element);
if (filters.accept(event)) {
hasNonFilteredViolations = true;
for (final AuditListener listener : listeners) {
listener.addError(event);
}
}
}
if (hasNonFilteredViolations && cache != null) {
cache.remove(fileName);
}
}
示例6: getFilteredMessages
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
/**
* Returns filtered set of {@link LocalizedMessage}.
* @param fileName path to the file
* @param fileContents the contents of the file
* @param rootAST root AST element {@link DetailAST} of the file
* @return filtered set of messages
*/
private SortedSet<LocalizedMessage> getFilteredMessages(
String fileName, FileContents fileContents, DetailAST rootAST) {
final SortedSet<LocalizedMessage> result = new TreeSet<LocalizedMessage>(messages);
for (LocalizedMessage element : messages) {
final TreeWalkerAuditEvent event =
new TreeWalkerAuditEvent(fileContents, fileName, element, rootAST);
for (TreeWalkerFilter filter : filters) {
if (!filter.accept(event)) {
result.remove(element);
break;
}
}
}
return result;
}
示例7: testDefaultHooks
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testDefaultHooks() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
npathComplexityCheckObj.visitToken(ast);
final SortedSet<LocalizedMessage> messages1 = npathComplexityCheckObj.getMessages();
Assert.assertEquals("No exception messages expected", 0, messages1.size());
npathComplexityCheckObj.leaveToken(ast);
final SortedSet<LocalizedMessage> messages2 = npathComplexityCheckObj.getMessages();
Assert.assertEquals("No exception messages expected", 0, messages2.size());
}
示例8: testParents
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testParents() {
final DetailAST parent = new DetailAST();
parent.setType(TokenTypes.STATIC_INIT);
final DetailAST method = new DetailAST();
method.setType(TokenTypes.METHOD_DEF);
parent.setFirstChild(method);
final DetailAST ctor = new DetailAST();
ctor.setType(TokenTypes.CTOR_DEF);
method.setNextSibling(ctor);
final DeclarationOrderCheck check = new DeclarationOrderCheck();
check.visitToken(method);
final SortedSet<LocalizedMessage> messages1 = check.getMessages();
assertEquals("No exception messages expected", 0, messages1.size());
check.visitToken(ctor);
final SortedSet<LocalizedMessage> messages2 = check.getMessages();
assertEquals("No exception messages expected", 0, messages2.size());
}
示例9: testWrongFile
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testWrongFile() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(NewlineAtEndOfFileCheck.class);
final NewlineAtEndOfFileCheck check = new NewlineAtEndOfFileCheck();
check.configure(checkConfig);
final List<String> lines = new ArrayList<String>(1);
lines.add("txt");
final File impossibleFile = new File("");
final FileText fileText = new FileText(impossibleFile, lines);
final Set<LocalizedMessage> messages = check.process(impossibleFile, fileText);
assertEquals("Amount of messages is unexpected",
1, messages.size());
final Iterator<LocalizedMessage> iterator = messages.iterator();
assertEquals("Violation message differs from expected",
getCheckMessage(MSG_KEY_UNABLE_OPEN, ""), iterator.next().getMessage());
}
示例10: testIsSuppressedWithAllArgument
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testIsSuppressedWithAllArgument() throws Exception {
createHolder("all", 100, 100, 350, 350);
final Checker source = new Checker();
final LocalizedMessage firstMessageForTest =
new LocalizedMessage(100, 10, null, null, null, "id", MemberNameCheck.class, "msg");
final AuditEvent firstEventForTest =
new AuditEvent(source, "fileName", firstMessageForTest);
assertFalse("Event is suppressed",
SuppressWarningsHolder.isSuppressed(firstEventForTest));
final LocalizedMessage secondMessageForTest =
new LocalizedMessage(100, 150, null, null, null, "id", MemberNameCheck.class, "msg");
final AuditEvent secondEventForTest =
new AuditEvent(source, "fileName", secondMessageForTest);
assertTrue("Event is not suppressed",
SuppressWarningsHolder.isSuppressed(secondEventForTest));
final LocalizedMessage thirdMessageForTest =
new LocalizedMessage(200, 1, null, null, null, "id", MemberNameCheck.class, "msg");
final AuditEvent thirdEventForTest =
new AuditEvent(source, "fileName", thirdMessageForTest);
assertTrue("Event is not suppressed",
SuppressWarningsHolder.isSuppressed(thirdEventForTest));
}
示例11: testIoException
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
/**
* Tests IO exception, that can occur during reading of properties file.
*/
@Test
public void testIoException() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(UniquePropertiesCheck.class);
final UniquePropertiesCheck check = new UniquePropertiesCheck();
check.configure(checkConfig);
final String fileName =
getPath("InputUniquePropertiesCheckNotExisting.properties");
final File file = new File(fileName);
final FileText fileText = new FileText(file, Collections.<String>emptyList());
final SortedSet<LocalizedMessage> messages =
check.process(file, fileText);
assertEquals("Wrong messages count: " + messages.size(),
1, messages.size());
final LocalizedMessage message = messages.iterator().next();
final String retrievedMessage = messages.iterator().next().getKey();
assertEquals("Message key '" + retrievedMessage
+ "' is not valid", "unable.open.cause",
retrievedMessage);
assertEquals("Message '" + message.getMessage()
+ "' is not valid", message.getMessage(),
getCheckMessage(MSG_IO_EXCEPTION_KEY, fileName, getFileNotFoundDetail(file)));
}
示例12: testBadFile
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testBadFile() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(FileTabCharacterCheck.class);
checkConfig.addAttribute("eachLine", "false");
final String path = getPath("Claira");
final String exceptionMessage = " (No such file or directory)";
final LocalizedMessage localizedMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, "general.exception",
new String[] {path + exceptionMessage}, null, getClass(), null);
final String[] expected = {
"0: " + localizedMessage.getMessage(),
};
final File[] files = {
new File(path),
};
verify(createChecker(checkConfig), files, path, expected);
}
示例13: testCreateModuleWithNonExistName
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
private void testCreateModuleWithNonExistName(String name) {
try {
factory.createModule(name);
fail("Exception is expected");
}
catch (CheckstyleException ex) {
final String attemptedNames = BASE_PACKAGE + PACKAGE_SEPARATOR + name + STRING_SEPARATOR
+ name + CHECK_SUFFIX + STRING_SEPARATOR
+ BASE_PACKAGE + PACKAGE_SEPARATOR + name + CHECK_SUFFIX;
final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE,
new String[] {name, attemptedNames}, null, factory.getClass(), null);
assertEquals("Invalid exception message",
exceptionMessage.getMessage(), ex.getMessage());
}
}
示例14: testCreateObjectFromFullModuleNamesWithAmbiguousException
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testCreateObjectFromFullModuleNamesWithAmbiguousException() {
final String barPackage = BASE_PACKAGE + ".internal.testmodules.packageobjectfactory.bar";
final String fooPackage = BASE_PACKAGE + ".internal.testmodules.packageobjectfactory.foo";
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final PackageObjectFactory objectFactory = new PackageObjectFactory(
new LinkedHashSet<String>(Arrays.asList(barPackage, fooPackage)), classLoader);
final String name = "FooCheck";
try {
objectFactory.createModule(name);
fail("Exception is expected");
}
catch (CheckstyleException ex) {
final String optionalNames = barPackage + PACKAGE_SEPARATOR + name
+ STRING_SEPARATOR + fooPackage + PACKAGE_SEPARATOR + name;
final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE,
new String[] {name, optionalNames}, null, getClass(), null);
assertEquals("Invalid exception message",
exceptionMessage.getMessage(), ex.getMessage());
}
}
示例15: testCreateObjectFromFullModuleNamesWithCantInstantiateException
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testCreateObjectFromFullModuleNamesWithCantInstantiateException() {
final String package1 = BASE_PACKAGE + ".wrong1";
final String package2 = BASE_PACKAGE + ".wrong2";
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final PackageObjectFactory objectFactory = new PackageObjectFactory(
new LinkedHashSet<String>(Arrays.asList(package1, package2)), classLoader);
final String name = "FooCheck";
final String checkName = name + CHECK_SUFFIX;
try {
objectFactory.createModule(name);
fail("Exception is expected");
}
catch (CheckstyleException ex) {
final String attemptedNames = package1 + PACKAGE_SEPARATOR + name + STRING_SEPARATOR
+ package2 + PACKAGE_SEPARATOR + name + STRING_SEPARATOR
+ checkName + STRING_SEPARATOR
+ package1 + PACKAGE_SEPARATOR + checkName + STRING_SEPARATOR
+ package2 + PACKAGE_SEPARATOR + checkName;
final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE,
new String[] {name, attemptedNames}, null, getClass(), null);
assertEquals("Invalid exception message",
exceptionMessage.getMessage(), ex.getMessage());
}
}