Skip to content

Commit

Permalink
Updates AST Parser and using computeIfAbsence on maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariana Azevedo committed Dec 31, 2017
1 parent ee1e989 commit adc469a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
10 changes: 1 addition & 9 deletions src/com/o3smeasures/plugin/chart/BarChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,7 @@ private void createFactors(ItemMeasured itemsMeasured) throws FactorNotFoundExce

String factorName = O3SMeasuresConfigurationEnum.searchByValue(item.getName()).getFactor();
if (!factorName.equals("None") && !factorName.equals("High Cohesion of Methods")){
Factor factor = factorsMap.get(factorName);

if (factor == null){
factor = new Factor();
factor.setName(factorName);
factor.setDescription(factorName);
factor.setNumberOfIndicators(0);
factorsMap.put(factorName, factor);
}
Factor factor = factorsMap.computeIfAbsent(factorName, f -> new Factor(factorName, factorName, 0));
factor.getIndicators().add(new Indicator(item, 0.0));
factor.setNumberOfIndicators(factor.getNumberOfIndicators()+1);
}
Expand Down
9 changes: 1 addition & 8 deletions src/com/o3smeasures/plugin/chart/BoxAndWhiskerChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,7 @@ private void createFactors(ItemMeasured itemsMeasured) throws FactorNotFoundExce

String factorName = O3SMeasuresConfigurationEnum.searchByValue(item.getName()).getFactor();
if (!factorName.equals("None") && !factorName.equals("High Cohesion of Methods")){
Factor factor = factorsMap.get(factorName);

if (factor == null){
factor = new Factor();
factor.setName(factorName);
factor.setDescription(factorName);
factorsMap.put(factorName, factor);
}
Factor factor = factorsMap.computeIfAbsent(factorName, f -> new Factor(factorName, factorName, 0));
factor.getIndicators().add(new Indicator(item, 0.0));
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/com/o3smeasures/statistic/Factor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public class Factor {
private int numberOfIndicators;

public Factor(){
indicators = new ArrayList<>();
this.indicators = new ArrayList<>();
}

public Factor(String name, String description, int numberOfIndicators) {
this.name = name;
this.description = description;
this.numberOfIndicators = numberOfIndicators;
this.indicators = new ArrayList<>();
}

public String getName() {
Expand Down
2 changes: 1 addition & 1 deletion src/com/o3smeasures/structures/Measure.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum Granularity {

public Measure(){
applicableGranularities = new ArrayList<>(4);
parser = ASTParser.newParser(AST.JLS8);
parser = ASTParser.newParser(AST.JLS9);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setResolveBindings(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/o3smeasures/util/JavaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static CompilationUnit parseAST(FileInputStream fileInputStream){
ASTSession.getInstance().reset();

if (cacheParser) {
astParser = ASTParser.newParser(AST.JLS8);
astParser = ASTParser.newParser(AST.JLS9);
astParser.setKind(ASTParser.K_COMPILATION_UNIT);
astParser.setResolveBindings(true);
char[] source = getFileContent(fileInputStream);
Expand Down

0 comments on commit adc469a

Please sign in to comment.