Java: an enhanced `for (T x : xs)` loop is not counted (cx, ccx, nest, ev and the qd kinds built on them)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 88/100
Direzione di ricerca
Inizia da src/ingest_metrics.h, in particolare da isDecisionType, cc_isNestingControl ed ev_ctrlKindFor; l’issue individua il tipo di nodo Java mancante in ciascun elenco. Leggi i fixture delle metriche corrispondenti in test/metricscheck.sh e test/essentialcxcheck.sh, poi aggiungi casi abbinati per indice e ciclo enhanced. Il lavoro è terminato quando i valori cx, ccx, nest ed ev corrispondono e entrambi i controlli passano; incrementa la versione del parser ed esegui bash test/qschemetripcheck.sh.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Claim it in this issue first. Size: XS. Depends on: nothing. Language: Java. Good for a first contribution: the fix is one node-type name added to three lists in one file, and the test is a twin fixture.
The problem, in user terms
for (T x : xs) is how most Java code loops. ripwire's metrics walk does not know the node enhanced_for_statement, so the loop adds nothing to cyclomatic complexity (cx), cognitive complexity (ccx), nesting (nest) or essential complexity (ev). The --quality-delta kinds built on nesting (nesting, complexity, tangle, and the deep / humps facts) read idiomatic Java as flatter than it is. The same loop written with an index is counted.
Fixture Probe.java (two pairs, each pair the same shape):
import java.util.List;
class Probe {
static int indexFor(int[] xs, int[] ys) {
int hits = 0;
for (int i = 0; i < xs.length; i++) {
for (int j = 0; j < ys.length; j++) {
if (xs[i] == ys[j]) {
hits++;
}
}
}
return hits;
}
static int enhancedFor(List<Integer> xs, List<Integer> ys) {
int hits = 0;
for (int x : xs) {
for (int y : ys) {
if (x == y) {
hits++;
}
}
}
return hits;
}
static int indexBreak(int[] xs, boolean on) {
int s = 0;
for (int i = 0; i < xs.length; i++) {
if (on) {
if (xs[i] == 3) {
break;
}
s += xs[i];
}
}
return s;
}
static int enhancedBreak(List<Integer> xs, boolean on) {
int s = 0;
for (int x : xs) {
if (on) {
if (x == 3) {
break;
}
s += x;
}
}
return s;
}
}
On main (e94757295), with the other attributes cut for reading:
ripwire . --no-cache --metrics
<s t="method" n="indexFor" cx="4" ccx="6" nest="3"
<s t="method" n="enhancedFor" cx="2" ccx="1" nest="1"
<s t="method" n="indexBreak" cx="4" ccx="6" nest="3" ev="4" ev_floor="1" ev_why="loop-escape:1"
<s t="method" n="enhancedBreak" cx="3" ccx="3" nest="2"
Expected: each enhanced* row prints exactly what its index* twin prints. The grammar has the node: ripwire . --match='(enhanced_for_statement) @l' finds all three enhanced loops. Only the metric lists miss it.
Where to look
All in src/ingest_metrics.h. grep -n enhanced_for_statement src/ingest_metrics.h prints nothing today.
isDecisionType(line 32): the cyclomatic decision list.for_statementis at line 35.cc_isNestingControl(line 107): the nesting list.for_statementis at line 110.ev_ctrlKindFor(line 1573): the loop list forev, lines 1588-1597. Without it abreakinside an enhancedforfinds no loop below the function, and the floor rule marks nothing.
Other files already know the node, so the spelling is proven: src/ingest_binds.h:3170, src/slice.h:832.
Suggested approach
Add kindIs( t, "enhanced_for_statement" ) next to for_statement in all three lists. No language gate is needed: of the vendored grammars only Java's has that node name (grep -l '"enhanced_for_statement"' third_party/deps/*/src/parser.c prints only third_party/deps/java/src/parser.c).
The test to add (red first)
- Add the four functions above to the Java part of
test/metricscheck.sh(it already writes Java fixtures, see itsCalc.javaarm), or to a new small Java arm there. Assert eachenhanced*row equals itsindex*twin oncx,ccx,nestandev. Show the arm red onmainfirst. - Add
enhancedBreakto the Java section oftest/essentialcxcheck.sh(javaLabelledlives there) with itsevvalue. - The metrics are cached: bump
kParserVerinsrc/ingest_cache.h:409and its mirrorkIngestParserVerMirrorinsrc/quality.h:3335to any number abovemain's. Runbash test/qschemetripcheck.sh.
Acceptance criteria
- The four rows above print twin-equal numbers.
bash test/metricscheck.sh "$PWD/build/ripwire"andbash test/essentialcxcheck.sh "$PWD/build/ripwire"pass, with the new arms red onmain.bash test/langidentitycheck.sh origin/main HEAD --langs=java,kt,cs,py,cpp: every language except Java is SAME. Java DIFFs only on metric attributes of functions that contain an enhancedfor, waived by--intendedrows naming the new arm. If you have a real Java repository, add--repo=java:<your clone>and say how many functions moved.ripwire . --quality-delta=origin/main..HEADgates 0.
Size
XS: three one-line additions, one fixture arm, one version bump.
How to verify locally
cmake -S . -B build && cmake --build build -j # plain build: no build type
mkdir -p /tmp/efor && cp Probe.java /tmp/efor/ && ./build/ripwire /tmp/efor --no-cache --metrics
bash test/metricscheck.sh "$PWD/build/ripwire"
bash test/essentialcxcheck.sh "$PWD/build/ripwire"
bash test/qschemetripcheck.sh
bash test/langidentitycheck.sh origin/main HEAD --langs=java,kt,cs,py,cpp
./build/ripwire . --quality-delta=origin/main..HEAD --legend=compact
Not in scope
Java stream chains (xs.stream().filter(...)) and lambdas: they are not loops for cx by design. Kotlin's for (x in xs) is already counted (for_statement).
Claiming it only takes a comment here. Every contributor is credited by handle in the CHANGELOG entry and the release notes. Thank you!
- Lingua principale
- C++
- Stelle
- 2.6k
- Fork
- 182
- Merge medio
- 21h 12m
- PR unite (30g)
- 262
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di redhat-et/ripwire
-
TS/JS: a generator function expression (const f = function* / async function*) is not indexedForse già presa @shivam512262 l’ha presa 6 giorni fa. Apertabug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
redhat-et/ripwire#730 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 78/100
redhat-et/ripwire#334 · 8 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
redhat-et/ripwire#68 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement help wanted
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement help wanted
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di redhat-et/ripwire
Issue simili
-
difficulty:easy func:gui prio:normal type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NatronGitHub/Natron#2118 ·
I maintainer di solito rispondono entro 1 giorno
-
bug difficulty:easy prio:low
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NatronGitHub/openfx-io#523 ·
I maintainer di solito rispondono entro 1 giorno
-
area:text difficulty:easy prio:low type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
NatronGitHub/openfx-arena#293 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug: Potential ?
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
MarlinFirmware/Marlin#28935 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
ZuluSCSI/ZuluSCSI-firmware#1077 ·
I maintainer di solito rispondono entro 1 giorno