maxVisibilityMethods
Description
With this configuration option you can filter out methods from the diagram by their visibility in Java.
The following options are supported:
-
PUBLIC
only public methods will be displayed -
PROTECTED
only public and protected methods will be displayed -
PACKAGE_PRIVATE
only public, protected and package_private methods will be displayed -
PRIVATE
all fields will be displayed if not removed or ignored by other parameters
Example
Maximum visibility public
Here is an example from the JUnit tests using this configuration parameter:
String filename = "class/0014_max_visibility_methods_public.txt";
classLoader.loadClass("de.elnarion.test.domain.t0014.Testclass");
List<String> scanPackages = new ArrayList<>();
scanPackages.add("de.elnarion.test.domain.t0014");
PlantUMLClassDiagramConfig config = new PlantUMLClassDiagramConfigBuilder(scanPackages)
.withMaximumMethodVisibility(VisibilityType.PUBLIC).build(); (1)
PlantUMLClassDiagramGenerator generator = new PlantUMLClassDiagramGenerator(config);
String result = generator.generateDiagramText();
String expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource(filename)), StandardCharsets.UTF_8);
assertNotNull(result);
assertNotNull(expectedDiagramText);
assertEquals(expectedDiagramText.replaceAll("\\s+", ""), result.replaceAll("\\s+", ""));
which is rendered this way:
and produces this PlantUML diagram text:
@startuml
class de.elnarion.test.domain.t0014.Testclass {
{method} +doSomething4() : void
}
@enduml
Maximum visibility protected
Here is an example from the JUnit tests using this configuration parameter:
config = new PlantUMLClassDiagramConfigBuilder(scanPackages)
.withMaximumMethodVisibility(VisibilityType.PROTECTED).build(); (1)
generator = new PlantUMLClassDiagramGenerator(config);
result = generator.generateDiagramText();
filename = "class/0014_max_visibility_methods_protected.txt";
expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource(filename)), StandardCharsets.UTF_8);
assertNotNull(result);
assertNotNull(expectedDiagramText);
assertEquals(expectedDiagramText.replaceAll("\\s+", ""), result.replaceAll("\\s+", ""));
which is rendered this way:
and produces this PlantUML diagram text:
@startuml
class de.elnarion.test.domain.t0014.Testclass {
{method} #doSomething3() : void
{method} +doSomething4() : void
}
@enduml
Maximum visibility package private
Here is an example from the JUnit tests using this configuration parameter:
config = new PlantUMLClassDiagramConfigBuilder(scanPackages)
.withMaximumMethodVisibility(VisibilityType.PACKAGE_PRIVATE).build(); (1)
generator = new PlantUMLClassDiagramGenerator(config);
result = generator.generateDiagramText();
filename = "class/0014_max_visibility_methods_package_private.txt";
expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource(filename)), StandardCharsets.UTF_8);
assertNotNull(result);
assertNotNull(expectedDiagramText);
assertEquals(expectedDiagramText.replaceAll("\\s+", ""), result.replaceAll("\\s+", ""));
which is rendered this way:
and produces this PlantUML diagram text:
@startuml
class de.elnarion.test.domain.t0014.Testclass {
{method} ~doSomething2() : void
{method} #doSomething3() : void
{method} +doSomething4() : void
}
@enduml
Maximum visibility private
Here is an example from the JUnit tests using this configuration parameter:
config = new PlantUMLClassDiagramConfigBuilder(scanPackages).withMaximumMethodVisibility(VisibilityType.PRIVATE)
.build(); (1)
generator = new PlantUMLClassDiagramGenerator(config);
result = generator.generateDiagramText();
filename = "class/0014_max_visibility_methods_private.txt";
expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource(filename)), StandardCharsets.UTF_8);
assertNotNull(result);
assertNotNull(expectedDiagramText);
assertEquals(expectedDiagramText.replaceAll("\\s+", ""), result.replaceAll("\\s+", ""));
which is rendered this way:
and produces this PlantUML diagram text:
@startuml
class de.elnarion.test.domain.t0014.Testclass {
{method} -doSomething1() : void
{method} ~doSomething2() : void
{method} #doSomething3() : void
{method} +doSomething4() : void
}
@enduml