diff options
author | jonmv <venstad@gmail.com> | 2023-10-10 14:10:55 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2023-10-10 14:10:55 +0200 |
commit | d61c151211024dbb5e9a5d71ac921217ae00f34b (patch) | |
tree | ac631396124b74c5bf77b09119e7ff561cb7723c /vespa-documentgen-plugin | |
parent | 955b46e82a969ed722a008d84878518337803b74 (diff) |
Non-functional changes
Diffstat (limited to 'vespa-documentgen-plugin')
-rw-r--r-- | vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java | 28 | ||||
-rw-r--r-- | vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java | 18 |
2 files changed, 22 insertions, 24 deletions
diff --git a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java index 67b97bb5ae6..65aecd09931 100644 --- a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java +++ b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java @@ -914,10 +914,10 @@ public class DocumentGenMojo extends AbstractMojo { if (DataType.BOOL.equals(dt)) return "java.lang.Boolean"; if (DataType.TAG.equals(dt)) return "java.lang.String"; if (dt instanceof StructDataType) return className(dt.getName()); - if (dt instanceof WeightedSetDataType) return "java.util.Map<"+toJavaType(((WeightedSetDataType)dt).getNestedType())+",java.lang.Integer>"; - if (dt instanceof ArrayDataType) return "java.util.List<"+toJavaType(((ArrayDataType)dt).getNestedType())+">"; - if (dt instanceof MapDataType) return "java.util.Map<"+toJavaType(((MapDataType)dt).getKeyType())+","+toJavaType(((MapDataType)dt).getValueType())+">"; - if (dt instanceof AnnotationReferenceDataType) return className(((AnnotationReferenceDataType) dt).getAnnotationType().getName()); + if (dt instanceof WeightedSetDataType wdt) return "java.util.Map<"+toJavaType(wdt.getNestedType())+",java.lang.Integer>"; + if (dt instanceof ArrayDataType adt) return "java.util.List<"+toJavaType(adt.getNestedType())+">"; + if (dt instanceof MapDataType mdt) return "java.util.Map<"+toJavaType(mdt.getKeyType())+","+toJavaType((mdt).getValueType())+">"; + if (dt instanceof AnnotationReferenceDataType ardt) return className(ardt.getAnnotationType().getName()); if (dt instanceof NewDocumentReferenceDataType) { return "com.yahoo.document.DocumentId"; } @@ -942,22 +942,22 @@ public class DocumentGenMojo extends AbstractMojo { if (DataType.BOOL.equals(dt)) return "com.yahoo.document.DataType.BOOL"; if (DataType.TAG.equals(dt)) return "com.yahoo.document.DataType.TAG"; if (dt instanceof StructDataType) return className(dt.getName()) +".type"; - if (dt instanceof WeightedSetDataType) return "new com.yahoo.document.WeightedSetDataType("+toJavaReference(((WeightedSetDataType)dt).getNestedType())+", "+ - ((WeightedSetDataType)dt).createIfNonExistent()+", "+ ((WeightedSetDataType)dt).removeIfZero()+","+dt.getId()+")"; - if (dt instanceof ArrayDataType) return "new com.yahoo.document.ArrayDataType("+toJavaReference(((ArrayDataType)dt).getNestedType())+")"; - if (dt instanceof MapDataType) return "new com.yahoo.document.MapDataType("+toJavaReference(((MapDataType)dt).getKeyType())+", "+ - toJavaReference(((MapDataType)dt).getValueType())+", "+dt.getId()+")"; + if (dt instanceof WeightedSetDataType wdt) return "new com.yahoo.document.WeightedSetDataType("+toJavaReference(wdt.getNestedType())+", "+ + wdt.createIfNonExistent()+", "+ wdt.removeIfZero()+","+dt.getId()+")"; + if (dt instanceof ArrayDataType adt) return "new com.yahoo.document.ArrayDataType("+toJavaReference(adt.getNestedType())+")"; + if (dt instanceof MapDataType mdt) return "new com.yahoo.document.MapDataType("+toJavaReference(mdt.getKeyType())+", "+ + toJavaReference(mdt.getValueType())+", "+dt.getId()+")"; // For annotation references and generated types, the references are to the actual objects of the correct types, so most likely this is never needed, // but there might be scenarios where we want to look up the AnnotationType in the AnnotationTypeRegistry here instead. - if (dt instanceof AnnotationReferenceDataType) return "new com.yahoo.document.annotation.AnnotationReferenceDataType(new com.yahoo.document.annotation.AnnotationType(\""+((AnnotationReferenceDataType)dt).getAnnotationType().getName()+"\"))"; - if (dt instanceof NewDocumentReferenceDataType) { + if (dt instanceof AnnotationReferenceDataType adt) return "new com.yahoo.document.annotation.AnnotationReferenceDataType(new com.yahoo.document.annotation.AnnotationType(\""+adt.getAnnotationType().getName()+"\"))"; + if (dt instanceof NewDocumentReferenceDataType nrdt) { // All concrete document types have a public `type` constant with their DocumentType. return String.format("new com.yahoo.document.ReferenceDataType(%s.type, %d)", - className(((NewDocumentReferenceDataType) dt).getTargetType().getName()), dt.getId()); + className(nrdt.getTargetType().getName()), dt.getId()); } - if (dt instanceof TensorDataType) { + if (dt instanceof TensorDataType tdt) { return String.format("new com.yahoo.document.TensorDataType(com.yahoo.tensor.TensorType.fromSpec(\"%s\"))", - ((TensorDataType)dt).getTensorType().toString()); + tdt.getTensorType().toString()); } return "com.yahoo.document.DataType.RAW"; } diff --git a/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java b/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java index f55b226b11b..a9904bf5092 100644 --- a/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java +++ b/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java @@ -11,8 +11,9 @@ import java.io.File; import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; public class DocumentGenTest { @@ -39,7 +40,7 @@ public class DocumentGenTest { assertEquals(searches.get("music3").getDocument("music3").getField("pos").getDataType().getName(), "position"); assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType); assertTrue(searches.get("book").getDocument("book").getField("mywsinteger").getDataType() instanceof WeightedSetDataType); - assertTrue(((WeightedSetDataType)(searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType() == DataType.INT); + assertSame(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType(), DataType.INT); } @Test @@ -50,18 +51,15 @@ public class DocumentGenTest { assertEquals(searches.get("video").getDocument("video").getField("weight").getDataType(), DataType.FLOAT); assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType); assertTrue(searches.get("book").getDocument("book").getField("mywsinteger").getDataType() instanceof WeightedSetDataType); - assertTrue(((WeightedSetDataType)(searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType() == DataType.INT); + assertSame(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType(), DataType.INT); } @Test public void testEmptyPkgNameForbidden() { - DocumentGenMojo mojo = new DocumentGenMojo(); - try { - mojo.execute(new File("etc/localapp/"), new File("target/generated-test-sources/vespa-documentgen-plugin/"), ""); - fail("Didn't throw in empty pkg"); - } catch (IllegalArgumentException e) { - - } + assertThrows(IllegalArgumentException.class, + () -> new DocumentGenMojo().execute(new File("etc/localapp/"), + new File("target/generated-test-sources/vespa-documentgen-plugin/"), + "")); } } |