List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:de.fischer.thotti.core.configuration.ConfigDenormalizer.java
private String getFQCNFromHolderOfDTJ(ThottiAnnotationHolder<DistributedTestJob> holder) { AnnotatedElement element = holder.getOrigin(); assert element instanceof Class : "Only methods are currently supported."; Class clazz = (Class) element; assert clazz.isInterface() == false : "Annotation of interfaces is not supported."; return clazz.getCanonicalName(); }
From source file:net.sf.jasperreports.export.PropertiesDefaultsConfigurationFactory.java
/** * //from ww w. j a v a 2 s . c om */ private final C getProxy(Class<?> clazz, InvocationHandler handler) { List<Class<?>> allInterfaces = new ArrayList<Class<?>>(); if (clazz.isInterface()) { allInterfaces.add(clazz); } else { @SuppressWarnings("unchecked") List<Class<?>> lcInterfaces = ClassUtils.getAllInterfaces(clazz); allInterfaces.addAll(lcInterfaces); } @SuppressWarnings("unchecked") C proxy = (C) Proxy.newProxyInstance(ExporterConfiguration.class.getClassLoader(), allInterfaces.toArray(new Class<?>[allInterfaces.size()]), handler); return proxy; }
From source file:com.android.build.gradle.internal.incremental.fixture.ClassEnhancement.java
private void patchClass(@NonNull String name, @Nullable String patch) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException { Class<?> originalEnhancedClass = getClass().getClassLoader().loadClass(name); if (originalEnhancedClass.isInterface()) { // we don't patch interfaces. return;/*from w w w . j a va 2s . c o m*/ } Field newImplementationField = originalEnhancedClass.getField("$change"); // class might not be accessible from there newImplementationField.setAccessible(true); if (patch == null) { // Revert to original implementation. newImplementationField.set(null, null); return; } Object change = mEnhancedClassLoaders.get(patch).loadClass(name + "$override").newInstance(); newImplementationField.set(null, change); }
From source file:ClassTree.java
/** * Adds a new class and any parent classes that aren't yet part of the tree * @param c the class to add/*from ww w . j a v a2s .c om*/ * @return the newly added node. */ public DefaultMutableTreeNode addClass(Class<?> c) { // add a new class to the tree // skip non-class types if (c.isInterface() || c.isPrimitive()) return null; // if the class is already in the tree, return its node DefaultMutableTreeNode node = findUserObject(c); if (node != null) return node; // class isn't present--first add class parent recursively Class<?> s = c.getSuperclass(); DefaultMutableTreeNode parent; if (s == null) parent = root; else parent = addClass(s); // add the class as a child to the parent DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(c); model.insertNodeInto(newNode, parent, parent.getChildCount()); // make node visible TreePath path = new TreePath(model.getPathToRoot(newNode)); tree.makeVisible(path); return newNode; }
From source file:de.fischer.thotti.core.configuration.ConfigDenormalizer.java
private String getFQCNFromHolder(ThottiAnnotationHolder<NDTest> holder) { AnnotatedElement element = holder.getOrigin(); assert element instanceof Method : "Only methods are currently supported."; Method method = (Method) element; Class clazz = method.getDeclaringClass(); assert clazz.isInterface() == false : "Annotation of interfaces is not supported."; return clazz.getCanonicalName(); }
From source file:com.github.steveash.typedconfig.ConfigProxyFactory.java
/** * Simple convenience method that creates a proxy, implementing the given interface class, that retrieves values from the given {@link HierarchicalConfiguration}. * <p/>// www . j a va 2s . com * <tt>interfaze</tt> must represent a class that will be used as a "strongly-typed" configuration proxy whcih may * be optionally annotated with {@link com.github.steveash.typedconfig.annotation.ConfigProxy} containing methods optionally annotated with {@link com.github.steveash.typedconfig.annotation.Config} * * @param interfaze * @param configuration * @return */ @SuppressWarnings("unchecked") public <T> T make(Class<T> interfaze, HierarchicalConfiguration configuration) { Preconditions.checkNotNull(interfaze); Preconditions.checkArgument(interfaze.isInterface(), "You can only build proxies for interfaces"); // the context listens to the root configuration because the subnode configs dont seem to propagate events configuration.addConfigurationListener(context); ConfigBinding binding = ConfigBinding.makeRootBinding(TypeToken.of(interfaze)); ValueResolverFactory factory = context.getRegistry().lookup(binding); return (T) factory.makeForThis(binding, configuration, context).resolve(); }
From source file:com.agimatec.validation.jsr303.AgimatecValidatorFactory.java
/** * Return an object of the specified type to allow access to the * provider-specific API. If the Bean Validation provider * implementation does not support the specified class, the * ValidationException is thrown.// w w w. j a v a2 s.c o m * * @param type the class of the object to be returned. * @return an instance of the specified class * @throws ValidationException if the provider does not * support the call. */ public <T> T unwrap(Class<T> type) { if (type.isAssignableFrom(getClass())) { return (T) this; } else if (!type.isInterface()) { return SecureActions.newInstance(type); } else { try { Class<T> cls = ClassUtils.getClass(type.getName() + "Impl"); return SecureActions.newInstance(cls); } catch (ClassNotFoundException e) { throw new ValidationException("Type " + type + " not supported"); } } }
From source file:com.sleepcamel.ifdtoutils.MvnPluginMojo.java
@SuppressWarnings("deprecation") public void execute() throws MojoExecutionException { try {//from www. j a va 2s . c om if (outputDirectory == null || !outputDirectory.exists()) { throw new MojoExecutionException("Class directory must exist"); } URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { outputDirectory.toURL() }, getClass().getClassLoader()); Thread.currentThread().setContextClassLoader(urlClassLoader); Collection<File> listFiles = FileUtils.listFiles(outputDirectory, new String[] { "class" }, true); for (File file : listFiles) { getLog().debug("\nClass found: " + file.getName()); try { Class<?> loadedClass = urlClassLoader.loadClass(fileToClass(outputDirectory, file)); getLog().debug("Class " + loadedClass.getName() + " loaded"); if (!loadedClass.isInterface()) { getLog().debug("Not an interface :("); continue; } ToDTO annotation = loadedClass.getAnnotation(ToDTO.class); if (annotation == null) { getLog().debug("No annotation not found :("); } else { dtosToGenerate.add(loadedClass); getLog().debug("Annotation found!"); } } catch (ClassNotFoundException e) { } } getLog().info("Found " + dtosToGenerate.size() + " interfaces to generate their DTOs...\n"); for (Class<?> interfaceClass : dtosToGenerate) { String interfaceClassName = interfaceClass.getName(); try { Thread.currentThread().getContextClassLoader() .loadClass(InterfaceDTOInfo.getInfo(interfaceClass).getDTOCanonicalName()); getLog().info("DTO for interface " + interfaceClassName + " exists, skipping generation\n"); } catch (ClassNotFoundException e) { getLog().info("Generating dto for interface " + interfaceClassName + "..."); DTOClassGenerator.generateDTOForInterface(interfaceClass, outputDirectory.getAbsolutePath()); getLog().info("DTO generated for interface " + interfaceClassName + "\n"); } } } catch (Exception e1) { throw new MojoExecutionException(e1.getMessage()); } }
From source file:com.metaparadigm.jsonrpc.BeanSerializer.java
@Override public boolean canSerialize(Class clazz, Class jsonClazz) { return (!clazz.isArray() && !clazz.isPrimitive() && !clazz.isInterface() && (jsonClazz == null || jsonClazz == JSONObject.class)); }
From source file:org.crazydog.util.spring.ClassUtils.java
/** * Return all interfaces that the given class implements as Set, * including ones implemented by superclasses. * <p>If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze for interfaces * @param classLoader the ClassLoader that the interfaces need to be visible in * (may be {@code null} when accepting all declared interfaces) * @return all interfaces that the given object implements as Set *//*from w ww .j a v a 2 s. co m*/ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) { org.springframework.util.Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface() && isVisible(clazz, classLoader)) { return Collections.<Class<?>>singleton(clazz); } Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>(); while (clazz != null) { Class<?>[] ifcs = clazz.getInterfaces(); for (Class<?> ifc : ifcs) { interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader)); } clazz = clazz.getSuperclass(); } return interfaces; }