Skip to content

Commit

Permalink
Added option to disable boolean array warning
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Dec 3, 2023
1 parent 0ecc6b5 commit e9fa865
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ dependencies {
implementation("io.github.over-run:marshal:$marshalVersion")
}
```

## Compiler Arguments

You can disable the warning of marshalling boolean arrays
by using the compiler argument `-Aoverrun.marshal.disableBoolArrayWarn=true`.
1 change: 1 addition & 0 deletions src/main/java/overrun/marshal/Checks.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static void checkArraySize(int expected, int got) {
/**
* A check entry
*
* @param <T> the type of the value
* @author squid233
* @since 0.1.0
*/
Expand Down
51 changes: 32 additions & 19 deletions src/main/java/overrun/marshal/NativeApiProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package overrun.marshal;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.type.ArrayType;
Expand Down Expand Up @@ -48,6 +45,30 @@
@SupportedAnnotationTypes("overrun.marshal.NativeApi")
@SupportedSourceVersion(SourceVersion.RELEASE_22)
public final class NativeApiProcessor extends AbstractProcessor {
private boolean disableBoolArrayWarn = false;

/**
* constructor
*/
public NativeApiProcessor() {
}

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
disableBoolArrayWarn = Boolean.parseBoolean(processingEnv.getOptions().get("overrun.marshal.disableBoolArrayWarn"));
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
processClasses(roundEnv);
} catch (Exception e) {
printStackTrace(e);
}
return false;
}

private void processClasses(RoundEnvironment roundEnv) {
final Set<? extends Element> marshalApis = roundEnv.getElementsAnnotatedWith(NativeApi.class);
final Set<TypeElement> types = ElementFilter.typesIn(marshalApis);
Expand Down Expand Up @@ -226,11 +247,13 @@ private void appendMethodBody(TypeElement type,
final boolean returnBooleanArray = returnArray && isBooleanArray(returnType);
final boolean returnStringArray = returnArray && isString(getArrayComponentType(returnType));
// send a warning if using any boolean array
if (returnBooleanArray || parameters.stream().anyMatch(e -> {
final TypeMirror type1 = e.asType();
return isArray(type1) && isBooleanArray(type1);
})) {
processingEnv.getMessager().printWarning(type + "::" + method + ": Marshalling boolean array");
if (!disableBoolArrayWarn) {
if (returnBooleanArray || parameters.stream().anyMatch(e -> {
final TypeMirror type1 = e.asType();
return isArray(type1) && isBooleanArray(type1);
})) {
processingEnv.getMessager().printWarning(type + "::" + method + ": Marshalling boolean array");
}
}
// check array size
parameters.stream()
Expand Down Expand Up @@ -479,16 +502,6 @@ private static void appendFields(List<VariableElement> fields, StringBuilder sb)
sb.append('\n');
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
processClasses(roundEnv);
} catch (Exception e) {
printStackTrace(e);
}
return false;
}

private static void prependOverloadArgs(StringBuilder sb, List<? extends VariableElement> parameters) {
parameters.forEach(e -> {
final TypeMirror type = e.asType();
Expand Down

0 comments on commit e9fa865

Please sign in to comment.