Skip to content

Commit 3c129fc

Browse files
committed
Java: Align BinaryExpr.getOp() with AssignOp.getOp().
1 parent fe032a5 commit 3c129fc

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

java/ql/consistency-queries/BinaryExpr.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ where
1010
e.isNthChildOf(be, i) and i != 0 and i != 1 and reason = "Unexpected operand " + i.toString()
1111
)
1212
or
13-
be.getOp() = " ?? " and reason = "No operator name"
13+
be.getOp() = "??" and reason = "No operator name"
1414
select be, reason

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -739,155 +739,155 @@ class BinaryExpr extends Expr, @binaryexpr {
739739
}
740740

741741
/** Gets a printable representation of this expression. */
742-
override string toString() { result = "..." + this.getOp() + "..." }
742+
override string toString() { result = "... " + this.getOp() + " ..." }
743743

744744
/** Gets a string representation of the operator of this binary expression. */
745-
/*abstract*/ string getOp() { result = " ?? " }
745+
/*abstract*/ string getOp() { result = "??" }
746746
}
747747

748748
/** A binary expression using the `*` operator. */
749749
class MulExpr extends BinaryExpr, @mulexpr {
750-
override string getOp() { result = " * " }
750+
override string getOp() { result = "*" }
751751

752752
override string getAPrimaryQlClass() { result = "MulExpr" }
753753
}
754754

755755
/** A binary expression using the `/` operator. */
756756
class DivExpr extends BinaryExpr, @divexpr {
757-
override string getOp() { result = " / " }
757+
override string getOp() { result = "/" }
758758

759759
override string getAPrimaryQlClass() { result = "DivExpr" }
760760
}
761761

762762
/** A binary expression using the `%` operator. */
763763
class RemExpr extends BinaryExpr, @remexpr {
764-
override string getOp() { result = " % " }
764+
override string getOp() { result = "%" }
765765

766766
override string getAPrimaryQlClass() { result = "RemExpr" }
767767
}
768768

769769
/** A binary expression using the `+` operator. */
770770
class AddExpr extends BinaryExpr, @addexpr {
771-
override string getOp() { result = " + " }
771+
override string getOp() { result = "+" }
772772

773773
override string getAPrimaryQlClass() { result = "AddExpr" }
774774
}
775775

776776
/** A binary expression using the `-` operator. */
777777
class SubExpr extends BinaryExpr, @subexpr {
778-
override string getOp() { result = " - " }
778+
override string getOp() { result = "-" }
779779

780780
override string getAPrimaryQlClass() { result = "SubExpr" }
781781
}
782782

783783
/** A binary expression using the `<<` operator. */
784784
class LeftShiftExpr extends BinaryExpr, @lshiftexpr {
785-
override string getOp() { result = " << " }
785+
override string getOp() { result = "<<" }
786786

787787
override string getAPrimaryQlClass() { result = "LeftShiftExpr" }
788788
}
789789

790790
/** A binary expression using the `>>` operator. */
791791
class RightShiftExpr extends BinaryExpr, @rshiftexpr {
792-
override string getOp() { result = " >> " }
792+
override string getOp() { result = ">>" }
793793

794794
override string getAPrimaryQlClass() { result = "RightShiftExpr" }
795795
}
796796

797797
/** A binary expression using the `>>>` operator. */
798798
class UnsignedRightShiftExpr extends BinaryExpr, @urshiftexpr {
799-
override string getOp() { result = " >>> " }
799+
override string getOp() { result = ">>>" }
800800

801801
override string getAPrimaryQlClass() { result = "UnsignedRightShiftExpr" }
802802
}
803803

804804
/** A binary expression using the `&` operator. */
805805
class AndBitwiseExpr extends BinaryExpr, @andbitexpr {
806-
override string getOp() { result = " & " }
806+
override string getOp() { result = "&" }
807807

808808
override string getAPrimaryQlClass() { result = "AndBitwiseExpr" }
809809
}
810810

811811
/** A binary expression using the `|` operator. */
812812
class OrBitwiseExpr extends BinaryExpr, @orbitexpr {
813-
override string getOp() { result = " | " }
813+
override string getOp() { result = "|" }
814814

815815
override string getAPrimaryQlClass() { result = "OrBitwiseExpr" }
816816
}
817817

818818
/** A binary expression using the `^` operator. */
819819
class XorBitwiseExpr extends BinaryExpr, @xorbitexpr {
820-
override string getOp() { result = " ^ " }
820+
override string getOp() { result = "^" }
821821

822822
override string getAPrimaryQlClass() { result = "XorBitwiseExpr" }
823823
}
824824

825825
/** A binary expression using the `&&` operator. */
826826
class AndLogicalExpr extends BinaryExpr, @andlogicalexpr {
827-
override string getOp() { result = " && " }
827+
override string getOp() { result = "&&" }
828828

829829
override string getAPrimaryQlClass() { result = "AndLogicalExpr" }
830830
}
831831

