Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Exceptions not actually thrown #1065

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -85,7 +84,7 @@ public void setUp() throws Exception {
* Resolves a package
*/
@Test
public void testResolvePackage() throws FileNotFoundException, CoreException {
public void testResolvePackage() throws CoreException {
assertNotNull("the testing baseline should exist", fBaseline); //$NON-NLS-1$
IApiComponent[] components = fBaseline.resolvePackage(fBaseline.getApiComponent(COMPONENT_B), COMPONENT_A);
assertNotNull("No component", components); //$NON-NLS-1$
Expand All @@ -97,7 +96,7 @@ public void testResolvePackage() throws FileNotFoundException, CoreException {
* Resolves a package within a single component
*/
@Test
public void testResolvePackageWithinComponent() throws FileNotFoundException, CoreException {
public void testResolvePackageWithinComponent() throws CoreException {
assertNotNull("the testing baseline should exist", fBaseline); //$NON-NLS-1$
IApiComponent[] components = fBaseline.resolvePackage(fBaseline.getApiComponent(COMPONENT_A), "a.b.c"); //$NON-NLS-1$
assertNotNull("No component", components); //$NON-NLS-1$
Expand All @@ -109,7 +108,7 @@ public void testResolvePackageWithinComponent() throws FileNotFoundException, Co
* Resolves a system package
*/
@Test
public void testResolveJavaLangPackage() throws FileNotFoundException, CoreException {
public void testResolveJavaLangPackage() throws CoreException {
assertNotNull("the testing baseline should exist", fBaseline); //$NON-NLS-1$
IApiComponent[] components = fBaseline.resolvePackage(fBaseline.getApiComponent(COMPONENT_B), "java.lang"); //$NON-NLS-1$
assertNotNull("No component", components); //$NON-NLS-1$
Expand All @@ -121,7 +120,7 @@ public void testResolveJavaLangPackage() throws FileNotFoundException, CoreExcep
* Resolves a system package
*/
@Test
public void testResolveSystemPackage() throws FileNotFoundException, CoreException {
public void testResolveSystemPackage() throws CoreException {
assertNotNull("the testing baseline should exist", fBaseline); //$NON-NLS-1$
IApiComponent[] components = fBaseline.resolvePackage(fBaseline.getApiComponent(COMPONENT_B), "org.w3c.dom"); //$NON-NLS-1$
assertNotNull("No component", components); //$NON-NLS-1$
Expand All @@ -133,7 +132,7 @@ public void testResolveSystemPackage() throws FileNotFoundException, CoreExcepti
* Finds the class file for java.lang.Object
*/
@Test
public void testFindJavaLangObject() throws FileNotFoundException, CoreException {
public void testFindJavaLangObject() throws CoreException {
assertNotNull("the testing baseline should exist", fBaseline); //$NON-NLS-1$
IApiComponent[] components = fBaseline.resolvePackage(fBaseline.getApiComponent(COMPONENT_B), "java.lang"); //$NON-NLS-1$
assertNotNull("No component", components); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -243,7 +242,7 @@ public void testVisitTypes() {
* D has SPI visibility for component "a.friend"
*/
@Test
public void testRestoreFromXML() throws FileNotFoundException, IOException, CoreException {
public void testRestoreFromXML() throws CoreException {
IPath path = TestSuiteHelper.getPluginDirectoryPath();
path = path.append("test-xml"); //$NON-NLS-1$
File file = path.toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.pde.api.tools.internal.ApiFilterStore;
Expand Down Expand Up @@ -71,7 +68,7 @@ public void setUp() throws Exception {
IJavaProject project = getTestingJavaProject(TESTING_PLUGIN_PROJECT_NAME);
IPackageFragmentRoot srcroot = project.findPackageFragmentRoot(project.getProject().getFullPath().append("src")); //$NON-NLS-1$
assertNotNull("the default src root must exist", srcroot); //$NON-NLS-1$
FileUtils.importFileFromDirectory(projectSrc, srcroot.getPath(), new NullProgressMonitor());
FileUtils.importFileFromDirectory(projectSrc, srcroot.getPath());

// Import the test .api_filters file
File xmlsrc = XML_LOC.append(".api_filters").toFile(); //$NON-NLS-1$
Expand All @@ -80,7 +77,7 @@ public void setUp() throws Exception {
assertNotNull("no project", project); //$NON-NLS-1$
IProject project2 = project.getProject();
IPath settings = project2.getFullPath().append(".settings"); //$NON-NLS-1$
FileUtils.importFileFromDirectory(xmlsrc, settings, new NullProgressMonitor());
FileUtils.importFileFromDirectory(xmlsrc, settings);
IResource filters = project2.findMember("/.settings/.api_filters", true); //$NON-NLS-1$
assertNotNull("the .api_filters file must exist in the testing project", filters); //$NON-NLS-1$
}
Expand Down Expand Up @@ -242,10 +239,10 @@ public void testAddFilterFromProblem() throws CoreException {
* Tests that a filter store will not be annotated from a bundle
*/
@Test
public void testAnnotateStoreFromBundle() throws InvocationTargetException, IOException, CoreException {
public void testAnnotateStoreFromBundle() throws CoreException {
IProject project = getTestingJavaProject(TESTING_PLUGIN_PROJECT_NAME).getProject();
FileUtils.importFileFromDirectory(PLUGIN_LOC.append("component_c_1.0.0.jar").toFile(), project.getFullPath(), //$NON-NLS-1$
new NullProgressMonitor());
FileUtils.importFileFromDirectory(PLUGIN_LOC.append("component_c_1.0.0.jar").toFile(), project.getFullPath()); //$NON-NLS-1$

IResource res = project.findMember("component_c_1.0.0.jar"); //$NON-NLS-1$
assertNotNull("the jar should exist in the project dir", res); //$NON-NLS-1$
IResource jar = project.findMember("component_c_1.0.0.jar"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.pde.api.tools.internal.FilterStore;
Expand Down Expand Up @@ -67,7 +66,7 @@ public void setUp() throws Exception {
IJavaProject project = getTestingJavaProject(TESTING_PLUGIN_PROJECT_NAME);
IPackageFragmentRoot srcroot = project.findPackageFragmentRoot(project.getProject().getFullPath().append("src")); //$NON-NLS-1$
assertNotNull("the default src root must exist", srcroot); //$NON-NLS-1$
FileUtils.importFileFromDirectory(projectSrc, srcroot.getPath(), new NullProgressMonitor());
FileUtils.importFileFromDirectory(projectSrc, srcroot.getPath());

// Import the test .api_filters file
File xmlsrc = XML_LOC.append(".api_filters").toFile(); //$NON-NLS-1$
Expand All @@ -76,7 +75,7 @@ public void setUp() throws Exception {
assertNotNull("no project", project); //$NON-NLS-1$
IProject project2 = project.getProject();
IPath settings = project2.getFullPath().append(".settings"); //$NON-NLS-1$
FileUtils.importFileFromDirectory(xmlsrc, settings, new NullProgressMonitor());
FileUtils.importFileFromDirectory(xmlsrc, settings);
IResource filters = project2.findMember("/.settings/.api_filters", true); //$NON-NLS-1$
assertNotNull("the .api_filters file must exist in the testing project", filters); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public IApiScope getScope() {
* Checks the given {@link IApiComponent} to see if we allow it to appear in the scope or not
* @return true if the given component should be allowed in the scope false otherwise
*/
private boolean acceptComponent0(IApiComponent component) throws CoreException {
private boolean acceptComponent0(IApiComponent component) {
return component != null &&
!this.excluded.contains(component.getSymbolicName()) &&
isApiComponent(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
Expand All @@ -37,7 +35,6 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.eclipse.pde.api.tools.model.tests.TestSuiteHelper;

Expand Down Expand Up @@ -74,17 +71,15 @@ public static void addJavaFiles(File dir, List<File> collection) throws IOExcept
subDirs.add(file);
}
}
Iterator<File> iter = subDirs.iterator();
while (iter.hasNext()) {
File subDir = iter.next();
for (File subDir : subDirs) {
addJavaFiles(subDir, collection);
}
}

/**
* Imports files from the specified root directory into the specified path
*/
public static void importFilesFromDirectory(File rootDir, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException, IOException {
public static void importFilesFromDirectory(File rootDir, IPath destPath) {
IResource findMember = ResourcesPlugin.getWorkspace().getRoot().getFolder(destPath);
File dest = findMember.getLocation().toFile();
if (!dest.exists()) {
Expand All @@ -100,7 +95,7 @@ public static void importFilesFromDirectory(File rootDir, IPath destPath, IProgr
/**
* Imports the specified file to the destination path
*/
public static void importFileFromDirectory(File file, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException, IOException {
public static void importFileFromDirectory(File file, IPath destPath) {
IResource findMember = null;
if (destPath.segmentCount() == 1) {
findMember = ResourcesPlugin.getWorkspace().getRoot().getProject(destPath.lastSegment());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -299,9 +297,9 @@ public void testCleanUpMmanager() {
* @param sourcename the name of the source file without an extension e.g.
* TestClass1
*/
public void assertTestSource(IPackageFragmentRoot root, String packagename, String sourcename) throws InvocationTargetException, IOException {
public void assertTestSource(IPackageFragmentRoot root, String packagename, String sourcename) {
IPackageFragment fragment = root.getPackageFragment(packagename);
FileUtils.importFileFromDirectory(SRC_LOC.append(sourcename + ".java").toFile(), fragment.getPath(), new NullProgressMonitor()); //$NON-NLS-1$
FileUtils.importFileFromDirectory(SRC_LOC.append(sourcename + ".java").toFile(), fragment.getPath()); //$NON-NLS-1$
}

/**
Expand Down Expand Up @@ -334,14 +332,14 @@ public IPackageFragment assertTestPackage(IJavaProject project, IPath srcroot, S
* imported to
* @param libname the name of the library
*/
public IFolder assertTestLibrary(IJavaProject project, IPath folderpath, String libname) throws CoreException, InvocationTargetException, IOException {
public IFolder assertTestLibrary(IJavaProject project, IPath folderpath, String libname) throws CoreException {
IFolder folder = null;
// import library
folder = project.getProject().getFolder(folderpath);
if (!folder.exists()) {
folder.create(false, true, null);
}
FileUtils.importFileFromDirectory(PLUGIN_LOC.append(libname).toFile(), folder.getFullPath(), null);
FileUtils.importFileFromDirectory(PLUGIN_LOC.append(libname).toFile(), folder.getFullPath());
IPath libPath = folder.getFullPath().append(libname);

// add to manifest bundle classpath
Expand Down Expand Up @@ -468,9 +466,8 @@ public void testWPUpdateSourceTypeChanged() throws Exception {
assertNotNull("The testing project must exist", project); //$NON-NLS-1$
IPackageFragmentRoot root = project.findPackageFragmentRoot(IPath.fromOSString(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute());
assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$
NullProgressMonitor monitor = new NullProgressMonitor();
IPackageFragment fragment = root.getPackageFragment("a.b.c"); //$NON-NLS-1$
FileUtils.importFileFromDirectory(SRC_LOC.append("TestClass2.java").toFile(), fragment.getPath(), monitor); //$NON-NLS-1$
FileUtils.importFileFromDirectory(SRC_LOC.append("TestClass2.java").toFile(), fragment.getPath()); //$NON-NLS-1$
ICompilationUnit element = (ICompilationUnit) project.findElement(IPath.fromOSString("a/b/c/TestClass2.java")); //$NON-NLS-1$
assertNotNull("TestClass2 must exist in the test project", element); //$NON-NLS-1$
updateTagInSource(element, "TestClass2", null, "@noinstantiate", false); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -198,7 +197,7 @@ public void setUp() throws Exception {
assertTrue("the source dir must exist", src.exists()); //$NON-NLS-1$
assertTrue("the source dir must be a directory", src.isDirectory()); //$NON-NLS-1$
assertNotNull("the srcroot for the test java project must not be null", srcroot); //$NON-NLS-1$
FileUtils.importFilesFromDirectory(src, srcroot.getPath().append("javadoc"), new NullProgressMonitor()); //$NON-NLS-1$
FileUtils.importFilesFromDirectory(src, srcroot.getPath().append("javadoc")); //$NON-NLS-1$

ApiToolingSetupRefactoring refactoring = new ApiToolingSetupRefactoring();
CompositeChange change = new CompositeChange("Test"); //$NON-NLS-1$
Expand Down Expand Up @@ -265,8 +264,6 @@ private void createTagChanges(CompositeChange projectchange, IJavaProject projec
}
} catch (CoreException e) {
ApiUIPlugin.log(e);
} catch (IOException e) {
ApiUIPlugin.log(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -85,15 +83,14 @@ public void tearDown() throws Exception {
* Tests importing the java source for the Javadoc tag update tests
*/
@Test
public void testImportJavadocTestSource() throws InvocationTargetException, IOException, JavaModelException {
public void testImportJavadocTestSource() throws JavaModelException {
File dest = new File(JAVADOC_SRC_DIR);
assertTrue("the source dir must exist", dest.exists()); //$NON-NLS-1$
assertTrue("the source dir must be a directory", dest.isDirectory()); //$NON-NLS-1$
IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
IPackageFragmentRoot srcroot = project.getPackageFragmentRoot(ProjectUtils.SRC_FOLDER);
assertNotNull("the srcroot for the test java project must not be null", srcroot); //$NON-NLS-1$
FileUtils.importFilesFromDirectory(dest, project.getPath().append(srcroot.getPath()).append("javadoc"), //$NON-NLS-1$
new NullProgressMonitor());
FileUtils.importFilesFromDirectory(dest, project.getPath().append(srcroot.getPath()).append("javadoc")); //$NON-NLS-1$
// try to look up a file to test if it worked
IType type = project.findType("javadoc.JavadocTestClass1", new NullProgressMonitor()); //$NON-NLS-1$
assertNotNull("the JavadocTestClass1 type should exist in the javadoc package", type); //$NON-NLS-1$
Expand All @@ -103,16 +100,15 @@ public void testImportJavadocTestSource() throws InvocationTargetException, IOEx
* Tests importing the java source for the javadoc tag reading tests
*/
@Test
public void testImportClassesTestSource() throws InvocationTargetException, IOException {
public void testImportClassesTestSource() {
File dest = new File(JAVADOC_READ_SRC_DIR);
assertTrue("the source dir must exist", dest.exists()); //$NON-NLS-1$
assertTrue("the source dir must be a directory", dest.isDirectory()); //$NON-NLS-1$
IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
IPackageFragmentRoot srcroot = project.getPackageFragmentRoot(ProjectUtils.SRC_FOLDER);
assertNotNull("the srcroot for the test java project must not be null", srcroot); //$NON-NLS-1$
FileUtils.importFilesFromDirectory(dest,
project.getPath().append(srcroot.getPath()).append("a").append("b").append("c"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new NullProgressMonitor());
project.getPath().append(srcroot.getPath()).append("a").append("b").append("c")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.pde.api.tools.ui.internal.wizards;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -360,7 +359,7 @@ void createTagChanges(CompositeChange projectchange, IJavaProject project, File
}
projectchange.add(change);
}
} catch (CoreException | IOException e) {
} catch (CoreException e) {
ApiUIPlugin.log(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.pde.api.tools.internal.provisional.ApiDescriptionVisitor;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
Expand Down Expand Up @@ -166,12 +165,10 @@
type = typeInProject;
}
if (type != null) {
processTagUpdates(type, refType, apiDescription, members, fCollector);
processTagUpdates(type, apiDescription, members, fCollector);
}
} catch (CoreException e) {
addStatus(e.getStatus());
} catch (BadLocationException e) {
addStatus(Status.error(ScannerMessages.ComponentXMLScanner_0 + element.toString(), e));
}
members.clear();
}
Expand Down Expand Up @@ -446,7 +443,7 @@
*/
public static String serializeComponentXml(File location) {
if (location.exists()) {
ZipFile jarFile = null;

Check warning on line 446 in apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/ApiDescriptionProcessor.java

View check run for this annotation

Jenkins - eclipse-pde / Eclipse ECJ

Code Style

NORMAL: Resource 'jarFile' should be managed by try-with-resource
InputStream stream = null;
try {
String extension = IPath.fromOSString(location.getName()).getFileExtension();
Expand Down Expand Up @@ -499,7 +496,8 @@
* @param project the java project to update
* @param componentxml the component.xml file to update from
*/
public static void collectTagUpdates(IJavaProject project, File componentxml, Map<IFile, Set<TextEdit>> collector) throws CoreException, IOException {
public static void collectTagUpdates(IJavaProject project, File componentxml, Map<IFile, Set<TextEdit>> collector)
throws CoreException {
IApiDescription description = new ApiDescription(null);
annotateApiSettings(project, description, serializeComponentXml(componentxml));
// visit the types
Expand All @@ -518,7 +516,8 @@
*
* @param members members with API annotations
*/
static void processTagUpdates(IType type, IReferenceTypeDescriptor desc, IApiDescription description, List<IElementDescriptor> members, Map<IFile, Set<TextEdit>> collector) throws CoreException, BadLocationException {
static void processTagUpdates(IType type, IApiDescription description,
List<IElementDescriptor> members, Map<IFile, Set<TextEdit>> collector) throws CoreException {
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
ICompilationUnit cunit = type.getCompilationUnit();
if (cunit != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ public InputStream getInputStream() throws FileNotFoundException {
* Returns the encoding for this compilation unit.
*
* @return the encoding to use
* @since 1.0.600
*/
public String getEncoding() throws CoreException {
public String getEncoding() {
return this.encoding;
}

Expand Down
Loading
Loading