View Javadoc

    1   package net.sourceforge.pmd.lang.java.rule.comments;
    2
    3
    4   import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
    5   import net.sourceforge.pmd.lang.rule.properties.EnumeratedProperty;
    6   import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty;
    7
    8   /**
    9    * Restrictions regarding the legal placement and content of the file header.
    10   *
    11   * @author Brian Remedios
    12   */
    13  public class HeaderCommentsRule extends AbstractCommentRule {
    14
    15  	private static final String[] requiredWords = new String[] { "copyright" };
    16  	private static final String[] requiredTags = new String[] { "author", "version" };
    17
    18  	public static final StringMultiProperty REQUIRED_TERMS_DESCRIPTOR = new StringMultiProperty("requiredTerms",
    19  	    	"Expected terms or phrases in the code header", requiredWords, 1.0f, '|');
    20
    21  	public static final StringMultiProperty REQUIRED_TAGS_DESCRIPTOR = new StringMultiProperty("requiredTags",
    22      		"Expected tags in the header", requiredTags, 2.0f, '|');
    23
    24  	enum RequiredHeaderPlacement {
    25  		BeforePackageDeclaration("Before package"),
    26  		BeforeImportStatements("Before imports"),
    27  		BeforeTypeDeclaration("Before types"),
    28  		Anywhere("Anywhere");
    29
    30  		private final String label;
    31
    32  		RequiredHeaderPlacement(String theLabel) {
    33  			label = theLabel;
    34  		}
    35
    36  		public static String[] labels() {
    37  			String[] labels = new String[values().length];
    38  			int i=0;
    39  			for (RequiredHeaderPlacement placement : values()) {
    40  				labels[i++] = placement.label;
    41  			}
    42  			return labels;
    43  		}
    44  	}
    45
    46      public static final EnumeratedProperty<RequiredHeaderPlacement> HEADER_PLACEMENT_DESCRIPTOR = new EnumeratedProperty<RequiredHeaderPlacement>(
    47      	    "headerPlacement",
    48      	    "Placement of the header comment",
    49      	    RequiredHeaderPlacement.labels(),
    50      	    RequiredHeaderPlacement.values(),
    51      	    0, 3.0f
    52      	    );
    53
    54  	public HeaderCommentsRule() {
    55  		definePropertyDescriptor(REQUIRED_TERMS_DESCRIPTOR);
    56  		definePropertyDescriptor(REQUIRED_TAGS_DESCRIPTOR);
    57  		definePropertyDescriptor(HEADER_PLACEMENT_DESCRIPTOR);
    58  	}
    59
    60  	@Override
    61      public Object visit(ASTCompilationUnit cUnit, Object data) {
    62
    63  //		SortedMap<Integer, Object> itemsByLineNumber = orderedCommentsAndDeclarations(cUnit);
    64
    65          return super.visit(cUnit, data);
    66      }
    67  }