当前位置: 首页>>代码示例>>Java>>正文


Java Reflect类代码示例

本文整理汇总了Java中org.joor.Reflect的典型用法代码示例。如果您正苦于以下问题:Java Reflect类的具体用法?Java Reflect怎么用?Java Reflect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Reflect类属于org.joor包,在下文中一共展示了Reflect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: xmlBean2Map

import org.joor.Reflect; //导入依赖的package包/类
private Map<String, String> xmlBean2Map(Object bean) {
  Map<String, String> result = Maps.newHashMap();
  for (Entry<String, Reflect> entry : Reflect.on(bean).fields().entrySet()) {
    Reflect reflect = entry.getValue();
    if (reflect.get() == null) {
      continue;
    }

    try {
      Field field = bean.getClass().getDeclaredField(entry.getKey());
      if (field.isAnnotationPresent(XStreamAlias.class)) {
        result.put(field.getAnnotation(XStreamAlias.class).value(),
            reflect.get().toString());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

  }

  return result;
}
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:23,代码来源:WxMpPayServiceImpl.java

示例2: shouldCreateRemoteDriverInstance

import org.joor.Reflect; //导入依赖的package包/类
@Test
public void shouldCreateRemoteDriverInstance() throws MalformedURLException {
    XmlConfig config = new XmlConfig(new HashMap<String, String>() {
        {
            put(BROWSER_NAME, "firefox");
            put(PLATFORM_NAME, "ANY");
            put(TEST_NAME, "shouldCreateRemoteDriverInstance");
        }
    });

    WebDriver driver = mock(RemoteWebDriver.class, RETURNS_DEEP_STUBS);
    WebDriverProvider spyFactory = spy(defaultFactory);
    Reflect spyReflectedDriver = spy(spyFactory.wrapDriver(firefox));

    doReturn(spyReflectedDriver).when(spyFactory).wrapDriver(firefox);
    doReturn(on(driver)).when(spyReflectedDriver).create(new URL(firefox.url()), firefox.configuration(config));

    assertThat(spyFactory.createDriver(firefox, config)).isInstanceOf(RemoteWebDriver.class);
}
 
开发者ID:sskorol,项目名称:webdriver-supplier,代码行数:20,代码来源:CoreTests.java

示例3: shouldCreateLocalDriverInstance

import org.joor.Reflect; //导入依赖的package包/类
@Test
public void shouldCreateLocalDriverInstance() {
    Browser edge = StreamEx.of(browsers)
                             .findFirst(f -> f.name() == Browser.Name.Edge)
                             .orElseThrow(() -> new AssertionError(
                                     "Unable to get Edge implementation"));

    XmlConfig config = new XmlConfig(new HashMap<String, String>() {
        {
            put(BROWSER_NAME, "edge");
        }
    });

    PowerMockito.mockStatic(WebDriverManager.class);
    BrowserManager browserManager = mock(BrowserManager.class, RETURNS_DEEP_STUBS);
    WebDriver driver = mock(EdgeDriver.class, RETURNS_DEEP_STUBS);
    WebDriverProvider spyFactory = spy(defaultFactory);
    Reflect spyReflectedDriver = spy(spyFactory.wrapDriver(edge));

    PowerMockito.when(WebDriverManager.getInstance(spyReflectedDriver.type())).thenReturn(browserManager);
    doNothing().when(browserManager).setup();
    doReturn(spyReflectedDriver).when(spyFactory).wrapDriver(edge);
    doReturn(on(driver)).when(spyReflectedDriver).create(edge.configuration(config));

    assertThat(spyFactory.createDriver(edge, config)).isInstanceOf(EdgeDriver.class);
}
 
开发者ID:sskorol,项目名称:webdriver-supplier,代码行数:27,代码来源:CoreTests.java

示例4: getIssue

import org.joor.Reflect; //导入依赖的package包/类
@Override
public GHIssue getIssue(int number) {
    try {
        // Create spy object
        GHIssue ghIssue = spy(impl.getIssue(number));

        // If milestone != null, fetch it from memory
        doAnswer(call -> {
            String mlsNumber = Reflect.on(ghIssue).field("issue").call("json").call("getString", "milestone").get();
            if (mlsNumber.equals("null")) {
                return Optional.empty();
            }
            return Optional.of(getMilestones().get(Integer.parseInt(mlsNumber) - 1));
        }).when(ghIssue).getMilestone();

        // Return spy object
        return ghIssue;
    } catch (FB2GHException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:sudiamanj,项目名称:fogbugz-to-github,代码行数:22,代码来源:OfflineGHRepo.java

示例5: parseTag

import org.joor.Reflect; //导入依赖的package包/类
public static <T> T parseTag(Class<T> clazz, Spec spec) {
    T object = Reflect.on(clazz).create().get();

    if (object instanceof SpecAppliable)
        ((SpecAppliable) object).applySpec(spec);

    if (object instanceof InitializingBean) {
        try {
            ((InitializingBean) object).afterPropertiesSet();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    return object;
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:17,代码来源:Specs.java

示例6: checkParameters

import org.joor.Reflect; //导入依赖的package包/类
private void checkParameters(WxMpStoreBaseInfo request) {
  List<String> nullFields = Lists.newArrayList();
  for (Entry<String, Reflect> entry : Reflect.on(request).fields()
      .entrySet()) {
    Reflect reflect = entry.getValue();
    try {
      Field field = request.getClass().getDeclaredField(entry.getKey());
      if (field.isAnnotationPresent(Required.class)
          && reflect.get() == null) {
        nullFields.add(entry.getKey());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  if (!nullFields.isEmpty()) {
    throw new IllegalArgumentException("必填字段[" + nullFields + "]必须提供值");
  }

}
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:22,代码来源:WxMpStoreServiceImpl.java

示例7: test

import org.joor.Reflect; //导入依赖的package包/类
public void test() throws NoSuchFieldException, SecurityException {

    WxSendRedpackRequest request = new WxSendRedpackRequest();
    request.setMchBillno("123");
    request.setActName("ab");
    for (Entry<String, Reflect> entry : Reflect.on(request).fields().entrySet()) {
      Reflect reflect = entry.getValue();
      if (reflect.get() == null) {
        continue;
      }

      Field field = WxSendRedpackRequest.class.getDeclaredField(entry.getKey());
      if (field.isAnnotationPresent(XStreamAlias.class)) {
        System.err.println(reflect.get() + "  =  " + field.getAnnotation(XStreamAlias.class).value());
      }
    }

  }
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:19,代码来源:WxSendRedpackRequestTest.java

示例8: IndexControllerTest

import org.joor.Reflect; //导入依赖的package包/类
public IndexControllerTest() {
    final ZonedDateTime eventDate = ZonedDateTime.of(2016, 7, 7, 19, 0, 0, 0, ZoneId.of("Europe/Berlin"));
    final EventEntity event1 = Reflect.on(
            new EventEntity(GregorianCalendar.from(eventDate), "name-1", "desc-1")
    ).set("id", 23).set("createdAt", GregorianCalendar.from(eventDate)).get();
    event1.setDuration(60);
    event1.setSpeaker("Farin Urlaub");
    event1.setLocation("Am Strand\n4223 Schlaraffenland\n\nirgendwo");

    final ZonedDateTime eventDate2 = ZonedDateTime.of(2016, 11, 22, 18, 0, 0, 0, ZoneId.of("Europe/Berlin"));
    final EventEntity event2 = Reflect.on(
            new EventEntity(GregorianCalendar.from(eventDate2), "name-2", "desc-2")
    ).set("id", 42).set("createdAt", GregorianCalendar.from(eventDate2)).get();
    this.events = Arrays.asList(event1, event2);

    this.posts = new ArrayList<>();
    final PostEntity post = Reflect.on(new PostEntity(Date.from(LocalDate.of(2016, 8, 5).atStartOfDay(ZoneId.systemDefault()).toInstant()), "foo", "foo", "foo")).set("id", 2).get();
    post.setStatus(Status.published);
    this.posts.add(post);
    this.posts.add(Reflect.on(new PostEntity(Date.from(LocalDate.of(2016, 8, 4).atStartOfDay(ZoneId.systemDefault()).toInstant()), "bar", "bar", "bar")).set("id", 1).get());

    this.links = new ArrayList<>();
    this.links.add(new LinkEntity("http://michael-simons.eu", "Michael Simons"));
}
 
开发者ID:EuregJUG-Maas-Rhine,项目名称:site,代码行数:25,代码来源:IndexControllerTest.java

示例9: failedMimetypeDetectionShouldWork

import org.joor.Reflect; //导入依赖的package包/类
@Test
@DirtiesContext
public void failedMimetypeDetectionShouldWork() throws Exception {
    final Reflect controllerReflect = Reflect.on(this.controller);
    // Much more evil isn't possible, i guess... DirtiesContext!!!!
    Tika tika = controllerReflect.field("tika").get();
    tika = spy(tika);
    when(tika.detect(any(InputStream.class), any(String.class))).thenThrow(IOException.class);
    controllerReflect.set("tika", tika);

    final MockMultipartFile multipartFile = new MockMultipartFile("assetData", "asset.png", null, this.getClass().getResourceAsStream("/eu/euregjug/site/assets/asset.png"));
    when(this.gridFsTemplate.findOne(any(Query.class))).thenReturn(null);

    mvc
            .perform(
                    fileUpload("/api/assets")
                    .file(multipartFile)
            )
            .andExpect(status().isCreated())
            .andExpect(content().string("asset.png"));

    verify(this.gridFsTemplate).findOne(any(Query.class));
    verify(this.gridFsTemplate).store(any(InputStream.class), eq("asset.png"), isNull(String.class));
    verifyNoMoreInteractions(this.gridFsTemplate);
}
 
开发者ID:EuregJUG-Maas-Rhine,项目名称:site,代码行数:26,代码来源:AssetApiControllerTest.java

示例10: searchShouldWork

import org.joor.Reflect; //导入依赖的package包/类
@Test
public void searchShouldWork() throws Exception {
    final PostEntity p1 = Reflect.on(
            new PostEntity(new Date(), "new-site-is-live", "New site is live", "Welcome to the new EuregJUG website. We have switched off the old static pages and replaced it with a little application based on Hibernate, Spring Data JPA, Spring Boot and Thymeleaf.")
    ).call("updateUpdatedAt").set("id", 23).get();

    when(this.postRepository.searchByKeyword("website")).thenReturn(Arrays.asList(p1));

    this.mvc
            .perform(
                    get("/api/posts/search")
                            .param("q", "website")
                            .principal(() -> "euregjug")
            )
            .andExpect(status().isOk())
            .andExpect(jsonPath("$", hasSize(1)))
            .andExpect(jsonPath("$[0].slug", equalTo("new-site-is-live")))
            .andDo(document("api/posts/search",
                    preprocessRequest(prettyPrint()),
                    preprocessResponse(prettyPrint())
            ));

    verify(this.postRepository).searchByKeyword("website");
    verifyNoMoreInteractions(this.postRepository);
}
 
开发者ID:EuregJUG-Maas-Rhine,项目名称:site,代码行数:26,代码来源:PostApiControllerTest.java

示例11: fromJson

import org.joor.Reflect; //导入依赖的package包/类
@Test
public void fromJson() throws URISyntaxException, JsonIOException, JsonSyntaxException, IOException {
    try (final Reader reader = new InputStreamReader(new FileInputStream(PATH_IN + fileName))) {
        Type t = new TypeToken<Set<NinePatch>>() {}.getType();
        Set<NinePatch> ninePatchSet = new GsonBuilder().create().fromJson(reader, t);
        NinePatchMap ninePatchMap = NinePatch.init(ninePatchSet);

        QualifiedResource mockedResource = Mockito.mock(QualifiedResource.class);
        Mockito.when(mockedResource.getName()).thenReturn(resourceName);
        Mockito.when(mockedResource.getTypedQualifiers()).thenReturn(typedQualifiers);

        NinePatch ninePatch = ninePatchMap.getBestMatch(mockedResource);
        assertTrue(resultExpected ^ (ninePatch == null));
        if (resultExpected && ninePatch != null) {
        	assertEquals(nameExpected, Reflect.on(ninePatch).get("name"));
        }
    }
}
 
开发者ID:avianey,项目名称:androidsvgdrawable-plugin,代码行数:19,代码来源:NinePatchMatchingTest.java

示例12: test

import org.joor.Reflect; //导入依赖的package包/类
@Test
 public void test() throws IOException, TranscoderException, InstantiationException, IllegalAccessException {
 	// verify bounds
     QualifiedResource svg = qualifiedSVGResourceFactory.fromSVGFile(new File(PATH_IN + filename));
     Rectangle svgBounds = svg.getBounds();
     assertNotNull(svgBounds);
     assertEquals(ceil(expectedWidth), svgBounds.getWidth(), 0);
     assertEquals(ceil(expectedHeight), svgBounds.getHeight(), 0);
     Rectangle svgConstrainedBounds = svg.getScaledBounds(svg.getDensity().getValue());
     assertNotNull(svgConstrainedBounds);
     assertEquals(ceil(constrainedWidth), svgConstrainedBounds.getWidth(), 0);
     assertEquals(ceil(constrainedHeight), svgConstrainedBounds.getHeight(), 0);

     // verify generated png (width, height) for each target density
     final String name = svg.getName();
     for (Density.Value d : Density.Value.values()) {
     	Reflect.on(svg).set("name", name + "_" + d.name());
plugin.transcode(svg, d, new File(PATH_OUT), null);
      BufferedImage image = ImageIO.read(new FileInputStream(new File(PATH_OUT, svg.getName() + "." + OUTPUT_FORMAT.name().toLowerCase())));
Rectangle expectedBounds = svg.getScaledBounds(d);
assertEquals(expectedBounds.getWidth(), image.getWidth(), 0);
      assertEquals(expectedBounds.getHeight(), image.getHeight(), 0);
     }
 }
 
开发者ID:avianey,项目名称:androidsvgdrawable-plugin,代码行数:25,代码来源:BoundsExtractionTest.java

示例13: createDriver

import org.joor.Reflect; //导入依赖的package包/类
public WebDriver createDriver(final Browser browser, final XmlConfig config) {
    final Reflect driver = wrapDriver(browser);
    return Try.of(() -> Match(browser).of(
            Case($(Browser::isRemote), () -> createRemote(driver, browser, config)),
            Case($(), () -> createLocal(driver, browser, config)))
    ).map(d -> setCustomScreenResolution(d.get())).getOrElseThrow(ex -> {
        throw new SkipException("Unable to create " + browser.name().getDriverClassName()
                + " with the following capabilities: " + browser.configuration(config), ex);
    });
}
 
开发者ID:sskorol,项目名称:webdriver-supplier,代码行数:11,代码来源:WebDriverFactory.java

示例14: extraction

import org.joor.Reflect; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> List<Class<? extends T>> extraction(Class<T> clazz, List<String> classFileList) {
    List<Class<? extends T>> classList = Lists.newArrayList();
    for (String classFile : classFileList) {
        Class<?> classInFile = Reflect.on(classFile).get();
        if (clazz.isAssignableFrom(classInFile) && clazz != classInFile) {
            classList.add((Class<? extends T>) classInFile);
        }
    }

    return classList;
}
 
开发者ID:WhatAKitty,项目名称:spark-project,代码行数:13,代码来源:ClassSearcher.java

示例15: annotationed

import org.joor.Reflect; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T extends Annotation> List<Class<? extends T>> annotationed(Class<T> clazz, List<String> classFileList) {
    List<Class<? extends T>> classList = Lists.newArrayList();
    for (String classFile : classFileList) {
        Class<?> classInFile = Reflect.on(classFile).get();
        if (classInFile.isAnnotationPresent(clazz)) {
            classList.add((Class<? extends T>) classInFile);
        }
    }

    return classList;
}
 
开发者ID:WhatAKitty,项目名称:spark-project,代码行数:13,代码来源:ClassSearcher.java


注:本文中的org.joor.Reflect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。