Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion plugins/axiomcode/skills/axiomcode/scripts/axiomcode-changed
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ class Changed:
m = narrowest(ln, {'method', 'function', 'constructor', 'module'})
t = narrowest(ln, {'class', 'interface', 'enum', 'type', 'namespace'})
key = None
# a callable that starts on the type's own header line and ends within the type is one the front end
# synthesised for it (an implicit constructor, a Python class body): the header is the TYPE's, or a new class
# is named by it (#1377). A file's module declaration also starts on line 1 but spans past the type
if m and t and m[0] == t[0] and m[1] <= t[1] and t[0] <= ln <= self.header_end(OL, t[0]): m = None
if f: key = ('field', f)
elif m and m[0] <= ln <= self.header_end(OL, m[0]): key = ('signature', m)
elif m: key = ('body', m)
Expand Down Expand Up @@ -271,7 +275,10 @@ class Changed:
span_lines = [x for x in range(a, min(b, len(OL)) + 1) if not noise(OL[x - 1])]
gone = a in removed_lines and span_lines and sum(1 for x in span_lines if x in removed_lines) >= 0.6 * len(span_lines) and \
not any(re.search(rf'\b{re.escape(n)}\s*\(', NL[j - 1]) and ndepth_ok(j) for j in range(max(1, (new_of.get(a) or a) - 3), min(len(NL), (new_of.get(a) or a) + 3) + 1))
if gone: entry['kind'] = 'removed'; entry['target'] = self.target(kind, d, k, n); out.append(entry); continue
if gone:
# a header line and a body line of one declaration are two keys; it is removed once
if not any(e['kind'] == 'removed' and e['id'] == i for e in out): entry['kind'] = 'removed'; entry['target'] = self.target(kind, d, k, n); out.append(entry)
continue
if kind == 'signature':
# compared with comments removed: `f( /* note */ a)` is `f(a)`. Strings stay, so an edited route in a
# decoration is still a header change
Expand Down
6 changes: 6 additions & 0 deletions tests/cases/java/removed-class-listed-once/case.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"lang": "java", "src": "src",
"checks": [
{"why": "a removed class and its one method are two declarations, each listed once: the method's header line and its body lines used to give it two rows, and the class was named by its implicit constructor instead of by its own name",
"run": ["changed", "{repo}", "--old", "{repo}/old.java", "--new", "{repo}/new.java", "--file", "src/Meter.java"],
"want": ["changed declarations (2)", "removed Meter ", "Meter.read"],
"avoid": ["Meter.Meter"]}]}
Empty file.
6 changes: 6 additions & 0 deletions tests/cases/java/removed-class-listed-once/old.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Meter {
int read(int raw) {
int value = raw * 2;
return value;
}
}
6 changes: 6 additions & 0 deletions tests/cases/java/removed-class-listed-once/src/Meter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Meter {
int read(int raw) {
int value = raw * 2;
return value;
}
}
6 changes: 6 additions & 0 deletions tests/cases/python/removed-class-listed-once/case.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"lang": "python", "src": ".",
"checks": [
{"why": "a removed class and its one method are two declarations, each listed once: the method's header line and its body lines used to give it two rows, and the class was named by its class-body initializer instead of by its own name",
"run": ["changed", "{repo}", "--old", "{repo}/old.txt", "--new", "{repo}/new.txt", "--file", "lib.py"],
"want": ["changed declarations (2)", "removed Meter ", "Meter.read"],
"avoid": ["<classbody>"]}]}
4 changes: 4 additions & 0 deletions tests/cases/python/removed-class-listed-once/lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Meter:
def read(self, raw):
value = raw * 2
return value
Empty file.
4 changes: 4 additions & 0 deletions tests/cases/python/removed-class-listed-once/old.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Meter:
def read(self, raw):
value = raw * 2
return value
Loading