Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding analyzer for need for speed concept exercise #134

Merged
merged 9 commits into from
Feb 16, 2024

Conversation

manumafe98
Copy link
Contributor

@manumafe98 manumafe98 commented Feb 14, 2024

@manumafe98 manumafe98 added the x:size/medium Medium amount of work label Feb 14, 2024
@manumafe98 manumafe98 self-assigned this Feb 14, 2024
@manumafe98 manumafe98 requested a review from a team as a code owner February 14, 2024 20:53
@manumafe98
Copy link
Contributor Author

I have a couple of doubts of this particular case, cause this exercise has two classes, so I need to create an analyzer for RaceTrack ? I would like your tips @sanderploegsma to know if I'm in the correct path

@sanderploegsma
Copy link
Contributor

Overall this looks good!

I have a couple of doubts of this particular case, cause this exercise has two classes, so I need to create an analyzer for RaceTrack ?

No there is no need to create separate analyzers for each class. The analyzer is invoked with a list of CompilationUnits, which contain all the classes in the solution. Each CompilationUnit corresponds to a Java file, FYI.

If your analyzer needs to have some logic specific to a single class of a multi-class solution, there are multiple ways of achieving this. Here's one from the top of my head:

public class NeedForSpeedAnalyzer implements Analyzer {
    @Override
    public void analyze(Solution solution, OutputCollector output) {
        var needForSpeedClassAnalyzer = new NeedForSpeedClassAnalyzer();
        var raceTrackClassAnalyzer = new RaceTrackClassAnalyzer();

        for (var compilationUnit : solution.getCompilationUnits()) {
            compilationUnit.getClassByName("NeedForSpeed").ifPresent(c -> c.accept(needForSpeedClassAnalyzer, output));
            compilationUnit.getClassByName("RaceTrack").ifPresent(c -> c.accept(raceTrackClassAnalyzer, output));
        }
    }
}

class NeedForSpeedClassAnalyzer extends VoidVisitorAdapter<OutputCollector> {
    @Override
    public void visit(MethodDeclaration node, OutputCollector output) {
        // Only called for methods in the NeedForSpeed class
    }
}

class RaceTrackClassAnalyzer extends VoidVisitorAdapter<OutputCollector> {
    @Override
    public void visit(MethodDeclaration node, OutputCollector output) {
        // Only called for methods in the RaceTrack class
    }
}

Hope that helps!

Modifying order to be alphabetical on AnalyzerRoot
Updating path to use exercise slug need-for-speed
Adding javadoc to analyzer comments and do not make them public
@SleeplessByte
Copy link
Member

Analyzer comments have been merged into website-copy

@manumafe98 manumafe98 merged commit 5e16028 into exercism:main Feb 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:size/medium Medium amount of work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

need-for-speed: implement analyzer
4 participants