public static String getBeanLocation(IBean bean, boolean includeElementName) { StringBuilder sb = new StringBuilder(); sb.append(SEPARATOR); ITextSourceReference origin = null; if (bean instanceof AbstractBeanElement) { AbstractBeanElement e = (AbstractBeanElement) bean; origin = e.getDefinition().getOriginalDefinition(); } if (origin != null) { // If toString() is not enough, another interface should be introduced. sb.append(origin.toString()); } else { String pkg = bean.getBeanClass().getPackageFragment().getElementName(); if (pkg.length() > 0) { sb.append(pkg); } if (includeElementName) { if (pkg.length() > 0) { sb.append(DOT); } sb.append(bean.getElementName()); } sb.append(SEPARATOR); IPath path = bean.getBeanClass().getPackageFragment().getParent().getPath(); sb.append(path.toString()); } return sb.toString(); }
public void testExact() throws CoreException, IOException { ICDIProject cdi = CDICorePlugin.getCDIProject(getTestProject(), true); Collection<IBean> bs = cdi.getBeans(new Path("/CDISolderTest/src/org/jboss/exact/FishFactory.java")); assertEquals(2, bs.size()); IClassBean cls = null; IProducerMethod mtd = null; for (IBean b : bs) { if (b instanceof IClassBean) { cls = (IClassBean) b; } else if (b instanceof IProducerMethod) { mtd = (IProducerMethod) b; } } assertNotNull(cls); assertNotNull(mtd); Collection<IInjectionPoint> points = cls.getInjectionPoints(); int count = 0; for (IInjectionPoint p : points) { Collection<IBean> injected = cdi.getBeans(false, p); IMember member = p.getSourceMember(); if (member.getElementName().equals("peacefulFish")) { assertEquals(1, injected.size()); IBean ib = injected.iterator().next(); assertEquals("org.jboss.exact.Salmon", ib.getBeanClass().getFullyQualifiedName()); count++; } else if (member.getElementName().equals("dangerousFish")) { assertEquals(1, injected.size()); IBean ib = injected.iterator().next(); assertEquals("org.jboss.exact.Shark", ib.getBeanClass().getFullyQualifiedName()); count++; } else if (member.getElementName().equals("getTastyFish")) { assertEquals(1, injected.size()); IBean ib = injected.iterator().next(); assertEquals("org.jboss.exact.Salmon", ib.getBeanClass().getFullyQualifiedName()); count++; } else { } } assertEquals(3, count); }