GithubHelp home page GithubHelp logo

exercism / java-analyzer Goto Github PK

View Code? Open in Web Editor NEW
7.0 9.0 14.0 855 KB

License: GNU Affero General Public License v3.0

Java 97.92% Shell 1.91% Dockerfile 0.17%
exercism-tooling exercism-analyzer community-contributions-accepted

java-analyzer's Introduction

Java Analyzer Coverage Status

The Java analyzer uses Abstract Syntax Trees (ASTs) to analyze submitted solutions using the javaparser library.

The documentation for this project can be found at exercism.github.io/java-analyzer/.

Contributing

If you want to contribute to the Java analyzer, please refer to the Contributing Guide.

Usage

Running directly

Start by building the JAR using Gradle:

./gradlew build

Then, run the Java analyzer using build/libs/java-analyzer.jar. For example, to analyze a solution for the leap exercise, run:

java -jar build/libs/java-analyzer.jar leap /path/to/leap /path/to/output/folder

The analyzer output is written to analysis.json and tags.json in /path/to/output/folder.

Running with Docker

To run the Java analyzer using Docker, first build and tag the Docker image:

docker build -t exercism/java-analyzer .

Then, run the image and mount the directory of the solution to analyze. For example, to analyze a solution for the leap exercise located at ~/exercism/java/leap, run:

docker run -v /path/to/leap:/input -v /path/to/output/folder:/output exercism/java-analyzer leap /input /output

The analyzer output is written to analysis.json and tags.json in /path/to/output/folder.

Tests

Unit tests

To run the unit tests:

./gradlew test

Smoke tests

To run the smoke tests using Docker:

bin/run-tests-in-docker.sh

java-analyzer's People

Contributors

dependabot[bot] avatar erikschierboom avatar exercism-bot avatar faisalafroz avatar gyoo avatar ihid avatar jmrunkle avatar manumafe98 avatar mirkoperillo avatar nobbz avatar olapokon avatar sanderploegsma avatar smarticles101 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-analyzer's Issues

annalyns-infiltration feedback

it suggests that you should return the expression when check for fast attack but the logic is reversed e.g when the knight is awake you must return false and not true

Analyzer upgrade

Hello. I am interested in contributing to exercism, and specifically to the analyzers and representers. I am opening a new issue here, as discussed in exercism/java#1969

I looked a bit into the existing analyzer and here are some things I noticed so far.

Regarding the new Analyzer interface:

  1. The CLI interface doesn't seem to conform to that described, as it does not accept an output directory. It writes the analysis.json file to the exercise directory by default.
  2. The "status" field in the output should be removed, as it is no longer needed.

Other things:

  1. It looks like ExerciseRegistry is not populated with the existing exercise classes so it's not possible to use the analyzer through the CLI at all (unless I make a minor change to make sure they load)? It's possible I'm just missing something, but since these classes are put in the registry in a static block, it seems this block is never run because the classes are not loaded, so there is an exception that they are not in the registry. Does anyone know why this may be happening in my case, or if it is a problem in general?

  2. Since the analyzer depends on the comments here https://github.com/exercism/website-copy/tree/47af5b309ac263629ca5c52904046f81e0cc8def/automated-comments/java does that mean that it should only accept exercises for which a directory in automated-comments and a class in java-analyzer exercises package are available? Or is it intended that the analyzer should eventually be refactored to be able to accept all exercises and at least apply the general comments?

How can I contribute to this analyzer?

Hey java-analyzer folks. I'd like to get involved in this project, but it looks like there is next to no tracking of anything. Can we use issues to track tasks and assign them to contributors? I don't know if the existing 3 contributors have any sort of process going at the present. Cheers!

PS: Perhaps we can also add some documentation on the README describing a project workflow of some kind and how to get involved...

Start outputting tags

So far the Java analyzer only provides automated feedback on submitted solutions, but analyzers can also tag them.

There are multiple approaches to implement this:

  • We can start outputting tags in the exercise-specific analyzers, and exercises for which no analyzer is implemented yet will receive no tags on their submissions.
  • We can implement a 'global' analyzer that is able to identify paradigms, techniques, constructs etc regardless of which exercise a solution belongs to, so that all submissions will receive tags.
  • We can combine both options of course.

I found that the C# Analyzer took the second option. This makes sense, since a large portion of the tags currently implemented are exercise-agnostic. Perhaps it can serve as a good example to get started.

The master branch will be renamed to main

In line with our new org-wide policy, the master branch of this repo will be renamed to main. All open PRs will be automatically repointed.

GitHub will show you a notification about this when you look at this repo after renaming:

Screenshot 2021-01-27 at 15 31 45

In case it doesn't, this is the command it suggests:

