Skip to content

Commit

Permalink
minor code cleanup (#73)
Browse files Browse the repository at this point in the history
* style: remove unnecessary semicolons

* style: add missing `@Override` annotations

* style: access Thread.interrupted() statically

* fix: transitive dependency compiler warning: in org.joni.Regex class

"The type `Encoding` from module org.jruby.jcodings may not be accessible to clients due to missing 'requires transitive'"
  • Loading branch information
sebthom authored Jun 14, 2023
1 parent e5f3761 commit 6a0d556
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
exports org.joni.constants;
exports org.joni.exception;

requires org.jruby.jcodings;
requires transitive org.jruby.jcodings;
}
1 change: 1 addition & 0 deletions src/org/joni/ApplyCaseFold.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
final class ApplyCaseFold implements ApplyAllCaseFoldFunction {

// i_apply_case_fold
@Override
public void apply(int from, int[]to, int length, Object o) {
ApplyCaseFoldArg arg = (ApplyCaseFoldArg)o;

Expand Down
1 change: 1 addition & 0 deletions src/org/joni/BitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private static int log2(int n){
}

private static final int BITS_TO_STRING_WRAP = 4;
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("BitSet");
Expand Down
4 changes: 3 additions & 1 deletion src/org/joni/ByteCodeMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ByteCodeMachine extends StackMachine {
this.code = regex.code;
}

@Override
public void interrupt() {
interrupted = true;
// might have no effect on the executing thread but worth a try
Expand Down Expand Up @@ -153,6 +154,7 @@ private boolean stringCmpIC(int caseFlodFlag, int s1, IntHolder ps2, int mbLen,
return true;
}

@Override
protected final int matchAt(int _range, int _sstart, int _sprev, boolean interrupt) throws InterruptedException {
range = _range;
sstart = _sstart;
Expand Down Expand Up @@ -444,7 +446,7 @@ private final int executeSb(final boolean checkThreadInterrupt) throws Interrupt

private void handleInterrupted(final boolean checkThreadInterrupt) throws InterruptedException {
if (interrupted || (checkThreadInterrupt && Thread.currentThread().isInterrupted())) {
Thread.currentThread().interrupted();
Thread.interrupted();
throw new InterruptedException();
}
interruptCheckEvery = Math.min(interruptCheckEvery << 1, MAX_INTERRUPT_CHECK_EVERY);
Expand Down
2 changes: 2 additions & 0 deletions src/org/joni/CodeRangeBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void writeCodePoint(int pos, int b) {
if (used < u) used = u;
}

@Override
public CodeRangeBuffer clone() {
return new CodeRangeBuffer(this);
}
Expand Down Expand Up @@ -374,6 +375,7 @@ public static CodeRangeBuffer andCodeRangeBuff(CodeRangeBuffer bbuf1, boolean no
return pbuf;
}

@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("CodeRange");
Expand Down
7 changes: 7 additions & 0 deletions src/org/joni/MultiRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,40 @@ public MultiRegion(int begin, int end) {
this.begEnd = new int[]{begin, end};
}

@Override
public final int getNumRegs() {
return begEnd.length / 2;
}

@Override
public MultiRegion clone() {
MultiRegion region = new MultiRegion(getNumRegs());
System.arraycopy(begEnd, 0, region.begEnd, 0, begEnd.length);
if (getCaptureTree() != null) region.setCaptureTree(getCaptureTree().cloneTree());
return region;
}

@Override
public int getBeg(int index) {
return begEnd[index * 2];
}

@Override
public int setBeg(int index, int value) {
return begEnd[index * 2] = value;
}

@Override
public int getEnd(int index) {
return begEnd[index * 2 + 1];
}

@Override
public int setEnd(int index, int value) {
return begEnd[index * 2 + 1] = value;
}

@Override
void clear() {
Arrays.fill(begEnd, REGION_NOTPOS);
}
Expand Down
1 change: 1 addition & 0 deletions src/org/joni/NameEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void addBackref(int backRef) {
}
}

@Override
public String toString() {
StringBuilder buff = new StringBuilder(new String(name, nameP, nameEnd - nameP) + " ");
if (backNum == 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/org/joni/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static Region newRegion(int begin, int end) {
return new SingleRegion(begin, end);
}

@Override
public abstract Region clone();

public abstract int getNumRegs();
Expand All @@ -45,6 +46,7 @@ public static Region newRegion(int begin, int end) {

public abstract int setEnd(int index, int value);

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Region: \n");
Expand Down
2 changes: 1 addition & 1 deletion src/org/joni/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ final int search(Matcher matcher, byte[]text, int textP, int adjustText, int tex
s--;
}
return -1;
};
}
};

static final Forward BM_FORWARD = new Forward() {
Expand Down
7 changes: 7 additions & 0 deletions src/org/joni/SingleRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,43 @@ public SingleRegion(int begin, int end) {
this.end = end;
}

@Override
public int getNumRegs() {
return 1;
}

@Override
public SingleRegion clone() {
SingleRegion region = new SingleRegion(beg, end);
if (getCaptureTree() != null) region.setCaptureTree(getCaptureTree().cloneTree());
return region;
}

@Override
public int getBeg(int index) {
if (index != 0) throw new IndexOutOfBoundsException(""+index);
return beg;
}

@Override
public int setBeg(int index, int value) {
if (index != 0) throw new IndexOutOfBoundsException(""+index);
return beg = value;
}

@Override
public int getEnd(int index) {
if (index != 0) throw new IndexOutOfBoundsException(""+index);
return end;
}

@Override
public int setEnd(int index, int value) {
if (index != 0) throw new IndexOutOfBoundsException(""+index);
return end = value;
}

@Override
void clear() {
beg = end = REGION_NOTPOS;
}
Expand Down
4 changes: 3 additions & 1 deletion src/org/joni/StackMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private void stateCheckMark() {

// STATE_CHECK_BUFF_INIT
private static final int STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE = 16;
@Override
protected final void stateCheckBuffInit(int strLength, int offset, int stateNum) {
if (stateNum > 0 && strLength >= Config.CHECK_STRING_THRESHOLD_LEN) {
int size = ((strLength + 1) * stateNum + 7) >>> 3;
Expand All @@ -156,6 +157,7 @@ protected final void stateCheckBuffInit(int strLength, int offset, int stateNum)
}
}

@Override
protected final void stateCheckBuffClear() {
stateCheckBuff = null;
stateCheckBuffSize = 0;
Expand Down Expand Up @@ -549,7 +551,7 @@ protected final int nullCheckMemStRec(int id, int s) {
isNull = 0;
break;
} else if (endp != s) {
isNull = -1;; /* empty, but position changed */
isNull = -1; /* empty, but position changed */
}
}
k++;
Expand Down
1 change: 1 addition & 0 deletions src/org/joni/UnsetAddrList.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void fix(Regex regex) {
}
}

@Override
public String toString() {
StringBuilder value = new StringBuilder();
if (num > 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/org/joni/WarnCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
*/
public interface WarnCallback {
WarnCallback DEFAULT = new WarnCallback() {
public void warn(String message) {
@Override
public void warn(String message) {
System.err.println(message);
}
};

WarnCallback NONE = new WarnCallback() {
@Override
public void warn(String message) {
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/org/joni/ast/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected void setChild(Node tgt){
protected Node getChild(){
// default definition
return null;
};
}

public void replaceWith(Node with) {
with.parent = parent;
Expand All @@ -59,6 +59,7 @@ public String getAddressName() {
return getName() + ":0x" + Integer.toHexString(System.identityHashCode(this));
}

@Override
public final String toString() {
StringBuilder s = new StringBuilder();
s.append("<" + getAddressName() + " (" + (parent == null ? "NULL" : parent.getAddressName()) + ")>");
Expand Down
3 changes: 3 additions & 0 deletions test/org/joni/test/TestInterrupt.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public Syntax syntax() {
}

@org.junit.Test
@Override
public void test() throws Exception {
interruptAfter(new InterruptibleRunnable() {
@Override
public void run() throws InterruptedException {
x2s("a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0, 0);
Expand All @@ -69,6 +71,7 @@ public void run() throws InterruptedException {
final int status[] = new int[1];

interruptAfter(new InterruptibleRunnable() {
@Override
public void run() throws InterruptedException {
try {
x2s("a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
Expand Down
3 changes: 3 additions & 0 deletions test/org/joni/test/TestU.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ private String uconv(byte []bytes, int len) {
return sb.toString();
}

@Override
protected String repr(byte[]bytes) {
return uconv(bytes, ulen(bytes));
}

@Override
protected int length(byte[]bytes) {
return ulen(bytes);
}

@Override
public void test() throws Exception {
x2s("\000\000", "\000\000", 0, 0);
Expand Down

0 comments on commit 6a0d556

Please sign in to comment.