All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.is24.javaparser.ImportDeclarations Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package de.is24.javaparser;

import com.google.common.base.Predicate;
import japa.parser.ast.ImportDeclaration;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static de.is24.deadcode4j.Utils.checkNotNull;

/**
 * Provides convenience methods for dealing with {@link japa.parser.ast.ImportDeclaration}s.
 *
 * @since 2.0.0
 */
public final class ImportDeclarations {

    private ImportDeclarations() {}

    /**
     * Returns a Predicate that evaluates to true if the ImportDeclaration being
     * tested is an asterisk import.
     *
     * @since 2.0.0
     */
    @Nonnull
    public static Predicate isAsterisk() {
        return new Predicate() {
            @Override
            @SuppressWarnings("ConstantConditions")
            public boolean apply(@Nullable ImportDeclaration input) {
                return checkNotNull(input).isAsterisk();
            }
        };
    }

    /**
     * Returns a Predicate that evaluates to true if the ImportDeclaration being
     * tested is a static import.
     *
     * @since 2.0.0
     */
    @Nonnull
    public static Predicate isStatic() {
        return new Predicate() {
            @Override
            @SuppressWarnings("ConstantConditions")
            public boolean apply(@Nullable ImportDeclaration input) {
                return checkNotNull(input).isStatic();
            }
        };
    }

    /**
     * Returns a Predicate that evaluates to true if the last qualifier of the
     * ImportDeclaration being tested matches the given String.
     *
     * @since 2.0.0
     */
    @Nonnull
    public static Predicate refersTo(@Nonnull final String lastQualifier) {
        return new Predicate() {
            @Override
            @SuppressWarnings("ConstantConditions")
            public boolean apply(@Nullable ImportDeclaration input) {
                return lastQualifier.equals(checkNotNull(input).getName().getName());
            }
        };
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy