The existing JavacParser uses bit operations to manage mode flags so you end up with code that looks like:
```
if (token.kind == LT &&
(mode & TYPE) != 0 &&
(mode & NOPARAMS) == 0) {
```
when
```
if (token.kind == LT &&
isMode(TYPE) &&
!isMode(NOPARAMS)) {
```
might be easier to read.
The task is to replace
```
/** When terms are parsed, the mode determines which is expected:
* mode = EXPR : an expression
* mode = TYPE : a type
* mode = NOPARAMS : no parameters allowed for type
* mode = TYPEARG : type argument
* mode |= NOLAMBDA : lambdas are not allowed
*/
protected static final int EXPR = 0x1;
protected static final int TYPE = 0x2;
protected static final int NOPARAMS = 0x4;
protected static final int TYPEARG = 0x8;
protected static final int DIAMOND = 0x10;
protected static final int NOLAMBDA = 0x20;
```
with
```
/** When terms are parsed, the mode determines which is expected:
* mode = EXPR : an expression
* mode = TYPE : a type
* mode = NOPARAMS : no parameters allowed for type
* mode = TYPEARG : type argument
* mode |= NOLAMBDA : lambdas are not allowed
*/
protected static final int EXPR = 1 << 0;
protected static final int TYPE = 1 << 1;
protected static final int NOPARAMS = 1 << 2;
protected static final int TYPEARG = 1 << 3;
protected static final int DIAMOND = 1 << 4;
protected static final int NOLAMBDA = 1 << 5;
protected void setMode(int mode) {
this.mode = mode;
}
protected void setLastMode(int mode) {
lastmode = mode;
}
protected boolean isMode(int mode) {
return (this.mode & mode) != 0;
}
protected boolean wasTypeMode() {
return (lastmode & TYPE) != 0;
}
```
```
if (token.kind == LT &&
(mode & TYPE) != 0 &&
(mode & NOPARAMS) == 0) {
```
when
```
if (token.kind == LT &&
isMode(TYPE) &&
!isMode(NOPARAMS)) {
```
might be easier to read.
The task is to replace
```
/** When terms are parsed, the mode determines which is expected:
* mode = EXPR : an expression
* mode = TYPE : a type
* mode = NOPARAMS : no parameters allowed for type
* mode = TYPEARG : type argument
* mode |= NOLAMBDA : lambdas are not allowed
*/
protected static final int EXPR = 0x1;
protected static final int TYPE = 0x2;
protected static final int NOPARAMS = 0x4;
protected static final int TYPEARG = 0x8;
protected static final int DIAMOND = 0x10;
protected static final int NOLAMBDA = 0x20;
```
with
```
/** When terms are parsed, the mode determines which is expected:
* mode = EXPR : an expression
* mode = TYPE : a type
* mode = NOPARAMS : no parameters allowed for type
* mode = TYPEARG : type argument
* mode |= NOLAMBDA : lambdas are not allowed
*/
protected static final int EXPR = 1 << 0;
protected static final int TYPE = 1 << 1;
protected static final int NOPARAMS = 1 << 2;
protected static final int TYPEARG = 1 << 3;
protected static final int DIAMOND = 1 << 4;
protected static final int NOLAMBDA = 1 << 5;
protected void setMode(int mode) {
this.mode = mode;
}
protected void setLastMode(int mode) {
lastmode = mode;
}
protected boolean isMode(int mode) {
return (this.mode & mode) != 0;
}
protected boolean wasTypeMode() {
return (lastmode & TYPE) != 0;
}
```