本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.LocalizedMessage类的典型用法代码示例。如果您正苦于以下问题:Java LocalizedMessage类的具体用法?Java LocalizedMessage怎么用?Java LocalizedMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalizedMessage类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了LocalizedMessage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:TranslationCheck.java
示例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);
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:AbstractTypeAwareCheck.java
示例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;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:30,代码来源:Main.java
示例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;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:33,代码来源:PackageObjectFactory.java
示例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);
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:Checker.java
示例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;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:23,代码来源:TreeWalker.java
示例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());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:NPathComplexityCheckTest.java
示例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());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:DeclarationOrderCheckTest.java
示例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());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:NewlineAtEndOfFileCheckTest.java
示例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));
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:SuppressWarningsHolderTest.java
示例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)));
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:UniquePropertiesCheckTest.java
示例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);
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:FileTabCharacterCheckTest.java
示例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());
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:PackageObjectFactoryTest.java
示例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());
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:23,代码来源:PackageObjectFactoryTest.java
示例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());
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:PackageObjectFactoryTest.java
示例16: testAddErrorOnZeroColumns
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testAddErrorOnZeroColumns() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final LocalizedMessage message =
new LocalizedMessage(1, 0,
"messages.properties", "key", null, SeverityLevel.ERROR, null,
getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.fileStarted(ev);
logger.addError(ev);
logger.fileFinished(ev);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerErrorZeroColumn.xml"), outStream,
message.getMessage());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:XMLLoggerTest.java
示例17: testAddExceptionAfterFileStarted
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testAddExceptionAfterFileStarted()
throws Exception {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final AuditEvent fileStartedEvent = new AuditEvent(this, "Test.java");
logger.fileStarted(fileStartedEvent);
final LocalizedMessage message =
new LocalizedMessage(1, 1,
"messages.properties", null, null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
logger.fileFinished(ev);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerException2.xml"), outStream);
assertEquals("Invalid close count", 1, outStream.getCloseCount());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:XMLLoggerTest.java
示例18: testAddExceptionBeforeFileFinished
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testAddExceptionBeforeFileFinished()
throws Exception {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final LocalizedMessage message =
new LocalizedMessage(1, 1,
"messages.properties", null, null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
final AuditEvent fileFinishedEvent = new AuditEvent(this, "Test.java");
logger.fileFinished(fileFinishedEvent);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerException3.xml"), outStream);
assertEquals("Invalid close count", 1, outStream.getCloseCount());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:XMLLoggerTest.java
示例19: testAddExceptionBetweenFileStartedAndFinished
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testAddExceptionBetweenFileStartedAndFinished()
throws Exception {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final LocalizedMessage message =
new LocalizedMessage(1, 1,
"messages.properties", null, null, null, getClass(), null);
final AuditEvent fileStartedEvent = new AuditEvent(this, "Test.java");
logger.fileStarted(fileStartedEvent);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
final AuditEvent fileFinishedEvent = new AuditEvent(this, "Test.java");
logger.fileFinished(fileFinishedEvent);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerException2.xml"), outStream);
assertEquals("Invalid close count", 1, outStream.getCloseCount());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:XMLLoggerTest.java
示例20: testAuditFinishedWithoutFileFinished
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入依赖的package包/类
@Test
public void testAuditFinishedWithoutFileFinished() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final AuditEvent fileStartedEvent = new AuditEvent(this, "Test.java");
logger.fileStarted(fileStartedEvent);
final LocalizedMessage message =
new LocalizedMessage(1, 1,
"messages.properties", "key", null, SeverityLevel.ERROR, null,
getClass(), null);
final AuditEvent errorEvent = new AuditEvent(this, "Test.java", message);
logger.addError(errorEvent);
logger.fileFinished(errorEvent);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerError.xml"), outStream, message.getMessage());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:XMLLoggerTest.java
注:本文中的com.puppycrawl.tools.checkstyle.api.LocalizedMessage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论