git branch -m master main
git fetch origin
git branch -u origin/main main

You may like to update the primary branch on your forks too, which you can do under Settings->Branches and clicking the pencil icon on the right-hand-side under Default Branch:

Screenshot 2021-01-27 at 18 50 08

We will post a comment below when this is done. We expect it to happen within the next 12 hours.

Remove comment to use `isEmpty()` from Hamming analyzer

So I'm getting this recommendation on the hamming practice exercise.

image

And checking the solutions that are mostly like the one in as reference in the exercise definition, I'm not understanding how this helps improve the code.

Because if both strands are empty the code works properly and the count is 0, there is even a test that checks that

secrets: implement analyzer

Implement an analyzer for the concept exercise secrets.
Details on the feedback that should be provided by the analyzer can be found in the exercise's .meta/design.md file, see exercism/java#2685.

Remove redundant analyzer comments

The analyzers for hamming and two-fer contain some redundant comments: the cases that trigger them will only occur when the solution doesn't pass the exercise tests. Since the analyzer is not run by the platform if the tests didn't pass (source, these comments should be deleted.

Document guidelines on testing

I think we should come up with some guidelines on how analyzers should be tested. My proposal would be:

  • Unit tests should exist to obtain as much code coverage as possible. Correctness of each exercise analyzer should be tested that way.
  • Each exercise should have at least two smoke tests: one with an optimal solution that receives no feedback, and one with a solution that receives at least one exercise-specific comment.
  • Next to that, a few smoke tests to cover exercises for which no analyzer is implemented should be present too, to make sure the analyzer works properly for every exercise. By that I mean that it shouldn't crash or something.

Once we come up with some concrete guidelines, we should probably write them down in the docs.

Originally posted by @sanderploegsma in #122 (comment)

Create an analyzer for the Hamming distance exercise

Just creating an issue so that I can claim this task.

Basically, we need an analyzer for Hamming distance. I can probably request a handful of exercise examples from ihid, but otherwise I should be good to start working on this.

Make the tests run on pull requests

Up until now, I have been running the tests manually. We should really be running the tests anytime a new pull-request is created to verify that the pull request is not introducing any regressions.

Skip analysis of non-solution files

Some exercises consist of more than one file in the src/main/java folder, and some of them are designed to be read-only files. These are marked as such in the exercise's .meta/config.json file, because they should be listed in the files.editor list.

For example, the configuration for the wizards-and-warriors-2 exercise lists the following files as read-only:

  • src/main/java/Character.java
  • src/main/java/Destination.java
  • src/main/java/TravelMethod.java

The goal of this issue is to make sure that read-only files are never processed by the analyzer.

In most cases processing these files may not introduce any issues, but just in case one of them contains code that triggers an analyzer comment we should skip them by default. If not, a student may receive feedback on a file that they did not write and cannot edit, which is just confusing.

Log Levels: feedback incorrectly recommends to use the substring method

Issue in Log Levels Exercise

I used the substring method to solve the exercise but the automated feedback insists me to use substring. Resolve this issue as soon as possible.

image

class LogLevels {

	public static String message(String logLine) {
		logLine = logLine.substring(logLine.indexOf(":") + 1);
		return logLine.trim();
	}

	public static String logLevel(String logLine) {
		if (logLine.toLowerCase().contains("info"))
			return "info";
		if (logLine.toLowerCase().contains("warning"))
			return "warning";

		return "error";
	}

	public static String reformat(String logLine) {
		return message(logLine) + " (" + logLevel(logLine) + ")";
	}
}

Solution directory structure

Currently, the analyzer doesn’t expect any directory structure for a solution. It’s just looking for the solution files. While deployed, the analyzer is being passed the directory which contains src/java/main/etc and then the solution files. The analyzer should be patched to expect this directory structure.

Background

there is no need to use substring in the result method in this code, kindly review

public class LogLevels {

public static String message(String logLine) {
    int startMessageIndex = logLine.indexOf("]:") + 2;
    String result = logLine.substring(startMessageIndex, logLine.length());
    return result.trim();
}
public static String logLevel(String logLine) {
    int startLevelIndex = logLine.indexOf("[") + 1;
    int endLevelIndex = logLine.indexOf("]");
    return logLine.substring(startLevelIndex, endLevelIndex).toLowerCase();
}
public static String reformat(String logLine) {
    return LogLevels.message(logLine) + " (" + LogLevels.logLevel(logLine) + ")";
}
public static void result() {
    String logLine = "[ERROR]: Invalid operation";
    String formattedString =  LogLevels.reformat(logLine);
}

}

and the suggestion is:
Consider using the substring method in result to solve this exercise. but for this exercise the substring method is implemented in the other methods, kindly review.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.