From 011466786a90505b70cdd851e72113d70dabd8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Sat, 13 Jan 2024 17:19:27 +0200 Subject: [PATCH] Code style improvements in toc tests --- .../internal/validation/TocValidator.java | 30 ++++++++++--------- .../internal/linkchecker/TocLinkChecker.java | 20 ++++++------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ua/org.eclipse.help.base/src/org/eclipse/help/internal/validation/TocValidator.java b/ua/org.eclipse.help.base/src/org/eclipse/help/internal/validation/TocValidator.java index 039f7afd590..14429502992 100644 --- a/ua/org.eclipse.help.base/src/org/eclipse/help/internal/validation/TocValidator.java +++ b/ua/org.eclipse.help.base/src/org/eclipse/help/internal/validation/TocValidator.java @@ -6,6 +6,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import javax.xml.parsers.ParserConfigurationException; @@ -53,8 +54,8 @@ public String getHref() { return href; } } - public static abstract class Filter { - abstract public boolean isIncluded(String href); + public abstract static class Filter { + public abstract boolean isIncluded(String href); } public static class PassThroughFilter extends Filter { @@ -73,11 +74,13 @@ public boolean isIncluded(String href) { * @return An ArrayList of BrokenLink objects in the toc. If no broken links are found, an empty ArrayList * is returned. */ - public static ArrayList validate(String[] hrefs) throws IOException, SAXException, ParserConfigurationException{ + public static List validate(String[] hrefs) + throws IOException, SAXException, ParserConfigurationException { return filteredValidate(hrefs, new PassThroughFilter()); } - public static ArrayList filteredValidate (String[] hrefs, Filter filter) throws IOException, SAXException, ParserConfigurationException{ + public static List filteredValidate(String[] hrefs, Filter filter) + throws IOException, SAXException, ParserConfigurationException { TocValidator v = new TocValidator(); ArrayList result = new ArrayList<>(); for (String href : hrefs) @@ -127,27 +130,26 @@ private void processToc(String href, String plugin, ArrayList result */ private void process(IUAElement element, String plugin, String path, ArrayList result, Filter filter) throws SAXException, ParserConfigurationException { String href; - if (element instanceof ILink) { - href = ((ILink)element).getToc(); + if (element instanceof ILink link) { + href = link.getToc(); try { processToc(href, plugin, result, filter); } catch (IOException e) { result.add(new BrokenLink("/" + plugin + "/" + path, href)); //$NON-NLS-1$ //$NON-NLS-2$ } } - else if (element instanceof IHelpResource) { - if (element instanceof IToc) - href = ((IToc)element).getTopic(null).getHref(); + else if (element instanceof IHelpResource helpResource) { + if (element instanceof IToc toc) + href = toc.getTopic(null).getHref(); else - href = ((IHelpResource)element).getHref(); - if (href != null && filter.isIncluded(href)) - if (!checkLink(href, plugin)) { + href = helpResource.getHref(); + if (href != null && filter.isIncluded(href) && !checkLink(href, plugin)) { result.add(new BrokenLink("/" + plugin + "/" + path, href)); //$NON-NLS-1$ //$NON-NLS-2$ } } IUAElement [] children = element.getChildren(); - for (int i = 0; i < children.length; i++) - process(children[i], plugin, path, result, filter); + for (IUAElement child : children) + process(child, plugin, path, result, filter); } /* Checks validity of a given link from a toc in a given plug-in. diff --git a/ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/TocLinkChecker.java b/ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/TocLinkChecker.java index 271a81c74e5..336ee15b8de 100644 --- a/ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/TocLinkChecker.java +++ b/ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/linkchecker/TocLinkChecker.java @@ -14,7 +14,6 @@ *******************************************************************************/ package org.eclipse.ua.tests.doc.internal.linkchecker; -import java.util.ArrayList; import java.util.List; import org.eclipse.help.internal.validation.TocValidator; @@ -74,56 +73,55 @@ public boolean isIncluded(String href) { @Test public void testPlatformUser() throws Exception { - ArrayList failures = TocValidator.validate(PLATFORM_USER); + List failures = TocValidator.validate(PLATFORM_USER); doAssert(failures); } @Test public void testPlatformIsvStatic() throws Exception { - ArrayList failures = TocValidator.filteredValidate(PLATFORM_ISV, new NonReferenceNonSampleFilter()); + List failures = TocValidator.filteredValidate(PLATFORM_ISV, new NonReferenceNonSampleFilter()); doAssert(failures); } @Test public void testPlatformIsvGenerated() throws Exception { - ArrayList failures = TocValidator.filteredValidate(PLATFORM_ISV, new ReferenceOrSampleFilter()); + List failures = TocValidator.filteredValidate(PLATFORM_ISV, new ReferenceOrSampleFilter()); doAssert(failures); } @Test public void testPdeUserStatic() throws Exception { - ArrayList failures = TocValidator.filteredValidate(PDE_USER, new NonReferenceFilter()); + List failures = TocValidator.filteredValidate(PDE_USER, new NonReferenceFilter()); doAssert(failures); } @Test public void testPdeUserGenerated() throws Exception { - ArrayList failures = TocValidator.filteredValidate(PDE_USER, new ReferenceFilter()); + List failures = TocValidator.filteredValidate(PDE_USER, new ReferenceFilter()); doAssert(failures); } @Test public void testJdtUser() throws Exception { - ArrayList failures = TocValidator.validate(JDT_USER); + List failures = TocValidator.validate(JDT_USER); doAssert(failures); } @Test public void testJdtIsvStatic() throws Exception { - ArrayList failures = TocValidator.filteredValidate(JDT_ISV, new NonReferenceFilter()); + List failures = TocValidator.filteredValidate(JDT_ISV, new NonReferenceFilter()); doAssert(failures); } @Test public void testJdtIsvGenerated() throws Exception { - ArrayList failures = TocValidator.filteredValidate(JDT_ISV, new ReferenceFilter()); + List failures = TocValidator.filteredValidate(JDT_ISV, new ReferenceFilter()); doAssert(failures); } private void doAssert(List failures) { StringBuilder message = new StringBuilder(); - for (int i = 0; i < failures.size(); i++) { - BrokenLink link = failures.get(i); + for (BrokenLink link : failures) { message.append("Invalid link in \"" + link.getTocID() + "\": " + link.getHref() + "\n"); } Assert.assertTrue(message.toString(), failures.isEmpty());