Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.puppycrawl.tools.checkstyle.checks
Class TranslationCheck  view TranslationCheck download TranslationCheck.java

java.lang.Object
  extended bycom.puppycrawl.tools.checkstyle.api.AutomaticBean
      extended bycom.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
          extended bycom.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
              extended bycom.puppycrawl.tools.checkstyle.checks.TranslationCheck
All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable, com.puppycrawl.tools.checkstyle.api.FileSetCheck

public class TranslationCheck
extends com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck

The TranslationCheck class helps to ensure the correct translation of code by checking property files for consistency regarding their keys. Two property files describing one and the same context are consistent if they contain the same keys.

An example of how to configure the check is:

 <module name="Translation"/>
 


Field Summary
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
 
Constructor Summary
TranslationCheck()
          Creates a new TranslationCheck instance.
 
Method Summary
private static java.util.Map arrangePropertyFiles(java.io.File[] aPropFiles)
          Arranges a set of property files by their prefix.
private  void checkPropertyFileSets(java.util.Map aPropFiles)
          Tests whether the given property files (arranged by their prefixes in a Map) contain the proper keys.
private  void compareKeySets(java.util.Set aKeys, java.util.Map aFileMap)
          Compares the key sets of the given property files (arranged in a map) with the specified key set.
private static java.lang.String extractPropertyIdentifier(java.io.File aFile)
          Gets the basename (the unique prefix) of a property file.
private  java.util.Set loadKeys(java.io.File aFile)
          Loads the keys of the specified property file into a set.
private  void logIOException(java.io.IOException aEx, java.io.File aFile)
          helper method to log an io exception.
 void process(java.io.File[] aFiles)
          This method searches for property files in the specified file array and checks whether the key usage is consistent.
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
destroy, filter, fireErrors, getMessageCollector, getMessageDispatcher, log, log, setFileExtensions, setMessageDispatcher
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, setSeverity
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurable
configure
 
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizable
contextualize
 

Constructor Detail

TranslationCheck

public TranslationCheck()
Creates a new TranslationCheck instance.

Method Detail

extractPropertyIdentifier

private static java.lang.String extractPropertyIdentifier(java.io.File aFile)
Gets the basename (the unique prefix) of a property file. For example "xyz/messages" is the basename of "xyz/messages.properties", "xyz/messages_de_AT.properties", "xyz/messages_en.properties", etc.


arrangePropertyFiles

private static java.util.Map arrangePropertyFiles(java.io.File[] aPropFiles)
Arranges a set of property files by their prefix. The method returns a Map object. The filename prefixes work as keys each mapped to a set of files.


loadKeys

private java.util.Set loadKeys(java.io.File aFile)
Loads the keys of the specified property file into a set.


logIOException

private void logIOException(java.io.IOException aEx,
                            java.io.File aFile)
helper method to log an io exception.


compareKeySets

private void compareKeySets(java.util.Set aKeys,
                            java.util.Map aFileMap)
Compares the key sets of the given property files (arranged in a map) with the specified key set. All missing keys are reported.


checkPropertyFileSets

private void checkPropertyFileSets(java.util.Map aPropFiles)
Tests whether the given property files (arranged by their prefixes in a Map) contain the proper keys. Each group of files must have the same keys. If this is not the case an error message is posted giving information which key misses in which file.


process

public void process(java.io.File[] aFiles)
This method searches for property files in the specified file array and checks whether the key usage is consistent. Two property files which have the same prefix should use the same keys. If this is not the case the missing keys are reported.