Skip to content

Commit 647ce61

Browse files
authored
Merge pull request #7 from Saxonica/method-fixes
Method fixes
2 parents 77380b3 + 825c659 commit 647ce61

File tree

14 files changed

+150
-22
lines changed

14 files changed

+150
-22
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,18 @@ incomplete or incorrect, please [open an issue](https://github.com/Saxonica/xmld
120120

121121
## Change log
122122

123+
* **0.6.0** Improved handling of method names and inheritance
124+
125+
Changed the “name” of methods to include the parameter types. (i.e., `foo(int)`
126+
instead of `foo`). This allows them to be distinguished.
127+
128+
Fixed a bug where the methods inherited from interfaces were not shown.
129+
130+
Fixed a bug in computing visibility. Previously, the code looked for an explicit
131+
~public~ or ~protected~ modifier. Now it *excludes* things explicitly marked ~private~.
132+
133+
Experimentally removed ~java.lang.Object~ as a supertype in the generated XML.
134+
135+
The previous version looked for methods and fields marked as public or protected, but that's not the same thing!
136+
123137
* **0.5.0** String constants now use “backslash-U” escapes for non-ASCII characters.

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
docletVersion=0.5.0
2-
schemaVersion=0.5.0
1+
docletVersion=0.6.0
2+
schemaVersion=0.6.0
33
docletTitle=XmlDoclet
44
docletName=xmldoclet
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
package org.example;
22

33
abstract public class AbstractClass implements TestInterface {
4+
abstract void one(int value);
5+
abstract void one(int value, int otherValue);
6+
abstract void one(String value);
7+
public void foo() {
8+
System.err.println("impl in AbstractClass");
9+
}
10+
public void inAbsr() {
11+
System.err.println("impl in AbstractClass");
12+
}
413
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.example;
2+
3+
public class AlternateImplementation extends Implementation {
4+
@Override
5+
void one(int value, int otherValue) {
6+
System.err.println("alternate: " + value + ", " + otherValue);
7+
}
8+
9+
@Override
10+
void one(String value) {
11+
// nop
12+
}
13+
14+
@Override
15+
public void foo() {
16+
System.err.println("alternate foo");
17+
}
18+
19+
@Override
20+
public void baz() {
21+
System.err.println("alternate baz");
22+
}
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.example;
2+
3+
public interface AxisIterator extends SequenceIterator {
4+
@Override
5+
String next();
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.example;
2+
3+
public class EmptyIterator implements SequenceIterator {
4+
@Override
5+
public Object next() {
6+
return null;
7+
}
8+
9+
private static class OfNodes extends EmptyIterator implements AxisIterator {
10+
11+
public final static OfNodes THE_INSTANCE = new OfNodes();
12+
@Override
13+
public String next() {
14+
return null;
15+
}
16+
}
17+
}

sample/src/main/java/org/example/Implementation.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.example;
22

3-
public class Implementation extends AbstractClass {
3+
public abstract class Implementation extends AbstractClass {
44
@Override
55
public void foo() {
66
// nop
@@ -10,4 +10,18 @@ public void foo() {
1010
public void bar() {
1111
// nop
1212
}
13+
14+
@Override
15+
void one(int value) {
16+
System.err.println("int: " + value);
17+
}
18+
19+
@Override
20+
void one(int value, int otherValue) {
21+
System.err.println("int: " + value + ", " + otherValue);
22+
}
23+
24+
void inImpl() {
25+
System.err.println("In impl");
26+
}
1327
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.example;
2+
3+
public class IterImpl implements SequenceIterator {
4+
@Override
5+
public boolean hasNext() {
6+
return false;
7+
}
8+
9+
@Override
10+
public Object next() {
11+
return null;
12+
}
13+
14+
@Override
15+
public void close() {
16+
// nop
17+
}
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.example;
2+
3+
public class ParameterizedClass<T> {
4+
private T[] _value;
5+
public T get(int key) {
6+
return _value[key];
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.example;
2+
3+
import java.io.Closeable;
4+
5+
public interface SequenceIterator extends Closeable {
6+
public Object next();
7+
default void close() {}
8+
}

sample/src/main/java/org/example/TestClass.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.sf.saxon.lib.Feature;
66
import net.sf.saxon.serialize.charcode.CharacterSet;
77

8+
import java.lang.reflect.Parameter;
89
import java.util.*;
910

1011
/**
@@ -13,12 +14,19 @@
1314

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

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

2022
private static final TestClass theInstance = new TestClass();
2123

24+
/**
25+
* Constant indicating 1.0
26+
*/
27+
28+
public static final int XML10 = 10;
29+
2230
/**
2331
* Private constructor to force the singular instance to be used
2432
*/

sample/src/main/java/org/example/TestInterface.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ public interface TestInterface {
1212
* <p>See also {@link #foo()}.</p>
1313
*/
1414
void bar();
15+
void baz();
1516
}

xmldoclet/src/main/java/com/saxonica/xmldoclet/scanners/XmlExecutableElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void scan(DocTree tree) {
2525

2626
// Hack
2727
if (!"constructor".equals(typeName())) {
28-
attr.put("name", element.getSimpleName().toString());
28+
attr.put("name", element.toString());
2929
}
3030

3131
Map<String,DeclaredType> thrownTypes = new HashMap<>();

xmldoclet/src/main/java/com/saxonica/xmldoclet/scanners/XmlTypeElement.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public void scan(DocTree tree) {
7676
}
7777

7878
private void showSuperclass(TypeElement element, DeclaredType superclass, Implemented impl) {
79+
if (element.getSuperclass() instanceof DeclaredType) {
80+
String name = ((DeclaredType) element.getSuperclass()).toString();
81+
if ("java.lang.Object".equals(name)) {
82+
return;
83+
}
84+
}
85+
7986
builder.startElement("superclass");
8087
TypeUtils.xmlType(builder, "type", element.getSuperclass());
8188

@@ -84,7 +91,7 @@ private void showSuperclass(TypeElement element, DeclaredType superclass, Implem
8491
List<Element> inherited = new ArrayList<>();
8592
for (Element elem : enclosed) {
8693
String name = elem.toString();
87-
if (elem.getModifiers().contains(Modifier.PUBLIC) || elem.getModifiers().contains(Modifier.PROTECTED)) {
94+
if (!elem.getModifiers().contains(Modifier.PRIVATE)) {
8895
if (elem.getKind() == ElementKind.FIELD) {
8996
if (!impl.fields.contains(name)) {
9097
impl.fields.add(name);
@@ -104,7 +111,7 @@ private void showSuperclass(TypeElement element, DeclaredType superclass, Implem
104111
builder.startElement("inherited");
105112
for (Element elem : inherited) {
106113
Map<String, String> amap = new HashMap<>();
107-
amap.put("name", elem.getSimpleName().toString());
114+
amap.put("name", elem.toString());
108115
if (elem.getKind() == ElementKind.FIELD) {
109116
builder.startElement("field", amap);
110117
builder.endElement("field");
@@ -123,21 +130,6 @@ private void showSuperclass(TypeElement element, DeclaredType superclass, Implem
123130

124131
showInterfaces(setype, impl);
125132

126-
/*
127-
128-
if (!setype.getInterfaces().isEmpty()) {
129-
builder.startElement("interfaces");
130-
for (TypeMirror tm : setype.getInterfaces()) {
131-
if (tm.getKind() == TypeKind.DECLARED) {
132-
DeclaredType dtm = (DeclaredType) tm;
133-
System.err.println(dtm);
134-
}
135-
TypeUtils.xmlType(builder, "interfaceref", tm);
136-
}
137-
builder.endElement("interfaces");
138-
}
139-
*/
140-
141133
if (sstype.getKind() == TypeKind.DECLARED) {
142134
showSuperclass(setype, (DeclaredType) sstype, impl);
143135
}
@@ -171,6 +163,14 @@ private void showInterfaces(TypeElement element, Implemented impl) {
171163
builder.startElement("field", amap);
172164
builder.endElement("field");
173165
}
166+
if (celem.getKind() == ElementKind.METHOD) {
167+
if (!impl.methods.contains(celem.toString())) {
168+
amap = new HashMap<>();
169+
amap.put("name", celem.toString());
170+
builder.startElement("method", amap);
171+
builder.endElement("method");
172+
}
173+
}
174174
}
175175

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

182182
private void updateImplemented(TypeElement element, Implemented impl) {
183183
for (Element elem : element.getEnclosedElements()) {
184-
if (elem.getModifiers().contains(Modifier.PUBLIC) || elem.getModifiers().contains(Modifier.PROTECTED)) {
184+
Set<Modifier> modifiers = elem.getModifiers();
185+
if (!(modifiers.contains(Modifier.PRIVATE))) {
186+
ElementKind kind = elem.getKind();
185187
if (elem.getKind() == ElementKind.FIELD) {
186188
impl.fields.add(elem.toString());
187189
}

0 commit comments

Comments
 (0)