本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.LocalizedMessage.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java LocalizedMessage.getMessage方法的具体用法?Java LocalizedMessage.getMessage怎么用?Java LocalizedMessage.getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.LocalizedMessage
的用法示例。
在下文中一共展示了LocalizedMessage.getMessage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
示例5: testMissedHtmlTagParseErrorMessage
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入方法依赖的package包/类
@Test
public void testMissedHtmlTagParseErrorMessage() throws Exception {
final String actual = (String) GET_PARSE_ERROR_MESSAGE.invoke(null,
new ParseErrorMessage(35, MSG_JAVADOC_MISSED_HTML_CLOSE, 7, "xyz"));
final LocalizedMessage localizedMessage = new LocalizedMessage(
35,
"com.puppycrawl.tools.checkstyle.checks.javadoc.messages",
MSG_JAVADOC_MISSED_HTML_CLOSE,
new Object[] {7, "xyz"},
"",
DetailNodeTreeStringPrinter.class,
null);
final String expected = "[ERROR:35] " + localizedMessage.getMessage();
assertEquals("Javadoc parse error message for missed HTML tag doesn't meet expectations",
expected, actual);
}
示例6: testParseErrorMessage
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入方法依赖的package包/类
@Test
public void testParseErrorMessage() throws Exception {
final String actual = (String) GET_PARSE_ERROR_MESSAGE.invoke(null,
new ParseErrorMessage(10, MSG_JAVADOC_PARSE_RULE_ERROR,
9, "no viable alternative at input ' xyz'", "SOME_JAVADOC_ELEMENT"));
final LocalizedMessage localizedMessage = new LocalizedMessage(
10,
"com.puppycrawl.tools.checkstyle.checks.javadoc.messages",
MSG_JAVADOC_PARSE_RULE_ERROR,
new Object[] {9, "no viable alternative at input ' xyz'", "SOME_JAVADOC_ELEMENT"},
"",
DetailNodeTreeStringPrinter.class,
null);
final String expected = "[ERROR:10] " + localizedMessage.getMessage();
assertEquals("Javadoc parse error message doesn't meet expectations", expected, actual);
}
示例7: testWrongSingletonParseErrorMessage
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入方法依赖的package包/类
@Test
public void testWrongSingletonParseErrorMessage() throws Exception {
final String actual = (String) GET_PARSE_ERROR_MESSAGE.invoke(null,
new ParseErrorMessage(100, MSG_JAVADOC_WRONG_SINGLETON_TAG,
9, "tag"));
final LocalizedMessage localizedMessage = new LocalizedMessage(
100,
"com.puppycrawl.tools.checkstyle.checks.javadoc.messages",
MSG_JAVADOC_WRONG_SINGLETON_TAG,
new Object[] {9, "tag"},
"",
DetailNodeTreeStringPrinter.class,
null);
final String expected = "[ERROR:100] " + localizedMessage.getMessage();
assertEquals("Javadoc parse error message for void elements with close tag "
+ "doesn't meet expectations", expected, actual);
}
示例8: 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 {
final String optionalNames = fullModuleNames.stream()
.sorted()
.collect(Collectors.joining(STRING_SEPARATOR));
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;
}
示例9: getParseErrorMessage
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入方法依赖的package包/类
/**
* Builds error message base on ParseErrorMessage's message key, its arguments, etc.
* @param parseErrorMessage ParseErrorMessage
* @return error message
*/
private static String getParseErrorMessage(ParseErrorMessage parseErrorMessage) {
final LocalizedMessage lmessage = new LocalizedMessage(
parseErrorMessage.getLineNumber(),
"com.puppycrawl.tools.checkstyle.checks.javadoc.messages",
parseErrorMessage.getMessageKey(),
parseErrorMessage.getMessageArguments(),
"",
DetailNodeTreeStringPrinter.class,
null);
return "[ERROR:" + parseErrorMessage.getLineNumber() + "] " + lmessage.getMessage();
}
示例10: createModule
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入方法依赖的package包/类
/**
* Creates a new instance of a class from a given name, or that name
* concatenated with "Check". If the name is
* a class name, creates an instance of the named class. Otherwise, creates
* an instance of a class name obtained by concatenating the given name
* to a package name from a given list of package names.
* @param name the name of a class.
* @return the {@code Object} created by loader.
* @throws CheckstyleException if an error occurs.
*/
@Override
public Object createModule(String name) throws CheckstyleException {
Object instance = null;
// if the name is a simple class name, try to find it in maps at first
if (!name.contains(PACKAGE_SEPARATOR)) {
instance = createFromStandardCheckSet(name);
// find the name in third party map
if (instance == null) {
if (thirdPartyNameToFullModuleNames == null) {
thirdPartyNameToFullModuleNames =
generateThirdPartyNameToFullModuleName(moduleClassLoader);
}
instance = createObjectFromMap(name, thirdPartyNameToFullModuleNames);
}
}
if (instance == null) {
instance = createObject(name);
}
if (instance == null
&& moduleLoadOption == ModuleLoadOption.TRY_IN_ALL_REGISTERED_PACKAGES) {
instance = createModuleByTryInEachPackage(name);
}
if (instance == null) {
String attemptedNames = null;
if (!name.contains(PACKAGE_SEPARATOR)) {
final String nameCheck = name + CHECK_SUFFIX;
attemptedNames = joinPackageNamesWithClassName(name, packages)
+ STRING_SEPARATOR + nameCheck + STRING_SEPARATOR
+ joinPackageNamesWithClassName(nameCheck, packages);
}
final LocalizedMessage exceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE,
new String[] {name, attemptedNames}, null, getClass(), null);
throw new CheckstyleException(exceptionMessage.getMessage());
}
return instance;
}
示例11: createListener
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入方法依赖的package包/类
/**
* Creates the audit listener.
*
* @param format format of the audit listener
* @param outputLocation the location of output
* @return a fresh new {@code AuditListener}
* @exception FileNotFoundException when provided output location is not found
* @noinspection IOResourceOpenedButNotSafelyClosed
*/
private static AuditListener createListener(String format,
String outputLocation)
throws FileNotFoundException {
// setup the output stream
final OutputStream out;
final AutomaticBean.OutputStreamOptions closeOutputStream;
if (outputLocation == null) {
out = System.out;
closeOutputStream = AutomaticBean.OutputStreamOptions.NONE;
}
else {
out = new FileOutputStream(outputLocation);
closeOutputStream = AutomaticBean.OutputStreamOptions.CLOSE;
}
// setup a listener
final AuditListener listener;
if (XML_FORMAT_NAME.equals(format)) {
listener = new XMLLogger(out, closeOutputStream);
}
else if (PLAIN_FORMAT_NAME.equals(format)) {
listener = new DefaultLogger(out, closeOutputStream, out,
AutomaticBean.OutputStreamOptions.NONE);
}
else {
if (closeOutputStream == AutomaticBean.OutputStreamOptions.CLOSE) {
CommonUtils.close(out);
}
final LocalizedMessage outputFormatExceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, CREATE_LISTENER_EXCEPTION,
new String[] {format, PLAIN_FORMAT_NAME, XML_FORMAT_NAME}, null,
Main.class, null);
throw new IllegalStateException(outputFormatExceptionMessage.getMessage());
}
return listener;
}
示例12: createListener
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入方法依赖的package包/类
/**
* Creates the audit listener.
*
* @param format format of the audit listener
* @param outputLocation the location of output
* @return a fresh new {@code AuditListener}
* @exception FileNotFoundException when provided output location is not found
* @noinspection IOResourceOpenedButNotSafelyClosed
*/
private static AuditListener createListener(String format,
String outputLocation)
throws FileNotFoundException {
// setup the output stream
final OutputStream out;
final AutomaticBean.OutputStreamOptions closeOutputStream;
if (outputLocation == null) {
out = System.out;
closeOutputStream = AutomaticBean.OutputStreamOptions.NONE;
}
else {
out = new FileOutputStream(outputLocation);
closeOutputStream = AutomaticBean.OutputStreamOptions.CLOSE;
}
// setup a listener
final AuditListener listener;
if (XML_FORMAT_NAME.equals(format)) {
listener = new XMLLogger(out, closeOutputStream);
}
else if (PLAIN_FORMAT_NAME.equals(format)) {
listener = new DefaultLogger(out, closeOutputStream, out,
AutomaticBean.OutputStreamOptions.NONE);
}
else {
if (closeOutputStream == AutomaticBean.OutputStreamOptions.CLOSE) {
CommonUtils.close(out);
}
final LocalizedMessage outputFormatExceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, CREATE_LISTENER_EXCEPTION,
new String[] {format, PLAIN_FORMAT_NAME, XML_FORMAT_NAME}, null,
Main.class, null);
throw new IllegalStateException(outputFormatExceptionMessage.getMessage());
}
return listener;
}
示例13: testLoadPropertiesIoException
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; //导入方法依赖的package包/类
@Test
public void testLoadPropertiesIoException() throws Exception {
final Class<?>[] param = new Class<?>[1];
param[0] = File.class;
final Method method = Main.class.getDeclaredMethod("loadProperties", param);
method.setAccessible(true);
try {
if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("windows")) {
// https://support.microsoft.com/en-us/kb/177506 but this only for NTFS
// WindowsServer 2012 use Resilient File System (ReFS), so any name is ok
final File file = new File(File.separator + ":invalid");
if (file.exists()) {
file.delete();
}
method.invoke(null, new File(file.getAbsolutePath()));
}
else {
method.invoke(null, new File(File.separator + "\0:invalid"));
}
fail("Exception was expected");
}
catch (InvocationTargetException ex) {
assertTrue("Invalid error cause",
ex.getCause() instanceof CheckstyleException);
// We do separate validation for message as in Windows
// disk drive letter appear in message,
// so we skip that drive letter for compatibility issues
final LocalizedMessage loadPropertiesMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, Main.LOAD_PROPERTIES_EXCEPTION,
new String[] {""}, null, getClass(), null);
final String causeMessage = ex.getCause().getLocalizedMessage();
final String localizedMessage = loadPropertiesMessage.getMessage();
final boolean samePrefix = causeMessage.substring(0, causeMessage.indexOf(' '))
.equals(localizedMessage
.substring(0, localizedMessage.indexOf(' ')));
final boolean sameSuffix =
causeMessage.substring(causeMessage.lastIndexOf(' '), causeMessage.length())
.equals(localizedMessage
.substring(localizedMessage.lastIndexOf(' '),
localizedMessage.length()));
assertTrue("Invalid error message", samePrefix || sameSuffix);
assertTrue("Invalid error message",
causeMessage.contains(":invalid"));
}
}