Search in sources :

Example 1 with CodeElement

use of com.structurizr.model.CodeElement in project agile-architecture-documentation-system by Riduidel.

the class SequenceDiagramGenerator method findImplementationOf.

private MethodDeclarationRepresentation findImplementationOf(MethodCallRepresentation methodCallRepresentation) {
    Component component = classesToComponents.get(methodCallRepresentation.calledTypeName);
    MethodDeclarationRepresentation representation = null;
    for (CodeElement code : component.getCode()) {
        representation = callGraphModel.getClassFor(code.getType()).getMethodFor(methodCallRepresentation);
        // This will be null.
        if (representation != null) {
            if (!representation.getChildren().isEmpty()) {
                break;
            }
        }
    }
    return representation;
}
Also used : MethodDeclarationRepresentation(org.ndx.agile.architecture.sequence.generator.javaparser.adapter.MethodDeclarationRepresentation) Component(com.structurizr.model.Component) CodeElement(com.structurizr.model.CodeElement)

Example 2 with CodeElement

use of com.structurizr.model.CodeElement in project agile-architecture-documentation-system by Riduidel.

the class AdaptableSpringComponentFinderStrategy method afterFindComponents.

/**
 * In some Spring projects, recognized components are the implementations.
 * In such a case, to ease dependency detection, it's a good thing to replace implementation by interfaces.
 * As it has to be done after supporting type detection, but before dependency resolution,
 * we have to rewrite the whole {@link AbstractSpringComponentFinderStrategy#afterFindComponents()} method
 */
@Override
public void afterFindComponents() {
    findSupportingTypes(componentsFound);
    if (componentFinder.getContainer().getProperties().containsKey(SPRING_COMPONENTS_OPTIONS_FAVOR_INTERFACE)) {
        logger.warning(String.format("Container %s requires its components to favor interfaces. So we're replacing all impls by interfaces", componentFinder.getContainer().getName()));
        for (Component component : componentsFound) {
            String componentBaseName = component.getName();
            componentBaseName = componentBaseName.replace("Impl", "");
            for (CodeElement element : component.getCode()) {
                if (element.getName().contains(componentBaseName)) {
                    switch(element.getCategory()) {
                        case "interface":
                            CodeElementHack.setRole(element, CodeElementRole.Primary);
                            break;
                        case "class":
                            CodeElementHack.setRole(element, CodeElementRole.Supporting);
                            break;
                    }
                }
            }
            boolean foundBase = component.getCode().stream().filter(c -> CodeElementRole.Primary.equals(c.getRole())).findFirst().isPresent();
            if (!foundBase) {
                // Seems like we never found any interface this component implements as primary
                // So that mean its class is the main code element/
                componentBaseName = component.getName();
                for (CodeElement element : component.getCode()) {
                    if (element.getName().equals(componentBaseName)) {
                        foundBase = true;
                        CodeElementHack.setRole(element, CodeElementRole.Primary);
                    }
                }
            }
        }
    }
    findDependencies();
}
Also used : Component(com.structurizr.model.Component) CodeElement(com.structurizr.model.CodeElement)

Aggregations

CodeElement (com.structurizr.model.CodeElement)2 Component (com.structurizr.model.Component)2 MethodDeclarationRepresentation (org.ndx.agile.architecture.sequence.generator.javaparser.adapter.MethodDeclarationRepresentation)1