Skip to content

Commit

Permalink
Fix #152 by filtering on 'isIncluded' for inner classes too
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoerdtalsma committed Feb 27, 2019
1 parent 099705d commit 21ea1bc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public Diagram createClassDiagram(TypeElement classElement) {
classElement.getEnclosedElements().stream()
.filter(child -> child.getKind().isInterface() || child.getKind().isClass())
.filter(TypeElement.class::isInstance).map(TypeElement.class::cast)
.filter(env::isIncluded)
.forEach(innerclassElem -> {
Type innerType = createType(null, innerclassElem);
classDiagram.addChild(innerType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2016-2019 Talsma ICT
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.talsmasoftware.umldoclet.features;

import nl.talsmasoftware.umldoclet.UMLDoclet;
import nl.talsmasoftware.umldoclet.util.Testing;
import org.junit.Test;

import java.io.File;
import java.util.spi.ToolProvider;
import java.util.stream.Stream;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

public class Issue152InnerClassIncludeVisibilityTest {
private static final String packageName = Issue152InnerClassIncludeVisibilityTest.class.getPackageName();
private static final File outputdir = new File("target/issues/152");

@Test
public void testPublicInnerClassVisibility() {
assertThat("Javadoc result", ToolProvider.findFirst("javadoc").get().run(
System.out, System.err,
"-d", outputdir.getPath(),
"-doclet", UMLDoclet.class.getName(),
"-quiet", "-createPumlFiles",
"--show-types", "public",
"-sourcepath", "src/test/java",
packageName
), is(0));
File dir = new File(outputdir, packageName.replace('.', '/'));

String packageUml = Testing.read(new File(dir, "package.puml"));
assertThat("Package uml", packageUml, allOf(
containsString("PublicClass.PublicInnerClass"),
not(containsString("PublicClass.ProtectedInnerClass")),
not(containsString("PublicClass.PackageProtectedInnerClass")),
not(containsString("PublicClass.PrivateInnerClass"))
));
String classUml = Testing.read(new File(dir, "PublicClass.puml"));
assertThat("Class uml", classUml, allOf(
containsString("PublicClass.PublicInnerClass"),
not(containsString("PublicClass.ProtectedInnerClass")),
not(containsString("PublicClass.PackageProtectedInnerClass")),
not(containsString("PublicClass.PrivateInnerClass"))
));
Stream.of(".html", ".puml", ".svg").forEach(extension -> {
assertThat("public innerclass " + extension, new File(dir, "PublicClass.PublicInnerClass" + extension).exists(), is(true));
assertThat("protected innerclass " + extension, new File(dir, "PublicClass.ProtectedInnerClass" + extension).exists(), is(false));
assertThat("package innerclass " + extension, new File(dir, "PublicClass.PackageProtectedInnerClass" + extension).exists(), is(false));
assertThat("private innerclass " + extension, new File(dir, "PublicClass.PrivateInnerClass" + extension).exists(), is(false));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ protected String getProtectedValue() {
public String getPublicValue() {
return publicField;
}

private static final class PrivateInnerClass {
}

static final class PackageProtectedInnerClass {
}

protected static final class ProtectedInnerClass {
}

public static final class PublicInnerClass {
}
}

0 comments on commit 21ea1bc

Please sign in to comment.