Skip to content

Commit

Permalink
Merge pull request #21 from Saxonica/fix-package-again
Browse files Browse the repository at this point in the history
Fix package again
  • Loading branch information
ndw authored Oct 4, 2024
2 parents 4c3542b + 1280292 commit bf7e63c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 46 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ incomplete or incorrect, please [open an issue](https://github.com/Saxonica/xmld

## Change log

* **0.14.0** Fixed package name

The package name was sometimes (e.g., in the superclass type)
incorrect (missed in the fix to [#10](https://github.com/Saxonica/xmldoclet/issues/10)).

* **0.13.0** Handle type parameters on methods, renamed a few attributes

Extended support for type parameters to methods. On several elements, renamed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docletVersion=0.13.0
docletVersion=0.14.0
schemaVersion=0.13.0
docletTitle=XmlDoclet
docletName=xmldoclet
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ 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", pkgName);
attr.put("name", typeName);
attr.put("package", TypeUtils.getPackage(element));
attr.put("name", TypeUtils.getType(element));
attr.put("nesting", element.getNestingKind().toString().toLowerCase());
attr.putAll(modifierAttributes(element));

Expand Down Expand Up @@ -97,42 +94,6 @@ 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>
Expand Down Expand Up @@ -234,9 +195,9 @@ private void showSuperclass(TypeElement element, DeclaredType superclass, Implem

private void showInterfaces(TypeElement element, DeclaredType xinter, Implemented impl) {
Map<String, String> attr = new HashMap<>();
attr.put("name", xinter.asElement().getSimpleName().toString());
attr.put("name", TypeUtils.getType(xinter.asElement()));
attr.put("fullname", xinter.asElement().toString());
attr.put("package", xinter.asElement().getEnclosingElement().toString());
attr.put("package", TypeUtils.getPackage(xinter.asElement()));
builder.startElement("interface", attr);

for (TypeMirror tm : xinter.getTypeArguments()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.saxonica.xmldoclet.builder.XmlProcessor;

import javax.lang.model.element.Element;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.*;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -60,9 +63,9 @@ private static void primitiveType(XmlProcessor builder, String wrapper, TypeMirr
private static void declaredType(XmlProcessor builder, String wrapper, DeclaredType dtype) {
Map<String, String> attr = new HashMap<>();

attr.put("name", dtype.asElement().getSimpleName().toString());
attr.put("name", getType(dtype.asElement()));
attr.put("fullname", dtype.asElement().toString());
attr.put("package", dtype.asElement().getEnclosingElement().toString());
attr.put("package", getPackage(dtype.asElement()));
builder.startElement(wrapper, attr);

for (TypeMirror tm : dtype.getTypeArguments()) {
Expand All @@ -73,6 +76,42 @@ private static void declaredType(XmlProcessor builder, String wrapper, DeclaredT
builder.endElement(wrapper);
}

/**
* Find the element's package.
* <p>For nested classes, we may have to look up several times.</p>
* @return the package name
*/
public static 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
*/
public static 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();
}

private static void wildcardType(XmlProcessor builder, String wrapper, WildcardType wtype) {
Map<String, String> attr = new HashMap<>();

Expand Down

0 comments on commit bf7e63c

Please sign in to comment.