-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
65325ac
commit d33e6b4
Showing
21 changed files
with
344 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package analyzer.comments; | ||
|
||
import analyzer.Comment; | ||
import analyzer.CommentType; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @see <a href="https://github.com/exercism/website-copy/blob/main/analyzer-comments/java/general/optimal_solution.md">Markdown Template</a> | ||
*/ | ||
public class OptimalSolution extends Comment { | ||
private final String exerciseName; | ||
|
||
public OptimalSolution(String exerciseName) { | ||
this.exerciseName = exerciseName; | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "java.general.optimal_solution"; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getParameters() { | ||
return Map.of("exerciseName", this.exerciseName); | ||
} | ||
|
||
@Override | ||
public CommentType getType() { | ||
return CommentType.CELEBRATORY; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/analyzer/exercises/lasagna/LasagnaAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package analyzer.exercises.lasagna; | ||
|
||
import analyzer.Analysis; | ||
import analyzer.Analyzer; | ||
import analyzer.comments.OptimalSolution; | ||
import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.body.MethodDeclaration; | ||
import com.github.javaparser.ast.expr.MethodCallExpr; | ||
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; | ||
|
||
import java.util.List; | ||
|
||
public class LasagnaAnalyzer extends VoidVisitorAdapter<Analysis> implements Analyzer { | ||
private static final String EXERCISE_NAME = "Lasagna"; | ||
private static final String EXPECTED_MINUTES_IN_OVEN = "expectedMinutesInOven"; | ||
private static final String REMAINING_MINUTES_IN_OVEN = "remainingMinutesInOven"; | ||
private static final String PREPARATION_TIME_IN_MINUTES = "preparationTimeInMinutes"; | ||
private static final String TOTAL_TIME_IN_MINUTES = "totalTimeInMinutes"; | ||
|
||
@Override | ||
public void analyze(List<CompilationUnit> compilationUnits, Analysis analysis) { | ||
for (CompilationUnit compilationUnit : compilationUnits) { | ||
compilationUnit.accept(this, analysis); | ||
} | ||
|
||
if (analysis.getComments().isEmpty()) { | ||
analysis.addComment(new OptimalSolution(EXERCISE_NAME)); | ||
} | ||
} | ||
|
||
@Override | ||
public void visit(MethodDeclaration node, Analysis analysis) { | ||
if (node.getNameAsString().equals(REMAINING_MINUTES_IN_OVEN) | ||
&& doesNotCallMethod(node, EXPECTED_MINUTES_IN_OVEN)) { | ||
analysis.addComment(new ReuseCode(REMAINING_MINUTES_IN_OVEN, EXPECTED_MINUTES_IN_OVEN)); | ||
} | ||
|
||
if (node.getNameAsString().equals(TOTAL_TIME_IN_MINUTES) | ||
&& doesNotCallMethod(node, PREPARATION_TIME_IN_MINUTES)) { | ||
analysis.addComment(new ReuseCode(TOTAL_TIME_IN_MINUTES, PREPARATION_TIME_IN_MINUTES)); | ||
} | ||
|
||
super.visit(node, analysis); | ||
} | ||
|
||
private static boolean doesNotCallMethod(MethodDeclaration node, String otherMethodName) { | ||
return node.findAll(MethodCallExpr.class, x -> x.getNameAsString().contains(otherMethodName)).isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package analyzer.exercises.lasagna; | ||
|
||
import analyzer.Comment; | ||
import analyzer.CommentType; | ||
|
||
import java.util.Map; | ||
|
||
class ReuseCode extends Comment { | ||
private final String callingMethod; | ||
private final String methodToCall; | ||
|
||
ReuseCode(String callingMethod, String methodToCall) { | ||
this.callingMethod = callingMethod; | ||
this.methodToCall = methodToCall; | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "java.lasagna.reuse_code"; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getParameters() { | ||
return Map.of( | ||
"callingMethod", this.callingMethod, | ||
"methodToCall", this.methodToCall | ||
); | ||
} | ||
|
||
@Override | ||
public CommentType getType() { | ||
return CommentType.ACTIONABLE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"authors": [ | ||
"mirkoperillo" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/main/java/Lasagna.java" | ||
], | ||
"test": [ | ||
"src/test/java/LasagnaTest.java" | ||
], | ||
"exemplar": [ | ||
".meta/src/reference/java/Lasagna.java" | ||
], | ||
"invalidator": [ | ||
"build.gradle" | ||
] | ||
}, | ||
"forked_from": [ | ||
"csharp/lucians-luscious-lasagna" | ||
], | ||
"blurb": "Learn about the basics of Java by following a lasagna recipe." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{"comments": [{ | ||
"comment": "java.general.optimal_solution", | ||
"type": "celebratory", | ||
"params": {"exerciseName": "Lasagna"} | ||
}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Lasagna { | ||
public int expectedMinutesInOven() { | ||
return 40; | ||
} | ||
|
||
public int remainingMinutesInOven(int actualMinutesInOven) { | ||
return expectedMinutesInOven() - actualMinutesInOven; | ||
} | ||
|
||
public int preparationTimeInMinutes(int numberOfLayers) { | ||
return numberOfLayers * 2; | ||
} | ||
|
||
public int totalTimeInMinutes(int numberOfLayers, int actualMinutesInOven) { | ||
return preparationTimeInMinutes(numberOfLayers) + actualMinutesInOven; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"authors": [ | ||
"mirkoperillo" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/main/java/Lasagna.java" | ||
], | ||
"test": [ | ||
"src/test/java/LasagnaTest.java" | ||
], | ||
"exemplar": [ | ||
".meta/src/reference/java/Lasagna.java" | ||
], | ||
"invalidator": [ | ||
"build.gradle" | ||
] | ||
}, | ||
"forked_from": [ | ||
"csharp/lucians-luscious-lasagna" | ||
], | ||
"blurb": "Learn about the basics of Java by following a lasagna recipe." | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/lasagna/reuse-code/both-methods/expected_analysis.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{"comments": [ | ||
{ | ||
"comment": "java.lasagna.reuse_code", | ||
"type": "actionable", | ||
"params": { | ||
"callingMethod": "remainingMinutesInOven", | ||
"methodToCall": "expectedMinutesInOven" | ||
} | ||
}, | ||
{ | ||
"comment": "java.lasagna.reuse_code", | ||
"type": "actionable", | ||
"params": { | ||
"callingMethod": "totalTimeInMinutes", | ||
"methodToCall": "preparationTimeInMinutes" | ||
} | ||
}, | ||
{ | ||
"comment": "java.general.feedback_request", | ||
"type": "informative" | ||
} | ||
]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
17 changes: 17 additions & 0 deletions
17
tests/lasagna/reuse-code/both-methods/src/main/java/Lasagna.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Lasagna { | ||
public int expectedMinutesInOven() { | ||
return 40; | ||
} | ||
|
||
public int remainingMinutesInOven(int actualMinutesInOven) { | ||
return 40 - actualMinutesInOven; | ||
} | ||
|
||
public int preparationTimeInMinutes(int numberOfLayers) { | ||
return numberOfLayers * 2; | ||
} | ||
|
||
public int totalTimeInMinutes(int numberOfLayers, int actualMinutesInOven) { | ||
return 2 * numberOfLayers + actualMinutesInOven; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/lasagna/reuse-code/remaining-minutes-in-oven/.meta/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"authors": [ | ||
"mirkoperillo" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/main/java/Lasagna.java" | ||
], | ||
"test": [ | ||
"src/test/java/LasagnaTest.java" | ||
], | ||
"exemplar": [ | ||
".meta/src/reference/java/Lasagna.java" | ||
], | ||
"invalidator": [ | ||
"build.gradle" | ||
] | ||
}, | ||
"forked_from": [ | ||
"csharp/lucians-luscious-lasagna" | ||
], | ||
"blurb": "Learn about the basics of Java by following a lasagna recipe." | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/lasagna/reuse-code/remaining-minutes-in-oven/expected_analysis.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{"comments": [ | ||
{ | ||
"comment": "java.lasagna.reuse_code", | ||
"type": "actionable", | ||
"params": { | ||
"callingMethod": "remainingMinutesInOven", | ||
"methodToCall": "expectedMinutesInOven" | ||
} | ||
}, | ||
{ | ||
"comment": "java.general.feedback_request", | ||
"type": "informative" | ||
} | ||
]} |
1 change: 1 addition & 0 deletions
1
tests/lasagna/reuse-code/remaining-minutes-in-oven/expected_tags.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
17 changes: 17 additions & 0 deletions
17
tests/lasagna/reuse-code/remaining-minutes-in-oven/src/main/java/Lasagna.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Lasagna { | ||
public int expectedMinutesInOven() { | ||
return 40; | ||
} | ||
|
||
public int remainingMinutesInOven(int actualMinutesInOven) { | ||
return 40 - actualMinutesInOven; | ||
} | ||
|
||
public int preparationTimeInMinutes(int numberOfLayers) { | ||
return numberOfLayers * 2; | ||
} | ||
|
||
public int totalTimeInMinutes(int numberOfLayers, int actualMinutesInOven) { | ||
return preparationTimeInMinutes(numberOfLayers) + actualMinutesInOven; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/lasagna/reuse-code/total-time-in-minutes/.meta/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"authors": [ | ||
"mirkoperillo" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/main/java/Lasagna.java" | ||
], | ||
"test": [ | ||
"src/test/java/LasagnaTest.java" | ||
], | ||
"exemplar": [ | ||
".meta/src/reference/java/Lasagna.java" | ||
], | ||
"invalidator": [ | ||
"build.gradle" | ||
] | ||
}, | ||
"forked_from": [ | ||
"csharp/lucians-luscious-lasagna" | ||
], | ||
"blurb": "Learn about the basics of Java by following a lasagna recipe." | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/lasagna/reuse-code/total-time-in-minutes/expected_analysis.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{"comments": [ | ||
{ | ||
"comment": "java.lasagna.reuse_code", | ||
"type": "actionable", | ||
"params": { | ||
"callingMethod": "totalTimeInMinutes", | ||
"methodToCall": "preparationTimeInMinutes" | ||
} | ||
}, | ||
{ | ||
"comment": "java.general.feedback_request", | ||
"type": "informative" | ||
} | ||
]} |
1 change: 1 addition & 0 deletions
1
tests/lasagna/reuse-code/total-time-in-minutes/expected_tags.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
17 changes: 17 additions & 0 deletions
17
tests/lasagna/reuse-code/total-time-in-minutes/src/main/java/Lasagna.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Lasagna { | ||
public int expectedMinutesInOven() { | ||
return 40; | ||
} | ||
|
||
public int remainingMinutesInOven(int actualMinutesInOven) { | ||
return expectedMinutesInOven() - actualMinutesInOven; | ||
} | ||
|
||
public int preparationTimeInMinutes(int numberOfLayers) { | ||
return numberOfLayers * 2; | ||
} | ||
|
||
public int totalTimeInMinutes(int numberOfLayers, int actualMinutesInOven) { | ||
return 2 * numberOfLayers + actualMinutesInOven; | ||
} | ||
} |