Skip to content

Commit 10a494c

Browse files
7903830: apidiff: Review glyphs used to indicate same/difference
Reviewed-by: iris
1 parent e0b049a commit 10a494c

File tree

4 files changed

+61
-11
lines changed

4 files changed

+61
-11
lines changed

src/share/classes/jdk/codetools/apidiff/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ private Result run(List<String> args, Log log) {
170170
Selector s = new Selector(options.includes, options.excludes);
171171
AccessKind ak = options.getAccessKind();
172172

173+
// TODO: when APIDiff moves to JDK 21, thia can trivially become SequencedSet,
174+
// which would be useful in varoius places, such as PageReporter.getResultGlyph
173175
Set<API> apis = options.allAPIOptions.values().stream()
174176
.map(a -> API.of(a, s, ak, log))
175177
.collect(Collectors.toCollection(LinkedHashSet::new));

src/share/classes/jdk/codetools/apidiff/html/Entity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ public class Entity extends Content {
4545
public static final Entity CROSS = new Entity("cross", 0x2717);
4646
/** Unicode EQUALS SIGN. */
4747
public static final Entity EQUALS = new Entity("equals", 0x3d);
48-
/** Unicode NOT EQUAL TO. */
49-
public static final Entity NE = new Entity("ne", 0x2260);
48+
/** Unicode MINUS. */
49+
public static final Entity MINUS = new Entity("minus", 0x2212);
5050
/** Unicode NO-BREAK SPACE. */
5151
public static final Entity NBSP = new Entity("nbsp", 0xa0);
52+
/** Unicode NOT EQUAL TO. */
53+
public static final Entity NE = new Entity("ne", 0x2260);
54+
/** Unicode PLUS. */
55+
public static final Entity PLUS = new Entity("plus", 0x2b);
5256

5357
private static final boolean useNumericEntities = Boolean.getBoolean("useNumericEntities");
5458

src/share/classes/jdk/codetools/apidiff/report/html/PageReporter.java

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Collections;
3737
import java.util.Comparator;
3838
import java.util.HashMap;
39+
import java.util.Iterator;
3940
import java.util.List;
4041
import java.util.Locale;
4142
import java.util.Map;
@@ -862,9 +863,35 @@ protected Content buildResultTable() {
862863
return section;
863864
}
864865

865-
private static final Content CHECK = HtmlTree.SPAN(Entity.CHECK).setClass("same");
866-
private static final Content CROSS = HtmlTree.SPAN(Entity.CROSS).setClass("diff");
867-
private static final Content SINGLE = HtmlTree.SPAN(Entity.CIRCLED_DIGIT_ONE).setClass("single");
866+
// The following names are intended to be "semantic" or "abstract" names,
867+
// distinct from the concrete representations used in the generated documentation.
868+
// The names are intentionally different from any corresponding entity names.
869+
870+
/**
871+
* Used when two elements compare as equal.
872+
*/
873+
// possible alternatives: Entity.CHECK
874+
private static final Content SAME = HtmlTree.SPAN(Entity.EQUALS).setClass("same");
875+
/**
876+
* Used when two elements compare as not equal.
877+
*/
878+
// possible alternatives: Entity.CROSS
879+
private static final Content DIFFERENT = HtmlTree.SPAN(Entity.NE).setClass("diff");
880+
/**
881+
* Used when an element does not appear in all instances of the APIs being compared.
882+
* See also {@link #ADDED}, {@link #REMOVED}.
883+
*/
884+
private static final Content PARTIAL = HtmlTree.SPAN(Entity.CIRCLED_DIGIT_ONE).setClass("partial");
885+
/**
886+
* Used in a 2-way comparison when it is determined that an element has been added.
887+
*/
888+
// possible alternatives: '>' (for example, as used in text diff tools) or other right-pointing arrows
889+
private static final Content ADDED = HtmlTree.SPAN(Entity.PLUS).setClass("partial");
890+
/**
891+
* Used in a 2-way comparison when it is determined that an element has been removed.
892+
*/
893+
// possible alternatives: '<' (for example, as used in text diff tools) or other left-pointing arrows
894+
private static final Content REMOVED = HtmlTree.SPAN(Entity.MINUS).setClass("partial");
868895

869896

870897
protected Content getResultGlyph(ElementKey eKey) {
@@ -882,19 +909,36 @@ protected Content getResultGlyph(Position pos, APIMap<?> map) {
882909
return Text.of("?");
883910
}
884911
if (map.size() == 1) {
885-
return SINGLE;
912+
API api = map.keySet().iterator().next();
913+
Set<API> apis = parent.apis;
914+
if (apis.size() == 2) {
915+
// The following assumes an ordering on the order in which the
916+
// APIs were defined on the command line: older first, newer second
917+
Iterator<API> iter = apis.iterator();
918+
API oldAPI = iter.next();
919+
API newAPI = iter.next();
920+
if (api == oldAPI) { // and not in new API
921+
return REMOVED;
922+
} else if (api == newAPI) { // and not in old API
923+
return ADDED;
924+
} else {
925+
// should not happen?
926+
return PARTIAL;
927+
}
928+
}
929+
return PARTIAL;
886930
}
887931
Boolean eq = results.get(pos);
888-
return (eq == null) ? SINGLE : eq ? CHECK : CROSS;
932+
return (eq == null) ? PARTIAL : eq ? SAME : DIFFERENT;
889933
}
890934

891935
// TODO: improve abstraction; these args are typically reversed
892936
protected Content getResultGlyph(APIMap<?> map, Position pos) {
893937
if (map.size() == 1) {
894-
return SINGLE;
938+
return PARTIAL;
895939
}
896940
Boolean eq = results.get(pos);
897-
return (eq == null) ? SINGLE : eq ? CHECK : CROSS;
941+
return (eq == null) ? PARTIAL : eq ? SAME : DIFFERENT;
898942
}
899943

900944
protected APIMap<? extends Element> getElementMap(ElementKey eKey) {

src/share/classes/jdk/codetools/apidiff/report/html/resources/apidiff.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ div.signature {
179179

180180
.doc-files span.diff, .element span.diff, .enclosed span.diff, .serial-form span.diff,
181181
.doc-files span.same, .element span.same, .enclosed span.same, .serial-form span.same,
182-
.doc-files span.single, .element span.single, .enclosed span.single, .serial-form span.single {
182+
.doc-files span.partial, .element span.partial, .enclosed span.partial, .serial-form span.partial {
183183
display: inline-block;
184184
width: 2em;
185185
margin-right: 0.5ex;
@@ -197,7 +197,7 @@ div.signature {
197197
color: #080;
198198
}
199199

200-
.doc-files span.single, .element span.single, .enclosed span.single, .serial-form span.single {
200+
.doc-files span.partial, .element span.partial, .enclosed span.partial, .serial-form span.partial {
201201
background: #ddf;
202202
color: #008;
203203
}

0 commit comments

Comments
 (0)