Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix types and interfaces #12

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ incomplete or incorrect, please [open an issue](https://github.com/Saxonica/xmld

## Change log

* **0.9.0** Fixed package and type names; fixed interface lists

Package and type names are correct (fixed [#10](https://github.com/Saxonica/xmldoclet/issues/10)),
and the interfaces of supertypes are included in the list of implemented interfaces
(fixed [#11](https://github.com/Saxonica/xmldoclet/issues/11)).

* **0.8.0** Fixed method names

Output the “simple” method name in the name attribute on method elements.
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docletVersion=0.8.0
schemaVersion=0.8.0
docletVersion=0.9.0
schemaVersion=0.9.0
docletTitle=XmlDoclet
docletName=xmldoclet
25 changes: 25 additions & 0 deletions sample/src/main/java/org/example/ClassWithNested.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.example;

public abstract class ClassWithNested implements InterfaceA, InterfaceB {
/**
* Something goes here
* @return true
*/
public boolean isSomething() {
return true;
}

public abstract static class Nested<T extends Impl> extends ClassWithNested implements InterfaceAB {
protected T[] items;
public Nested(T[] items) {
this.items = items;
}
public void a() {}

public static class DoublyNested extends ClassWithNested {
public DoublyNested() {}
public void a() {}
public void b() {}
}
}
}
5 changes: 5 additions & 0 deletions sample/src/main/java/org/example/InterfaceB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.example;

public interface InterfaceB {
void b();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ public XmlTypeElement(XmlProcessor xmlproc, TypeElement element) {
public void scan(DocTree tree) {
String s = element.getQualifiedName().toString();

String pkgName = getPackage(element);
String typeName = getType(element);

Map<String, String> attr = new HashMap<>();
attr.put("fullname", element.getQualifiedName().toString());
attr.put("package", element.getEnclosingElement().toString());
attr.put("type", element.getSimpleName().toString());
attr.put("package", pkgName);
attr.put("type", typeName);
attr.put("nesting", element.getNestingKind().toString().toLowerCase());
attr.putAll(modifierAttributes(element));

Expand All @@ -42,9 +45,10 @@ public void scan(DocTree tree) {
showSuperclass(element, (DeclaredType) element.getSuperclass(), impl);
}

if (!element.getInterfaces().isEmpty()) {
List<TypeMirror> interfaces = getInterfaces(element);
if (!interfaces.isEmpty()) {
builder.startElement("interfaces");
for (TypeMirror tm : element.getInterfaces()) {
for (TypeMirror tm : interfaces) {
// Reset the implemented list each time
Implemented classimpl = new Implemented(impl);
updateImplemented(element, classimpl);
Expand Down Expand Up @@ -79,6 +83,62 @@ public void scan(DocTree tree) {
builder.endElement(typeName());
}

/**
* Find the element's package.
* <p>For nested classes, we may have to look up several times.</p>
* @return the package name
*/
private String getPackage(Element element) {
Element enclosing = element.getEnclosingElement();

if (enclosing == null) {
return "";
}

if (enclosing instanceof PackageElement) {
return enclosing.toString();
}

return getPackage(enclosing);
}

/**
* Find the name of this type; that's our ancestor names if this is a nested class.
* @param element The element
* @return The type name
*/
private String getType(Element element) {
Element enclosing = element.getEnclosingElement();
if (enclosing instanceof TypeElement) {
String stype = getType(enclosing);
if (!"".equals(stype)) {
return stype + "." + element.getSimpleName().toString();
}
return element.getSimpleName().toString();
}
return element.getSimpleName().toString();
}

/**
* Find the implemented interfaces
* <p>This includes the interfaces of any classes we extend.</p>
* @param element the starting element
* @return list of interfaces
*/
private List<TypeMirror> getInterfaces(TypeElement element) {
List<TypeMirror> interfaces = new ArrayList<>(element.getInterfaces());

TypeMirror superClass = element.getSuperclass();
if (superClass instanceof DeclaredType) {
Element superElem = ((DeclaredType) superClass).asElement();
if (superElem instanceof TypeElement) {
interfaces.addAll(getInterfaces((TypeElement) superElem));
}
}

return interfaces;
}

private void showSuperclass(TypeElement element, DeclaredType superclass, Implemented impl) {
if ("java.lang.Object".equals(superclass.toString())) {
return;
Expand Down
Loading