Skip to content

Commit ab44658

Browse files
authored
Code clean (no functionality changes) (#31)
* Address code warnings * Update to java 21 (LTS) * Remove package-info.java in test area (conflict with main) * Rename visitor members to avoid name hiding
1 parent abdc08e commit ab44658

16 files changed

Lines changed: 49 additions & 84 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ subdirectory.
2020

2121
# Requirements
2222

23-
* Java 8+
24-
* Maven (v3.6.3 is known to work); not necessary for running the pre-built JAR
23+
* Java 21+
24+
* Maven (v3.9.9 is known to work); not necessary for running the pre-built JAR
2525

2626
# Setup
2727

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
<properties>
3636
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
37-
<maven.compiler.source>1.8</maven.compiler.source>
38-
<maven.compiler.target>1.8</maven.compiler.target>
37+
<maven.compiler.source>21</maven.compiler.source>
38+
<maven.compiler.target>21</maven.compiler.target>
3939
</properties>
4040

4141
<dependencies>

src/main/java/edu/harvard/seas/pl/abcdatalog/ast/PositiveAtom.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public Substitution unify(PositiveAtom fact) {
127127
* @param subst the substitution
128128
* @return a new atom with the substitution applied
129129
*/
130+
@Override
130131
public PositiveAtom applySubst(Substitution subst) {
131132
return create(this.pred, subst.apply(this.args));
132133
}

src/main/java/edu/harvard/seas/pl/abcdatalog/ast/validation/DatalogValidationException.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
* #L%
3434
*/
3535

36-
@SuppressWarnings("serial")
3736
public class DatalogValidationException extends Exception {
3837

3938
public DatalogValidationException() {}

src/main/java/edu/harvard/seas/pl/abcdatalog/ast/validation/DatalogValidator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,22 @@ public Program(
262262
this.idbPredicateSymbols = idbPredicateSymbols;
263263
}
264264

265+
@Override
265266
public Set<ValidClause> getRules() {
266267
return this.rules;
267268
}
268269

270+
@Override
269271
public Set<PositiveAtom> getInitialFacts() {
270272
return this.initialFacts;
271273
}
272274

275+
@Override
273276
public Set<PredicateSym> getEdbPredicateSyms() {
274277
return this.edbPredicateSymbols;
275278
}
276279

280+
@Override
277281
public Set<PredicateSym> getIdbPredicateSyms() {
278282
return this.idbPredicateSymbols;
279283
}

src/main/java/edu/harvard/seas/pl/abcdatalog/ast/visitors/HeadVisitorBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ public HeadVisitor<I, O> orCrash() {
6161
}
6262

6363
private class Visitor implements HeadVisitor<I, O> {
64-
private final BiFunction<PositiveAtom, I, O> onPositiveAtom;
64+
private final BiFunction<PositiveAtom, I, O> _onPositiveAtom;
6565
private final BiFunction<Head, I, O> otherwise;
6666

6767
public Visitor(BiFunction<Head, I, O> otherwise) {
68-
this.onPositiveAtom = HeadVisitorBuilder.this.onPositiveAtom;
68+
this._onPositiveAtom = HeadVisitorBuilder.this.onPositiveAtom;
6969
this.otherwise = otherwise;
7070
}
7171

7272
@Override
7373
public O visit(PositiveAtom atom, I state) {
74-
if (this.onPositiveAtom != null) {
75-
return this.onPositiveAtom.apply(atom, state);
74+
if (this._onPositiveAtom != null) {
75+
return this._onPositiveAtom.apply(atom, state);
7676
}
7777
return this.otherwise.apply(atom, state);
7878
}

src/main/java/edu/harvard/seas/pl/abcdatalog/ast/visitors/PremiseVisitorBuilder.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,58 +92,58 @@ public PremiseVisitor<I, O> orNull() {
9292
}
9393

9494
private class Visitor implements PremiseVisitor<I, O> {
95-
private final BiFunction<PositiveAtom, I, O> onPositiveAtom;
96-
private final BiFunction<NegatedAtom, I, O> onNegatedAtom;
97-
private final BiFunction<BinaryUnifier, I, O> onBinaryUnifier;
98-
private final BiFunction<BinaryDisunifier, I, O> onBinaryDisunifier;
99-
private BiFunction<AnnotatedAtom, I, O> onAnnotatedAtom;
95+
private final BiFunction<PositiveAtom, I, O> _onPositiveAtom;
96+
private final BiFunction<NegatedAtom, I, O> _onNegatedAtom;
97+
private final BiFunction<BinaryUnifier, I, O> _onBinaryUnifier;
98+
private final BiFunction<BinaryDisunifier, I, O> _onBinaryDisunifier;
99+
private BiFunction<AnnotatedAtom, I, O> _onAnnotatedAtom;
100100
private final BiFunction<Premise, I, O> otherwise;
101101

102102
public Visitor(BiFunction<Premise, I, O> otherwise) {
103-
this.onPositiveAtom = PremiseVisitorBuilder.this.onPositiveAtom;
104-
this.onNegatedAtom = PremiseVisitorBuilder.this.onNegatedAtom;
105-
this.onBinaryUnifier = PremiseVisitorBuilder.this.onBinaryUnifier;
106-
this.onBinaryDisunifier = PremiseVisitorBuilder.this.onBinaryDisunifier;
107-
this.onAnnotatedAtom = PremiseVisitorBuilder.this.onAnnotatedAtom;
103+
this._onPositiveAtom = PremiseVisitorBuilder.this.onPositiveAtom;
104+
this._onNegatedAtom = PremiseVisitorBuilder.this.onNegatedAtom;
105+
this._onBinaryUnifier = PremiseVisitorBuilder.this.onBinaryUnifier;
106+
this._onBinaryDisunifier = PremiseVisitorBuilder.this.onBinaryDisunifier;
107+
this._onAnnotatedAtom = PremiseVisitorBuilder.this.onAnnotatedAtom;
108108
this.otherwise = otherwise;
109109
}
110110

111111
@Override
112112
public O visit(PositiveAtom atom, I state) {
113-
if (this.onPositiveAtom != null) {
114-
return this.onPositiveAtom.apply(atom, state);
113+
if (this._onPositiveAtom != null) {
114+
return this._onPositiveAtom.apply(atom, state);
115115
}
116116
return this.otherwise.apply(atom, state);
117117
}
118118

119119
@Override
120120
public O visit(BinaryUnifier u, I state) {
121-
if (this.onBinaryUnifier != null) {
122-
return this.onBinaryUnifier.apply(u, state);
121+
if (this._onBinaryUnifier != null) {
122+
return this._onBinaryUnifier.apply(u, state);
123123
}
124124
return this.otherwise.apply(u, state);
125125
}
126126

127127
@Override
128128
public O visit(BinaryDisunifier u, I state) {
129-
if (this.onBinaryDisunifier != null) {
130-
return this.onBinaryDisunifier.apply(u, state);
129+
if (this._onBinaryDisunifier != null) {
130+
return this._onBinaryDisunifier.apply(u, state);
131131
}
132132
return this.otherwise.apply(u, state);
133133
}
134134

135135
@Override
136136
public O visit(NegatedAtom atom, I state) {
137-
if (this.onNegatedAtom != null) {
138-
return this.onNegatedAtom.apply(atom, state);
137+
if (this._onNegatedAtom != null) {
138+
return this._onNegatedAtom.apply(atom, state);
139139
}
140140
return this.otherwise.apply(atom, state);
141141
}
142142

143143
@Override
144144
public O visit(AnnotatedAtom atom, I state) {
145-
if (this.onAnnotatedAtom != null) {
146-
return this.onAnnotatedAtom.apply(atom, state);
145+
if (this._onAnnotatedAtom != null) {
146+
return this._onAnnotatedAtom.apply(atom, state);
147147
}
148148
return this.otherwise.apply(atom, state);
149149
}

src/main/java/edu/harvard/seas/pl/abcdatalog/ast/visitors/TermVisitorBuilder.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,28 @@ public TermVisitor<I, O> orCrash() {
6868
}
6969

7070
private class Visitor implements TermVisitor<I, O> {
71-
private final BiFunction<Variable, I, O> onVariable;
72-
private final BiFunction<Constant, I, O> onConstant;
71+
private final BiFunction<Variable, I, O> _onVariable;
72+
private final BiFunction<Constant, I, O> _onConstant;
7373
private final BiFunction<Term, I, O> otherwise;
7474

7575
public Visitor(BiFunction<Term, I, O> otherwise) {
76-
this.onVariable = TermVisitorBuilder.this.onVariable;
77-
this.onConstant = TermVisitorBuilder.this.onConstant;
76+
this._onVariable = TermVisitorBuilder.this.onVariable;
77+
this._onConstant = TermVisitorBuilder.this.onConstant;
7878
this.otherwise = otherwise;
7979
}
8080

8181
@Override
8282
public O visit(Variable t, I state) {
83-
if (onVariable != null) {
84-
return onVariable.apply(t, state);
83+
if (_onVariable != null) {
84+
return _onVariable.apply(t, state);
8585
}
8686
return otherwise.apply(t, state);
8787
}
8888

8989
@Override
9090
public O visit(Constant t, I state) {
91-
if (onConstant != null) {
92-
return onConstant.apply(t, state);
91+
if (_onConstant != null) {
92+
return _onConstant.apply(t, state);
9393
}
9494
return otherwise.apply(t, state);
9595
}

src/main/java/edu/harvard/seas/pl/abcdatalog/gui/DatalogGui.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import javax.swing.undo.UndoManager;
6868

6969
/** A GUI with a Datalog editor and interpreter. */
70-
@SuppressWarnings("serial")
7170
public class DatalogGui extends JFrame {
7271
private final TextEditor program;
7372
private final JTextArea results;

src/main/java/edu/harvard/seas/pl/abcdatalog/gui/TextEditor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import javax.swing.JTextArea;
3939
import javax.swing.text.BadLocationException;
4040

41-
@SuppressWarnings("serial")
4241
public class TextEditor extends JTextArea {
4342
TextEditor(int rows, int columns) {
4443
this.setRows(rows);

0 commit comments

Comments
 (0)