Class OrderedPropertiesCheck
- All Implemented Interfaces:
- Configurable,- Contextualizable,- FileSetCheck
   Rationale: Sorted properties make it easy for people to find required properties by name
   in file. This makes it easier to merge. While there are no problems at runtime.
   This check is valuable only on files with string resources where order of lines
   does not matter at all, but this can be improved.
   E.g.: checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/messages.properties
   You may suppress warnings of this check for files that have a logical structure like
   build files or log4j configuration files. See SuppressionFilter.
   
   <suppress checks="OrderedProperties"
     files="log4j.properties|ResourceBundle/Bug.*.properties|logging.properties"/>
   
 
Known limitation: The key should not contain a newline. The string compare will work, but not the line number reporting.
- Since:
- 8.22
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprivate static final classPrivate property implementation that keeps order of properties like in file.Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanAbstractAutomaticBean.OutputStreamOptions
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprivate static intInner method to get the index number of the position of keyName.private static PatterngetKeyPattern(String keyName) Method returns regular expression pattern given key name.private static intgetLineNumber(int startLineNo, FileText fileText, String previousProp, String propKey) Method returns the index number where the key is detected (starting at 0).protected voidprocessFiltered(File file, FileText fileText) Processes the file and check order.final voidsetFileExtensions(String... extensions) Setter to specify the file extensions of the files to process.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheckaddViolations, beginProcessing, destroy, finishProcessing, fireErrors, getFileContents, getFileExtensions, getMessageDispatcher, getTabWidth, getViolations, init, log, log, process, setFileContents, setMessageDispatcher, setTabWidthMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporterfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanconfigure, contextualize, getConfiguration, setupChildMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.puppycrawl.tools.checkstyle.api.ConfigurableconfigureMethods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizablecontextualize
- 
Field Details- 
MSG_KEYLocalization key for check violation.- See Also:
 
- 
MSG_IO_EXCEPTION_KEYLocalization key for IO exception occurred on file open.- See Also:
 
- 
SPACE_PATTERNPattern matching single space.
 
- 
- 
Constructor Details- 
OrderedPropertiesCheckpublic OrderedPropertiesCheck()Construct the check with default values.
 
- 
- 
Method Details- 
setFileExtensionsSetter to specify the file extensions of the files to process.- Overrides:
- setFileExtensionsin class- AbstractFileSetCheck
- Parameters:
- extensions- the set of file extensions. A missing initial '.' character of an extension is automatically added.
- Throws:
- IllegalArgumentException- is argument is null
 
- 
processFilteredProcesses the file and check order.- Specified by:
- processFilteredin class- AbstractFileSetCheck
- Parameters:
- file- the file to be processed
- fileText- the contents of the file.
 
- 
getLineNumberprivate static int getLineNumber(int startLineNo, FileText fileText, String previousProp, String propKey) Method returns the index number where the key is detected (starting at 0). To assure that we get the correct line it starts at the point of the last occurrence. Also, the previousProp should be in file before propKey.- Parameters:
- startLineNo- start searching at line
- fileText-- FileTextobject contains the lines to process
- previousProp- key name found last iteration, works only if valid
- propKey- key name to look for
- Returns:
- index number of first occurrence. If no key found in properties file, 0 is returned
 
- 
getIndexInner method to get the index number of the position of keyName.- Parameters:
- startLineNo- start searching at line
- fileText-- FileTextobject contains the lines to process
- keyName- key name to look for
- Returns:
- index number of first occurrence. If no key found in properties file, 0 is returned
 
- 
getKeyPatternMethod returns regular expression pattern given key name.- Parameters:
- keyName- key name to look for
- Returns:
- regular expression pattern given key name
 
 
-