target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test @Ignore public void givenPatch_addNewJsonToSource() throws Exception { JsonMergePatchExample jsonMergePatchExample = new JsonMergePatchExample(); JsonValue result = jsonMergePatchExample.addValue(); assertThat(((JsonString) result).getString()).isEqualToIgnoringCase("{\"colour\":\"blue\",\"blue\":\"light\"}"); }
public JsonValue addValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"blue\":\"light\"}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); }
JsonMergePatchExample extends JsonExample { public JsonValue addValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"blue\":\"light\"}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); } }
JsonMergePatchExample extends JsonExample { public JsonValue addValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"blue\":\"light\"}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); } }
JsonMergePatchExample extends JsonExample { public JsonValue addValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"blue\":\"light\"}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); } JsonValue changeValue(); JsonValue addValue(); JsonValue deleteValue(); }
JsonMergePatchExample extends JsonExample { public JsonValue addValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"blue\":\"light\"}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); } JsonValue changeValue(); JsonValue addValue(); JsonValue deleteValue(); }
@Test @Ignore public void givenPatch_deleteValue() throws Exception { JsonMergePatchExample jsonMergePatchExample = new JsonMergePatchExample(); JsonValue result = jsonMergePatchExample.deleteValue(); assertThat(((JsonString) result).getString()).isEqualToIgnoringCase("{}"); }
public JsonValue deleteValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"colour\":null}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); }
JsonMergePatchExample extends JsonExample { public JsonValue deleteValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"colour\":null}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); } }
JsonMergePatchExample extends JsonExample { public JsonValue deleteValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"colour\":null}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); } }
JsonMergePatchExample extends JsonExample { public JsonValue deleteValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"colour\":null}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); } JsonValue changeValue(); JsonValue addValue(); JsonValue deleteValue(); }
JsonMergePatchExample extends JsonExample { public JsonValue deleteValue() { JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue patch = Json.createValue("{\"colour\":null}"); JsonMergePatch jsonMergePatch = Json.createMergePatch(patch); return jsonMergePatch.apply(source); } JsonValue changeValue(); JsonValue addValue(); JsonValue deleteValue(); }
@Test public void ifValueIsMoved_shouldNotAmendOriginalJSON() { JsonPatchExample jsonPatchExample = new JsonPatchExample(); JsonObject jsonObject = jsonPatchExample.toJsonArray(); JsonPointer pointer = Json.createPointer("/series/0"); JsonString jsonString = (JsonString) pointer.getValue(jsonObject); assertThat(jsonString.getString()).isEqualToIgnoringCase("Cognitive"); }
public JsonObject toJsonArray() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonArray jsonArray = builder.copy("/series/0", "/topics/0").build().toJsonArray(); return Json.createPatchBuilder(jsonArray).build().apply(jsonObject); }
JsonPatchExample extends JsonExample { public JsonObject toJsonArray() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonArray jsonArray = builder.copy("/series/0", "/topics/0").build().toJsonArray(); return Json.createPatchBuilder(jsonArray).build().apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject toJsonArray() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonArray jsonArray = builder.copy("/series/0", "/topics/0").build().toJsonArray(); return Json.createPatchBuilder(jsonArray).build().apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject toJsonArray() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonArray jsonArray = builder.copy("/series/0", "/topics/0").build().toJsonArray(); return Json.createPatchBuilder(jsonArray).build().apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
JsonPatchExample extends JsonExample { public JsonObject toJsonArray() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonArray jsonArray = builder.copy("/series/0", "/topics/0").build().toJsonArray(); return Json.createPatchBuilder(jsonArray).build().apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
@Test public void ifValueExists_moveItToDestination() { JsonPatchExample jsonPatchExample = new JsonPatchExample(); JsonObject jsonObject = jsonPatchExample.test(); JsonPointer pointer = Json.createPointer("/series/2"); JsonString jsonString = (JsonString) pointer.getValue(jsonObject); assertThat(jsonString.getString()).isEqualToIgnoringCase("Data"); }
public JsonObject test() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .test("/topics/2", "Data") .move("/series/2", "/topics/2") .build(); return jsonPatch.apply(jsonObject); }
JsonPatchExample extends JsonExample { public JsonObject test() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .test("/topics/2", "Data") .move("/series/2", "/topics/2") .build(); return jsonPatch.apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject test() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .test("/topics/2", "Data") .move("/series/2", "/topics/2") .build(); return jsonPatch.apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject test() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .test("/topics/2", "Data") .move("/series/2", "/topics/2") .build(); return jsonPatch.apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
JsonPatchExample extends JsonExample { public JsonObject test() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .test("/topics/2", "Data") .move("/series/2", "/topics/2") .build(); return jsonPatch.apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
@Test public void givenPath_copyToTargetPath() throws Exception { JsonPatchExample jsonPatchExample = new JsonPatchExample(); JsonObject jsonObject = jsonPatchExample.copy(); JsonPointer pointer = Json.createPointer("/series/0"); JsonString jsonString = (JsonString) pointer.getValue(jsonObject); assertThat(jsonString.getString()).isEqualToIgnoringCase("Cognitive"); }
public JsonObject copy() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.copy("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); }
JsonPatchExample extends JsonExample { public JsonObject copy() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.copy("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject copy() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.copy("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject copy() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.copy("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
JsonPatchExample extends JsonExample { public JsonObject copy() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.copy("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
@Test public void givenPath_moveToTargetPath() throws Exception { JsonPatchExample jsonPatchExample = new JsonPatchExample(); JsonObject jsonObject = jsonPatchExample.move(); JsonPointer pointer = Json.createPointer("/series/0"); JsonString jsonString = (JsonString) pointer.getValue(jsonObject); assertThat(jsonString.getString()).isEqualToIgnoringCase("Cognitive"); }
public JsonObject move() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.move("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); }
JsonPatchExample extends JsonExample { public JsonObject move() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.move("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject move() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.move("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject move() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.move("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
JsonPatchExample extends JsonExample { public JsonObject move() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.move("/series/0", "/topics/0").build(); return jsonPatch.apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
@Test public void givenListOfBooks_shouldSerialiseToJson() { JsonBindingExample jsonBindingExample = new JsonBindingExample(); String json = jsonBindingExample.serializeListOfBooks(); assertThat(json).isEqualToIgnoringCase(bookListJson); }
public String serializeListOfBooks() { return JsonbBuilder.create().toJson(books); }
JsonBindingExample extends JsonData { public String serializeListOfBooks() { return JsonbBuilder.create().toJson(books); } }
JsonBindingExample extends JsonData { public String serializeListOfBooks() { return JsonbBuilder.create().toJson(books); } }
JsonBindingExample extends JsonData { public String serializeListOfBooks() { return JsonbBuilder.create().toJson(books); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
JsonBindingExample extends JsonData { public String serializeListOfBooks() { return JsonbBuilder.create().toJson(books); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
@Test public void givenPatchPath_shouldRemoveAndAdd() { JsonPatchExample jsonPatchExample = new JsonPatchExample(); JsonObject jsonObject = jsonPatchExample.addAndRemove(); JsonPointer pointer = Json.createPointer("/comments"); JsonValue jsonValue = pointer.getValue(jsonObject); assertThat(jsonValue.getValueType()).isEqualTo(JsonValue.ValueType.ARRAY); assertThat(jsonValue.asJsonArray().contains(Json.createValue("Very Good!"))).isTrue(); assertThat(jsonValue.asJsonArray().contains(Json.createValue("Excellent"))).isTrue(); pointer = Json.createPointer("/notes"); boolean contains = pointer.containsValue(jsonObject); assertThat(contains).isFalse(); }
public JsonObject addAndRemove() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .add("/comments", Json.createArrayBuilder().add("Very Good!").add("Excellent").build()) .remove("/notes") .build(); return jsonPatch.apply(jsonObject); }
JsonPatchExample extends JsonExample { public JsonObject addAndRemove() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .add("/comments", Json.createArrayBuilder().add("Very Good!").add("Excellent").build()) .remove("/notes") .build(); return jsonPatch.apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject addAndRemove() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .add("/comments", Json.createArrayBuilder().add("Very Good!").add("Excellent").build()) .remove("/notes") .build(); return jsonPatch.apply(jsonObject); } }
JsonPatchExample extends JsonExample { public JsonObject addAndRemove() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .add("/comments", Json.createArrayBuilder().add("Very Good!").add("Excellent").build()) .remove("/notes") .build(); return jsonPatch.apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
JsonPatchExample extends JsonExample { public JsonObject addAndRemove() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder .add("/comments", Json.createArrayBuilder().add("Very Good!").add("Excellent").build()) .remove("/notes") .build(); return jsonPatch.apply(jsonObject); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
@Test public void givenPatchPath_shouldReplaceElement() { JsonPatchExample jsonPatchExample = new JsonPatchExample(); String series = jsonPatchExample.replace(); assertThat(series).isEqualToIgnoringCase("Spring 5"); }
public String replace() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.replace("/series/0", "Spring 5").build(); JsonObject newJsonObject = jsonPatch.apply(jsonObject); JsonPointer pointer = Json.createPointer("/series/0"); JsonString jsonValue = (JsonString) pointer.getValue(newJsonObject); return jsonValue.getString(); }
JsonPatchExample extends JsonExample { public String replace() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.replace("/series/0", "Spring 5").build(); JsonObject newJsonObject = jsonPatch.apply(jsonObject); JsonPointer pointer = Json.createPointer("/series/0"); JsonString jsonValue = (JsonString) pointer.getValue(newJsonObject); return jsonValue.getString(); } }
JsonPatchExample extends JsonExample { public String replace() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.replace("/series/0", "Spring 5").build(); JsonObject newJsonObject = jsonPatch.apply(jsonObject); JsonPointer pointer = Json.createPointer("/series/0"); JsonString jsonValue = (JsonString) pointer.getValue(newJsonObject); return jsonValue.getString(); } }
JsonPatchExample extends JsonExample { public String replace() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.replace("/series/0", "Spring 5").build(); JsonObject newJsonObject = jsonPatch.apply(jsonObject); JsonPointer pointer = Json.createPointer("/series/0"); JsonString jsonValue = (JsonString) pointer.getValue(newJsonObject); return jsonValue.getString(); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
JsonPatchExample extends JsonExample { public String replace() { JsonPatchBuilder builder = Json.createPatchBuilder(); JsonPatch jsonPatch = builder.replace("/series/0", "Spring 5").build(); JsonObject newJsonObject = jsonPatch.apply(jsonObject); JsonPointer pointer = Json.createPointer("/series/0"); JsonString jsonValue = (JsonString) pointer.getValue(newJsonObject); return jsonValue.getString(); } String replace(); JsonObject addAndRemove(); JsonObject move(); JsonObject copy(); JsonObject test(); JsonObject toJsonArray(); }
@Test public void givenSourceAndTarget_shouldCreateMergePatch() { JsonMergeDiffExample jsonMergeDiffExample = new JsonMergeDiffExample(); JsonMergePatch mergePatch = jsonMergeDiffExample.createMergePatch(); JsonString jsonString = (JsonString) mergePatch.toJsonValue(); assertThat(jsonString.getString()).isEqualToIgnoringCase("{\"colour\":\"red\"}"); }
public JsonMergePatch createMergePatch(){ JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue target = Json.createValue("{\"colour\":\"red\"}"); JsonMergePatch jsonMergePatch = Json.createMergeDiff(source, target); return jsonMergePatch; }
JsonMergeDiffExample extends JsonExample { public JsonMergePatch createMergePatch(){ JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue target = Json.createValue("{\"colour\":\"red\"}"); JsonMergePatch jsonMergePatch = Json.createMergeDiff(source, target); return jsonMergePatch; } }
JsonMergeDiffExample extends JsonExample { public JsonMergePatch createMergePatch(){ JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue target = Json.createValue("{\"colour\":\"red\"}"); JsonMergePatch jsonMergePatch = Json.createMergeDiff(source, target); return jsonMergePatch; } }
JsonMergeDiffExample extends JsonExample { public JsonMergePatch createMergePatch(){ JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue target = Json.createValue("{\"colour\":\"red\"}"); JsonMergePatch jsonMergePatch = Json.createMergeDiff(source, target); return jsonMergePatch; } JsonMergePatch createMergePatch(); }
JsonMergeDiffExample extends JsonExample { public JsonMergePatch createMergePatch(){ JsonValue source = Json.createValue("{\"colour\":\"blue\"}"); JsonValue target = Json.createValue("{\"colour\":\"red\"}"); JsonMergePatch jsonMergePatch = Json.createMergeDiff(source, target); return jsonMergePatch; } JsonMergePatch createMergePatch(); }
@Test public void givenJsonArray_shouldFilterAllTopicsStartingCToList() throws Exception { Java8Integration java8Integration = new Java8Integration(); List<String> topics = java8Integration.filterJsonArrayToList(); assertThat(topics).contains("Cloud"); assertThat(topics).contains("Cognitive"); }
public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; }
Java8Integration extends JsonExample { public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; } }
Java8Integration extends JsonExample { public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; } }
Java8Integration extends JsonExample { public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; } List<String> filterJsonArrayToList(); JsonArray filterJsonArrayToJsonArray(); }
Java8Integration extends JsonExample { public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; } List<String> filterJsonArrayToList(); JsonArray filterJsonArrayToJsonArray(); }
@Test public void givenJsonArray_shouldFilterAllTopicsStartingCToJsonArray() throws Exception { Java8Integration java8Integration = new Java8Integration(); JsonArray topics = java8Integration.filterJsonArrayToJsonArray(); assertThat(topics.contains(Json.createValue("Cloud"))).isTrue(); assertThat(topics.contains(Json.createValue("Cognitive"))).isTrue(); }
public JsonArray filterJsonArrayToJsonArray() { JsonArray topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .collect(JsonCollectors.toJsonArray()); return topics; }
Java8Integration extends JsonExample { public JsonArray filterJsonArrayToJsonArray() { JsonArray topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .collect(JsonCollectors.toJsonArray()); return topics; } }
Java8Integration extends JsonExample { public JsonArray filterJsonArrayToJsonArray() { JsonArray topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .collect(JsonCollectors.toJsonArray()); return topics; } }
Java8Integration extends JsonExample { public JsonArray filterJsonArrayToJsonArray() { JsonArray topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .collect(JsonCollectors.toJsonArray()); return topics; } List<String> filterJsonArrayToList(); JsonArray filterJsonArrayToJsonArray(); }
Java8Integration extends JsonExample { public JsonArray filterJsonArrayToJsonArray() { JsonArray topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .collect(JsonCollectors.toJsonArray()); return topics; } List<String> filterJsonArrayToList(); JsonArray filterJsonArrayToJsonArray(); }
@Test public void givenListWithConstraints_shouldValidate() { Book book = new Book(); book.addChapterTitle("Chapter 1"); Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book); assertThat(constraintViolations.size()).isEqualTo(0); }
public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); }
Book { public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); } }
Book { public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); } }
Book { public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); } List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter); }
Book { public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); } List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter); }
@Test public void givenListWithConstraints_shouldNotValidate() { Book book = new Book(); book.addChapterTitle(" "); Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book); assertThat(constraintViolations.size()).isEqualTo(1); }
public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); }
Book { public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); } }
Book { public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); } }
Book { public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); } List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter); }
Book { public void addChapterTitle(String chapterTitle) { chapterTitles.add(chapterTitle); } List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter); }
@Test public void givenMapWithConstraints_shouldValidate() { Book book = new Book(); book.addAuthorChapter("Alex","Chapter 1"); book.addAuthorChapter("John","Chapter 2"); book.addAuthorChapter("May","Chapter 3"); Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book); assertThat(constraintViolations.size()).isEqualTo(0); }
public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); }
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); } }
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); } }
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); } List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter); }
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); } List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter); }
@Test public void givenMapWithConstraints_shouldNotValidate() { Book book = new Book(); book.addAuthorChapter(" "," "); Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book); assertThat(constraintViolations.size()).isEqualTo(2); }
public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); }
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); } }
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); } }
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); } List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter); }
Book { public void addAuthorChapter(String author, String chapter) { authorChapter.put(author,chapter); } List<String> getChapterTitles(); void addChapterTitle(String chapterTitle); Map<String, String> getAuthorChapter(); void addAuthorChapter(String author, String chapter); }
@Test public void givenListWithConstraints_shouldValidate() { ClientChoice clientChoice = new ClientChoice(); clientChoice.addChoices(new Choice(1, "Pineapple")); clientChoice.addChoices(new Choice(2, "Banana")); clientChoice.addChoices(new Choice(3, "Apple")); Set<ConstraintViolation<ClientChoice>> constraintViolations = validator.validate(clientChoice); assertThat(constraintViolations.size()).isEqualTo(0); }
public void addChoices(Choice choice) { choices.add(choice); }
ClientChoice { public void addChoices(Choice choice) { choices.add(choice); } }
ClientChoice { public void addChoices(Choice choice) { choices.add(choice); } }
ClientChoice { public void addChoices(Choice choice) { choices.add(choice); } void addChoices(Choice choice); void addClientChoices(String name, List<Choice> choices); List<Choice> getChoices(); Map<String, List<Choice>> getClientChoices(); }
ClientChoice { public void addChoices(Choice choice) { choices.add(choice); } void addChoices(Choice choice); void addClientChoices(String name, List<Choice> choices); List<Choice> getChoices(); Map<String, List<Choice>> getClientChoices(); }
@Test @Ignore public void givenJSON_deserializeToListOfBooks() { JsonBindingExample jsonBindingExample = new JsonBindingExample(); List<Book> actualBooks = jsonBindingExample.deserializeListOfBooks(); assertThat(actualBooks).isEqualTo(books); }
public List<Book> deserializeListOfBooks() { return JsonbBuilder.create().fromJson(bookListJson, new ArrayList<Book>().getClass().getGenericSuperclass()); }
JsonBindingExample extends JsonData { public List<Book> deserializeListOfBooks() { return JsonbBuilder.create().fromJson(bookListJson, new ArrayList<Book>().getClass().getGenericSuperclass()); } }
JsonBindingExample extends JsonData { public List<Book> deserializeListOfBooks() { return JsonbBuilder.create().fromJson(bookListJson, new ArrayList<Book>().getClass().getGenericSuperclass()); } }
JsonBindingExample extends JsonData { public List<Book> deserializeListOfBooks() { return JsonbBuilder.create().fromJson(bookListJson, new ArrayList<Book>().getClass().getGenericSuperclass()); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
JsonBindingExample extends JsonData { public List<Book> deserializeListOfBooks() { return JsonbBuilder.create().fromJson(bookListJson, new ArrayList<Book>().getClass().getGenericSuperclass()); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
@Test public void givenListWithConstraints_shouldNotValidate() { ClientChoice clientChoice = new ClientChoice(); clientChoice.addChoices(new Choice(1, "Fish")); clientChoice.addChoices(new Choice(2, "Egg")); clientChoice.addChoices(new Choice(3, "Apple")); Set<ConstraintViolation<ClientChoice>> constraintViolations = validator.validate(clientChoice); assertThat(constraintViolations.size()).isEqualTo(2); }
public void addChoices(Choice choice) { choices.add(choice); }
ClientChoice { public void addChoices(Choice choice) { choices.add(choice); } }
ClientChoice { public void addChoices(Choice choice) { choices.add(choice); } }
ClientChoice { public void addChoices(Choice choice) { choices.add(choice); } void addChoices(Choice choice); void addClientChoices(String name, List<Choice> choices); List<Choice> getChoices(); Map<String, List<Choice>> getClientChoices(); }
ClientChoice { public void addChoices(Choice choice) { choices.add(choice); } void addChoices(Choice choice); void addClientChoices(String name, List<Choice> choices); List<Choice> getChoices(); Map<String, List<Choice>> getClientChoices(); }
@Test public void givenMapWithConstraints_shouldValidate() { ClientChoice clientChoice = new ClientChoice(); clientChoice.addClientChoices("John", new ArrayList<Choice>() {{ add(new Choice(1, "Roast Lamb")); add(new Choice(1, "Ice Cream")); add(new Choice(1, "Apple")); }}); clientChoice.addClientChoices("May", new ArrayList<Choice>() {{ add(new Choice(1, "Grapes")); add(new Choice(1, "Beef Stake")); add(new Choice(1, "Pizza")); }}); Set<ConstraintViolation<ClientChoice>> constraintViolations = validator.validate(clientChoice); assertThat(constraintViolations.size()).isEqualTo(0); }
public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); }
ClientChoice { public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); } }
ClientChoice { public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); } }
ClientChoice { public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); } void addChoices(Choice choice); void addClientChoices(String name, List<Choice> choices); List<Choice> getChoices(); Map<String, List<Choice>> getClientChoices(); }
ClientChoice { public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); } void addChoices(Choice choice); void addClientChoices(String name, List<Choice> choices); List<Choice> getChoices(); Map<String, List<Choice>> getClientChoices(); }
@Test public void givenMapWithConstraints_shouldNotValidate() { ClientChoice clientChoice = new ClientChoice(); clientChoice.addClientChoices("John", new ArrayList<Choice>() {{ add(new Choice(1, "Fish")); add(new Choice(1, "Egg")); add(new Choice(1, "Apple")); }}); clientChoice.addClientChoices("May", new ArrayList<Choice>() {{ add(new Choice(1, "Grapes")); add(new Choice(1, "Beef Stake")); add(new Choice(1, "Pizza")); }}); Set<ConstraintViolation<ClientChoice>> constraintViolations = validator.validate(clientChoice); assertThat(constraintViolations.size()).isEqualTo(2); }
public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); }
ClientChoice { public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); } }
ClientChoice { public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); } }
ClientChoice { public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); } void addChoices(Choice choice); void addClientChoices(String name, List<Choice> choices); List<Choice> getChoices(); Map<String, List<Choice>> getClientChoices(); }
ClientChoice { public void addClientChoices(String name, List<Choice> choices) { clientChoices.put(name, choices); } void addChoices(Choice choice); void addClientChoices(String name, List<Choice> choices); List<Choice> getChoices(); Map<String, List<Choice>> getClientChoices(); }
@Test public void givenBeanWithValidEmailConstraints_shouldValidate() { Customer customer = new Customer(); customer.setEmail("[email protected]"); Set<ConstraintViolation<Customer>> constraintViolations = validator.validate(customer); assertThat(constraintViolations.size()).isEqualTo(0); }
public void setEmail(String email) { this.email = email; }
Customer { public void setEmail(String email) { this.email = email; } }
Customer { public void setEmail(String email) { this.email = email; } }
Customer { public void setEmail(String email) { this.email = email; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); }
Customer { public void setEmail(String email) { this.email = email; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); }
@Test public void givenBeanWithInvalidEmailConstraints_shouldNotValidate() { Customer customer = new Customer(); customer.setEmail("[email protected]"); Set<ConstraintViolation<Customer>> constraintViolations = validator.validate(customer); assertThat(constraintViolations.size()).isEqualTo(1); }
public void setEmail(String email) { this.email = email; }
Customer { public void setEmail(String email) { this.email = email; } }
Customer { public void setEmail(String email) { this.email = email; } }
Customer { public void setEmail(String email) { this.email = email; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); }
Customer { public void setEmail(String email) { this.email = email; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); }
@Test public void givenBeanWithValidEmailConstraints_shouldValidate() { Person person = new Person(); person.setEmail("[email protected]"); Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person); assertThat(constraintViolations.size()).isEqualTo(0); }
public void setEmail(String email) { this.email = email; }
Person { public void setEmail(String email) { this.email = email; } }
Person { public void setEmail(String email) { this.email = email; } }
Person { public void setEmail(String email) { this.email = email; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); }
Person { public void setEmail(String email) { this.email = email; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); }
@Test public void givenBeanWithInvalidEmailConstraints_shouldNotValidate() { Person person = new Person(); person.setEmail("alex.theedom@example"); Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person); assertThat(constraintViolations.size()).isEqualTo(0); }
public void setEmail(String email) { this.email = email; }
Person { public void setEmail(String email) { this.email = email; } }
Person { public void setEmail(String email) { this.email = email; } }
Person { public void setEmail(String email) { this.email = email; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); }
Person { public void setEmail(String email) { this.email = email; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); }
@Test public void givenBeanWithEmptyElementInCollection_shouldValidate() { Person person = new Person(); person.setCars(new ArrayList<String>() { { add(null); } }); Set<ConstraintViolation<Person>> constraintViolations = validator.validateProperty(person, "cars"); assertThat(constraintViolations.size()).isEqualTo(1); }
public void setCars(List<String> cars) { this.cars = cars; }
Person { public void setCars(List<String> cars) { this.cars = cars; } }
Person { public void setCars(List<String> cars) { this.cars = cars; } }
Person { public void setCars(List<String> cars) { this.cars = cars; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); List<String> getCars(); void setCars(List<String> cars); }
Person { public void setCars(List<String> cars) { this.cars = cars; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); List<String> getCars(); void setCars(List<String> cars); }
@Test public void givenBeanWithValidDomain_shouldValidate() { RepeatedConstraint repeatedConstraint = new RepeatedConstraint(); repeatedConstraint.setText("www.readlearncode.com"); Set<ConstraintViolation<RepeatedConstraint>> constraintViolations = validator.validate(repeatedConstraint); assertThat(constraintViolations.size()).isEqualTo(0); }
public void setText(String text) { this.text = text; }
RepeatedConstraint { public void setText(String text) { this.text = text; } }
RepeatedConstraint { public void setText(String text) { this.text = text; } }
RepeatedConstraint { public void setText(String text) { this.text = text; } String getText(); void setText(String text); }
RepeatedConstraint { public void setText(String text) { this.text = text; } String getText(); void setText(String text); }
@Test public void givenBeanWithInValidDomain_shouldNotValidate() { RepeatedConstraint repeatedConstraint = new RepeatedConstraint(); repeatedConstraint.setText("www.readlearncode.net"); Set<ConstraintViolation<RepeatedConstraint>> constraintViolations = validator.validate(repeatedConstraint); assertThat(constraintViolations.size()).isEqualTo(1); }
public void setText(String text) { this.text = text; }
RepeatedConstraint { public void setText(String text) { this.text = text; } }
RepeatedConstraint { public void setText(String text) { this.text = text; } }
RepeatedConstraint { public void setText(String text) { this.text = text; } String getText(); void setText(String text); }
RepeatedConstraint { public void setText(String text) { this.text = text; } String getText(); void setText(String text); }
@Test public void givenArrayOfBooks_shouldSerialiseToJson() { JsonBindingExample jsonBindingExample = new JsonBindingExample(); String json = jsonBindingExample.serializeArrayOfBooks(); assertThat(json).isEqualToIgnoringCase(bookListJson); }
public String serializeArrayOfBooks() { return JsonbBuilder.create().toJson(arrayBooks); }
JsonBindingExample extends JsonData { public String serializeArrayOfBooks() { return JsonbBuilder.create().toJson(arrayBooks); } }
JsonBindingExample extends JsonData { public String serializeArrayOfBooks() { return JsonbBuilder.create().toJson(arrayBooks); } }
JsonBindingExample extends JsonData { public String serializeArrayOfBooks() { return JsonbBuilder.create().toJson(arrayBooks); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
JsonBindingExample extends JsonData { public String serializeArrayOfBooks() { return JsonbBuilder.create().toJson(arrayBooks); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
@Test public void givenBeanWithOptionalStringExample_shouldNotValidate() { OptionalExample optionalExample = new OptionalExample(); optionalExample.setText(" "); Set<ConstraintViolation<OptionalExample>> constraintViolations = validator.validate(optionalExample); assertThat(constraintViolations.size()).isEqualTo(2); }
public void setText(String text) { this.text = Optional.of(text); }
OptionalExample { public void setText(String text) { this.text = Optional.of(text); } }
OptionalExample { public void setText(String text) { this.text = Optional.of(text); } }
OptionalExample { public void setText(String text) { this.text = Optional.of(text); } Optional<String> getName(); void setName(String name); Optional<String> getText(); void setText(String text); }
OptionalExample { public void setText(String text) { this.text = Optional.of(text); } Optional<String> getName(); void setName(String name); Optional<String> getText(); void setText(String text); }
@Test public void givenBeanWithEmptyElementInCollection_shouldNotValidate() { Person person = new Person(); person.setCars(new ArrayList<String>() { { add(null); } }); Set<ConstraintViolation<Person>> constraintViolations = validator.validateProperty(person, "cars"); assertThat(constraintViolations.size()).isEqualTo(1); }
public void setCars(List<String> cars) { this.cars = cars; }
Person { public void setCars(List<String> cars) { this.cars = cars; } }
Person { public void setCars(List<String> cars) { this.cars = cars; } }
Person { public void setCars(List<String> cars) { this.cars = cars; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); List<String> getCars(); void setCars(List<String> cars); }
Person { public void setCars(List<String> cars) { this.cars = cars; } String getFirstName(); void setFirstName(String firstName); String getSecondName(); void setSecondName(String secondName); String getEmail(); void setEmail(String email); List<String> getCars(); void setCars(List<String> cars); }
@Test public void givenArrayOfStrings_shouldSerialiseToJson() { JsonBindingExample jsonBindingExample = new JsonBindingExample(); String json = jsonBindingExample.serializeArrayOfStrings(); assertThat(json).isEqualToIgnoringCase("[\"Java EE\",\"Java SE\"]"); }
public String serializeArrayOfStrings() { return JsonbBuilder.create().toJson(new String[]{"Java EE", "Java SE"}); }
JsonBindingExample extends JsonData { public String serializeArrayOfStrings() { return JsonbBuilder.create().toJson(new String[]{"Java EE", "Java SE"}); } }
JsonBindingExample extends JsonData { public String serializeArrayOfStrings() { return JsonbBuilder.create().toJson(new String[]{"Java EE", "Java SE"}); } }
JsonBindingExample extends JsonData { public String serializeArrayOfStrings() { return JsonbBuilder.create().toJson(new String[]{"Java EE", "Java SE"}); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
JsonBindingExample extends JsonData { public String serializeArrayOfStrings() { return JsonbBuilder.create().toJson(new String[]{"Java EE", "Java SE"}); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
@Test public void givenCustomisationOnProperties_shouldProduceJSON() { JsonBindingExample jsonBindingExample = new JsonBindingExample(); String result = jsonBindingExample.customizedMapping(); assertThat(result).isEqualToIgnoringCase(customisedJson); }
public String customizedMapping() { JsonbConfig jsonbConfig = new JsonbConfig() .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES) .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL) .withStrictIJSON(true) .withFormatting(true) .withNullValues(true); Jsonb jsonb = JsonbBuilder.create(jsonbConfig); return jsonb.toJson(book1); }
JsonBindingExample extends JsonData { public String customizedMapping() { JsonbConfig jsonbConfig = new JsonbConfig() .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES) .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL) .withStrictIJSON(true) .withFormatting(true) .withNullValues(true); Jsonb jsonb = JsonbBuilder.create(jsonbConfig); return jsonb.toJson(book1); } }
JsonBindingExample extends JsonData { public String customizedMapping() { JsonbConfig jsonbConfig = new JsonbConfig() .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES) .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL) .withStrictIJSON(true) .withFormatting(true) .withNullValues(true); Jsonb jsonb = JsonbBuilder.create(jsonbConfig); return jsonb.toJson(book1); } }
JsonBindingExample extends JsonData { public String customizedMapping() { JsonbConfig jsonbConfig = new JsonbConfig() .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES) .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL) .withStrictIJSON(true) .withFormatting(true) .withNullValues(true); Jsonb jsonb = JsonbBuilder.create(jsonbConfig); return jsonb.toJson(book1); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
JsonBindingExample extends JsonData { public String customizedMapping() { JsonbConfig jsonbConfig = new JsonbConfig() .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES) .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL) .withStrictIJSON(true) .withFormatting(true) .withNullValues(true); Jsonb jsonb = JsonbBuilder.create(jsonbConfig); return jsonb.toJson(book1); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
@Test public void givenCustomisationOnMethods_shouldProduceJSON() { JsonBindingExample jsonBindingExample = new JsonBindingExample(); String result = jsonBindingExample.annotationMethodMapping(); assertThat(result).isEqualToIgnoringCase(customisedJsonNewspaper); }
public String annotationMethodMapping() { return JsonbBuilder.create().toJson(newspaper); }
JsonBindingExample extends JsonData { public String annotationMethodMapping() { return JsonbBuilder.create().toJson(newspaper); } }
JsonBindingExample extends JsonData { public String annotationMethodMapping() { return JsonbBuilder.create().toJson(newspaper); } }
JsonBindingExample extends JsonData { public String annotationMethodMapping() { return JsonbBuilder.create().toJson(newspaper); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
JsonBindingExample extends JsonData { public String annotationMethodMapping() { return JsonbBuilder.create().toJson(newspaper); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
@Test public void givenCustomisationOnPropertiesAndMethods_shouldProduceJSON() { JsonBindingExample jsonBindingExample = new JsonBindingExample(); String result = jsonBindingExample.annotationPropertyAndMethodMapping(); assertThat(result).isEqualToIgnoringCase("{\"cost\":\"10.00\",\"author\":{\"firstName\":\"Alex\",\"lastName\":\"Theedom\"}}"); }
public String annotationPropertyAndMethodMapping() { return JsonbBuilder.create().toJson(booklet); }
JsonBindingExample extends JsonData { public String annotationPropertyAndMethodMapping() { return JsonbBuilder.create().toJson(booklet); } }
JsonBindingExample extends JsonData { public String annotationPropertyAndMethodMapping() { return JsonbBuilder.create().toJson(booklet); } }
JsonBindingExample extends JsonData { public String annotationPropertyAndMethodMapping() { return JsonbBuilder.create().toJson(booklet); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
JsonBindingExample extends JsonData { public String annotationPropertyAndMethodMapping() { return JsonbBuilder.create().toJson(booklet); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
@Test public void givenAnnotationPojo_shouldProduceJson() { JsonBindingExample jsonBindingExample = new JsonBindingExample(); String result = jsonBindingExample.annotationPropertiesMapping(); assertThat(result).isEqualToIgnoringCase(expectedMagazine); }
public String annotationPropertiesMapping() { return JsonbBuilder.create().toJson(magazine); }
JsonBindingExample extends JsonData { public String annotationPropertiesMapping() { return JsonbBuilder.create().toJson(magazine); } }
JsonBindingExample extends JsonData { public String annotationPropertiesMapping() { return JsonbBuilder.create().toJson(magazine); } }
JsonBindingExample extends JsonData { public String annotationPropertiesMapping() { return JsonbBuilder.create().toJson(magazine); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
JsonBindingExample extends JsonData { public String annotationPropertiesMapping() { return JsonbBuilder.create().toJson(magazine); } String serializeBook(); Book deserializeBook(); String serializeListOfBooks(); List<Book> deserializeListOfBooks(); String serializeArrayOfBooks(); String serializeArrayOfStrings(); String customizedMapping(); String annotationPropertiesMapping(); String annotationMethodMapping(); String annotationPropertyAndMethodMapping(); String bookAdapterToJson(); Book bookAdapterToBook(); void usingAProvider(); String allCustomizedMapping(); }
@Test public void clearAuthentication_ShouldRemoveAuthenticationFromSecurityContext() { Authentication authentication = createAuthentication(); SecurityContextHolder.getContext().setAuthentication(authentication); AuthenticationUtil.clearAuthentication(); Authentication currentAuthentication = SecurityContextHolder.getContext().getAuthentication(); assertThat(currentAuthentication).isNull(); }
public static void clearAuthentication() { SecurityContextHolder.getContext().setAuthentication(null); }
AuthenticationUtil { public static void clearAuthentication() { SecurityContextHolder.getContext().setAuthentication(null); } }
AuthenticationUtil { public static void clearAuthentication() { SecurityContextHolder.getContext().setAuthentication(null); } private AuthenticationUtil(); }
AuthenticationUtil { public static void clearAuthentication() { SecurityContextHolder.getContext().setAuthentication(null); } private AuthenticationUtil(); static void clearAuthentication(); static void configureAuthentication(String role); }
AuthenticationUtil { public static void clearAuthentication() { SecurityContextHolder.getContext().setAuthentication(null); } private AuthenticationUtil(); static void clearAuthentication(); static void configureAuthentication(String role); }
@Test public void configurationAuthentication_ShouldSetAuthenticationToSecurityContext() { AuthenticationUtil.configureAuthentication(ROLE); Authentication currentAuthentication = SecurityContextHolder.getContext().getAuthentication(); assertThat(currentAuthentication.getAuthorities()).hasSize(1); assertThat(currentAuthentication.getAuthorities().iterator().next().getAuthority()).isEqualTo(ROLE); User principal = (User) currentAuthentication.getPrincipal(); assertThat(principal.getAuthorities()).hasSize(1); assertThat(principal.getAuthorities().iterator().next().getAuthority()).isEqualTo(ROLE); }
public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); }
AuthenticationUtil { public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); } }
AuthenticationUtil { public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); } private AuthenticationUtil(); }
AuthenticationUtil { public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); } private AuthenticationUtil(); static void clearAuthentication(); static void configureAuthentication(String role); }
AuthenticationUtil { public static void configureAuthentication(String role) { Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(role); Authentication authentication = new UsernamePasswordAuthenticationToken( USERNAME, role, authorities ); SecurityContextHolder.getContext().setAuthentication(authentication); } private AuthenticationUtil(); static void clearAuthentication(); static void configureAuthentication(String role); }
@Test public void getFactory_extensionsLoaded() throws Exception { SerializerFactory factory = SerializerFactoryLoader.getFactory(mockProcessingEnvironment); Serializer actualSerializer = factory.getSerializer(typeMirrorOf(String.class)); assertThat(actualSerializer.getClass().getName()) .contains("TestStringSerializerFactory$TestStringSerializer"); }
public static SerializerFactory getFactory(ProcessingEnvironment processingEnv) { return new SerializerFactoryImpl(loadExtensions(processingEnv), processingEnv); }
SerializerFactoryLoader { public static SerializerFactory getFactory(ProcessingEnvironment processingEnv) { return new SerializerFactoryImpl(loadExtensions(processingEnv), processingEnv); } }
SerializerFactoryLoader { public static SerializerFactory getFactory(ProcessingEnvironment processingEnv) { return new SerializerFactoryImpl(loadExtensions(processingEnv), processingEnv); } private SerializerFactoryLoader(); }
SerializerFactoryLoader { public static SerializerFactory getFactory(ProcessingEnvironment processingEnv) { return new SerializerFactoryImpl(loadExtensions(processingEnv), processingEnv); } private SerializerFactoryLoader(); static SerializerFactory getFactory(ProcessingEnvironment processingEnv); }
SerializerFactoryLoader { public static SerializerFactory getFactory(ProcessingEnvironment processingEnv) { return new SerializerFactoryImpl(loadExtensions(processingEnv), processingEnv); } private SerializerFactoryLoader(); static SerializerFactory getFactory(ProcessingEnvironment processingEnv); }
@Test public void getTypeMirrors() { TypeMirror insideClassA = getTypeElement(InsideClassA.class).asType(); TypeMirror insideClassB = getTypeElement(InsideClassB.class).asType(); AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "classValues"); ImmutableList<DeclaredType> valueElements = AnnotationValues.getTypeMirrors(value); assertThat(valueElements) .comparingElementsUsing(Correspondence.from(types::isSameType, "has Same Type")) .containsExactly(insideClassA, insideClassB) .inOrder(); }
public static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value) { return TYPE_MIRRORS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value) { return TYPE_MIRRORS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value) { return TYPE_MIRRORS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value) { return TYPE_MIRRORS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value) { return TYPE_MIRRORS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getAnnotationMirror() { TypeElement insideAnnotation = getTypeElement(InsideAnnotation.class); AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "insideAnnotationValue"); AnnotationMirror annotationMirror = AnnotationValues.getAnnotationMirror(value); assertThat(annotationMirror.getAnnotationType().asElement()).isEqualTo(insideAnnotation); assertThat(AnnotationMirrors.getAnnotationValue(annotationMirror, "value").getValue()) .isEqualTo(19); }
public static AnnotationMirror getAnnotationMirror(AnnotationValue value) { return AnnotationMirrorVisitor.INSTANCE.visit(value); }
AnnotationValues { public static AnnotationMirror getAnnotationMirror(AnnotationValue value) { return AnnotationMirrorVisitor.INSTANCE.visit(value); } }
AnnotationValues { public static AnnotationMirror getAnnotationMirror(AnnotationValue value) { return AnnotationMirrorVisitor.INSTANCE.visit(value); } private AnnotationValues(); }
AnnotationValues { public static AnnotationMirror getAnnotationMirror(AnnotationValue value) { return AnnotationMirrorVisitor.INSTANCE.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static AnnotationMirror getAnnotationMirror(AnnotationValue value) { return AnnotationMirrorVisitor.INSTANCE.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getAnnotationMirrors() { TypeElement insideAnnotation = getTypeElement(InsideAnnotation.class); AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "insideAnnotationValues"); ImmutableList<AnnotationMirror> annotationMirrors = AnnotationValues.getAnnotationMirrors(value); ImmutableList<Element> valueElements = annotationMirrors.stream() .map(AnnotationMirror::getAnnotationType) .map(DeclaredType::asElement) .collect(toImmutableList()); assertThat(valueElements).containsExactly(insideAnnotation, insideAnnotation); ImmutableList<Object> valuesStoredInAnnotation = annotationMirrors.stream() .map( annotationMirror -> AnnotationMirrors.getAnnotationValue(annotationMirror, "value").getValue()) .collect(toImmutableList()); assertThat(valuesStoredInAnnotation).containsExactly(20, 21).inOrder(); }
public static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value) { return ANNOTATION_MIRRORS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value) { return ANNOTATION_MIRRORS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value) { return ANNOTATION_MIRRORS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value) { return ANNOTATION_MIRRORS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value) { return ANNOTATION_MIRRORS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getString() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "stringValue"); assertThat(AnnotationValues.getString(value)).isEqualTo("hello"); }
public static String getString(AnnotationValue value) { return valueOfType(value, String.class); }
AnnotationValues { public static String getString(AnnotationValue value) { return valueOfType(value, String.class); } }
AnnotationValues { public static String getString(AnnotationValue value) { return valueOfType(value, String.class); } private AnnotationValues(); }
AnnotationValues { public static String getString(AnnotationValue value) { return valueOfType(value, String.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static String getString(AnnotationValue value) { return valueOfType(value, String.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getStrings() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "stringValues"); assertThat(AnnotationValues.getStrings(value)).containsExactly("it's", "me").inOrder(); }
public static ImmutableList<String> getStrings(AnnotationValue value) { return STRINGS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<String> getStrings(AnnotationValue value) { return STRINGS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<String> getStrings(AnnotationValue value) { return STRINGS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<String> getStrings(AnnotationValue value) { return STRINGS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<String> getStrings(AnnotationValue value) { return STRINGS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getEnum() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "enumValue"); assertThat(AnnotationValues.getEnum(value)).isEqualTo(value.getValue()); }
public static VariableElement getEnum(AnnotationValue value) { return EnumVisitor.INSTANCE.visit(value); }
AnnotationValues { public static VariableElement getEnum(AnnotationValue value) { return EnumVisitor.INSTANCE.visit(value); } }
AnnotationValues { public static VariableElement getEnum(AnnotationValue value) { return EnumVisitor.INSTANCE.visit(value); } private AnnotationValues(); }
AnnotationValues { public static VariableElement getEnum(AnnotationValue value) { return EnumVisitor.INSTANCE.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static VariableElement getEnum(AnnotationValue value) { return EnumVisitor.INSTANCE.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getEnums() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "enumValues"); assertThat(getEnumNames(AnnotationValues.getEnums(value))) .containsExactly(Foo.BAZ.name(), Foo.BAH.name()) .inOrder(); }
public static ImmutableList<VariableElement> getEnums(AnnotationValue value) { return ENUMS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<VariableElement> getEnums(AnnotationValue value) { return ENUMS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<VariableElement> getEnums(AnnotationValue value) { return ENUMS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<VariableElement> getEnums(AnnotationValue value) { return ENUMS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<VariableElement> getEnums(AnnotationValue value) { return ENUMS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getAnnotationValues() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "intValues"); ImmutableList<AnnotationValue> values = AnnotationValues.getAnnotationValues(value); assertThat(values) .comparingElementsUsing(Correspondence.transforming(AnnotationValue::getValue, "has value")) .containsExactly(1, 2) .inOrder(); }
public static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value) { return ANNOTATION_VALUES_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value) { return ANNOTATION_VALUES_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value) { return ANNOTATION_VALUES_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value) { return ANNOTATION_VALUES_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value) { return ANNOTATION_VALUES_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getInt() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "intValue"); assertThat(AnnotationValues.getInt(value)).isEqualTo(5); }
public static int getInt(AnnotationValue value) { return valueOfType(value, Integer.class); }
AnnotationValues { public static int getInt(AnnotationValue value) { return valueOfType(value, Integer.class); } }
AnnotationValues { public static int getInt(AnnotationValue value) { return valueOfType(value, Integer.class); } private AnnotationValues(); }
AnnotationValues { public static int getInt(AnnotationValue value) { return valueOfType(value, Integer.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static int getInt(AnnotationValue value) { return valueOfType(value, Integer.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getInts() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "intValues"); assertThat(AnnotationValues.getInts(value)).containsExactly(1, 2).inOrder(); }
public static ImmutableList<Integer> getInts(AnnotationValue value) { return INTS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<Integer> getInts(AnnotationValue value) { return INTS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<Integer> getInts(AnnotationValue value) { return INTS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<Integer> getInts(AnnotationValue value) { return INTS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<Integer> getInts(AnnotationValue value) { return INTS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void toProxy() { TypeMirror typeMirror = declaredTypeOf(Optional.class, Integer.class); Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get(); CodeBlock actualCodeBlock = serializer.toProxy(CodeBlock.of("x")); assertThat(actualCodeBlock.toString()).isEqualTo("x.isPresent() ? x.get() : null"); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); }
OptionalSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); } }
OptionalSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); } OptionalSerializerExtension(); }
OptionalSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); } OptionalSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
OptionalSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); } OptionalSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void getLong() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "longValue"); assertThat(AnnotationValues.getLong(value)).isEqualTo(6L); }
public static long getLong(AnnotationValue value) { return valueOfType(value, Long.class); }
AnnotationValues { public static long getLong(AnnotationValue value) { return valueOfType(value, Long.class); } }
AnnotationValues { public static long getLong(AnnotationValue value) { return valueOfType(value, Long.class); } private AnnotationValues(); }
AnnotationValues { public static long getLong(AnnotationValue value) { return valueOfType(value, Long.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static long getLong(AnnotationValue value) { return valueOfType(value, Long.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getLongs() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "longValues"); assertThat(AnnotationValues.getLongs(value)).containsExactly(3L, 4L).inOrder(); }
public static ImmutableList<Long> getLongs(AnnotationValue value) { return LONGS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<Long> getLongs(AnnotationValue value) { return LONGS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<Long> getLongs(AnnotationValue value) { return LONGS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<Long> getLongs(AnnotationValue value) { return LONGS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<Long> getLongs(AnnotationValue value) { return LONGS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getByte() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "byteValue"); assertThat(AnnotationValues.getByte(value)).isEqualTo((byte) 7); }
public static byte getByte(AnnotationValue value) { return valueOfType(value, Byte.class); }
AnnotationValues { public static byte getByte(AnnotationValue value) { return valueOfType(value, Byte.class); } }
AnnotationValues { public static byte getByte(AnnotationValue value) { return valueOfType(value, Byte.class); } private AnnotationValues(); }
AnnotationValues { public static byte getByte(AnnotationValue value) { return valueOfType(value, Byte.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static byte getByte(AnnotationValue value) { return valueOfType(value, Byte.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getBytes() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "byteValues"); assertThat(AnnotationValues.getBytes(value)).containsExactly((byte) 8, (byte) 9).inOrder(); }
public static ImmutableList<Byte> getBytes(AnnotationValue value) { return BYTES_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<Byte> getBytes(AnnotationValue value) { return BYTES_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<Byte> getBytes(AnnotationValue value) { return BYTES_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<Byte> getBytes(AnnotationValue value) { return BYTES_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<Byte> getBytes(AnnotationValue value) { return BYTES_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getShort() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "shortValue"); assertThat(AnnotationValues.getShort(value)).isEqualTo((short) 10); }
public static short getShort(AnnotationValue value) { return valueOfType(value, Short.class); }
AnnotationValues { public static short getShort(AnnotationValue value) { return valueOfType(value, Short.class); } }
AnnotationValues { public static short getShort(AnnotationValue value) { return valueOfType(value, Short.class); } private AnnotationValues(); }
AnnotationValues { public static short getShort(AnnotationValue value) { return valueOfType(value, Short.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static short getShort(AnnotationValue value) { return valueOfType(value, Short.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getShorts() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "shortValues"); assertThat(AnnotationValues.getShorts(value)).containsExactly((short) 11, (short) 12).inOrder(); }
public static ImmutableList<Short> getShorts(AnnotationValue value) { return SHORTS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<Short> getShorts(AnnotationValue value) { return SHORTS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<Short> getShorts(AnnotationValue value) { return SHORTS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<Short> getShorts(AnnotationValue value) { return SHORTS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<Short> getShorts(AnnotationValue value) { return SHORTS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getFloat() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "floatValue"); assertThat(AnnotationValues.getFloat(value)).isEqualTo(13F); }
public static float getFloat(AnnotationValue value) { return valueOfType(value, Float.class); }
AnnotationValues { public static float getFloat(AnnotationValue value) { return valueOfType(value, Float.class); } }
AnnotationValues { public static float getFloat(AnnotationValue value) { return valueOfType(value, Float.class); } private AnnotationValues(); }
AnnotationValues { public static float getFloat(AnnotationValue value) { return valueOfType(value, Float.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static float getFloat(AnnotationValue value) { return valueOfType(value, Float.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getFloats() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "floatValues"); assertThat(AnnotationValues.getFloats(value)).containsExactly(14F, 15F).inOrder(); }
public static ImmutableList<Float> getFloats(AnnotationValue value) { return FLOATS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<Float> getFloats(AnnotationValue value) { return FLOATS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<Float> getFloats(AnnotationValue value) { return FLOATS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<Float> getFloats(AnnotationValue value) { return FLOATS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<Float> getFloats(AnnotationValue value) { return FLOATS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getDouble() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "doubleValue"); assertThat(AnnotationValues.getDouble(value)).isEqualTo(16D); }
public static double getDouble(AnnotationValue value) { return valueOfType(value, Double.class); }
AnnotationValues { public static double getDouble(AnnotationValue value) { return valueOfType(value, Double.class); } }
AnnotationValues { public static double getDouble(AnnotationValue value) { return valueOfType(value, Double.class); } private AnnotationValues(); }
AnnotationValues { public static double getDouble(AnnotationValue value) { return valueOfType(value, Double.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static double getDouble(AnnotationValue value) { return valueOfType(value, Double.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getDoubles() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "doubleValues"); assertThat(AnnotationValues.getDoubles(value)).containsExactly(17D, 18D).inOrder(); }
public static ImmutableList<Double> getDoubles(AnnotationValue value) { return DOUBLES_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<Double> getDoubles(AnnotationValue value) { return DOUBLES_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<Double> getDoubles(AnnotationValue value) { return DOUBLES_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<Double> getDoubles(AnnotationValue value) { return DOUBLES_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<Double> getDoubles(AnnotationValue value) { return DOUBLES_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void fromProxy() { TypeMirror typeMirror = declaredTypeOf(Optional.class, Integer.class); Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get(); CodeBlock actualCodeBlock = serializer.fromProxy(CodeBlock.of("x")); assertThat(actualCodeBlock.toString()) .isEqualTo("java.util.Optional.ofNullable(x == null ? null : x)"); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); }
OptionalSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); } }
OptionalSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); } OptionalSerializerExtension(); }
OptionalSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); } OptionalSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
OptionalSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isOptional(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); return Optional.of(new OptionalSerializer(containedTypeSerializer)); } OptionalSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void getBoolean() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "booleanValue"); assertThat(AnnotationValues.getBoolean(value)).isTrue(); }
public static boolean getBoolean(AnnotationValue value) { return valueOfType(value, Boolean.class); }
AnnotationValues { public static boolean getBoolean(AnnotationValue value) { return valueOfType(value, Boolean.class); } }
AnnotationValues { public static boolean getBoolean(AnnotationValue value) { return valueOfType(value, Boolean.class); } private AnnotationValues(); }
AnnotationValues { public static boolean getBoolean(AnnotationValue value) { return valueOfType(value, Boolean.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static boolean getBoolean(AnnotationValue value) { return valueOfType(value, Boolean.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getBooleans() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "booleanValues"); assertThat(AnnotationValues.getBooleans(value)).containsExactly(true, false).inOrder(); }
public static ImmutableList<Boolean> getBooleans(AnnotationValue value) { return BOOLEANS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<Boolean> getBooleans(AnnotationValue value) { return BOOLEANS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<Boolean> getBooleans(AnnotationValue value) { return BOOLEANS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<Boolean> getBooleans(AnnotationValue value) { return BOOLEANS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<Boolean> getBooleans(AnnotationValue value) { return BOOLEANS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getChar() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "charValue"); assertThat(AnnotationValues.getChar(value)).isEqualTo('a'); }
public static char getChar(AnnotationValue value) { return valueOfType(value, Character.class); }
AnnotationValues { public static char getChar(AnnotationValue value) { return valueOfType(value, Character.class); } }
AnnotationValues { public static char getChar(AnnotationValue value) { return valueOfType(value, Character.class); } private AnnotationValues(); }
AnnotationValues { public static char getChar(AnnotationValue value) { return valueOfType(value, Character.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static char getChar(AnnotationValue value) { return valueOfType(value, Character.class); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getChars() { AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "charValues"); assertThat(AnnotationValues.getChars(value)).containsExactly('b', 'c').inOrder(); }
public static ImmutableList<Character> getChars(AnnotationValue value) { return CHARS_VISITOR.visit(value); }
AnnotationValues { public static ImmutableList<Character> getChars(AnnotationValue value) { return CHARS_VISITOR.visit(value); } }
AnnotationValues { public static ImmutableList<Character> getChars(AnnotationValue value) { return CHARS_VISITOR.visit(value); } private AnnotationValues(); }
AnnotationValues { public static ImmutableList<Character> getChars(AnnotationValue value) { return CHARS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
AnnotationValues { public static ImmutableList<Character> getChars(AnnotationValue value) { return CHARS_VISITOR.visit(value); } private AnnotationValues(); static Equivalence<AnnotationValue> equivalence(); static DeclaredType getTypeMirror(AnnotationValue value); static AnnotationMirror getAnnotationMirror(AnnotationValue value); static VariableElement getEnum(AnnotationValue value); static String getString(AnnotationValue value); static int getInt(AnnotationValue value); static long getLong(AnnotationValue value); static byte getByte(AnnotationValue value); static short getShort(AnnotationValue value); static float getFloat(AnnotationValue value); static double getDouble(AnnotationValue value); static boolean getBoolean(AnnotationValue value); static char getChar(AnnotationValue value); static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value); static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value); static ImmutableList<VariableElement> getEnums(AnnotationValue value); static ImmutableList<String> getStrings(AnnotationValue value); static ImmutableList<Integer> getInts(AnnotationValue value); static ImmutableList<Long> getLongs(AnnotationValue value); static ImmutableList<Byte> getBytes(AnnotationValue value); static ImmutableList<Short> getShorts(AnnotationValue value); static ImmutableList<Float> getFloats(AnnotationValue value); static ImmutableList<Double> getDoubles(AnnotationValue value); static ImmutableList<Boolean> getBooleans(AnnotationValue value); static ImmutableList<Character> getChars(AnnotationValue value); static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value); }
@Test public void getSerializer_emptyFactories_identitySerializerReturned() throws Exception { SerializerFactoryImpl factory = new SerializerFactoryImpl(ImmutableList.of(), mockProcessingEnvironment); Serializer actualSerializer = factory.getSerializer(typeMirrorOf(String.class)); assertThat(actualSerializer.getClass().getName()) .contains("IdentitySerializerFactory$IdentitySerializer"); }
@Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); }
SerializerFactoryImpl implements SerializerFactory { @Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); } }
SerializerFactoryImpl implements SerializerFactory { @Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); } SerializerFactoryImpl( ImmutableList<SerializerExtension> extensions, ProcessingEnvironment env); }
SerializerFactoryImpl implements SerializerFactory { @Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); } SerializerFactoryImpl( ImmutableList<SerializerExtension> extensions, ProcessingEnvironment env); @Override Serializer getSerializer(TypeMirror typeMirror); }
SerializerFactoryImpl implements SerializerFactory { @Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); } SerializerFactoryImpl( ImmutableList<SerializerExtension> extensions, ProcessingEnvironment env); @Override Serializer getSerializer(TypeMirror typeMirror); }
@Test public void getSerializer_factoriesProvided_factoryReturned() throws Exception { SerializerFactoryImpl factory = new SerializerFactoryImpl( ImmutableList.of(new TestStringSerializerFactory()), mockProcessingEnvironment); Serializer actualSerializer = factory.getSerializer(typeMirrorOf(String.class)); assertThat(actualSerializer.getClass().getName()) .contains("TestStringSerializerFactory$TestStringSerializer"); }
@Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); }
SerializerFactoryImpl implements SerializerFactory { @Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); } }
SerializerFactoryImpl implements SerializerFactory { @Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); } SerializerFactoryImpl( ImmutableList<SerializerExtension> extensions, ProcessingEnvironment env); }
SerializerFactoryImpl implements SerializerFactory { @Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); } SerializerFactoryImpl( ImmutableList<SerializerExtension> extensions, ProcessingEnvironment env); @Override Serializer getSerializer(TypeMirror typeMirror); }
SerializerFactoryImpl implements SerializerFactory { @Override public Serializer getSerializer(TypeMirror typeMirror) { for (SerializerExtension extension : extensions) { Optional<Serializer> serializer = extension.getSerializer(typeMirror, this, env); if (serializer.isPresent()) { return serializer.get(); } } return IdentitySerializerFactory.getSerializer(typeMirror); } SerializerFactoryImpl( ImmutableList<SerializerExtension> extensions, ProcessingEnvironment env); @Override Serializer getSerializer(TypeMirror typeMirror); }
@Test public void getSerializer_nonImmutableMap_emptyReturned() { TypeMirror typeMirror = typeMirrorOf(String.class); Optional<Serializer> actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment); assertThat(actualSerializer).isEmpty(); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void getSerializer_immutableMapWithSerializableContainedTypes_emptyReturned() { fakeSerializerFactory.setReturnIdentitySerializer(true); TypeMirror typeMirror = typeMirrorOf(ImmutableMap.class); Optional<Serializer> actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment); assertThat(actualSerializer).isEmpty(); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void getSerializer_immutableMap_serializerReturned() { TypeMirror typeMirror = typeMirrorOf(ImmutableMap.class); Serializer actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get(); assertThat(actualSerializer.getClass().getName()) .contains("ImmutableMapSerializerExtension$ImmutableMapSerializer"); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void proxyFieldType() { TypeMirror typeMirror = declaredTypeOf(ImmutableMap.class, Integer.class, String.class); Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get(); TypeMirror actualTypeMirror = serializer.proxyFieldType(); assertThat(typeUtils.isSameType(actualTypeMirror, typeMirror)).isTrue(); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void toProxy() { TypeMirror typeMirror = declaredTypeOf(ImmutableMap.class, Integer.class, String.class); Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get(); CodeBlock actualCodeBlock = serializer.toProxy(CodeBlock.of("x")); assertThat(actualCodeBlock.toString()) .isEqualTo( String.format( "x.entrySet().stream().collect(%s.toImmutableMap(value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getKey()), value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getValue())))", IMMUTABLE_MAP, FUNCTION_WITH_EXCEPTIONS, INTEGER, INTEGER, FUNCTION_WITH_EXCEPTIONS, STRING, STRING)); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void fromProxy() { TypeMirror typeMirror = declaredTypeOf(ImmutableMap.class, Integer.class, String.class); Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get(); CodeBlock actualCodeBlock = serializer.fromProxy(CodeBlock.of("x")); assertThat(actualCodeBlock.toString()) .isEqualTo( String.format( "x.entrySet().stream().collect(%s.toImmutableMap(value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getKey()), value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getValue())))", IMMUTABLE_MAP, FUNCTION_WITH_EXCEPTIONS, INTEGER, INTEGER, FUNCTION_WITH_EXCEPTIONS, STRING, STRING)); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void getSerializer_nonImmutableList_emptyReturned() { TypeMirror typeMirror = typeMirrorOf(String.class); Optional<Serializer> actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment); assertThat(actualSerializer).isEmpty(); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void proxyFieldType_isUnchanged() throws Exception { TypeMirror typeMirror = typeMirrorOf(String.class); TypeMirror actualTypeMirror = IdentitySerializerFactory.getSerializer(typeMirror).proxyFieldType(); assertThat(actualTypeMirror).isSameInstanceAs(typeMirror); }
public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); static Serializer getSerializer(TypeMirror typeMirror); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); static Serializer getSerializer(TypeMirror typeMirror); }
@Test public void toProxy_isUnchanged() throws Exception { TypeMirror typeMirror = typeMirrorOf(String.class); CodeBlock inputExpression = CodeBlock.of("x"); CodeBlock outputExpression = IdentitySerializerFactory.getSerializer(typeMirror).toProxy(inputExpression); assertThat(outputExpression).isSameInstanceAs(inputExpression); }
public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); static Serializer getSerializer(TypeMirror typeMirror); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); static Serializer getSerializer(TypeMirror typeMirror); }
@Test public void fromProxy_isUnchanged() throws Exception { TypeMirror typeMirror = typeMirrorOf(String.class); CodeBlock inputExpression = CodeBlock.of("x"); CodeBlock outputExpression = IdentitySerializerFactory.getSerializer(typeMirror).fromProxy(inputExpression); assertThat(outputExpression).isSameInstanceAs(inputExpression); }
public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); static Serializer getSerializer(TypeMirror typeMirror); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); static Serializer getSerializer(TypeMirror typeMirror); }
@Test public void isIdentity() throws Exception { TypeMirror typeMirror = typeMirrorOf(String.class); boolean actualIsIdentity = IdentitySerializerFactory.getSerializer(typeMirror).isIdentity(); assertThat(actualIsIdentity).isTrue(); }
public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); static Serializer getSerializer(TypeMirror typeMirror); }
IdentitySerializerFactory { public static Serializer getSerializer(TypeMirror typeMirror) { return new IdentitySerializer(typeMirror); } private IdentitySerializerFactory(); static Serializer getSerializer(TypeMirror typeMirror); }
@Test public void testSimple() { String input = "\n" + "package com.latin.declension; \n" + "\n" + "\n" + "public class Idem { \n" + " \n" + " Eadem idem ; \n" + "\n" + " Eundem eandem ( Idem eiusdem ) {\n" + "\n" + " eiusdem ( eiusdem ) ; \n" + "\n" + " eidem_eidem_eidem( ) ;\n" + "\n" + " }\n" + "\n" + "\n" + " Eodem ( Eadem eodem ) { }\n"; String output = "package com.latin.declension;\n" + "\n" + "public class Idem {\n" + "\n" + " Eadem idem;\n" + "\n" + " Eundem eandem (Idem eiusdem) {\n" + " eiusdem (eiusdem);\n" + " eidem_eidem_eidem();\n" + " }\n" + "\n" + " Eodem (Eadem eodem) { }\n"; assertEquals(output, Reformatter.fixup(input)); }
static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
@Test public void testSpecialSpaces() { String input = "\n" + "package com.example.whatever;\n" + "\n" + "public class SomeClass {\n" + " static final String STRING = \" hello world \\n\"; \n" + " static final String STRING_WITH_QUOTES = \" \\\"quote me now \\\" \" ;\n" + " static final int INT = 23 ;\n" + " static final char QUOTE = '\"' ;\n" + " static final char QUOTE2 = '\\\"' ;\n" + "}\n"; String output = "package com.example.whatever;\n" + "\n" + "public class SomeClass {\n" + " static final String STRING = \" hello world \\n\";\n" + " static final String STRING_WITH_QUOTES = \" \\\"quote me now \\\" \";\n" + " static final int INT = 23;\n" + " static final char QUOTE = '\"';\n" + " static final char QUOTE2 = '\\\"';\n" + "}\n"; assertEquals(output, Reformatter.fixup(input)); }
static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
@Test public void noTrailingNewline() { String input = "package com.example.whatever;\n\npublic class SomeClass {}"; String output = input + "\n"; assertEquals(output, Reformatter.fixup(input)); }
static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
Reformatter { static String fixup(String s) { StringBuilder out = new StringBuilder(); JavaScanner scanner = new JavaScanner(s); s = scanner.string(); int len = s.length(); for (int start = 0, previous = 0, braces = 0, parens = 0, end = 0; start < len; previous = start, start = end) { end = scanner.tokenEnd(start); switch (s.charAt(start)) { case '(': parens++; break; case ')': parens--; break; case '{': braces++; break; case '}': braces--; break; case ' ': if (s.charAt(previous) != '(' && "\n.,;)".indexOf(s.charAt(end)) < 0) { out.append(' '); } continue; case '\n': if (end < len && s.charAt(end) != '\n') { if (out.length() == 0) { start++; } break; } if (parens == 0 && braces < 2 && s.charAt(previous) != '\n' && out.length() > 0) { out.append('\n'); } continue; default: break; } out.append(s, start, end); } return out.toString(); } }
@Test public void loadOnce() throws Exception { ClassLoader loader = loaderForJarWithEntries( CharSequence.class.getName(), String.class.getName(), StringBuilder.class.getName()); ImmutableList<CharSequence> providers = SimpleServiceLoader.load(CharSequence.class, loader); assertThat(providers).contains(""); List<Class<?>> classes = providers.stream().map(Object::getClass).collect(toList()); assertThat(classes).containsExactly(String.class, StringBuilder.class).inOrder(); }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void blankLinesAndComments() throws Exception { ClassLoader loader = loaderForJarWithEntries( CharSequence.class.getName(), "", "# this is a comment", " # this is also a comment", " java.lang.String # this is a comment after a class name"); ImmutableList<CharSequence> providers = SimpleServiceLoader.load(CharSequence.class, loader); assertThat(providers).containsExactly(""); }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void loadTwiceFromSameLoader() throws Exception { ClassLoader loader = loaderForJarWithEntries( CharSequence.class.getName(), String.class.getName(), StringBuilder.class.getName()); ImmutableList<CharSequence> providers1 = SimpleServiceLoader.load(CharSequence.class, loader); ImmutableList<CharSequence> providers2 = SimpleServiceLoader.load(CharSequence.class, loader); List<Class<?>> classes1 = providers1.stream().map(Object::getClass).collect(toList()); List<Class<?>> classes2 = providers2.stream().map(Object::getClass).collect(toList()); assertThat(classes2).containsExactlyElementsIn(classes1).inOrder(); }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void getSerializer_immutableListWithSerializableContainedType_emptyReturned() { fakeSerializerFactory.setReturnIdentitySerializer(true); TypeMirror typeMirror = typeMirrorOf(ImmutableList.class); Optional<Serializer> actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment); assertThat(actualSerializer).isEmpty(); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void loadTwiceFromDifferentLoaders() throws Exception { URL jarUrl = urlForJarWithEntries( CharSequence.class.getName(), String.class.getName(), StringBuilder.class.getName()); ClassLoader loader1 = new URLClassLoader(new URL[] {jarUrl}); ImmutableList<CharSequence> providers1 = SimpleServiceLoader.load(CharSequence.class, loader1); assertThat(providers1).contains(""); ClassLoader loader2 = new URLClassLoader(new URL[] {jarUrl}); ImmutableList<CharSequence> providers2 = SimpleServiceLoader.load(CharSequence.class, loader2); List<Class<?>> classes1 = providers1.stream().map(Object::getClass).collect(toList()); List<Class<?>> classes2 = providers2.stream().map(Object::getClass).collect(toList()); assertThat(classes2).containsExactlyElementsIn(classes1).inOrder(); }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void noProviders() throws Exception { ClassLoader loader = loaderForJarWithEntries(CharSequence.class.getName()); ImmutableList<CharSequence> providers = SimpleServiceLoader.load(CharSequence.class, loader); assertThat(providers).isEmpty(); }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void classNotFound() throws Exception { ClassLoader loader = loaderForJarWithEntries(CharSequence.class.getName(), "this.is.not.a.Class"); try { SimpleServiceLoader.load(CharSequence.class, loader); fail(); } catch (ServiceConfigurationError expected) { assertThat(expected).hasMessageThat().startsWith("Could not load "); } }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void wrongTypeClass() throws Exception { ClassLoader loader = loaderForJarWithEntries(CharSequence.class.getName(), "java.lang.Thread"); try { SimpleServiceLoader.load(CharSequence.class, loader); fail(); } catch (ServiceConfigurationError expected) { assertThat(expected).hasMessageThat().startsWith("Class java.lang.Thread is not assignable"); } }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void couldNotConstruct() throws Exception { ClassLoader loader = loaderForJarWithEntries("java.lang.System", "java.lang.System"); try { SimpleServiceLoader.load(System.class, loader); fail(); } catch (ServiceConfigurationError expected) { assertThat(expected).hasMessageThat().startsWith("Could not construct"); } }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void brokenLoader() { ClassLoader loader = new URLClassLoader(new URL[0]) { @Override public Enumeration<URL> getResources(String name) throws IOException { throw new IOException("bang"); } }; try { SimpleServiceLoader.load(CharSequence.class, loader); fail(); } catch (ServiceConfigurationError expected) { assertThat(expected).hasMessageThat().startsWith("Could not look up"); assertThat(expected).hasCauseThat().hasMessageThat().isEqualTo("bang"); } }
public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
SimpleServiceLoader { public static <T> ImmutableList<T> load(Class<? extends T> service, ClassLoader loader) { String resourceName = "META-INF/services/" + service.getName(); List<URL> resourceUrls; try { resourceUrls = Collections.list(loader.getResources(resourceName)); } catch (IOException e) { throw new ServiceConfigurationError("Could not look up " + resourceName, e); } ImmutableList.Builder<T> providers = ImmutableList.builder(); for (URL resourceUrl : resourceUrls) { try { providers.addAll(providersFromUrl(resourceUrl, service, loader)); } catch (IOException e) { throw new ServiceConfigurationError("Could not read " + resourceUrl, e); } } return providers.build(); } private SimpleServiceLoader(); static ImmutableList<T> load(Class<? extends T> service, ClassLoader loader); }
@Test public void testHappy() { HappyVars happy = new HappyVars(); happy.integer = 23; happy.string = "wibble"; happy.list = ImmutableList.of(5, 17, 23); assertThat(HappyVars.IGNORED_STATIC_FINAL).isEqualTo("hatstand"); String expectedText = "integer=23 string=wibble list=[5, 17, 23]"; String actualText = happy.toText(); assertThat(actualText).isEqualTo(expectedText); }
String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
@Test public void testUnset() { HappyVars sad = new HappyVars(); sad.integer = 23; sad.list = ImmutableList.of(23); try { sad.toText(); fail("Did not get expected exception"); } catch (IllegalArgumentException expected) { } }
String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
@Test public void testSubSub() { SubHappyVars vars = new SubHappyVars(); vars.integer = 23; vars.string = "wibble"; vars.list = ImmutableList.of(5, 17, 23); vars.character = 'ß'; String expectedText = "integer=23 string=wibble list=[5, 17, 23] character=ß"; String actualText = vars.toText(); assertThat(actualText).isEqualTo(expectedText); }
String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
TemplateVars { String toText() { Map<String, Object> vars = toVars(); return parsedTemplate().evaluate(vars); } TemplateVars(); }
@Test public void testScanner() { String input = Joiner.on("").join(TOKENS); ImmutableList.Builder<String> tokensBuilder = ImmutableList.builder(); JavaScanner tokenizer = new JavaScanner(input); int end; for (int i = 0; i < input.length(); i = end) { end = tokenizer.tokenEnd(i); tokensBuilder.add(input.substring(i, end)); } assertThat(tokensBuilder.build()).containsExactlyElementsIn(TOKENS).inOrder(); }
int tokenEnd(int start) { if (start >= s.length()) { return s.length(); } switch (s.charAt(start)) { case ' ': case '\n': return spaceEnd(start); case '/': if (s.charAt(start + 1) == '*') { return blockCommentEnd(start); } else if (s.charAt(start + 1) == '/') { return lineCommentEnd(start); } else { return start + 1; } case '\'': case '"': case '`': return quoteEnd(start); default: return start + 1; } }
JavaScanner { int tokenEnd(int start) { if (start >= s.length()) { return s.length(); } switch (s.charAt(start)) { case ' ': case '\n': return spaceEnd(start); case '/': if (s.charAt(start + 1) == '*') { return blockCommentEnd(start); } else if (s.charAt(start + 1) == '/') { return lineCommentEnd(start); } else { return start + 1; } case '\'': case '"': case '`': return quoteEnd(start); default: return start + 1; } } }
JavaScanner { int tokenEnd(int start) { if (start >= s.length()) { return s.length(); } switch (s.charAt(start)) { case ' ': case '\n': return spaceEnd(start); case '/': if (s.charAt(start + 1) == '*') { return blockCommentEnd(start); } else if (s.charAt(start + 1) == '/') { return lineCommentEnd(start); } else { return start + 1; } case '\'': case '"': case '`': return quoteEnd(start); default: return start + 1; } } JavaScanner(String s); }
JavaScanner { int tokenEnd(int start) { if (start >= s.length()) { return s.length(); } switch (s.charAt(start)) { case ' ': case '\n': return spaceEnd(start); case '/': if (s.charAt(start + 1) == '*') { return blockCommentEnd(start); } else if (s.charAt(start + 1) == '/') { return lineCommentEnd(start); } else { return start + 1; } case '\'': case '"': case '`': return quoteEnd(start); default: return start + 1; } } JavaScanner(String s); }
JavaScanner { int tokenEnd(int start) { if (start >= s.length()) { return s.length(); } switch (s.charAt(start)) { case ' ': case '\n': return spaceEnd(start); case '/': if (s.charAt(start + 1) == '*') { return blockCommentEnd(start); } else if (s.charAt(start + 1) == '/') { return lineCommentEnd(start); } else { return start + 1; } case '\'': case '"': case '`': return quoteEnd(start); default: return start + 1; } } JavaScanner(String s); }
@Test public void getSerializer_immutableList_serializerReturned() { TypeMirror typeMirror = typeMirrorOf(ImmutableList.class); Serializer actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get(); assertThat(actualSerializer.getClass().getName()) .contains("ImmutableListSerializerExtension$ImmutableListSerializer"); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableListSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableList(typeMirror)) { return Optional.empty(); } TypeMirror containedType = getContainedType(typeMirror); Serializer containedTypeSerializer = factory.getSerializer(containedType); if (containedTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of(new ImmutableListSerializer(containedTypeSerializer, processingEnv)); } ImmutableListSerializerExtension(); @Override Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
@Test public void noTypeParameters() { TypeElement source1 = elementUtils.getTypeElement(Source1.class.getCanonicalName()); TypeElement target1 = elementUtils.getTypeElement(Target1.class.getCanonicalName()); List<ExecutableElement> sourceMethods = ElementFilter.methodsIn(source1.getEnclosedElements()); Map<ExecutableElement, TypeMirror> types = TypeVariables.rewriteReturnTypes(elementUtils, typeUtils, sourceMethods, source1, target1); assertThat(types).containsExactly(sourceMethods.get(0), sourceMethods.get(0).getReturnType()); }
static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
@Test public void simpleTypeParameter() { TypeElement source2 = elementUtils.getTypeElement(Source2.class.getCanonicalName()); TypeElement target2 = elementUtils.getTypeElement(Target2.class.getCanonicalName()); List<ExecutableElement> sourceMethods = ElementFilter.methodsIn(source2.getEnclosedElements()); Map<ExecutableElement, TypeMirror> types = TypeVariables.rewriteReturnTypes(elementUtils, typeUtils, sourceMethods, source2, target2); List<ExecutableElement> targetMethods = ElementFilter.methodsIn(target2.getEnclosedElements()); TypeMirror setFooParameter = targetMethods.get(0).getParameters().get(0).asType(); ExecutableElement getFoo = sourceMethods.get(0); TypeMirror originalGetFooReturn = getFoo.getReturnType(); TypeMirror rewrittenGetFooReturn = types.get(getFoo); assertThat(typeUtils.isAssignable(setFooParameter, originalGetFooReturn)).isFalse(); assertThat(typeUtils.isAssignable(setFooParameter, rewrittenGetFooReturn)).isTrue(); }
static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
@Test public void hairyTypeParameters() { TypeElement source3 = elementUtils.getTypeElement(Source3.class.getCanonicalName()); TypeElement target3 = elementUtils.getTypeElement(Target3.class.getCanonicalName()); List<ExecutableElement> sourceMethods = ElementFilter.methodsIn(source3.getEnclosedElements()); Map<ExecutableElement, TypeMirror> types = TypeVariables.rewriteReturnTypes(elementUtils, typeUtils, sourceMethods, source3, target3); List<ExecutableElement> targetMethods = ElementFilter.methodsIn(target3.getEnclosedElements()); TypeMirror setFooParameter = targetMethods.get(0).getParameters().get(0).asType(); ExecutableElement getFoo = sourceMethods.get(0); TypeMirror originalGetFooReturn = getFoo.getReturnType(); TypeMirror rewrittenGetFooReturn = types.get(getFoo); assertThat(typeUtils.isAssignable(setFooParameter, originalGetFooReturn)).isFalse(); assertThat(typeUtils.isAssignable(setFooParameter, rewrittenGetFooReturn)).isTrue(); }
static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
@Test public void nestedClasses() { TypeElement outer = elementUtils.getTypeElement(Outer.class.getCanonicalName()); TypeElement inner = elementUtils.getTypeElement(Outer.Inner.class.getCanonicalName()); List<ExecutableElement> outerMethods = ElementFilter.methodsIn(outer.getEnclosedElements()); Map<ExecutableElement, TypeMirror> types = TypeVariables.rewriteReturnTypes(elementUtils, typeUtils, outerMethods, outer, inner); List<ExecutableElement> innerMethods = ElementFilter.methodsIn(inner.getEnclosedElements()); ExecutableElement getFoo = methodNamed(outerMethods, "getFoo"); ExecutableElement getBar = methodNamed(outerMethods, "getBar"); ExecutableElement setFoo = methodNamed(innerMethods, "setFoo"); ExecutableElement setBar = methodNamed(innerMethods, "setBar"); TypeMirror setFooParameter = setFoo.getParameters().get(0).asType(); TypeMirror originalGetFooReturn = getFoo.getReturnType(); TypeMirror rewrittenGetFooReturn = types.get(getFoo); assertThat(typeUtils.isAssignable(setFooParameter, originalGetFooReturn)).isFalse(); assertThat(typeUtils.isAssignable(setFooParameter, rewrittenGetFooReturn)).isTrue(); TypeMirror setBarParameter = setBar.getParameters().get(0).asType(); TypeMirror originalGetBarReturn = getBar.getReturnType(); TypeMirror rewrittenGetBarReturn = types.get(getBar); assertThat(typeUtils.isAssignable(setBarParameter, originalGetBarReturn)).isFalse(); assertThat(typeUtils.isAssignable(setBarParameter, rewrittenGetBarReturn)).isTrue(); }
static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }
TypeVariables { static ImmutableMap<ExecutableElement, TypeMirror> rewriteReturnTypes( Elements elementUtils, Types typeUtils, Collection<ExecutableElement> methods, TypeElement sourceType, TypeElement targetType) { List<? extends TypeParameterElement> sourceTypeParameters = sourceType.getTypeParameters(); List<? extends TypeParameterElement> targetTypeParameters = targetType.getTypeParameters(); Preconditions.checkArgument( sourceTypeParameters.toString().equals(targetTypeParameters.toString()), "%s != %s", sourceTypeParameters, targetTypeParameters); EclipseHack eclipseHack = new EclipseHack(elementUtils, typeUtils); TypeMirror[] targetTypeParameterMirrors = new TypeMirror[targetTypeParameters.size()]; for (int i = 0; i < targetTypeParameters.size(); i++) { targetTypeParameterMirrors[i] = targetTypeParameters.get(i).asType(); } DeclaredType parallelSource = typeUtils.getDeclaredType(sourceType, targetTypeParameterMirrors); return methods.stream() .collect( ImmutableMap.toImmutableMap( m -> m, m -> eclipseHack.methodReturnType(m, parallelSource))); } private TypeVariables(); }