@Override public Set<Component> findComponents() { componentsFound.addAll(doFindComponents()); return componentsFound; }
protected Set<Component> findClassesWithAnnotation(Class<? extends Annotation> type, String technology) { return findClassesWithAnnotation(type, technology, false); }
@Override protected Set<Component> doFindComponents() { Set<Component> components = new HashSet<>(); for (AbstractComponentFinderStrategy componentFinderStrategy : componentFinderStrategies) { components.addAll(componentFinderStrategy.findComponents()); } return components; }
@Override public void afterFindComponents() { findSupportingTypes(componentsFound); findDependencies(); }
protected Set<Component> findClassesWithAnnotation(Class<? extends Annotation> type, String technology, boolean includePublicTypesOnly) { Set<Component> components = new HashSet<>(); Set<Class<?>> componentTypes = findTypesAnnotatedWith(type); for (Class<?> componentType : componentTypes) { if (!includePublicTypesOnly || Modifier.isPublic(componentType.getModifiers())) { final Container container = getComponentFinder().getContainer(); Component newComponent = addComponent( container, componentType.getSimpleName(), componentType.getCanonicalName(), "", technology); if (newComponent != null) { components.add(newComponent); } } } return components; }
private void addEfferentDependencies(Component component, String type, Set<String> typesVisited) { typesVisited.add(type); for (Class<?> referencedType : getTypeRepository().findReferencedTypes(type)) { try { if (!isNestedClass(referencedType)) { String referencedTypeName = referencedType.getCanonicalName(); if (!StringUtils.isNullOrEmpty(referencedTypeName)) { Component destinationComponent = componentFinder.getContainer().getComponentOfType(referencedTypeName); if (destinationComponent != null) { if (component != destinationComponent) { component.uses(destinationComponent, ""); } } else if (!typesVisited.contains(referencedTypeName)) { addEfferentDependencies(component, referencedTypeName, typesVisited); } } } } catch (Throwable t) { log.warn(t); } } }
private void findDependencies() { for (Component component : componentFinder.getContainer().getComponents()) { for (CodeElement codeElement : component.getCode()) { addEfferentDependencies(component, codeElement.getType(), new HashSet<>()); } } }
@Test public void test_addSupportingTypesStrategy_ThrowsAnException_WhenANullSupportingTypesStrategyIsSpecified() { try { strategy.addSupportingTypesStrategy(null); fail(); } catch (IllegalArgumentException iae) { assertEquals("A supporting types strategy must be provided.", iae.getMessage()); } }
@Override public void afterFindComponents() { // this will find component dependencies, but the relationship descriptions // will be empty because we can't get that from the code super.afterFindComponents(); for (Component component : getComponentFinder().getContainer().getComponents()) { for (CodeElement codeElement : component.getCode()) { // find the efferent dependencies findUsesComponentAnnotations(component, codeElement.getType()); findUsesSoftwareSystemsAnnotations(component, codeElement.getType()); findUsesContainerAnnotations(component, codeElement.getType()); // and also the afferent dependencies findUsedByPersonAnnotations(component, codeElement.getType()); findUsedBySoftwareSystemAnnotations(component, codeElement.getType()); findUsedByContainerAnnotations(component, codeElement.getType()); } } }