Sample

Schnappinger/jsweet/org.jsweet.input.typescriptdef.visitor.TypeReferenceExpander

Human rating uses the original dataset scale.

Human2.17
Lines86

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
43.1Δ 33.2
Scalabrino0.560–1; higher is more readable
16.1Δ 6.2
Dorn0.4260–1; higher is more readable
57.4Δ 47.5
Mi0.1820–1; higher is more readable
14.5Δ 4.6
LLOC24Logical lines; fewer is more readable
54.3Δ 44.4
DeepSeek V4 Pro140–20; mean of three runs
29.9Δ 20.0
GPT-6.1 Sol14.330–20; mean of three runs
19.8Δ 9.9
BTTF0.4540–1; higher is more readable
39.9Δ 30.0
Human2.171–4; original rating
9.9

Views

Source code

/* * TypeScript definitions to Java translator - 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.input.typescriptdef.visitor; import org.jsweet.JSweetDefTranslatorConfig; import org.jsweet.input.typescriptdef.ast.Context; import org.jsweet.input.typescriptdef.ast.Scanner; import org.jsweet.input.typescriptdef.ast.Type; import org.jsweet.input.typescriptdef.ast.TypeDeclaration; import org.jsweet.input.typescriptdef.ast.TypeReference; import org.jsweet.input.typescriptdef.util.Util; /** * This scanner expands the partial type references to fully qualified type * references, so that it is unambiguous to Java. It the case JSWeet is not in * JDK replacement mode, it also forces core types in the JSWeet's lang package * to reference java.lang package core types. * * @author Renaud Pawlak */ public class TypeReferenceExpander extends Scanner { private int typeCount = 0; public TypeReferenceExpander(Context context) { super(context); } @Override public void visitTypeReference(TypeReference typeReference) { if (typeReference.getName() != null) { if (!JSweetDefTranslatorConfig.isJDKReplacementMode() && !"any".equals(typeReference.getName()) && Util.coreTypeMap.containsKey(typeReference.getName())) { String name = Util.coreTypeMap.get(typeReference.getName()); typeCount++; if (context.verbose) { logger.debug("WARNING: rewriting type ref " + typeReference.getName() + " -> " + name + " at " + getCurrentToken().getLocation()); } typeReference.setName(name); } else { if (typeReference.getName().contains(".")) { Type t = lookupType(typeReference, null); if (t instanceof TypeDeclaration && !((TypeDeclaration) t).isExternal()) { TypeDeclaration typeDeclaration = (TypeDeclaration) t; String typeName = context.getTypeName(typeDeclaration); if (!typeName.equals(typeReference.getName())) { typeCount++; if (context.verbose) { logger.debug("WARNING: rewriting type ref " + typeReference.getName() + " -> " + typeName + " at " + getCurrentToken().getLocation()); } typeReference.setName(typeName); } } } } } super.visitTypeReference(typeReference); } @Override public void onScanEnded() { if (typeCount > 0) { logger.debug(typeCount + " type reference(s) rewritten/expanded."); } } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.2499.171−82.473
Source linesThe number of non-empty source lines.86+34.4
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.074−7.611

Intercept 8.87 + feature contributions = -46.814 (log-odds).
Score = sigmoid(-46.814) = 0.

Score0.56

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.87−2.044
Indentation frequencyHow rapidly indentation changes from line to line.62+1.407
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.62−1.002
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.98.943+0.792
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.85.94+0.791
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.98.977−0.527
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.075+0.212

Intercept 0.07 + feature contributions = -0.3 (log-odds).
Score = sigmoid(-0.3) = 0.426.

Score0.182
Score24
Run 1

The code is moderately readable. The class has a clear purpose and follows a logical structure with imports, header comment, and method organization. Method names and variable names are descriptive. The main method visitTypeReference has some logical complexity with nested if-else blocks that could be extracted into helper methods. The nesting depth reaches 4 levels in places, which impacts readability. The action granularity is mostly good with one logical operation per line, though some lines combine multiple operations. The use of static imports or constants for string literals like 'any' would improve clarity. The verbose logging blocks are repeated, creating some redundancy that could be refactored. The method onScanEnded is clean and simple. Overall, the code follows reasonable Java conventions but could benefit from extracting the type rewriting logic into smaller, more focused methods to reduce nesting and improve clarity of intent.

Run 2

The code is reasonably structured with a clear single-purpose class and logical method organization. However, it suffers from deep nesting (3-4 levels in visitTypeReference) and multiple actions within complex conditional blocks. The intent is mostly clear from the class-level Javadoc, but the branch logic is verbose and could be simplified with early returns or extracted methods. The repeated verbose logging blocks add length and reduce readability. While naming is good and the overall flow is understandable, the nested conditional logic makes the main method harder to follow than necessary. Action granularity is mixed—some lines do one thing, but most conditionals bundle multiple related operations.

Run 3

The code has a clear structure with good separation of concerns in the visitTypeReference method. However, it suffers from deeply nested conditionals (4+ levels), making the logic harder to follow. The intent is generally clear - expanding type references - but the nested if-else blocks obscure the flow. Code length is appropriate but could be more concise by extracting helper methods. Action granularity is mostly good with one operation per line. Reading flow is somewhat disrupted by the nesting and the need to mentally track multiple conditions. Variable names are descriptive and the comments help understanding. The main improvement would be reducing nesting through early returns or guard clauses, and extracting the type rewriting logic into smaller, named methods.

Run 1

Code Structure: The class is logically organized into initialization, reference processing, and scan completion, but rewriting and logging logic are duplicated. Nesting: Several nested conditionals make the main method harder to follow; guard clauses and extracted helpers would flatten it. Clarity of intent: The class documentation and descriptive names explain its purpose, although the variable 't' and the compound core-type condition require extra interpretation. Code length: Reasonably compact overall, but repeated logging and name-update sequences add avoidable length. Action granularity: Most lines perform one action, with clear separation between lookup, counting, logging, and mutation. Reading flow: Formatting and method order support natural reading, but the nested else/if chain and repeated getName() calls interrupt the flow.

Run 2

Code Structure: The class is logically organized into initialization, reference processing, and a completion hook, although the main method could separate its two rewriting cases into helpers. Nesting: Several nested conditionals, including an else containing another if, make the qualification branch harder to follow. Clarity of intent: The class documentation and descriptive names explain the purpose well; the short variable name 't' and compound condition slightly reduce clarity. Code length: Generally compact, but repeated logging and rewrite bookkeeping add avoidable duplication. Action granularity: Most statements perform one action per line, with sensible wrapping of long expressions. Reading flow: Processing proceeds naturally from validation to rewriting and superclass traversal, then summary reporting; deep indentation and repeated getName calls interrupt an otherwise clear flow.

Run 3

Code Structure: The class is logically organized into initialization, reference processing, and end-of-scan reporting, though rewriting and logging could be extracted into helpers. Nesting: The main method has several deeply nested conditionals; guard clauses and an else-if would simplify it. Clarity of intent: The class documentation, descriptive names, and explicit type updates explain its purpose, although the variable 't' and documentation typos reduce clarity slightly. Code length: Overall length is reasonable, but duplicated logging and repeated getName() calls add avoidable verbosity. Action granularity: Statements generally perform one action per line, with compound conditions formatted across lines. Reading flow: Processing proceeds naturally from validation to transformation and traversal, but nested branches and repeated logging interrupt the flow.