Adding Missing Import Statements

Introduction

When you declare or use a class that is in the classpath but is not yet imported into your Java program, Eclipse provides a Quick Fix that can add an import statement for that class to the top of the source file. Eclipse also provides an Organize Imports action that can add the necessary imports for a given source file. However, neither the Eclipse Quick Fix nor the Organize Imports action are aware of the SAS Versioned Jar Repository.
If you are using content from the SAS Versioned Jar Repository, use the SAS Import from Repository Quick Fix and the Organize SAS Imports action because both are aware of the SAS Versioned Jar Repository.

Using a SAS Import from Repository Quick Fix

A SAS Import from Repository Quick Fix is displayed when there is a compilation error because a class used in the code cannot be resolved in the current source file.
If you accept the Quick Fix, the SAS Import from Repository Quick Fix adds the following items:
  • the JAR file containing the class to the project classpath
  • an import statement for the class to the current file.
If the name of the class (excluding the package) is included on the current project classpath, Eclipse provides a Quick Fix for each of the candidate class names. If there are additional candidate class names in the latest versions of one or more JAR files in the SAS Versioned Jar Repository, Quick Fixes are also provided for those class names.
A displayed Quick Fix
To use one of the SAS Import from Repository Quick Fixes (marked with a SAS icon), double-click the Quick Fix or select the Quick Fix and press Enter. If you use a SAS Import from Repository Quick Fix and the Build Automatically option is enabled, the entire project is rebuilt because the classpath has changed.

Using the Organize SAS Imports Action

In cases where there are multiple unknown types used in a source file, the Organize SAS Imports action can guide you through the process of resolving all of the unknown classes (both classes from the SAS Versioned Jar Repository and other classes) in the current source file. If you add any new JAR files to the project dependencies, the project must be rebuilt.
A Java file that cannot be found in a class exists in one of two states:
  • the class is currently on the project classpath, but it has not been imported into the Java file. In this case, an import statement is added to the file and a build of that particular file is required.
  • the class is not currently on the project classpath. In this case, the classpath must be modified to include the required jar file or files, and an import statement must be added to the file. A full build of the project is required because of the change to the classpath.
To start the Organize SAS Imports action, right-click in a Java file in the Java editor and select Sourcethen selectOrganize SAS Imports.