Example usage for java.lang Class isInterface

List of usage examples for java.lang Class isInterface

Introduction

In this page you can find the example usage for java.lang Class isInterface.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isInterface();

Source Link

Document

Determines if the specified Class object represents an interface type.

Usage

From source file:se.crisp.codekvast.agent.daemon.codebase.CodeBaseScanner.java

void findTrackedMethods(CodeBase codeBase, Set<String> packages, Set<String> excludePackages, Class<?> clazz) {
    if (clazz.isInterface()) {
        log.debug("Ignoring interface {}", clazz);
        return;/*from   w ww  .  ja  va2  s  . c o  m*/
    }

    log.debug("Analyzing {}", clazz);
    MethodAnalyzer methodAnalyzer = codeBase.getConfig().getMethodAnalyzer();
    try {
        Method[] declaredMethods = clazz.getDeclaredMethods();
        Method[] methods = clazz.getMethods();
        Method[] allMethods = new Method[declaredMethods.length + methods.length];
        System.arraycopy(declaredMethods, 0, allMethods, 0, declaredMethods.length);
        System.arraycopy(methods, 0, allMethods, declaredMethods.length, methods.length);

        for (Method method : allMethods) {
            SignatureStatus status = methodAnalyzer.apply(method);

            // Some AOP frameworks (e.g., Guice) push methods from a base class down to subclasses created in runtime.
            // We need to map those back to the original declaring signature, or else the original declared method will look unused.

            MethodSignature thisSignature = SignatureUtils.makeMethodSignature(clazz, method);

            MethodSignature declaringSignature = SignatureUtils.makeMethodSignature(
                    findDeclaringClass(method.getDeclaringClass(), method, packages), method);

            if (shouldExcludeSignature(declaringSignature, excludePackages)) {
                status = SignatureStatus.EXCLUDED_BY_PACKAGE_NAME;
            }
            codeBase.addSignature(thisSignature, declaringSignature, status);
        }

        for (Class<?> innerClass : clazz.getDeclaredClasses()) {
            findTrackedMethods(codeBase, packages, excludePackages, innerClass);
        }
    } catch (NoClassDefFoundError e) {
        log.warn("Cannot analyze {}: {}", clazz, e.toString());
    }
}

From source file:com.wavemaker.tools.apidocs.tools.parser.impl.ReflectionModelParser.java

protected Map<String, Property> getModelProperties(Class<?> classToScan) {

    Map<String, Property> propertyMap;
    if (classToScan.isInterface()) {
        propertyMap = parsePropertiesUsingGetters(classToScan);
    } else {/*from  w  ww .  ja  v  a  2s .  co m*/
        propertyMap = parsePropertiesUsingFields(classToScan);
    }

    return propertyMap;
}

From source file:org.codeseed.common.config.ext.CommandLineOptionsBuilder.java

/**
 * Scans the supplied configuration interface for command line options.
 *
 * @param configuration//from w ww .j ava2s.c o  m
 *            the configuration interface to find command line options from
 * @return this builder
 */
public CommandLineOptionsBuilder addFrom(Class<? extends Configuration> configuration) {
    checkArgument(configuration.isInterface(), "must be an interface: %s", configuration);
    for (Method method : configuration.getMethods()) {
        CommandLine commandLine = method.getAnnotation(CommandLine.class);
        if (commandLine != null) {
            methods.add(method);
        }
    }
    return this;
}

From source file:adalid.core.XS1.java

private static boolean isRestrictedFieldType(Class<?> fieldType) {
    int modifiers = fieldType.getModifiers();
    boolean b = fieldType.isPrimitive();
    b |= Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers);
    b |= fieldType.isAnnotation();//from w ww  . ja va  2  s. co m
    b |= fieldType.isAnonymousClass();
    b |= fieldType.isArray();
    b |= fieldType.isEnum();
    b |= fieldType.isLocalClass();
    b |= fieldType.isInterface();
    return b;
}

From source file:org.impalaframework.command.basic.ModuleDefinitionAwareClassFilter.java

