Skip to content

Commit

Permalink
cleanup jsx getter and function return types
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Oct 16, 2024
1 parent 99a9a64 commit 9af4ffc
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 76 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/htmlunit/javascript/host/dom/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public String getCharset() {
* @return the value of this property
*/
@JsxGetter
public Object getAnchors() {
public HTMLCollection getAnchors() {
final HTMLCollection anchors = new HTMLCollection(getDomNodeOrDie(), true);

anchors.setIsMatchingPredicate(
Expand Down Expand Up @@ -812,7 +812,7 @@ public Object getAnchors() {
* @return the value of this property
*/
@JsxGetter
public Object getApplets() {
public HTMLCollection getApplets() {
return new HTMLCollection(getDomNodeOrDie(), false);
}

Expand Down Expand Up @@ -1658,7 +1658,7 @@ public Object elementFromPoint(final int x, final int y) {
* @return the value of the {@code forms} property
*/
@JsxGetter
public Object getForms() {
public HTMLCollection getForms() {
final HTMLCollection forms = new HTMLCollection(getDomNodeOrDie(), false) {
@Override
public Object call(final Context cx, final Scriptable scope,
Expand All @@ -1678,7 +1678,7 @@ public Object call(final Context cx, final Scriptable scope,
* @return the value of the {@code embeds} property
*/
@JsxGetter
public Object getEmbeds() {
public HTMLCollection getEmbeds() {
final HTMLCollection embeds = new HTMLCollection(getDomNodeOrDie(), false) {
@Override
public Object call(final Context cx, final Scriptable scope,
Expand All @@ -1696,7 +1696,7 @@ public Object call(final Context cx, final Scriptable scope,
* @return the value of the {@code embeds} property
*/
@JsxGetter
public Object getImages() {
public HTMLCollection getImages() {
final HTMLCollection images = new HTMLCollection(getDomNodeOrDie(), false) {
@Override
public Object call(final Context cx, final Scriptable scope,
Expand All @@ -1714,7 +1714,7 @@ public Object call(final Context cx, final Scriptable scope,
* @return the value of the {@code scripts} property
*/
@JsxGetter
public Object getScripts() {
public HTMLCollection getScripts() {
final HTMLCollection scripts = new HTMLCollection(getDomNodeOrDie(), false) {
@Override
public Object call(final Context cx, final Scriptable scope,
Expand Down Expand Up @@ -1747,7 +1747,7 @@ public StyleSheetList getStyleSheets() {
* @return the value of the {@code plugins} property
*/
@JsxGetter
public Object getPlugins() {
public HTMLCollection getPlugins() {
return getEmbeds();
}

Expand All @@ -1757,7 +1757,7 @@ public Object getPlugins() {
* @return the value of this property
*/
@JsxGetter
public Object getLinks() {
public HTMLCollection getLinks() {
final HTMLCollection links = new HTMLCollection(getDomNodeOrDie(), true);

links.setEffectOnCacheFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void jsConstructor() {
* @return the {@code options} attribute
*/
@JsxGetter
public Object getOptions() {
public HTMLCollection getOptions() {
if (options_ == null) {
options_ = new HTMLCollection(getDomNodeOrDie(), false);
options_.setIsMatchingPredicate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,11 +1076,11 @@ public int getOffsetTop() {
* @see <a href="http://dump.testsuite.org/2006/dom/style/offset/spec">Reverse Engineering by Anne van Kesteren</a>
*/
@JsxGetter(propertyName = "offsetParent")
public Object getOffsetParent_js() {
public HtmlUnitScriptable getOffsetParent_js() {
return getOffsetParentInternal(getBrowserVersion().hasFeature(JS_OFFSET_PARENT_NULL_IF_FIXED));
}

private Object getOffsetParentInternal(final boolean returnNullIfFixed) {
private HtmlUnitScriptable getOffsetParentInternal(final boolean returnNullIfFixed) {
DomNode currentElement = getDomNodeOrDie();

if (currentElement.getParentNode() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public int getTextLength() {
* @return the selection start
*/
@JsxGetter
public Object getSelectionStart() {
public Integer getSelectionStart() {
final DomNode dom = getDomNodeOrDie();
if (dom instanceof SelectableTextInput) {
if ("number".equalsIgnoreCase(getType())) {
Expand Down Expand Up @@ -256,7 +256,7 @@ public void setSelectionStart(final int start) {
* @return the selection end
*/
@JsxGetter
public Object getSelectionEnd() {
public Integer getSelectionEnd() {
final DomNode dom = getDomNodeOrDie();
if (dom instanceof SelectableTextInput) {
if ("number".equalsIgnoreCase(getType())) {
Expand Down Expand Up @@ -622,7 +622,7 @@ public void setAutocomplete(final String autocomplete) {
* @return the {@code files} property
*/
@JsxGetter
public Object getFiles() {
public FileList getFiles() {
final HtmlInput htmlInput = getDomNodeOrDie();
if (htmlInput instanceof HtmlFileInput) {
final FileList list = new FileList(((HtmlFileInput) htmlInput).getFiles());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void jsConstructor() {
* @return the {@code width} property
*/
@JsxGetter(propertyName = "width")
public Object getWidth_js() {
public Integer getWidth_js() {
final String value = getDomNodeOrDie().getAttributeDirect("width");
final Integer intValue = HTMLCanvasElement.getValue(value);
if (intValue != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.htmlunit.html.HtmlTableFooter;
import org.htmlunit.html.HtmlTableHeader;
import org.htmlunit.html.HtmlTableRow;
import org.htmlunit.javascript.HtmlUnitScriptable;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.configuration.JsxClass;
import org.htmlunit.javascript.configuration.JsxConstructor;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void jsConstructor() {
* @return the table's caption element
*/
@JsxGetter
public Object getCaption() {
public HtmlUnitScriptable getCaption() {
final List<HtmlElement> captions = getDomNodeOrDie().getElementsByTagName("caption");
if (captions.isEmpty()) {
return null;
Expand Down Expand Up @@ -94,7 +95,7 @@ public void setCaption(final Object o) {
* @return the table's tfoot element
*/
@JsxGetter
public Object getTFoot() {
public HtmlUnitScriptable getTFoot() {
final List<HtmlElement> tfoots = getDomNodeOrDie().getElementsByTagName("tfoot");
if (tfoots.isEmpty()) {
return null;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void setTFoot(final Object o) {
* @return the table's thead element
*/
@JsxGetter
public Object getTHead() {
public HtmlUnitScriptable getTHead() {
final List<HtmlElement> theads = getDomNodeOrDie().getElementsByTagName("thead");
if (theads.isEmpty()) {
return null;
Expand Down Expand Up @@ -157,7 +158,7 @@ public void setTHead(final Object o) {
* @return the tbody's in the table
*/
@JsxGetter
public Object getTBodies() {
public HtmlUnitScriptable getTBodies() {
final HtmlTable table = (HtmlTable) getDomNodeOrDie();
final HTMLCollection bodies = new HTMLCollection(table, false);
bodies.setElementsSupplier((Supplier<List<DomNode>> & Serializable) () -> new ArrayList<>(table.getBodies()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public int getSectionRowIndex() {
* @return the cells in the row
*/
@JsxGetter
public Object getCells() {
public HTMLCollection getCells() {
final HtmlTableRow row = (HtmlTableRow) getDomNodeOrDie();

final HTMLCollection cells = new HTMLCollection(row, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void setReadOnly(final boolean readOnly) {
* @return the maximum number of characters in this text area
*/
@JsxGetter
public Object getMaxLength() {
public int getMaxLength() {
final String maxLength = getDomNodeOrDie().getAttribute("maxLength");

try {
Expand Down Expand Up @@ -303,7 +303,7 @@ public void setMaxLength(final String maxLength) {
* @return the minimum number of characters in this text area
*/
@JsxGetter
public Object getMinLength() {
public int getMinLength() {
final String minLength = getDomNodeOrDie().getAttribute("minLength");

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void jsConstructor() {
* @return the {@code text} attribute
*/
@JsxGetter
public Object getText() {
public String getText() {
final HtmlTitle htmlTitle = (HtmlTitle) getDomNodeOrDie();
return htmlTitle.getText();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class RowContainer extends HTMLElement {
* @return the rows in the element
*/
@JsxGetter
public Object getRows() {
public HTMLCollection getRows() {
final HTMLCollection rows = new HTMLCollection(getDomNodeOrDie(), false);
rows.setIsMatchingPredicate(
(Predicate<DomNode> & Serializable)
Expand Down
55 changes: 3 additions & 52 deletions src/test/java/org/htmlunit/archunit/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,8 @@ public boolean test(final JavaClass javaClass) {
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.DOMException.getLineNumber()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.DOMException.getMessage()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getActiveElement()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getAnchors()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getApplets()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getDefaultView()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getEmbeds()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getForms()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getHead()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getImages()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getLinks()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getPlugins()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getScripts()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Node.getParentNode()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.NodeIterator.getFilter()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Range.getCommonAncestorContainer()")
Expand All @@ -230,63 +222,22 @@ public boolean test(final JavaClass javaClass) {
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.InputEvent.getInputType()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.MessageEvent.getData()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.MessageEvent.getPorts()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.PointerEvent.getAltitudeAngle()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.PointerEvent.getAzimuthAngle()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.PointerEvent.getPressure()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.PopStateEvent.getState()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.ProgressEvent.getLoaded()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.TextEvent.getData()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.event.UIEvent.getView()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.file.FileReader.getResult()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.geo.GeolocationCoordinates.getAccuracy()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.geo.GeolocationCoordinates.getLatitude()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.geo.GeolocationCoordinates.getLongitude()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLButtonElement.getValue()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLDataListElement.getOptions()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLElement.getOffsetParent_js()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLInputElement.getFiles()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLInputElement.getSelectionEnd()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLInputElement.getSelectionStart()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLMeterElement.getHigh()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLMeterElement.getLow()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLMeterElement.getMax()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLMeterElement.getMin()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLMeterElement.getOptimum()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLMeterElement.getValue()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLPreElement.getWidth_js()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLProgressElement.getMax()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLProgressElement.getValue()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableElement.getCaption()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableElement.getTBodies()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableElement.getTFoot()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableElement.getTHead()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableRowElement.getCells()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTextAreaElement.getMaxLength()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTextAreaElement.getMinLength()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTitleElement.getText()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.RowContainer.getRows()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.media.AudioParam.getDefaultValue()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.media.AudioParam.getMaxValue()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.media.AudioParam.getMinValue()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.media.AudioParam.getValue()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.network.NetworkInformation.getDownlink()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGMatrix.getA()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGMatrix.getB()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGMatrix.getC()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGMatrix.getD()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGMatrix.getE()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGMatrix.getF()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGRect.getHeight()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGRect.getWidth()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGRect.getX()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGRect.getY()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.worker.DedicatedWorkerGlobalScope.getSelf()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.xml.XMLHttpRequest.getResponse()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.xml.XMLHttpRequest.getResponseXML()")

.should().haveRawReturnType(String.class)
.orShould().haveRawReturnType("int")
.orShould().haveRawReturnType(Integer.class)
.orShould().haveRawReturnType("long")
.orShould().haveRawReturnType("double")
.orShould().haveRawReturnType(Double.class)
.orShould().haveRawReturnType("boolean")
.orShould().haveRawReturnType(isAssignableToScriptable);

Expand Down

0 comments on commit 9af4ffc

Please sign in to comment.