001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2012 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.java.squid; 021 022 import java.nio.charset.Charset; 023 import java.util.HashSet; 024 import java.util.Set; 025 026 import org.sonar.squid.api.SquidConfiguration; 027 028 public class JavaSquidConfiguration extends SquidConfiguration { 029 030 private boolean analysePropertyAccessors = true; 031 private Set<String> fieldsToExcludeFromLcom4Calculation = new HashSet<String>(); 032 033 private static final double COMMENTED_CODE_DEFAULT_THRESHOLD = 0.9; 034 private double commentedCodeThreshold = COMMENTED_CODE_DEFAULT_THRESHOLD; 035 036 public JavaSquidConfiguration() { 037 } 038 039 public JavaSquidConfiguration(boolean analysePropertyAccessors) { 040 this.analysePropertyAccessors = analysePropertyAccessors; 041 } 042 043 public JavaSquidConfiguration(double commentedCodeThreshold) { 044 setCommentedCodeThreshold(commentedCodeThreshold); 045 } 046 047 public JavaSquidConfiguration(boolean analysePropertyAccessors, Charset charset) { 048 super(charset); 049 this.analysePropertyAccessors = analysePropertyAccessors; 050 } 051 052 public JavaSquidConfiguration(boolean analysePropertyAccessors, Charset charset, double commentedCodeThreshold) { 053 super(charset); 054 this.analysePropertyAccessors = analysePropertyAccessors; 055 setCommentedCodeThreshold(commentedCodeThreshold); 056 } 057 058 public boolean isAnalysePropertyAccessors() { 059 return analysePropertyAccessors; 060 } 061 062 public Set<String> getFielsToExcludeFromLcom4Calculation() { 063 return fieldsToExcludeFromLcom4Calculation; 064 } 065 066 public void addFieldToExcludeFromLcom4Calculation(String fieldName) { 067 fieldsToExcludeFromLcom4Calculation.add(fieldName); 068 } 069 070 private void setCommentedCodeThreshold(double commentedCodeThreshold) { 071 if (commentedCodeThreshold < 0 || commentedCodeThreshold > 1) { 072 throw new IllegalArgumentException("Commented Code Threshold should be between [0...1]. Current value : " + commentedCodeThreshold); 073 } 074 this.commentedCodeThreshold = commentedCodeThreshold; 075 } 076 077 public double getCommentedCodeThreshold() { 078 return commentedCodeThreshold; 079 } 080 }