Commit b4ec8091 authored by Iulia Tamas's avatar Iulia Tamas Committed by Andrew Twyman

Fixes to Java nullability annotations:

- Mark interfaces as nullable
- Add missing annotations on static method arguments
parent d47163a4
......@@ -10,8 +10,8 @@ import javax.annotation.Nonnull;
public abstract class SortItems {
public abstract void sort(@Nonnull SortOrder order, @Nonnull ItemList items);
@Nonnull
public static native SortItems createWithListener(TextboxListener listener);
@CheckForNull
public static native SortItems createWithListener(@CheckForNull TextboxListener listener);
public static final class CppProxy extends SortItems
{
......
......@@ -156,7 +156,10 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
skipFirst { w.wl }
writeDoc(w, m.doc)
val ret = marshal.returnType(m.ret)
val params = m.params.map(p => marshal.paramType(p.ty) + " " + idJava.local(p.ident))
val params = m.params.map(p => {
val nullityAnnotation = marshal.nullityAnnotation(p.ty).map(_ + " ").getOrElse("")
nullityAnnotation + marshal.paramType(p.ty) + " " + idJava.local(p.ident)
})
marshal.nullityAnnotation(m.ret).foreach(w.wl)
w.wl("public static native "+ ret + " " + idJava.method(m.ident) + params.mkString("(", ", ", ")") + ";")
}
......
......@@ -44,6 +44,12 @@ class JavaMarshal(spec: Spec) extends Marshal(spec) {
ty.resolved.base match {
case MOptional => javaNullableAnnotation
case p: MPrimitive => None
case m: MDef =>
m.defType match {
case DInterface => javaNullableAnnotation
case DEnum => javaNonnullAnnotation
case DRecord => javaNonnullAnnotation
}
case _ => javaNonnullAnnotation
}
}
......
......@@ -10,7 +10,7 @@ import javax.annotation.Nonnull;
public abstract class CppException {
public abstract int throwAnException();
@Nonnull
@CheckForNull
public static native CppException get();
public static final class CppProxy extends CppException
......
......@@ -12,62 +12,62 @@ public abstract class TestHelpers {
@Nonnull
public static native SetRecord getSetRecord();
public static native boolean checkSetRecord(SetRecord rec);
public static native boolean checkSetRecord(@Nonnull SetRecord rec);
@Nonnull
public static native PrimitiveList getPrimitiveList();
public static native boolean checkPrimitiveList(PrimitiveList pl);
public static native boolean checkPrimitiveList(@Nonnull PrimitiveList pl);
@Nonnull
public static native NestedCollection getNestedCollection();
public static native boolean checkNestedCollection(NestedCollection nc);
public static native boolean checkNestedCollection(@Nonnull NestedCollection nc);
@Nonnull
public static native HashMap<String, Long> getMap();
public static native boolean checkMap(HashMap<String, Long> m);
public static native boolean checkMap(@Nonnull HashMap<String, Long> m);
@Nonnull
public static native HashMap<String, Long> getEmptyMap();
public static native boolean checkEmptyMap(HashMap<String, Long> m);
public static native boolean checkEmptyMap(@Nonnull HashMap<String, Long> m);
@Nonnull
public static native MapListRecord getMapListRecord();
public static native boolean checkMapListRecord(MapListRecord m);
public static native boolean checkMapListRecord(@Nonnull MapListRecord m);
public static native void checkClientInterfaceAscii(ClientInterface i);
public static native void checkClientInterfaceAscii(@CheckForNull ClientInterface i);
public static native void checkClientInterfaceNonascii(ClientInterface i);
public static native void checkClientInterfaceNonascii(@CheckForNull ClientInterface i);
public static native void checkEnumMap(HashMap<Color, String> m);
public static native void checkEnumMap(@Nonnull HashMap<Color, String> m);
public static native void checkEnum(Color c);
public static native void checkEnum(@Nonnull Color c);
@Nonnull
public static native Token tokenId(Token t);
@CheckForNull
public static native Token tokenId(@CheckForNull Token t);
@Nonnull
@CheckForNull
public static native Token createCppToken();
public static native void checkCppToken(Token t);
public static native void checkCppToken(@CheckForNull Token t);
public static native long cppTokenId(Token t);
public static native long cppTokenId(@CheckForNull Token t);
public static native void checkTokenType(Token t, String type);
public static native void checkTokenType(@CheckForNull Token t, @Nonnull String type);
@CheckForNull
public static native Integer returnNone();
/** Ensures that we generate integer translation code */
@Nonnull
public static native AssortedPrimitives assortedPrimitivesId(AssortedPrimitives i);
public static native AssortedPrimitives assortedPrimitivesId(@Nonnull AssortedPrimitives i);
@Nonnull
public static native byte[] idBinary(byte[] b);
public static native byte[] idBinary(@Nonnull byte[] b);
public static final class CppProxy extends TestHelpers
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment