Skip to content

Commit

Permalink
Merge pull request #7 from Saxonica/method-fixes
Browse files Browse the repository at this point in the history
Method fixes
  • Loading branch information
ndw authored Sep 18, 2024
2 parents 77380b3 + 825c659 commit 647ce61
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 22 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,18 @@ incomplete or incorrect, please [open an issue](https://github.com/Saxonica/xmld

## Change log

* **0.6.0** Improved handling of method names and inheritance

Changed the “name” of methods to include the parameter types. (i.e., `foo(int)`
instead of `foo`). This allows them to be distinguished.

Fixed a bug where the methods inherited from interfaces were not shown.

Fixed a bug in computing visibility. Previously, the code looked for an explicit
~public~ or ~protected~ modifier. Now it *excludes* things explicitly marked ~private~.

Experimentally removed ~java.lang.Object~ as a supertype in the generated XML.

The previous version looked for methods and fields marked as public or protected, but that's not the same thing!

* **0.5.0** String constants now use “backslash-U” escapes for non-ASCII characters.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docletVersion=0.5.0
schemaVersion=0.5.0
docletVersion=0.6.0
schemaVersion=0.6.0
docletTitle=XmlDoclet
docletName=xmldoclet
9 changes: 9 additions & 0 deletions sample/src/main/java/org/example/AbstractClass.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package org.example;

abstract public class AbstractClass implements TestInterface {
abstract void one(int value);
abstract void one(int value, int otherValue);
abstract void one(String value);
public void foo() {
System.err.println("impl in AbstractClass");
}
public void inAbsr() {
System.err.println("impl in AbstractClass");
}
}
23 changes: 23 additions & 0 deletions sample/src/main/java/org/example/AlternateImplementation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example;

public class AlternateImplementation extends Implementation {
@Override
void one(int value, int otherValue) {
System.err.println("alternate: " + value + ", " + otherValue);
}

@Override
void one(String value) {
// nop
}

@Override
public void foo() {
System.err.println("alternate foo");
}

@Override
public void baz() {
System.err.println("alternate baz");
}
}
6 changes: 6 additions & 0 deletions sample/src/main/java/org/example/AxisIterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.example;

public interface AxisIterator extends SequenceIterator {
@Override
String next();
}
17 changes: 17 additions & 0 deletions sample/src/main/java/org/example/EmptyIterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.example;

public class EmptyIterator implements SequenceIterator {
@Override
public Object next() {
return null;
}

private static class OfNodes extends EmptyIterator implements AxisIterator {

public final static OfNodes THE_INSTANCE = new OfNodes();
@Override
public String next() {
return null;
}
}
}
16 changes: 15 additions & 1 deletion sample/src/main/java/org/example/Implementation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example;

public class Implementation extends AbstractClass {
public abstract class Implementation extends AbstractClass {
@Override
public void foo() {
// nop
Expand All @@ -10,4 +10,18 @@ public void foo() {
public void bar() {
// nop
}

@Override
void one(int value) {
System.err.println("int: " + value);
}

@Override
void one(int value, int otherValue) {
System.err.println("int: " + value + ", " + otherValue);
}

void inImpl() {
System.err.println("In impl");
}
}
18 changes: 18 additions & 0 deletions sample/src/main/java/org/example/IterImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.example;

public class IterImpl implements SequenceIterator {
@Override
public boolean hasNext() {
return false;
}

@Override
public Object next() {
return null;
}

@Override
public void close() {
// nop
}
}
8 changes: 8 additions & 0 deletions sample/src/main/java/org/example/ParameterizedClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example;

public class ParameterizedClass<T> {
private T[] _value;
public T get(int key) {
return _value[key];
}
}
8 changes: 8 additions & 0 deletions sample/src/main/java/org/example/SequenceIterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example;

import java.io.Closeable;

public interface SequenceIterator extends Closeable {
public Object next();
default void close() {}
}
8 changes: 8 additions & 0 deletions sample/src/main/java/org/example/TestClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.sf.saxon.lib.Feature;
import net.sf.saxon.serialize.charcode.CharacterSet;

import java.lang.reflect.Parameter;
import java.util.*;

/**
Expand All @@ -13,12 +14,19 @@

public class TestClass implements CharacterSet {
public static final TestClass CONSTANTVALUE = new TestClass();
protected ParameterizedClass<String> stringParameterizedClass = new ParameterizedClass<>();

/** The tick! With {@value}*/
protected final int spoon = 17;

private static final TestClass theInstance = new TestClass();

/**
* Constant indicating 1.0
*/

public static final int XML10 = 10;

/**
* Private constructor to force the singular instance to be used
*/
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/java/org/example/TestInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface TestInterface {
* <p>See also {@link #foo()}.</p>
*/
void bar();
void baz();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void scan(DocTree tree) {

// Hack
if (!"constructor".equals(typeName())) {
attr.put("name", element.getSimpleName().toString());
attr.put("name", element.toString());
}

Map<String,DeclaredType> thrownTypes = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public void scan(DocTree tree) {
}

private void showSuperclass(TypeElement element, DeclaredType superclass, Implemented impl) {
if (element.getSuperclass() instanceof DeclaredType) {
String name = ((DeclaredType) element.getSuperclass()).toString();
if ("java.lang.Object".equals(name)) {
return;
}
}

builder.startElement("superclass");
TypeUtils.xmlType(builder, "type", element.getSuperclass());

Expand All @@ -84,7 +91,7 @@ private void showSuperclass(TypeElement element, DeclaredType superclass, Implem
List<Element> inherited = new ArrayList<>();
for (Element elem : enclosed) {
String name = elem.toString();
if (elem.getModifiers().contains(Modifier.PUBLIC) || elem.getModifiers().contains(Modifier.PROTECTED)) {
if (!elem.getModifiers().contains(Modifier.PRIVATE)) {
if (elem.getKind() == ElementKind.FIELD) {
if (!impl.fields.contains(name)) {
impl.fields.add(name);
Expand All @@ -104,7 +111,7 @@ private void showSuperclass(TypeElement element, DeclaredType superclass, Implem
builder.startElement("inherited");
for (Element elem : inherited) {
Map<String, String> amap = new HashMap<>();
amap.put("name", elem.getSimpleName().toString());
amap.put("name", elem.toString());
if (elem.getKind() == ElementKind.FIELD) {
builder.startElement("field", amap);
builder.endElement("field");
Expand All @@ -123,21 +130,6 @@ private void showSuperclass(TypeElement element, DeclaredType superclass, Implem

showInterfaces(setype, impl);

/*
if (!setype.getInterfaces().isEmpty()) {
builder.startElement("interfaces");
for (TypeMirror tm : setype.getInterfaces()) {
if (tm.getKind() == TypeKind.DECLARED) {
DeclaredType dtm = (DeclaredType) tm;
System.err.println(dtm);
}
TypeUtils.xmlType(builder, "interfaceref", tm);
}
builder.endElement("interfaces");
}
*/

if (sstype.getKind() == TypeKind.DECLARED) {
showSuperclass(setype, (DeclaredType) sstype, impl);
}
Expand Down Expand Up @@ -171,6 +163,14 @@ private void showInterfaces(TypeElement element, Implemented impl) {
builder.startElement("field", amap);
builder.endElement("field");
}
if (celem.getKind() == ElementKind.METHOD) {
if (!impl.methods.contains(celem.toString())) {
amap = new HashMap<>();
amap.put("name", celem.toString());
builder.startElement("method", amap);
builder.endElement("method");
}
}
}

showInterfaces(ttm, impl);
Expand All @@ -181,7 +181,9 @@ private void showInterfaces(TypeElement element, Implemented impl) {

private void updateImplemented(TypeElement element, Implemented impl) {
for (Element elem : element.getEnclosedElements()) {
if (elem.getModifiers().contains(Modifier.PUBLIC) || elem.getModifiers().contains(Modifier.PROTECTED)) {
Set<Modifier> modifiers = elem.getModifiers();
if (!(modifiers.contains(Modifier.PRIVATE))) {
ElementKind kind = elem.getKind();
if (elem.getKind() == ElementKind.FIELD) {
impl.fields.add(elem.toString());
}
Expand Down

0 comments on commit 647ce61

Please sign in to comment.