832832
/** A binary expression using the `||` operator. */
833833
class OrLogicalExpr extends BinaryExpr, @orlogicalexpr {
834-
override string getOp() { result = " || " }
834+
override string getOp() { result = "||" }
835835

836836
override string getAPrimaryQlClass() { result = "OrLogicalExpr" }
837837
}
838838

839839
/** A binary expression using the `<` operator. */
840840
class LTExpr extends BinaryExpr, @ltexpr {
841-
override string getOp() { result = " < " }
841+
override string getOp() { result = "<" }
842842

843843
override string getAPrimaryQlClass() { result = "LTExpr" }
844844
}
845845

846846
/** A binary expression using the `>` operator. */
847847
class GTExpr extends BinaryExpr, @gtexpr {
848-
override string getOp() { result = " > " }
848+
override string getOp() { result = ">" }
849849

850850
override string getAPrimaryQlClass() { result = "GTExpr" }
851851
}
852852

853853
/** A binary expression using the `<=` operator. */
854854
class LEExpr extends BinaryExpr, @leexpr {
855-
override string getOp() { result = " <= " }
855+
override string getOp() { result = "<=" }
856856

857857
override string getAPrimaryQlClass() { result = "LEExpr" }
858858
}
859859

860860
/** A binary expression using the `>=` operator. */
861861
class GEExpr extends BinaryExpr, @geexpr {
862-
override string getOp() { result = " >= " }
862+
override string getOp() { result = ">=" }
863863

864864
override string getAPrimaryQlClass() { result = "GEExpr" }
865865
}
866866

867867
/** A binary expression using Java's `==` or Kotlin's `===` operator. */
868868
class EQExpr extends BinaryExpr, @eqexpr {
869-
override string getOp() { result = " == " }
869+
override string getOp() { result = "==" }
870870

871871
override string getAPrimaryQlClass() { result = "EQExpr" }
872872
}
873873

874874
/** A binary expression using the Kotlin `==` operator, semantically equivalent to `Objects.equals`. */
875875
class ValueEQExpr extends BinaryExpr, @valueeqexpr {
876-
override string getOp() { result = " (value equals) " }
876+
override string getOp() { result = "(value equals)" }
877877

878878
override string getAPrimaryQlClass() { result = "ValueEQExpr" }
879879
}
880880

881881
/** A binary expression using Java's `!=` or Kotlin's `!==` operator. */
882882
class NEExpr extends BinaryExpr, @neexpr {
883-
override string getOp() { result = " != " }
883+
override string getOp() { result = "!=" }
884884

885885
override string getAPrimaryQlClass() { result = "NEExpr" }
886886
}
887887

888888
/** A binary expression using the Kotlin `!=` operator, semantically equivalent to `Objects.equals`. */
889889
class ValueNEExpr extends BinaryExpr, @valueneexpr {
890-
override string getOp() { result = " (value not-equals) " }
890+
override string getOp() { result = "(value not-equals)" }
891891

892892
override string getAPrimaryQlClass() { result = "ValueNEExpr" }
893893
}

java/ql/lib/semmle/code/java/PrettyPrintAst.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private class PpLiteral extends PpAst, Literal {
229229
}
230230

231231
private class PpBinaryExpr extends PpAst, BinaryExpr {
232-
override string getPart(int i) { i = 1 and result = this.getOp() }
232+
override string getPart(int i) { i = 1 and result = " " + this.getOp() + " " }
233233

234234
override PpAst getChild(int i) {
235235
i = 0 and result = this.getLeftOperand()

java/ql/src/Likely Bugs/Arithmetic/WhitespaceContradictsPrecedence.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int operatorWS(BinaryExpr expr) {
138138
endOfBinaryLhs(expr, line, lcol) and
139139
startOfBinaryRhs(expr, line, rcol) and
140140
parens = getParensNextToOp(expr) and
141-
result = rcol - lcol + 1 - expr.getOp().length() - parens
141+
result = rcol - lcol - 1 - expr.getOp().length() - parens
142142
)
143143
}
144144

java/ql/test/library-tests/guards/GuardsInline.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ string ppGuard(Guard g, Boolean branch) {
1111
or
1212
exists(BinaryExpr bin |
1313
bin = g and
14-
result = "'" + bin.getLeftOperand() + bin.getOp() + bin.getRightOperand() + ":" + branch + "'"
14+
result =
15+
"'" + bin.getLeftOperand() + " " + bin.getOp() + " " + bin.getRightOperand() + ":" + branch +
16+
"'"
1517
)
1618
or
1719
exists(SwitchCase cc, Expr s, string match, string value |

0 commit comments

Comments
 (0)