public boolean accept(File pathname) {
    if (!super.accept(pathname)) {
        return false;
    }/*from w ww  .  j  av  a 2  s .  c o m*/

    if (pathname.isDirectory()) {
        return true;
    }

    if (rootCanonicalPath == null) {
        throw new ConfigurationException("root canonical path not set");
    }

    String canonicalPath = null;
    try {
        canonicalPath = pathname.getCanonicalPath();
    } catch (IOException e) {
        logger.error("Could not read canonical path for " + pathname, e);
        return false;
    }
    String relativePath = canonicalPath.substring(rootCanonicalPath.length());

    relativePath = relativePath.replace(File.separator, ".");
    relativePath = relativePath.replace("/", ".");
    relativePath = relativePath.substring(0, relativePath.length() - ".class".length());
    if (relativePath.startsWith(".")) {
        relativePath = relativePath.substring(1);
    }

    //create a classloader pointing to the supplied root file location
    ModuleClassLoader classLoader = new ModuleClassLoader(new File[] { this.rootFile });

    Class<?> forName = null;
    try {
        forName = Class.forName(relativePath, false, classLoader);
        if (forName.isInterface()) {
            return false;
        }

        int mods = forName.getModifiers();
        if (Modifier.isAbstract(mods)) {
            return false;
        }

        if (ModuleDefinitionSource.class.isAssignableFrom(forName)) {
            return true;
        }
    } catch (ClassNotFoundException e) {
        logger.error("Unable to resolve class associated with path " + pathname, e);
    }

    return false;

}

From source file:org.blocks4j.feature.toggle.factory.FeatureToggleFactory.java

private boolean isCommonInterfaceValid(Class<?> commonInterface) {
    return (commonInterface != null) && commonInterface.isInterface();
}

From source file:com.orange.mmp.api.ws.jsonrpc.SimpleListSerializer.java

@SuppressWarnings("unchecked")
@Override/*  w  ww  . jav  a2 s.c  om*/
public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    List list = null;
    try {
        try {
            try {
                if (clazz.isInterface()) {
                    list = new java.util.ArrayList();
                } else
                    list = (List) clazz.newInstance();
            } catch (ClassCastException cce) {
                throw new UnmarshallException("invalid unmarshalling Class " + cce.getMessage());
            }
        } catch (IllegalAccessException iae) {
            throw new UnmarshallException("no access unmarshalling object " + iae.getMessage());
        }
    } catch (InstantiationException ie) {
        throw new UnmarshallException("unable to instantiate unmarshalling object " + ie.getMessage());
    }
    JSONArray jsa = (JSONArray) o;

    state.setSerialized(o, list);
    int i = 0;
    try {
        for (; i < jsa.length(); i++) {
            list.add(ser.unmarshall(state, null, jsa.get(i)));
        }
    } catch (UnmarshallException e) {
        throw new UnmarshallException("element " + i + " " + e.getMessage());
    } catch (JSONException e) {
        throw new UnmarshallException("element " + i + " " + e.getMessage());
    }
    return list;
}

From source file:com.github.yuxiaobin.mybatis.gm.GeneralSqlSessionFactoryBean.java

private boolean checkValidateClassTypes(Class<?> entityClazz) {
    return !ClassUtils.isPrimitiveOrWrapper(entityClazz) && !entityClazz.isArray() && !entityClazz.isInterface()
            && !Object.class.equals(entityClazz) && checkBeanType(entityClazz);
}

From source file:org.jabsorb.ng.serializer.impl.ReferenceSerializer.java

@Override
public boolean canSerialize(final Class<?> clazz, final Class<?> jsonClazz) {

    return (!clazz.isArray() && !clazz.isPrimitive() && !clazz.isInterface()
            && (bridge.isReference(clazz) || bridge.isCallableReference(clazz))
            && (jsonClazz == null || jsonClazz == JSONObject.class));
}

From source file:de.digiway.rapidbreeze.server.infrastructure.objectstorage.migration.ObjectStorageMigrate.java

private List<Class<MigrateScript>> getScripts(String packageName) {
    try {//from   ww w  .jav  a 2 s.  com
        List<Class<MigrateScript>> newScripts = new ArrayList<>();
        for (Class clazz : getClasses(packageName)) {
            if (MigrateScript.class.isAssignableFrom(clazz) && !clazz.isInterface()) {
                newScripts.add(clazz);
            }
        }
        Collections.sort(newScripts, new Comparator<Class<MigrateScript>>() {
            @Override
            public int compare(Class<MigrateScript> o1, Class<MigrateScript> o2) {
                return o1.getSimpleName().compareTo(o2.getSimpleName());
            }
        });
        return newScripts;
    } catch (ClassNotFoundException | IOException ex) {
        throw new IllegalArgumentException("Cannot read migration scripts.", ex);
    }
}