Skip to content

Commit

Permalink
Streamline ua.tests.doc bundle code
Browse files Browse the repository at this point in the history
* Reduce variable/method scopes
* Do not needlessly convert from collection to array and back
* Use foreach
  • Loading branch information
akurtakov committed Jan 14, 2025
1 parent b9d3edb commit fad7fcd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corporation and others.
* Copyright (c) 2009, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -64,10 +64,9 @@ private void checkLinks() {
System.out.println("Checked " + count + " links");
}
//System.out.println("Process " + next);
URL url;
boolean opened;
try {
url = new URL(next);
URL url = new URL(next);

Check warning on line 69 in ua/org.eclipse.ua.tests.doc/src/org/eclipse/ua/tests/doc/internal/actions/CheckLinkAction.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler and API Tools

Deprecation

NORMAL: The constructor URL(String) is deprecated since version 20
//URLConnection connection = url.openConnection();
//connection.
try (InputStream input = url.openStream()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corporation and others.
* Copyright (c) 2009, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,7 +14,6 @@

package org.eclipse.ua.tests.doc.internal.actions;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.ILog;
Expand All @@ -30,14 +29,12 @@

public class CheckTocAction implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
public static List<BrokenLink> errors = new ArrayList<>();

public static void showErrors() {
private static void showErrors(List<BrokenLink> errors) {
if (errors.isEmpty()) {
reportStatus("No errors detected in load");
}
for (int i = 0; i < errors.size(); i++) {
BrokenLink link = errors.get(i);
for (BrokenLink link : errors) {
reportStatus("Invalid link in \"" + link.getTocID() + "\": " + link.getHref());
}
}
Expand Down Expand Up @@ -66,22 +63,22 @@ public void run(IAction action) {
if (dlg.getReturnCode() == Window.CANCEL) {
return;
}
Toc[] tocsToCheck = dlg.getTocsToCheck();
List<Toc> tocsToCheck = dlg.getTocsToCheck();
checkTocFilesExist(tocsToCheck);

}

public void checkTocFilesExist(Toc[] tocsToCheck) {
public void checkTocFilesExist(List<Toc> tocsToCheck) {
for (Toc toc : tocsToCheck) {
String id = toc.getTocContribution().getId();
reportStatus("Testing " + id);
String[] href = { id };
try {
errors = TocValidator.validate(href);
List<BrokenLink> errors = TocValidator.validate(href);
showErrors(errors);
} catch (Exception e) {
e.printStackTrace();
}
showErrors();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corporation and others.
* Copyright (c) 2009, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -84,8 +84,7 @@ public static void showErrors() {
} else {
reportStatus("Testing complete, errors found");
}
for (Iterator<String> iter = errors.iterator(); iter.hasNext();) {
String errorMessage = iter.next();
for (String errorMessage : errors) {
reportStatus(errorMessage);
}
errors = null;
Expand Down Expand Up @@ -170,11 +169,11 @@ public void run(IAction action) {
return;
}
int testKind = dlg.getTestKind();
PrioritizedFilter[] filters = new PrioritizedFilter[] {
PrioritizedFilter[] filters = {
new PrioritizedFilter(new OnLoadFilter(testKind), 1),
new PrioritizedFilter(new AddScriptFilter(), 2)};
ExtraFilters.setFilters(filters);
Toc[] tocsToCheck = dlg.getTocsToCheck();
List<Toc> tocsToCheck = dlg.getTocsToCheck();
if (testKind == SelectTocDialog.PAGES_EXIST) {
new CheckTocAction().checkTocFilesExist(tocsToCheck);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ protected void okPressed() {
super.okPressed();
}

public Toc[] getTocsToCheck() {
ArrayList<Toc> selected = new ArrayList<>();
public java.util.List<Toc> getTocsToCheck() {
java.util.List<Toc> selected = new ArrayList<>();
for (int selectedToc : selectedTocs) {
selected.add(tocs[selectedToc]);
}
Toc[] tocsToCheck = selected.toArray(new Toc[0]) ;
return tocsToCheck;
return selected;
}

public int getTestKind() {
Expand Down

0 comments on commit fad7fcd

Please sign in to comment.