Search in sources :

Example 31 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.

the class JavaSourceInspector method setGroupNrs.

void setGroupNrs() {
    // all javasources from the same package should have the same groupNr
    Map<String, Integer> packagePaths = new HashMap<>();
    int groupNr = 1;
    for (JavaSource javaSource : JavaSourceContainer.getInstance().getJavaSources()) {
        if (!packagePaths.containsKey(javaSource.getPackagePath())) {
            packagePaths.put(javaSource.getPackagePath(), groupNr);
            groupNr++;
        }
    }
    for (JavaSource javaSource : JavaSourceContainer.getInstance().getJavaSources()) {
        int group = packagePaths.get(javaSource.getPackagePath());
        javaSource.setGroup(group);
    }
}
Also used : HashMap(java.util.HashMap) JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource)

Example 32 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource 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 33 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource 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)

Example 34 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.

the class ExaminerTest method testScanAfterClosedParenthesis.

@Test
public void testScanAfterClosedParenthesis() {
    JavaSource javaSource;
    String sourceCode;
    String actual;
    String expected;
    Scanner scanner;
    String currentToken;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
    sourceCode = "@NotNull(groups = PersistenceConstraint.class)\n" + "private Album album;\n";
    javaSource.setSourceCode(sourceCode);
    scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
    // now @NotNull((groups
    currentToken = scanner.next();
    ExaminerImpl.scanAfterClosedParenthesis(currentToken, scanner);
    expected = "Album";
    actual = scanner.next();
    assertEquals(expected, actual);
    javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
    sourceCode = "@NotNull((groups = PersistenceConstraint.class) saddas)\n" + "private Album2 album;\n";
    javaSource.setSourceCode(sourceCode);
    scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
    // now @NotNull((groups
    currentToken = scanner.next();
    ExaminerImpl.scanAfterClosedParenthesis(currentToken, scanner);
    expected = "Album2";
    // scan after private
    actual = scanner.next();
    assertEquals(expected, actual);
    javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
    sourceCode = "@Resource(mappedName=\"java:global/jms/myQueue2\")\n" + "private Album2 album;\n";
    javaSource.setSourceCode(sourceCode);
    scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
    currentToken = scanner.next();
    actual = ExaminerImpl.scanAfterClosedParenthesis(currentToken, scanner);
    expected = "private";
    assertEquals(expected, actual);
}
Also used : Scanner(java.util.Scanner) JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Test(org.junit.Test)

Example 35 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.

the class ExaminerEJBTest method testFindAndSetAttributesEJBSetterWithAnnotations.

@Test
public void testFindAndSetAttributesEJBSetterWithAnnotations() {
    JavaSource javaSource;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("ZeiterfassungEingabeModel");
    sourceCode = "public class ZeiterfassungEingabeModel implements Serializable\n" + "{\n" + "@EJB\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.EJB, 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)

Aggregations

JavaSource (de.strullerbaumann.visualee.source.entity.JavaSource)50 Test (org.junit.Test)44 Dependency (de.strullerbaumann.visualee.dependency.entity.Dependency)31 Scanner (java.util.Scanner)5 DependencyType (de.strullerbaumann.visualee.dependency.entity.DependencyType)3 ArrayList (java.util.ArrayList)3 JsonArrayBuilder (javax.json.JsonArrayBuilder)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 ExaminerInject (de.strullerbaumann.visualee.examiner.cdi.ExaminerInject)1 ExaminerProduces (de.strullerbaumann.visualee.examiner.cdi.ExaminerProduces)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 Ignore (org.junit.Ignore)1