Indenter bug corrections; indented files according to indenter

svn: r10371
This commit is contained in:
Kathy Gray 2008-06-19 13:40:25 +00:00
parent 707315b1b4
commit 08015efba8
3 changed files with 84 additions and 76 deletions

View File

@ -182,18 +182,20 @@
(cond (cond
[(equal? opener #\{) [(equal? opener #\{)
(let* ([previous-open (get-sexp-start (sub1 open-at))] (let* ([previous-open (get-sexp-start (sub1 open-at))]
[brace? (and previous-open (equal? #\{ (get-character (sub1 previous-open))))] [brace? (and previous-open
[base-line-start (and brace? (skip-whitespace (add1 previous-open) 'forward #f))]) (> (sub1 previous-open) 0)
#;(printf "brace? ~a bls ~a~n" brace? base-line-start) (equal? #\{ (get-character (sub1 previous-open))))]
[base-line-text (and brace? (skip-whitespace (add1 previous-open) 'forward #f))]
[base-line-start (and base-line-text (find-string eol 'backward base-line-text 0 #f))])
#;(printf "brace? ~a blt ~a bls ~a~n" brace? base-line-text base-line-start)
(cond (cond
[base-line-start (+ single-tab-stop [base-line-start (+ single-tab-stop
(max 0 (sub1 (- base-line-start previous-open))))] (max 0 (sub1 (- base-line-text base-line-start))))]
[brace? (+ single-tab-stop 0)] [brace? (+ single-tab-stop 0)]
[else (+ single-tab-stop last-line-indent)]))] [else (+ single-tab-stop last-line-indent)]))]
[(equal? opener #\() [(equal? opener #\()
(+ (max 0 (+ (max 0
(- open-at #;(find-string "(" 'forward last-line-start start-pos #f) (- open-at last-line-start))
last-line-start))
last-line-indent)] last-line-indent)]
[(equal? opener #\[) [(equal? opener #\[)
(+ (max 0 (+ (max 0
@ -240,6 +242,7 @@
(cond (cond
[(not old-open) last-line-indent] [(not old-open) last-line-indent]
[(and old-open (<= curr-open old-open)) last-line-indent] [(and old-open (<= curr-open old-open)) last-line-indent]
[(< (sub1 curr-open) 0) base-offset]
[else [else
(sensitive-indent last-line-indent last-line-start (get-character (sub1 curr-open)) curr-open) (sensitive-indent last-line-indent last-line-start (get-character (sub1 curr-open)) curr-open)
#;(+ single-tab-stop last-line-indent)]))] #;(+ single-tab-stop last-line-indent)]))]
@ -251,6 +254,7 @@
(cond (cond
[(not old-open) last-line-indent] [(not old-open) last-line-indent]
[(and old-open (<= curr-open old-open)) last-line-indent] [(and old-open (<= curr-open old-open)) last-line-indent]
[(< (sub1 curr-open) 0) base-offset]
[else [else
(sensitive-indent last-line-indent last-line-start (get-character (sub1 curr-open)) curr-open) (sensitive-indent last-line-indent last-line-start (get-character (sub1 curr-open)) curr-open)
#;(+ single-tab-stop last-line-indent)]))]))])))]) #;(+ single-tab-stop last-line-indent)]))]))])))])
@ -311,15 +315,20 @@
[end-para (position-paragraph (get-end-position))]) [end-para (position-paragraph (get-end-position))])
(begin-edit-sequence) (begin-edit-sequence)
(let loop ([para start-para]) (let loop ([para start-para])
#;(printf "in tabify outer loop ~a ~a~n" para end-para)
(let* ([para-start (paragraph-start-position para)] (let* ([para-start (paragraph-start-position para)]
[curr-white-space (skip-whitespace para-start 'forward #f)]
[insertion (get-indentation (max 0 (sub1 para-start)))] [insertion (get-indentation (max 0 (sub1 para-start)))]
[closer? #f] [closer? #f]
[delete? #f]) [delete? #f])
(let loop () (let loop ()
#;(printf "in tabify inner loop ~a ~a, ~a ~n" para para-start curr-white-space)
(let ([c (get-character para-start)] (let ([c (get-character para-start)]
[class (classify-position para-start)]) [class (classify-position para-start)])
#;(printf "character is ~a, ~a~n" c class)
(cond (cond
[(and (eq? 'white-space class) [(and (eq? 'white-space class)
(not (= curr-white-space para-start))
(not (char=? c #\015)) (not (char=? c #\015))
(not (char=? c #\012))) (not (char=? c #\012)))
(set! delete? #t) (set! delete? #t)
@ -332,8 +341,7 @@
(insert (substring insertion 0 (max 0 (- (string-length insertion) single-tab-stop))) para-start para-start)] (insert (substring insertion 0 (max 0 (- (string-length insertion) single-tab-stop))) para-start para-start)]
[(or delete? (not (eq? 'block-comment (classify-position para-start)))) [(or delete? (not (eq? 'block-comment (classify-position para-start))))
(insert insertion para-start para-start)])) (insert insertion para-start para-start)]))
(unless (= para end-para) (unless (= para end-para) (loop (+ para 1))))
(loop (+ para 1))))
(end-edit-sequence))) (end-edit-sequence)))
(super-new))) (super-new)))

View File

@ -12,19 +12,19 @@ interface Automobile {
} }
class Car implements Automobile { class Car implements Automobile {
String make; String make;
String model; String model;
int miles; int miles;
double basePrice; double basePrice;
Car(String make, String model, int miles, double basePrice) { Car(String make, String model, int miles, double basePrice) {
this.make = make; this.make = make;
this.model = model; this.model = model;
this.miles = miles; this.miles = miles;
this.basePrice = basePrice; this.basePrice = basePrice;
} }
int milesTraveled() { int milesTraveled() {
return this.miles; return this.miles;
} }
@ -35,10 +35,10 @@ class Car implements Automobile {
Automobile travel(int miles) { Automobile travel(int miles) {
return new Car(this.make, this.model, this.miles+miles, this.basePrice); return new Car(this.make, this.model, this.miles+miles, this.basePrice);
} }
double price(int year) { double price(int year) {
if ((2006 - year) == 0) { if ((2006 - year) == 0) {
return this.basePrice; return this.basePrice;
} else { } else {
if ((2006 - year) > 0) { if ((2006 - year) > 0) {
return this.basePrice - (this.basePrice / (2006 - year)); return this.basePrice - (this.basePrice / (2006 - year));
@ -47,34 +47,34 @@ class Car implements Automobile {
} }
} }
} }
} }
class CarExamples { class CarExamples {
CarExamples() { } CarExamples() { }
Car myCar = new Car("Toyota","Tercel",100000, 16000.00); Car myCar = new Car("Toyota","Tercel",100000, 16000.00);
Car momCar = new Car("Honda","Excel",10000, 32000.00); Car momCar = new Car("Honda","Excel",10000, 32000.00);
boolean test1 = check this.myCar expect this.momCar; boolean test1 = check this.myCar expect this.momCar;
boolean test2 = check this.myCar.milesTraveled() expect 100000; boolean test2 = check this.myCar.milesTraveled() expect 100000;
boolean testTravel() { boolean testTravel() {
return (check this.myCar.travel(10) expect new Car("Toyota","Tercel",100010, 16000.00)) || return (check this.myCar.travel(10) expect new Car("Toyota","Tercel",100010, 16000.00)) ||
(check this.momCar.travel(90000) expect this.myCar); (check this.momCar.travel(90000) expect this.myCar);
} }
boolean testMakeModel() { boolean testMakeModel() {
return check this.myCar.makeAndModel() expect "ToyotaTercel"; return check this.myCar.makeAndModel() expect "ToyotaTercel";
} }
boolean testPrice() { boolean testPrice() {
return (check this.myCar.price(2006) expect 16000.00 within .01) && return (check this.myCar.price(2006) expect 16000.00 within .01) &&
(check this.myCar.price(1991) expect 14933.33 within .01) && (check this.myCar.price(1991) expect 14933.33 within .01) &&
(check this.myCar.price(2007) expect 32000.00 within .01); (check this.myCar.price(2007) expect 32000.00 within .01);
} }
} }
class Truck implements Automobile { class Truck implements Automobile {
@ -83,22 +83,22 @@ class Truck implements Automobile {
int numDoors; int numDoors;
boolean extendedBed; boolean extendedBed;
double basePrice; double basePrice;
Truck( String make, int miles, int numDoors, boolean bed, double basePrice) { Truck( String make, int miles, int numDoors, boolean bed, double basePrice) {
this.make = make; this.make = make;
this.miles = miles; this.miles = miles;
this.numDoors = numDoors; this.numDoors = numDoors;
this.extendedBed = bed; this.extendedBed = bed;
this.basePrice = basePrice; this.basePrice = basePrice;
} }
int milesTraveled() { return this.miles; } int milesTraveled() { return this.miles; }
String makeAndModel() { String makeAndModel() {
if (this.extendedBed) { if (this.extendedBed) {
return this.make.concat("Extended"); return this.make.concat("Extended");
} else { } else {
return this.make.concat(String.valueOf(this.numDoors)); return this.make.concat(String.valueOf(this.numDoors));
} }
} }
Automobile travel(int miles) { Automobile travel(int miles) {
return new Truck(this.make, this.miles + miles, this.numDoors, this.extendedBed, this.basePrice); return new Truck(this.make, this.miles + miles, this.numDoors, this.extendedBed, this.basePrice);
@ -118,25 +118,25 @@ class Truck implements Automobile {
class TruckExamples { class TruckExamples {
Truck oneTruck = new Truck("Toyota",10000, 2,false,20000.00); Truck oneTruck = new Truck("Toyota",10000, 2,false,20000.00);
Truck twoTruck = new Truck("Ford",100000,2,true,35000.00); Truck twoTruck = new Truck("Ford",100000,2,true,35000.00);
boolean test1 = check this.oneTruck.milesTraveled() expect 10000; boolean test1 = check this.oneTruck.milesTraveled() expect 10000;
boolean test2 = check this.oneTruck expect this.twoTruck; boolean test2 = check this.oneTruck expect this.twoTruck;
TruckExamples() { } TruckExamples() { }
boolean testPrice() { boolean testPrice() {
return (check this.oneTruck.price(2006) expect 20000.00 within .01) && return (check this.oneTruck.price(2006) expect 20000.00 within .01) &&
(check this.oneTruck.price(1996) expect 16000.00 within .01); (check this.oneTruck.price(1996) expect 16000.00 within .01);
} }
boolean testTravel() { boolean testTravel() {
return check this.oneTruck.travel(1000) expect new Truck("Toyota",11000,2,false,20000.00); return check this.oneTruck.travel(1000) expect new Truck("Toyota",11000,2,false,20000.00);
} }
boolean testMakeAndModel() { boolean testMakeAndModel() {
return (check this.oneTruck.makeAndModel() expect "Toyota2") && return (check this.oneTruck.makeAndModel() expect "Toyota2") &&
(check this.twoTruck.makeAndModel() expect "FordExtended"); (check this.twoTruck.makeAndModel() expect "FordExtended");
} }
} }

View File

@ -8,42 +8,42 @@ interface Automobile {
} }
abstract class Auto implements Automobile { abstract class Auto implements Automobile {
int miles; int miles;
int milesTraveled() { return miles; } int milesTraveled() { return miles; }
void travel(int miles) { void travel(int miles) {
this.miles = this.miles + miles; this.miles = this.miles + miles;
} }
} }
class Car extends Auto { class Car extends Auto {
double basePrice; double basePrice;
Car(int miles, double basePrice) { Car(int miles, double basePrice) {
this.miles = miles; this.miles = miles;
this.basePrice = basePrice; this.basePrice = basePrice;
} }
double price(int year) { double price(int year) {
if ((2006 - year) == 0) { if ((2006 - year) == 0) {
return this.basePrice; return this.basePrice;
} else { } else {
if ((2006 - year) > 0) { if ((2006 - year) > 0) {
return this.basePrice - (this.basePrice / (2006 - year)); return this.basePrice - (this.basePrice / (2006 - year));
} else { } else {
return this.basePrice + (this.basePrice / (year - 2006)); return this.basePrice + (this.basePrice / (year - 2006));
} }
} }
} }
} }
class CarExamples { class CarExamples {
Car myCar = new Car(100000, 16000.00); Car myCar = new Car(100000, 16000.00);
Car momCar = new Car(10000, 32000.00); Car momCar = new Car(10000, 32000.00);
boolean test1 = check this.myCar expect this.momCar; boolean test1 = check this.myCar expect this.momCar;
boolean test2 = check this.myCar.milesTraveled() expect 100000; boolean test2 = check this.myCar.milesTraveled() expect 100000;
@ -51,18 +51,18 @@ class CarExamples {
myCar.travel(10); myCar.travel(10);
return (check this.myCar expect new Car(100010, 16000.00)); return (check this.myCar expect new Car(100010, 16000.00));
} }
boolean testTravel2() { boolean testTravel2() {
myCar.travel(10); myCar.travel(10);
return (check this.myCar expect new Car(100020, 16000.00)); return (check this.myCar expect new Car(100020, 16000.00));
} }
boolean testPrice() { boolean testPrice() {
return (check this.myCar.price(2006) expect 16000.00 within .01) && return (check this.myCar.price(2006) expect 16000.00 within .01) &&
(check this.myCar.price(1991) expect 14933.33 within .01) && (check this.myCar.price(1991) expect 14933.33 within .01) &&
(check this.myCar.price(2007) expect 32000.00 within .01); (check this.myCar.price(2007) expect 32000.00 within .01);
} }
} }
class Truck extends Auto { class Truck extends Auto {
@ -70,21 +70,21 @@ class Truck extends Auto {
int numDoors; int numDoors;
boolean extendedBed; boolean extendedBed;
double basePrice; double basePrice;
Truck( String make, int miles, int numDoors, boolean bed, double basePrice) { Truck( String make, int miles, int numDoors, boolean bed, double basePrice) {
this.make = make; this.make = make;
this.miles = miles; this.miles = miles;
this.numDoors = numDoors; this.numDoors = numDoors;
this.extendedBed = bed; this.extendedBed = bed;
this.basePrice = basePrice; this.basePrice = basePrice;
} }
String makeAndModel() { String makeAndModel() {
if (this.extendedBed) { if (this.extendedBed) {
return this.make.concat("Extended"); return this.make.concat("Extended");
} else { } else {
return this.make.concat(String.valueOf(this.numDoors)); return this.make.concat(String.valueOf(this.numDoors));
} }
} }
double price( int year ) { double price( int year ) {
// Uncomment to test runtime error behavior // Uncomment to test runtime error behavior
@ -101,25 +101,25 @@ class Truck extends Auto {
class TruckExamples { class TruckExamples {
Truck oneTruck = new Truck("Toyota",10000, 2,false,20000.00); Truck oneTruck = new Truck("Toyota",10000, 2,false,20000.00);
Truck twoTruck = new Truck("Ford",100000,2,true,35000.00); Truck twoTruck = new Truck("Ford",100000,2,true,35000.00);
boolean test1 = check this.oneTruck.milesTraveled() expect 10000; boolean test1 = check this.oneTruck.milesTraveled() expect 10000;
boolean test2 = check this.oneTruck expect this.twoTruck; boolean test2 = check this.oneTruck expect this.twoTruck;
TruckExamples() { } TruckExamples() { }
boolean testPrice() { boolean testPrice() {
return (check this.oneTruck.price(2006) expect 20000.00 within .01) && return (check this.oneTruck.price(2006) expect 20000.00 within .01) &&
(check this.oneTruck.price(1996) expect 16000.00 within .01); (check this.oneTruck.price(1996) expect 16000.00 within .01);
} }
boolean testTravel() { boolean testTravel() {
oneTruck.travel(1000); oneTruck.travel(1000);
return check this.oneTruck expect new Truck("Toyota",11000,2,false,20000.00); return check this.oneTruck expect new Truck("Toyota",11000,2,false,20000.00);
} }
boolean testMakeAndModel() { boolean testMakeAndModel() {
return (check this.oneTruck.makeAndModel() expect "Toyota2") && return (check this.oneTruck.makeAndModel() expect "Toyota2") &&
(check this.twoTruck.makeAndModel() expect "FordExtended"); (check this.twoTruck.makeAndModel() expect "FordExtended");
} }
} }