org.eclipse.jdt.core.dom.rewrite

## Class ImportRewrite.ImportRewriteContext

- java.lang.Object
- - org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext

Enclosing class:
  ImportRewrite

    public abstract static class ImportRewrite.ImportRewriteContext
    extends Object

A `ImportRewrite.ImportRewriteContext` can optionally be used in e.g. `ImportRewrite.addImport(String, ImportRewrite.ImportRewriteContext)` to give more information about the types visible in the scope. These types can be for example inherited inner types where it is unnecessary to add import statements for.

This class can be implemented by clients.

### Field Summary

Fields
`static int` `KIND_STATIC_FIELD` Kind constant specifying that the element is a static field import.
`static int` `KIND_STATIC_METHOD` Kind constant specifying that the element is a static method import.
`static int` `KIND_TYPE` Kind constant specifying that the element is a type import.
`static int` `RES_NAME_CONFLICT` Result constant signaling that the given element is conflicting with an other element in the context.
`static int` `RES_NAME_FOUND` Result constant signaling that the given element is know in the context.
`static int` `RES_NAME_UNKNOWN` Result constant signaling that the given element is not know in the context.
`static int` `RES_NAME_UNKNOWN_NEEDS_EXPLICIT_IMPORT` Result constant signaling that the given element must be imported explicitly (and must not be folded into an on-demand import or filtered as an implicit import).

### Constructor Summary

Constructors
Constructor and Description
`ImportRewriteContext()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`abstract int` `findInContext(String qualifier, String name, int kind)` Searches for the given element in the context and reports if the element is known (`RES_NAME_FOUND`), unknown (`RES_NAME_UNKNOWN`), unknown in the context but known to require an explicit import (`RES_NAME_UNKNOWN_NEEDS_EXPLICIT_IMPORT`), or if its name conflicts (`RES_NAME_CONFLICT`) with an other element.
`IAnnotationBinding[]` `removeRedundantTypeAnnotations(IAnnotationBinding[] annotations, ImportRewrite.TypeLocation location, ITypeBinding type)` This method can be overridden in subclasses to remove annotations that are redundant, e.g. because of NonNullByDefault.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### RES_NAME_FOUND

    public static final int RES_NAME_FOUND

Result constant signaling that the given element is know in the context.

See Also:
  Constant Field Values

#### RES_NAME_UNKNOWN

    public static final int RES_NAME_UNKNOWN

Result constant signaling that the given element is not know in the context.

See Also:
  Constant Field Values

#### RES_NAME_CONFLICT

    public static final int RES_NAME_CONFLICT

Result constant signaling that the given element is conflicting with an other element in the context.

See Also:
  Constant Field Values

#### RES_NAME_UNKNOWN_NEEDS_EXPLICIT_IMPORT

    public static final int RES_NAME_UNKNOWN_NEEDS_EXPLICIT_IMPORT

Result constant signaling that the given element must be imported explicitly (and must not be folded into an on-demand import or filtered as an implicit import).

Since:
  3.11
See Also:
  Constant Field Values

#### KIND_TYPE

    public static final int KIND_TYPE

Kind constant specifying that the element is a type import.

See Also:
  Constant Field Values

#### KIND_STATIC_FIELD

    public static final int KIND_STATIC_FIELD

Kind constant specifying that the element is a static field import.

See Also:
  Constant Field Values

#### KIND_STATIC_METHOD

    public static final int KIND_STATIC_METHOD

Kind constant specifying that the element is a static method import.

See Also:
  Constant Field Values

### Constructor Detail

#### ImportRewriteContext

    public ImportRewriteContext()

### Method Detail

#### findInContext

    public abstract int findInContext(String qualifier,
                                      String name,
                                      int kind)

Searches for the given element in the context and reports if the element is known (`RES_NAME_FOUND`), unknown (`RES_NAME_UNKNOWN`), unknown in the context but known to require an explicit import (`RES_NAME_UNKNOWN_NEEDS_EXPLICIT_IMPORT`), or if its name conflicts (`RES_NAME_CONFLICT`) with an other element.

Parameters:
  `qualifier` - The qualifier of the element, can be package or the qualified name of a type
  `name` - The simple name of the element; either a type, method or field name or * for on-demand imports.
  `kind` - The kind of the element. Can be either `KIND_TYPE`, `KIND_STATIC_FIELD` or `KIND_STATIC_METHOD`. Implementors should be prepared for new, currently unspecified kinds and return `RES_NAME_UNKNOWN` by default.
Returns:
  Returns the result of the lookup. Can be either `RES_NAME_FOUND`, `RES_NAME_UNKNOWN`, `RES_NAME_CONFLICT`, or `RES_NAME_UNKNOWN_NEEDS_EXPLICIT_IMPORT`.

#### removeRedundantTypeAnnotations

    public IAnnotationBinding[] removeRedundantTypeAnnotations(IAnnotationBinding[] annotations,
                                                               ImportRewrite.TypeLocation location,
                                                               ITypeBinding type)

This method can be overridden in subclasses to remove annotations that are redundant, e.g. because of NonNullByDefault.

Parameters:
  `annotations` - The array of type annotations to be filtered.
  `location` - Specifies how the type being annotated will be used.
  `type` - the type being annotated
Returns:
  Returns the annotations that should be added to the type.
Since:
  3.13