1   package com.stateofflow.eclipse.metrics.preferences;
2   
3   import org.eclipse.jface.preference.IPreferenceStore;
4   
5   import com.stateofflow.eclipse.metrics.calculators.EfferentCouplingsCalculator;
6   import com.stateofflow.eclipse.metrics.calculators.NumberOfFieldsCalculator;
7   import com.stateofflow.eclipse.metrics.calculators.NumberOfParametersCalculator;
8   import com.stateofflow.eclipse.metrics.calculators.cohesion.LackOfCohesionInMethodsCalculator;
9   import com.stateofflow.eclipse.metrics.calculators.complexity.CyclomaticComplexityCalculator;
10  import com.stateofflow.eclipse.metrics.calculators.levels.NumberOfLevelsCalculator;
11  import com.stateofflow.eclipse.metrics.calculators.linesofcode.LinesOfCodeCalculator;
12  import com.stateofflow.eclipse.metrics.calculators.localsinscope.NumberOfLocalsInScopeCalculator;
13  import com.stateofflow.eclipse.metrics.calculators.statements.NumberOfStatementsCalculator;
14  import com.stateofflow.eclipse.metrics.metric.MetricId;
15  
16  public final class DefaultInitialiser {
17      private final IPreferenceStore preferenceStore;
18  
19      public DefaultInitialiser(final IPreferenceStore preferenceStore) {
20          this.preferenceStore = preferenceStore;
21      }
22  
23      public void initialise() {
24          initialiseDefaultPreferencesForCyclomaticComplexity();
25          initialiseBasicPreferencesForMetric(EfferentCouplingsCalculator.METRIC_ID, 25);
26          initialiseBasicPreferencesForMetric(NumberOfFieldsCalculator.METRIC_ID, 10);
27          initialiseBasicPreferencesForMetric(NumberOfLevelsCalculator.METRIC_ID, 4);
28          initialiseBasicPreferencesForMetric(NumberOfLocalsInScopeCalculator.METRIC_ID, 4);
29          initialiseBasicPreferencesForMetric(NumberOfStatementsCalculator.METRIC_ID, 20);
30          initialiseDefaultPreferencesForNumberOfParameters();
31          initialiseDefaultPreferencesForLinesOfCode();
32  
33          initialiseBasicPreferencesForMetric(LackOfCohesionInMethodsCalculator.CHIDAMBER_KEMERER_METRIC_ID, 40);
34          initialiseBasicPreferencesForMetric(LackOfCohesionInMethodsCalculator.HENDERSON_SELLERS_METRIC_ID, 50);
35          initialiseBasicPreferencesForMetric(LackOfCohesionInMethodsCalculator.PAIRWISE_FIELD_IRRELATION_METRIC_ID, 50);
36          initialiseBasicPreferencesForMetric(LackOfCohesionInMethodsCalculator.TOTAL_CORRELATION_METRIC_ID, 50);
37      }
38  
39      private void initialiseBasicPreferencesForMetric(final MetricId id, final int preferredUpperBound) {
40          preferenceStore.setDefault(id.createEnablementPropertyKey().toString(), true);
41          preferenceStore.setDefault(id.createUpperBoundPropertyKey().toString(), preferredUpperBound);
42      }
43  
44      private void initialiseDefaultPreferencesForCyclomaticComplexity() {
45          initialiseBasicPreferencesForMetric(CyclomaticComplexityCalculator.METHOD_METRIC_ID, 4);
46          initialiseBasicPreferencesForMetric(CyclomaticComplexityCalculator.WEIGHTED_METHODS_PER_CLASS_METRIC_ID, 40);
47  
48          preferenceStore.setDefault(CyclomaticComplexityCalculator.COUNT_CASE_STATEMENTS_KEY.toString(), true);
49          preferenceStore.setDefault(CyclomaticComplexityCalculator.COUNT_CATCH_CLAUSES_KEY.toString(), true);
50          preferenceStore.setDefault(CyclomaticComplexityCalculator.COUNT_TERNARY_OPERATORS_KEY.toString(), true);
51      }
52  
53      private void initialiseDefaultPreferencesForLinesOfCode() {
54          initialiseBasicPreferencesForMetric(LinesOfCodeCalculator.METRIC_ID, 15);
55          preferenceStore.setDefault(LinesOfCodeCalculator.INCLUDE_METHOD_COMMENTS_KEY.toString(), true);
56      }
57  
58      private void initialiseDefaultPreferencesForNumberOfParameters() {
59          initialiseBasicPreferencesForMetric(NumberOfParametersCalculator.METRIC_ID, 4);
60          preferenceStore.setDefault(NumberOfParametersCalculator.INCLUDE_METHODS_DECLARED_IN_SUPERTYPE_KEY.toString(), true);
61      }
62  }
63