Sample

Schnappinger/jsweet/org.jsweet.transpiler.util.ErrorCountTranspilationHandler

Human rating uses the original dataset scale.

Human3.97
Lines100

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett0.8690–1; higher is more readable
86.6Δ 1.1
Scalabrino0.9310–1; higher is more readable
95.5Δ 10.1
Dorn0.4990–1; higher is more readable
60.7Δ 24.8
Mi0.7790–1; higher is more readable
94.4Δ 8.9
LLOC25Logical lines; fewer is more readable
53.0Δ 32.5
DeepSeek V4 Pro17.670–20; mean of three runs
83.0Δ 2.5
GPT-6.1 Sol180–20; mean of three runs
73.8Δ 11.7
BTTF0.7710–1; higher is more readable
92.7Δ 7.3
Human3.971–4; original rating
85.5

Views

Source code

/* * JSweet transpiler - http://www.jsweet.org * Copyright (C) 2015 CINCHEO SAS <renaud.pawlak@cincheo.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ package org.jsweet.transpiler.util; import org.jsweet.transpiler.JSweetProblem; import org.jsweet.transpiler.SourcePosition; import org.jsweet.transpiler.TranspilationHandler; /** * An error count decorator for a transpilation handler. * * @author Renaud Pawlak */ public class ErrorCountTranspilationHandler extends AbstractDelegatedTranspilationHandler { private int errorCount = 0; private int warningCount = 0; private int problemCount = 0; private boolean disabled = false; /** * Decorates the given transpilation handler. */ public ErrorCountTranspilationHandler(TranspilationHandler delegate) { super(delegate); } /** * Count the problems and delegates to the decorated transpilation handler. */ public void report(JSweetProblem problem, SourcePosition sourcePosition, String message) { if (!disabled) { switch (problem.getSeverity()) { case ERROR: problemCount++; errorCount++; break; case WARNING: problemCount++; warningCount++; break; default: problemCount++; } } super.report(problem, sourcePosition, message); } /** * Returns the error count. */ public int getErrorCount() { return errorCount; } /** * Returns the warning count. */ public int getWarningCount() { return warningCount; } /** * Returns the problem count (error + warning count). */ public int getProblemCount() { return problemCount; } /** * Returns false if this handler actually counts anything. */ public boolean isDisabled() { return disabled; } /** * Enables/disables the counting. */ public void setDisabled(boolean disabled) { this.disabled = disabled; } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Source linesThe number of non-empty source lines.100+40
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.1195.742−39.46
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.5.011−7.516

Intercept 8.87 + feature contributions = 1.895 (log-odds).
Score = sigmoid(1.895) = 0.869.

Score0.931

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.101−2.54
Indentation frequencyHow rapidly indentation changes from line to line.65+1.511
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.65−1.071
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.99.87+0.986
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.90.95+0.663
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.043+0.528
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.90.099−0.151

Intercept 0.07 + feature contributions = -0.003 (log-odds).
Score = sigmoid(-0.003) = 0.499.

Score0.779
Score25
Run 1

The code is well-structured, following a clear class hierarchy and standard Java conventions. It is logically organized with fields, constructor, and methods in a natural order. The nesting is minimal—only a simple switch statement within a single if block, without multi-level indentation. Intent is clear; the class serves as a counting decorator, and method names are descriptive. The code length is appropriate, with no unnecessary verbosity or duplication. Action granularity is good, though the switch statement packs multiple operations per case, including possible repetition of problemCount++ across branches. Reading flow is natural, aided by Javadoc comments that briefly clarify each method's purpose. Minor improvements could include extracting the common problemCount++ increment before the switch or using a more concise approach for counting, but overall readability is high and the code is easy to follow.

Run 2

The code is highly readable with clear separation of concerns, minimal nesting, and self-documenting methods. The class structure is logical, following the decorator pattern with a single inheritance and straightforward method overrides. Nesting is limited to one level (switch statement inside an if-check), maintaining flat control flow. Intent is explicit through descriptive method names like getErrorCount, getWarningCount, and isDisabled. Code length is appropriate—concise without omitting necessary functionality. Action granularity is well-balanced: each increment operation occupies its own line within case blocks, though the switch could be simplified. Reading flow is natural, progressing from constructor to report logic to getters/setters. Javadoc comments are consistent and informative without being excessive. Minor improvements could include extracting the counting logic or using a Map for severity counts, but overall the code demonstrates excellent clarity and maintainability.

Run 3

This code is highly readable across all evaluated criteria. The structure is logical and follows a clear class hierarchy with appropriate delegation to a parent class. Nesting is minimal—only a single switch statement within an if block, keeping the code flat and easy to follow. Intent is clearly documented through meaningful class, method, and variable names, along with concise Javadoc comments that explain the purpose of each component. The code is appropriately concise without sacrificing clarity; each method serves a single purpose and avoids unnecessary verbosity. Action granularity is well-maintained, with one action per line in the report method's switch statement, making counting logic transparent. The reading flow follows a natural progression from class declaration through constructor, core logic, and getter/setter methods. The only minor deduction is the slightly redundant problemCount++ appearing in every switch case, which could be consolidated, but this doesn't significantly impact readability. Overall, this is an exemplary piece of well-structured, maintainable code.

Run 1

Code Structure: Well-organized decorator with grouped fields, a constructor, reporting logic, and accessors. Nesting: Shallow; only an if enclosing a switch. Clarity of intent: Descriptive names and documentation clearly explain counting and delegation, although getProblemCount's comment implies only errors and warnings while the default branch counts other severities too. Code length: Compact overall, but repeated problemCount increments and obvious accessor comments add minor redundancy. Action granularity: Each statement performs one clear action on its own line. Reading flow: Natural progression from initialization to behavior and accessors; unconditional delegation after counting is easy to follow.

Run 2

Code Structure: Well-organized decorator class with clearly separated fields, constructor, reporting logic, and accessors. Nesting: Limited to an if statement containing a switch, making the control flow easy to follow. Clarity of intent: Descriptive names and documentation explain counting and delegation, though the problem-count comment suggests only errors and warnings while the default branch counts other severities too. The negatively phrased disabled flag adds slight cognitive overhead. Code length: Concise overall, although problemCount++ is unnecessarily repeated across switch branches and accessor comments are somewhat redundant. Action granularity: Each statement performs one clear action on its own line. Reading flow: Natural progression from initialization to behavior and accessors; unconditional delegation after optional counting is particularly clear.

Run 3

Code Structure: Clearly organized decorator with grouped fields, a constructor, reporting logic, and accessors. Nesting: Limited to an if statement containing a switch, making control flow easy to follow. Clarity of intent: Descriptive class, method, and variable names communicate counting and delegation well. However, the problem-count documentation suggests only errors and warnings, while the default branch also counts other severities; the negatively named disabled flag adds slight cognitive overhead. Code length: Compact overall, though repeated problemCount increments and routine getter comments add minor redundancy. Action granularity: Each statement performs a single clear action. Reading flow: Natural progression from initialization through processing to state access, with consistent formatting and unconditional delegation clearly placed after counting.