Search in sources :

Example 16 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency in project visualee by Thomas-S-B.

the class ExaminerInjectTest method testFindAndSetAttributesInjectSetterWithAnnotations.

@Test
public void testFindAndSetAttributesInjectSetterWithAnnotations() {
    JavaSource javaSource;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("ZeiterfassungEingabeModel");
    sourceCode = "public class ZeiterfassungEingabeModel implements Serializable\n" + "{\n" + "@Inject\n" + "protected void setBuchungsMonat(@Current @Zeiterfassung Date buchungsMonat)\n" + "{\n";
    javaSource.setSourceCode(sourceCode);
    examiner.examine(javaSource);
    assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
    Dependency dependency;
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
    assertEquals(DependencyType.INJECT, dependency.getDependencyType());
    assertEquals("ZeiterfassungEingabeModel", dependency.getJavaSourceFrom().getName());
    assertEquals("Date", dependency.getJavaSourceTo().getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 17 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency in project visualee by Thomas-S-B.

the class DependencyContainer method getFilteredJavaSources.

// TODO simplify
public Set<JavaSource> getFilteredJavaSources(DependencyFilter filter) {
    Set<JavaSource> filteredJavaSources = new HashSet<>();
    if (filter != null && filter.isDirectlyConnected()) {
        DependencyType primaryType = filter.getFilterTypes().get(0);
        for (Dependency d : getDependenciesOfType(primaryType)) {
            JavaSource to = d.getJavaSourceTo();
            List<Dependency> injects = new ArrayList<>();
            for (DependencyType dFilter : filter.getFilterTypes()) {
                if (!dFilter.equals(primaryType)) {
                    injects.addAll(findAllDependenciesWith(to, dFilter));
                }
            }
            if (injects.size() > 0) {
                filteredJavaSources.add(d.getJavaSourceFrom());
                filteredJavaSources.add(to);
                for (Dependency inject : injects) {
                    filteredJavaSources.add(inject.getJavaSourceFrom());
                }
            }
        }
    } else {
        for (Dependency dependency : DEPENDENCIES) {
            if (filter == null || filter.contains(dependency.getDependencyType())) {
                filteredJavaSources.add(dependency.getJavaSourceFrom());
                filteredJavaSources.add(dependency.getJavaSourceTo());
            }
        }
    }
    return filteredJavaSources;
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) DependencyType(de.strullerbaumann.visualee.dependency.entity.DependencyType) ArrayList(java.util.ArrayList) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) HashSet(java.util.HashSet)

Example 18 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency in project visualee by Thomas-S-B.

the class Examiner method createDependency.

// ### TODO simplifizieren, Möglichkeit schaffen, dass neue JavaSourcen über eine Factory gebaut werden
// und dann kann man da den isOK an einer Stelle einbauen. Also new JavaSource suchen und diese in die Factory
// JavaSourceFactory.getForName(String className) oder so und die liefert null wenn gefiltert
// Schaffen das JAvaSOurce nicht direkt instanziiert werden kann siehe
// http://stackoverflow.com/questions/1326230/avoid-instantiating-a-class-in-java
protected void createDependency(String classNameIn, DependencyType type, JavaSource javaSource) {
    // Need to convert primitives-names to wrapper-classnames (e.g. @Produces Integer xyz => @Inject int xyz
    String className = cleanPrimitives(classNameIn);
    JavaSource injectedJavaSource = JavaSourceContainer.getInstance().getJavaSourceByName(className);
    if (injectedJavaSource == null) {
        // Generate a new JavaSource, which is not explicit in the sources (e.g. Integer, String etc.)
        // ### TODO injectedJavaSource = new JavaSource(className);
        injectedJavaSource = JavaSourceFactory.getInstance().newJavaSource(className);
        // ### TODO auch sollen keine Dummies mehr angelegt werden da soll der Filter auch greifen
        if (injectedJavaSource != null) {
            JavaSourceContainer.getInstance().add(injectedJavaSource);
            if (isAValidClassName(className)) {
                LogProvider.getInstance().debug("Created new JavaSource with name: " + className);
            } else {
                LogProvider.getInstance().debug("Created new JavaSource (type=" + type.name() + ") with a suspicious name: " + className + " - Found in " + javaSource.getFullClassName());
            }
        } else {
            LogProvider.getInstance().debug("Didn't created new JavaSource, because of filter, with name: " + className);
        }
    }
    // ### TODO Dependency nur anlegen,  wenn JavaSource nicht gefiltert
    if (injectedJavaSource != null) {
        Dependency dependency = new Dependency(type, javaSource, injectedJavaSource);
        DependencyContainer.getInstance().add(dependency);
    }
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency)

Example 19 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency in project visualee by Thomas-S-B.

the class GraphCreator method buildJSONLinks.

static JsonArrayBuilder buildJSONLinks(DependencyFilter filter) {
    JsonArrayBuilder linksArray = Json.createArrayBuilder();
    int value = 1;
    Set<JavaSource> relevantClasses = DependencyContainer.getInstance().getFilteredJavaSources(filter);
    for (JavaSource javaSource : relevantClasses) {
        for (Dependency d : DependencyContainer.getInstance().getDependencies(javaSource)) {
            DependencyType type = d.getDependencyType();
            if (filter == null || (relevantClasses.contains(d.getJavaSourceTo()) && filter.contains(type))) {
                int source = d.getJavaSourceFrom().getId();
                int target = d.getJavaSourceTo().getId();
                JsonObjectBuilder linksBuilder = Json.createObjectBuilder();
                if (DependencyType.isInverseDirection(type)) {
                    linksBuilder.add("source", source);
                    linksBuilder.add("target", target);
                } else {
                    linksBuilder.add("source", target);
                    linksBuilder.add("target", source);
                }
                linksBuilder.add("value", value);
                linksBuilder.add("type", type.toString());
                linksArray.add(linksBuilder);
            }
        }
    }
    return linksArray;
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) DependencyType(de.strullerbaumann.visualee.dependency.entity.DependencyType) JsonArrayBuilder(javax.json.JsonArrayBuilder) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 20 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency in project visualee by Thomas-S-B.

the class DependencyContainerTest method testGetRelevantClassesFilter.

@Test
public void testGetRelevantClassesFilter() {
    JavaSourceContainer.getInstance().clear();
    int count = 10;
    int count1 = 0;
    int count2 = 0;
    DependencyType type1 = DependencyType.INJECT;
    DependencyType type2 = DependencyType.EJB;
    JavaSource javaSourceType1 = JavaSourceFactory.getInstance().newJavaSource("Testinject");
    JavaSourceContainer.getInstance().add(javaSourceType1);
    JavaSource javaSourceType2 = JavaSourceFactory.getInstance().newJavaSource("TestEjb");
    JavaSourceContainer.getInstance().add(javaSourceType2);
    for (int i = 0; i < count; i++) {
        String name = "Testclass " + i;
        JavaSource javaSource = JavaSourceFactory.getInstance().newJavaSource(name);
        List<Dependency> injected = new ArrayList<>();
        if (i % 2 > 0) {
            injected.add(new Dependency(type1, javaSource, javaSourceType1));
            count1++;
        } else {
            injected.add(new Dependency(type2, javaSource, javaSourceType2));
            count2++;
        }
        JavaSourceContainer.getInstance().add(javaSource);
        DependencyContainer.getInstance().addAll(injected);
    }
    // + 1 because of the injected javaSourceType1
    DependencyFilter filter1 = new DependencyFilter().addType(type1);
    assertEquals(count1 + 1, DependencyContainer.getInstance().getFilteredJavaSources(filter1).size());
    // + 1 because of the injected javaSourceType2
    DependencyFilter filter2 = new DependencyFilter().addType(type2);
    assertEquals(count2 + 1, DependencyContainer.getInstance().getFilteredJavaSources(filter2).size());
}
Also used : DependencyType(de.strullerbaumann.visualee.dependency.entity.DependencyType) JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) ArrayList(java.util.ArrayList) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Aggregations

Dependency (de.strullerbaumann.visualee.dependency.entity.Dependency)33 JavaSource (de.strullerbaumann.visualee.source.entity.JavaSource)31 Test (org.junit.Test)28 DependencyType (de.strullerbaumann.visualee.dependency.entity.DependencyType)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 Ignore (org.junit.Ignore)1