From 03e4ea51962566f36991a1a59d00a7fc91494d82 Mon Sep 17 00:00:00 2001 From: Sjoerd Talsma Date: Fri, 24 Nov 2023 19:33:29 +0100 Subject: [PATCH] Fix new 'package' usage for recent PlantUML versions. Signed-off-by: Sjoerd Talsma --- .../umldoclet/javadoc/TypeNameVisitor.java | 24 +++++++++---- .../umldoclet/javadoc/UMLFactory.java | 36 +++++++++++-------- .../talsmasoftware/umldoclet/uml/Diagram.java | 6 ++-- .../umldoclet/uml/Namespace.java | 4 +-- .../umldoclet/uml/PackageDiagram.java | 16 ++++++++- .../umldoclet/uml/TypeName.java | 23 +++++++----- .../Issue124PropertiesAsFieldsTest.java | 5 +-- .../issues/Bug107DefaultPackageTest.java | 4 +-- .../issues/Issue30JavaBeanPropertiesTest.java | 8 ++--- .../issues/Issue71DeprecationTest.java | 4 +-- .../bug146/Bug146SkipSuperclassTest.java | 6 ++-- .../umldoclet/uml/ClassDiagramTest.java | 6 ++-- .../uml/util/UmlPostProcessorsTest.java | 16 ++++++--- 13 files changed, 104 insertions(+), 54 deletions(-) diff --git a/src/main/java/nl/talsmasoftware/umldoclet/javadoc/TypeNameVisitor.java b/src/main/java/nl/talsmasoftware/umldoclet/javadoc/TypeNameVisitor.java index 9a3af2ed2..a2d506df8 100644 --- a/src/main/java/nl/talsmasoftware/umldoclet/javadoc/TypeNameVisitor.java +++ b/src/main/java/nl/talsmasoftware/umldoclet/javadoc/TypeNameVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import nl.talsmasoftware.umldoclet.uml.TypeName; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.QualifiedNameable; import javax.lang.model.type.ArrayType; import javax.lang.model.type.DeclaredType; @@ -75,17 +76,18 @@ private TypeName _visit(TypeMirror type, Void parameter) { public TypeName visitPrimitive(PrimitiveType primitiveType, Void parameter) { // "byte", "char", "short", "int", "long", "float", "double", "boolean" final String primitive = primitiveType.getKind().name().toLowerCase(); - return new TypeName(primitive, primitive); + return new TypeName(null, primitive, primitive); } @Override public TypeName visitNoType(NoType noType, Void parameter) { // "void", "package", "module", "none" final String none = noType.getKind().name().toLowerCase(); - return new TypeName(none, none); + return new TypeName(null, none, none); } @Override + public TypeName visitDeclared(DeclaredType declaredType, Void parameter) { final Element el = declaredType.asElement(); final String simpleName = el.getSimpleName().toString(); @@ -94,7 +96,17 @@ public TypeName visitDeclared(DeclaredType declaredType, Void parameter) { final TypeName[] generics = declaredType.getTypeArguments().stream() .map(generic -> _visit(generic, parameter)) .toArray(TypeName[]::new); - return new TypeName(simpleName, qualifiedName, generics); + final String packagename; + + Element enclosingElement = el.getEnclosingElement(); + if (enclosingElement.getKind().isInterface() || enclosingElement.getKind().isClass()) + { + packagename = visit(enclosingElement.asType()).packagename; + } else { + int dot = qualifiedName.lastIndexOf('.'); + packagename = dot > 0 ? qualifiedName.substring(0, dot) : null; + } + return new TypeName(packagename, simpleName, qualifiedName, generics); } @Override @@ -115,7 +127,6 @@ public TypeName visitTypeVariable(TypeVariable typeVariable, Void parameter) { TypeMirror lowerBound = typeVariable.getLowerBound(); if (lowerBound != null && !NO_KNOWN_TYPES.contains(lowerBound.getKind())) { return TypeName.Variable.superBound(typeVariable.toString(), _visit(lowerBound, parameter)); - } return defaultAction(typeVariable, parameter); @@ -136,7 +147,8 @@ protected TypeName defaultAction(TypeMirror tp, Void parameter) { String qualified = tp.toString(); int lt = qualified.lastIndexOf('<'); int dot = (lt < 0 ? qualified : qualified.substring(0, lt)).lastIndexOf('.'); - return new TypeName(qualified.substring(dot + 1), qualified); + String packagename = dot < 0 ? null : qualified.substring(0, dot); + return new TypeName(packagename, qualified.substring(dot + 1), qualified); } } diff --git a/src/main/java/nl/talsmasoftware/umldoclet/javadoc/UMLFactory.java b/src/main/java/nl/talsmasoftware/umldoclet/javadoc/UMLFactory.java index e4a60488f..c3540a31c 100644 --- a/src/main/java/nl/talsmasoftware/umldoclet/javadoc/UMLFactory.java +++ b/src/main/java/nl/talsmasoftware/umldoclet/javadoc/UMLFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -202,7 +202,7 @@ public Diagram createPackageDiagram(PackageElement packageElement) { Map> foreignTypes = new LinkedHashMap<>(); List references = new ArrayList<>(); - Namespace namespace = createPackage(packageDiagram, packageElement, foreignTypes, references); + Namespace namespace = createPackage(packageDiagram, packageElement, foreignTypes, references, "::"); packageDiagram.addChild(namespace); // Filter "java.lang" or "java.util" references that occur >= 3 times @@ -233,7 +233,6 @@ public Diagram createPackageDiagram(PackageElement packageElement) { .forEach(packageDiagram::addChild); namespace.addChild(UmlCharacters.NEWLINE); - references.stream().map(Reference::canonical).forEach(namespace::addChild); if (config.methods().javaBeanPropertiesAsFields()) { namespace.getChildren().stream() @@ -241,6 +240,9 @@ public Diagram createPackageDiagram(PackageElement packageElement) { .forEach(POST_PROCESSORS.javaBeanPropertiesAsFieldsPostProcessor()); } + if (!references.isEmpty()) packageDiagram.addChild(UmlCharacters.NEWLINE); + references.stream().map(Reference::canonical).forEach(packageDiagram::addChild); + return packageDiagram; } @@ -438,7 +440,7 @@ private void addForeignType(Map> foreignTypes, Element } private Collection findPackageReferences( - Namespace namespace, Map> foreignTypes, TypeElement typeElement, Type type) { + Namespace namespace, Map> foreignTypes, TypeElement typeElement, Type type, String separator) { Collection references = new LinkedHashSet<>(); // Superclass reference. @@ -452,9 +454,9 @@ private Collection findPackageReferences( TypeName superclassName = TypeNameVisitor.INSTANCE.visit(superclassType); if (!config.excludedTypeReferences().contains(superclassName.qualified)) { references.add(new Reference( - Reference.from(type.getName().qualified, null), + Reference.from(type.getName().getQualified(separator), null), "--|>", - Reference.to(superclassName.qualified, null))); + Reference.to(superclassName.getQualified(separator), null))); if (!namespace.contains(superclassName)) { addForeignType(foreignTypes, superclassElement); } @@ -466,9 +468,9 @@ private Collection findPackageReferences( TypeName interfaceName = TypeNameVisitor.INSTANCE.visit(interfaceType); if (!config.excludedTypeReferences().contains(interfaceName.qualified)) { references.add(new Reference( - Reference.from(type.getName().qualified, null), + Reference.from(type.getName().getQualified(separator), null), interfaceRefTypeFrom(type), - Reference.to(interfaceName.qualified, null))); + Reference.to(interfaceName.getQualified(separator), null))); // TODO Figure out what to do IF the interface is found BUT has a different typename if (!namespace.contains(interfaceName)) { addForeignType(foreignTypes, env.getTypeUtils().asElement(interfaceType)); @@ -480,7 +482,10 @@ private Collection findPackageReferences( ElementKind enclosingKind = typeElement.getEnclosingElement().getKind(); if (enclosingKind.isClass() || enclosingKind.isInterface()) { TypeName parentType = TypeNameVisitor.INSTANCE.visit(typeElement.getEnclosingElement().asType()); - references.add(new Reference(Reference.from(parentType.qualified, null), "+--", Reference.to(type.getName().qualified, null))); + references.add(new Reference( + Reference.from(parentType.getQualified(separator), null), + "+--", + Reference.to(type.getName().getQualified(separator), null))); // No check needed whether parent type lives in our namespace. } @@ -494,9 +499,9 @@ private Collection findPackageReferences( TypeNameWithCardinality fieldType = typeNameWithCardinality.apply(field.asType()); if (namespace.contains(fieldType.typeName)) { addReference(references, new Reference( - Reference.from(type.getName().qualified, null), + Reference.from(type.getName().getQualified(separator), null), "-->", - Reference.to(fieldType.typeName.qualified, fieldType.cardinality), + Reference.to(fieldType.typeName.getQualified(separator), fieldType.cardinality), fieldName)); type.removeChildren(child -> child instanceof Field && ((Field) child).name.equals(fieldName)); } @@ -513,9 +518,9 @@ private Collection findPackageReferences( TypeNameWithCardinality returnType = typeNameWithCardinality.apply(propertyType(method)); if (namespace.contains(returnType.typeName)) { addReference(references, new Reference( - Reference.from(type.getName().qualified, null), + Reference.from(type.getName().getQualified(separator), null), "-->", - Reference.to(returnType.typeName.qualified, returnType.cardinality), + Reference.to(returnType.typeName.getQualified(separator), returnType.cardinality), propertyName)); type.removeChildren(child -> child instanceof Method && ((Method) child).name.equals(method.getSimpleName().toString())); @@ -591,7 +596,8 @@ private static Stream innerTypes(TypeElement type) { Namespace createPackage(Diagram diagram, PackageElement packageElement, Map> foreignTypes, - List references) { + List references, + String referenceSeparator) { final ModuleElement module = env.getElementUtils().getModuleOf(packageElement); Namespace pkg = new Namespace(diagram, packageElement.getQualifiedName().toString(), module == null ? null : module.getQualifiedName().toString()); @@ -603,7 +609,7 @@ Namespace createPackage(Diagram diagram, .filter(env::isIncluded) .map(typeElement -> { Type type = createAndPopulateType(pkg, typeElement); - references.addAll(findPackageReferences(pkg, foreignTypes, typeElement, type)); + references.addAll(findPackageReferences(pkg, foreignTypes, typeElement, type, referenceSeparator)); return type; }) .flatMap(type -> Stream.of(UmlCharacters.NEWLINE, type)) diff --git a/src/main/java/nl/talsmasoftware/umldoclet/uml/Diagram.java b/src/main/java/nl/talsmasoftware/umldoclet/uml/Diagram.java index 517683e58..35101a7a4 100644 --- a/src/main/java/nl/talsmasoftware/umldoclet/uml/Diagram.java +++ b/src/main/java/nl/talsmasoftware/umldoclet/uml/Diagram.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,6 @@ public IPW writeTo(IPW output) { IndentingPrintWriter indented = output.indent(); writeCustomDirectives(config.customPlantumlDirectives(), indented); writeChildrenTo(indented); - indented.newline(); writeFooterTo(indented); output.append("@enduml").newline(); return output; @@ -71,6 +70,9 @@ public IPW writeTo(IPW output) { protected IPW writeCustomDirectives(List customDirectives, IPW output) { customDirectives.forEach(output::println); + if (!customDirectives.isEmpty()) { + output.newline(); + } return output; } diff --git a/src/main/java/nl/talsmasoftware/umldoclet/uml/Namespace.java b/src/main/java/nl/talsmasoftware/umldoclet/uml/Namespace.java index 7e71b73e0..dc4764979 100644 --- a/src/main/java/nl/talsmasoftware/umldoclet/uml/Namespace.java +++ b/src/main/java/nl/talsmasoftware/umldoclet/uml/Namespace.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,7 @@ private IPW writeNameTo(IPW output) { @Override public IPW writeTo(IPW output) { - writeNameTo(output.append("namespace").whitespace()).append('{').newline(); + writeNameTo(output.append("package").whitespace()).append('{').newline(); writeChildrenTo(output.indent()); output.append('}').newline(); return output; diff --git a/src/main/java/nl/talsmasoftware/umldoclet/uml/PackageDiagram.java b/src/main/java/nl/talsmasoftware/umldoclet/uml/PackageDiagram.java index c1e71c45f..c80d79bed 100644 --- a/src/main/java/nl/talsmasoftware/umldoclet/uml/PackageDiagram.java +++ b/src/main/java/nl/talsmasoftware/umldoclet/uml/PackageDiagram.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,12 @@ package nl.talsmasoftware.umldoclet.uml; import nl.talsmasoftware.umldoclet.configuration.Configuration; +import nl.talsmasoftware.umldoclet.rendering.indent.IndentingPrintWriter; import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import static java.util.Objects.requireNonNull; @@ -25,6 +29,8 @@ * @author Sjoerd Talsma */ public class PackageDiagram extends Diagram { + private static final String SEPARATOR_DIRECTIVE = "set separator "; + public static final String SEPARATOR = "::"; final String moduleName; final String packageName; @@ -36,6 +42,14 @@ public PackageDiagram(Configuration config, String packageName, String moduleNam this.moduleName = moduleName; } + @Override + protected IPW writeCustomDirectives(List customDirectives, IPW output) { + final List directives = new ArrayList<>(customDirectives == null ? Collections.emptyList() : customDirectives); + directives.removeIf(directive -> directive.startsWith(SEPARATOR_DIRECTIVE)); + directives.add(SEPARATOR_DIRECTIVE + SEPARATOR); + return super.writeCustomDirectives(directives, output); + } + @Override protected File getPlantUmlFile() { if (pumlFile == null) { diff --git a/src/main/java/nl/talsmasoftware/umldoclet/uml/TypeName.java b/src/main/java/nl/talsmasoftware/umldoclet/uml/TypeName.java index 6476a6865..ff5c10d08 100644 --- a/src/main/java/nl/talsmasoftware/umldoclet/uml/TypeName.java +++ b/src/main/java/nl/talsmasoftware/umldoclet/uml/TypeName.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,11 +36,13 @@ * @author Sjoerd Talsma */ public class TypeName { + public final String packagename; public final String simple; public final String qualified; private final TypeName[] generics; - public TypeName(String simpleName, String qualifiedName, TypeName... generics) { + public TypeName(String packagename, String simpleName, String qualifiedName, TypeName... generics) { + this.packagename = packagename; this.simple = simpleName; this.qualified = requireNonNull(qualifiedName, "Type has no qualified name"); this.generics = generics.clone(); @@ -54,16 +56,21 @@ private static boolean isQualified(TypeDisplay display) { return display != null && display.name().startsWith("QUALIFIED"); } + public String getQualified(String separator) { + int plen = packagename == null ? 0 : packagename.length(); + if (qualified.length() > plen && plen > 0 && separator != null && !separator.isEmpty()) { + return packagename + separator + qualified.substring(plen + 1); + } + return qualified; + } + protected String toUml(TypeDisplay display, Namespace namespace) { StringBuilder output = new StringBuilder(); if (display == null) display = TypeDisplay.SIMPLE; if (!TypeDisplay.NONE.equals(display)) try { if (namespace != null && this.qualified.startsWith(namespace.name + ".")) { - String name = this.qualified.substring(namespace.name.length() + 1); - // Workaround for PlantUML problem with namespace and inner classes - if (name.indexOf('.') > 0) name = this.qualified; - output.append(name); + output.append(this.qualified.substring(namespace.name.length() + 1)); } else if (isQualified(display)) { output.append(this.qualified); } else { @@ -120,7 +127,7 @@ public String toString() { public static class Array extends TypeName { private Array(TypeName componentType) { - super(componentType.simple, componentType.qualified, componentType.generics); + super(componentType.packagename, componentType.simple, componentType.qualified, componentType.generics); } public static Array of(TypeName componentType) { @@ -138,7 +145,7 @@ public static class Variable extends TypeName { private final boolean isExtends; private Variable(String variable, TypeName bound, boolean isExtends) { - super(bound.simple, bound.qualified, bound.generics); + super(bound.packagename, bound.simple, bound.qualified, bound.generics); this.variable = variable; this.isExtends = isExtends; } diff --git a/src/test/java/nl/talsmasoftware/umldoclet/features/Issue124PropertiesAsFieldsTest.java b/src/test/java/nl/talsmasoftware/umldoclet/features/Issue124PropertiesAsFieldsTest.java index 7306c5b1f..489bd021d 100644 --- a/src/test/java/nl/talsmasoftware/umldoclet/features/Issue124PropertiesAsFieldsTest.java +++ b/src/test/java/nl/talsmasoftware/umldoclet/features/Issue124PropertiesAsFieldsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,11 +70,12 @@ public void testPropertiesAsFieldsForPublicClass() { @Test public void testPropertiesAsFieldsForPackageDiagram() { String umlFileName = StandardJavaBean.class.getPackageName().replace('.', '/') + "/package.puml"; + String nameInPackage = StandardJavaBean.class.getPackageName() + "::" + StandardJavaBean.class.getSimpleName(); String uml = TestUtil.read(new File(outputdir, umlFileName)); assertThat(uml, containsString("+stringValue: String")); assertThat(uml, containsString("+intValue: int")); assertThat(uml, containsString("+booleanValue: boolean")); - assertThat(uml, containsString("StandardJavaBean --> StandardJavaBean: child")); + assertThat(uml, containsString(nameInPackage + " --> " + nameInPackage + ": child")); assertThat(uml, not(containsString("getStringValue("))); assertThat(uml, not(containsString("setStringValue("))); diff --git a/src/test/java/nl/talsmasoftware/umldoclet/issues/Bug107DefaultPackageTest.java b/src/test/java/nl/talsmasoftware/umldoclet/issues/Bug107DefaultPackageTest.java index 397f0c4dd..6452be68a 100644 --- a/src/test/java/nl/talsmasoftware/umldoclet/issues/Bug107DefaultPackageTest.java +++ b/src/test/java/nl/talsmasoftware/umldoclet/issues/Bug107DefaultPackageTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ public void testDefaultPackageDocumentation() { ), is(0)); String uml = TestUtil.read(new File("target/issues/107/package.puml")); - assertThat(uml, containsString("namespace unnamed")); + assertThat(uml, containsString("package unnamed")); assertThat(uml, containsString("class Foo")); } diff --git a/src/test/java/nl/talsmasoftware/umldoclet/issues/Issue30JavaBeanPropertiesTest.java b/src/test/java/nl/talsmasoftware/umldoclet/issues/Issue30JavaBeanPropertiesTest.java index 0e9acda93..b2e948457 100644 --- a/src/test/java/nl/talsmasoftware/umldoclet/issues/Issue30JavaBeanPropertiesTest.java +++ b/src/test/java/nl/talsmasoftware/umldoclet/issues/Issue30JavaBeanPropertiesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,19 +62,19 @@ public void testIssue30() { ); String uml = TestUtil.read(new File("target/issues/30/" + packageAsPath + "/package.puml")); - String name = getClass().getName(); String simpleName = getClass().getSimpleName(); + String nameInPackage = getClass().getPackageName() + "::" + simpleName; // someProperty should have been replaced by referene: assertThat(uml, not(containsString("+getSomeProperty()"))); assertThat(uml, not(containsString("+setSomeProperty"))); assertThat(uml, either(containsString(simpleName + " --> " + simpleName + ": someProperty")) - .or(containsString(name + " --> " + name + ": someProperty"))); + .or(containsString(nameInPackage + " --> " + nameInPackage + ": someProperty"))); // someValue must not be replaced by reference: assertThat(uml, containsString("+getSomeValue(Boolean): " + simpleName)); assertThat(uml, not(either(containsString(simpleName + " --> " + simpleName + ": someValue")) - .or(containsString(name + " --> " + name + ": someValue")))); + .or(containsString(nameInPackage + " --> " + nameInPackage + ": someValue")))); } } diff --git a/src/test/java/nl/talsmasoftware/umldoclet/issues/Issue71DeprecationTest.java b/src/test/java/nl/talsmasoftware/umldoclet/issues/Issue71DeprecationTest.java index c5398be80..6be51ed47 100644 --- a/src/test/java/nl/talsmasoftware/umldoclet/issues/Issue71DeprecationTest.java +++ b/src/test/java/nl/talsmasoftware/umldoclet/issues/Issue71DeprecationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -80,7 +80,7 @@ public void testClassDeprecatedByAnnotation() { @Test public void testClassDeprecatedByJavadoc() { - assertThat(packageUml, containsString("class " + getClass().getName() + ".MoreDeprecation <>")); + assertThat(packageUml, containsString("class " + getClass().getSimpleName() + ".MoreDeprecation <>")); } @Test diff --git a/src/test/java/nl/talsmasoftware/umldoclet/issues/bug146/Bug146SkipSuperclassTest.java b/src/test/java/nl/talsmasoftware/umldoclet/issues/bug146/Bug146SkipSuperclassTest.java index 8b9aa13b8..87f685bbd 100644 --- a/src/test/java/nl/talsmasoftware/umldoclet/issues/bug146/Bug146SkipSuperclassTest.java +++ b/src/test/java/nl/talsmasoftware/umldoclet/issues/bug146/Bug146SkipSuperclassTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,8 +52,8 @@ public static void generateJavadoc() { @Test public void testPackageProtectedSuperclassShouldBeSkipped() { assertThat(packageUml, allOf( - containsString("java.util.AbstractList <|-- PublicTestClass"), - not(containsString("PackageProtectedSuperclass <|-- PublicTestClass")) + containsString("java.util::AbstractList <|-- " + getClass().getPackageName() + "::PublicTestClass"), + not(containsString("PackageProtectedSuperclass")) )); assertThat(classUml, allOf( containsString( diff --git a/src/test/java/nl/talsmasoftware/umldoclet/uml/ClassDiagramTest.java b/src/test/java/nl/talsmasoftware/umldoclet/uml/ClassDiagramTest.java index b7b9e541f..47bac01a4 100644 --- a/src/test/java/nl/talsmasoftware/umldoclet/uml/ClassDiagramTest.java +++ b/src/test/java/nl/talsmasoftware/umldoclet/uml/ClassDiagramTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,14 +65,14 @@ public void testClassWithSuperClassInAnotherPackageRelativePath() { Type bar = new Type( new Namespace(null, "foo.bar", null), Type.Classification.CLASS, - new TypeName("Bar", "foo.bar.Bar")); + new TypeName("foo.bar", "Bar", "foo.bar.Bar")); ClassDiagram classDiagram = new ClassDiagram(config, bar); // Add Superclass com.foo.Foo Type foo = new Type(new Namespace(null, "foo", null), Type.Classification.CLASS, - new TypeName("Foo", "foo.Foo")); + new TypeName("foo", "Foo", "foo.Foo")); classDiagram.addChild(foo); classDiagram.addChild(new Reference( Reference.from("foo.Foo", null), diff --git a/src/test/java/nl/talsmasoftware/umldoclet/uml/util/UmlPostProcessorsTest.java b/src/test/java/nl/talsmasoftware/umldoclet/uml/util/UmlPostProcessorsTest.java index 0db7963ed..bf8afc7d2 100644 --- a/src/test/java/nl/talsmasoftware/umldoclet/uml/util/UmlPostProcessorsTest.java +++ b/src/test/java/nl/talsmasoftware/umldoclet/uml/util/UmlPostProcessorsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Talsma ICT + * Copyright 2016-2023 Talsma ICT * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,20 @@ */ package nl.talsmasoftware.umldoclet.uml.util; -import nl.talsmasoftware.umldoclet.uml.*; +import nl.talsmasoftware.umldoclet.uml.Field; +import nl.talsmasoftware.umldoclet.uml.Method; +import nl.talsmasoftware.umldoclet.uml.Namespace; +import nl.talsmasoftware.umldoclet.uml.Type; import nl.talsmasoftware.umldoclet.uml.Type.Classification; +import nl.talsmasoftware.umldoclet.uml.TypeName; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.fail; public class UmlPostProcessorsTest { @@ -77,6 +84,7 @@ public void testJavaBeanPropertiesAsFielsPostProcessorSimpleAccessors() { private static TypeName typeName(String qualified) { int lastDot = qualified.lastIndexOf('.'); String simpleName = lastDot >= 0 ? qualified.substring(lastDot + 1) : qualified; - return new TypeName(simpleName, qualified); + String packagename = lastDot > 0 ? qualified.substring(0, lastDot) : null; + return new TypeName(packagename, simpleName, qualified); } }