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);
}
}
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;
}
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());
}
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);
}
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());
}
Aggregations