Search in sources :

Example 51 with Type

use of java.lang.reflect.Type in project sonarqube by SonarSource.

the class ItUtils method jsonToMap.

public static Map<String, Object> jsonToMap(String json) {
    Gson gson = new Gson();
    Type type = new TypeToken<Map<String, Object>>() {
    }.getType();
    return gson.fromJson(json, type);
}
Also used : Type(java.lang.reflect.Type) Gson(com.google.gson.Gson) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 52 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method coercingStringMapOfIntListsShouldBeIdentity.

@Test
public void coercingStringMapOfIntListsShouldBeIdentity() throws CoerceFailedException, NoSuchFieldException {
    Type type = TestFields.class.getField("stringMapOfLists").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    ImmutableMap<String, ImmutableList<Integer>> input = ImmutableMap.of("foo", ImmutableList.of(4, 5), "bar", ImmutableList.of(6, 7));
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    assertEquals(input, result);
}
Also used : Type(java.lang.reflect.Type) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 53 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method hasElementTypesForContainers.

@Test
public void hasElementTypesForContainers() throws NoSuchFieldException {
    Type type = TestFields.class.getField("stringMapOfLists").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    assertTrue(coercer.hasElementClass(String.class));
    assertTrue(coercer.hasElementClass(Integer.class));
    assertTrue(coercer.hasElementClass(Integer.class, String.class));
    assertTrue(coercer.hasElementClass(Integer.class, SourcePath.class));
    assertFalse(coercer.hasElementClass(SourcePath.class));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Type(java.lang.reflect.Type) Test(org.junit.Test)

Example 54 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method coerceFromTurkishIsShouldWork.

@Test
public void coerceFromTurkishIsShouldWork() throws NoSuchFieldException, CoerceFailedException {
    Type type = TestFields.class.getField("listOfTestEnums").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    String pinkWithLowercaseTurkishI = "pınk";
    String pinkWithUppercaseTurkishI = "PİNK";
    String whiteWithLowercaseTurkishI = "whıte";
    String whiteWithUppercaseTurkishI = "WHİTE";
    ImmutableList<String> input = ImmutableList.of(pinkWithLowercaseTurkishI, pinkWithUppercaseTurkishI, whiteWithLowercaseTurkishI, whiteWithUppercaseTurkishI);
    ImmutableList<TestEnum> expected = ImmutableList.of(TestEnum.PINK, TestEnum.PINK, TestEnum.white, TestEnum.white);
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    assertEquals(expected, result);
}
Also used : Type(java.lang.reflect.Type) Test(org.junit.Test)

Example 55 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method invalidSourcePathShouldGiveSpecificErrorMsg.

@Test
public void invalidSourcePathShouldGiveSpecificErrorMsg() throws NoSuchFieldException, IOException {
    Type type = TestFields.class.getField("setOfSourcePaths").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    Path baratheon = Paths.get("Baratheon.java");
    Path lannister = Paths.get("Lannister.java");
    Path stark = Paths.get("Stark.java");
    Path targaryen = Paths.get("Targaryen.java");
    ImmutableList<Path> input = ImmutableList.of(baratheon, lannister, stark, targaryen);
    for (Path p : input) {
        if (!p.equals(baratheon)) {
            filesystem.touch(p);
        }
    }
    try {
        coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    } catch (CoerceFailedException e) {
        String result = e.getMessage();
        String expected = "cannot coerce 'Baratheon.java'";
        for (Path p : input) {
            if (!p.equals(baratheon)) {
                assertFalse(result.contains(p.toString()));
            }
        }
        assertTrue(result.contains(expected));
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) Type(java.lang.reflect.Type) Test(org.junit.Test)

Aggregations

Type (java.lang.reflect.Type)6423 ParameterizedType (java.lang.reflect.ParameterizedType)1761 ProgressRequestBody (io.kubernetes.client.ProgressRequestBody)722 ProgressResponseBody (io.kubernetes.client.ProgressResponseBody)722 GenericArrayType (java.lang.reflect.GenericArrayType)690 WildcardType (java.lang.reflect.WildcardType)571 Test (org.junit.Test)512 ArrayList (java.util.ArrayList)427 Method (java.lang.reflect.Method)416 TypeVariable (java.lang.reflect.TypeVariable)337 List (java.util.List)335 Map (java.util.Map)289 Gson (com.google.gson.Gson)231 V1Status (io.kubernetes.client.models.V1Status)228 V1Status (io.kubernetes.client.openapi.models.V1Status)224 HashMap (java.util.HashMap)204 Field (java.lang.reflect.Field)163 Annotation (java.lang.annotation.Annotation)160 IOException (java.io.IOException)140 Collection (java.util.Collection)111