List of usage examples for java.lang Class isAnonymousClass
public boolean isAnonymousClass()
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.DeltaXmlSerializerFactoryTest.java
@SuppressWarnings({ "RawUseOfParameterizedType" }) public void testASerializerCanBeBuiltForEveryDelta() throws Exception { List<String> errors = new ArrayList<String>(); for (Class<? extends Delta> aClass : domainReflections.getSubTypesOf(Delta.class)) { if (!Modifier.isAbstract(aClass.getModifiers()) && !aClass.isAnonymousClass()) { Delta d = aClass.newInstance(); try { factory.createXmlSerializer(d); } catch (StudyCalendarError sce) { errors.add(String.format("Failure with %s: %s", d, sce.getMessage())); }/*from w ww. j a v a 2s . c o m*/ } } if (!errors.isEmpty()) { fail(StringUtils.join(errors.iterator(), '\n')); } }
From source file:org.assertj.assertions.generator.AssertionGeneratorTest.java
@Test public void should_generate_assertion_for_classes_in_package() throws Exception { Set<Class<?>> classes = collectClasses("org.assertj.assertions.generator.data"); for (Class<?> clazz : classes) { assertThat(clazz.isAnonymousClass()).as("check that <" + clazz.getSimpleName() + "> is not anonymous") .isFalse();// ww w.j a v a2 s.co m assertThat(clazz.isLocalClass()).as("check that " + clazz.getSimpleName() + " is not local").isFalse(); assertThat(isPublic(clazz.getModifiers())).as("check that " + clazz.getSimpleName() + " is public") .isTrue(); logger.info("Generating assertions for {}", clazz.getName()); final ClassDescription classDescription = converter.convertToClassDescription(clazz); File customAssertionFile = assertionGenerator.generateCustomAssertionFor(classDescription); logger.info("Generated {} assertions file -> {}", clazz.getSimpleName(), customAssertionFile.getAbsolutePath()); } }
From source file:org.assertj.assertions.generator.AssertionGeneratorTest.java
@Test public void should_generate_assertion_for_classes_in_package_using_provided_class_loader() throws Exception { ClassLoader customClassLoader = new MyClassLoader(Thread.currentThread().getContextClassLoader()); Set<Class<?>> classes = collectClasses(customClassLoader, "org.assertj.assertions.generator.data"); for (Class<?> clazz : classes) { assertThat(clazz.isAnonymousClass()).as("check that " + clazz.getSimpleName() + " is not anonymous") .isFalse();/*from w w w. j ava 2 s.c om*/ assertThat(clazz.isLocalClass()).as("check that " + clazz.getSimpleName() + " is not local").isFalse(); assertThat(isPublic(clazz.getModifiers())).as("check that " + clazz.getSimpleName() + " is public") .isTrue(); logger.info("Generating assertions for {}", clazz.getName()); final ClassDescription classDescription = converter.convertToClassDescription(clazz); File customAssertionFile = assertionGenerator.generateCustomAssertionFor(classDescription); logger.info("Generated {} assertions file -> {}", clazz.getSimpleName(), customAssertionFile.getAbsolutePath()); } }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.ChangeableXmlSerializerFactoryTest.java
@SuppressWarnings({ "RawUseOfParameterizedType" }) public void testASerializerCanBeBuiltForEveryChangeable() throws Exception { List<String> errors = new ArrayList<String>(); for (Class<? extends Changeable> aClass : domainReflections.getSubTypesOf(Changeable.class)) { if (!Modifier.isAbstract(aClass.getModifiers()) && !aClass.isAnonymousClass()) { Changeable c = aClass.newInstance(); try { factory.createXmlSerializer(c); } catch (StudyCalendarError sce) { errors.add(String.format("Failure with %s: %s", c, sce.getMessage())); }//from w w w . j ava 2s .c o m } } if (!errors.isEmpty()) { fail(StringUtils.join(errors.iterator(), '\n')); } }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.ChangeableXmlSerializerFactoryTest.java
@SuppressWarnings({ "RawUseOfParameterizedType" }) public void testASerializerCanBeBuiltForEveryElementCorrespondingToAChangeable() throws Exception { List<String> errors = new ArrayList<String>(); for (Class<? extends Changeable> aClass : domainReflections.getSubTypesOf(Changeable.class)) { if (!Modifier.isAbstract(aClass.getModifiers()) && !aClass.isAnonymousClass()) { XsdElement x = XsdElement.forCorrespondingClass(aClass); try { factory.createXmlSerializer(x.create()); } catch (StudyCalendarError sce) { errors.add(String.format("Failure with %s: %s", x, sce.getMessage())); }/*ww w .jav a 2s . com*/ } } if (!errors.isEmpty()) { fail(StringUtils.join(errors.iterator(), '\n')); } }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.ChangeXmlSerializerFactoryTest.java
@SuppressWarnings({ "RawUseOfParameterizedType" }) public void testASerializerCanBeBuiltForEveryChange() throws Exception { List<String> errors = new ArrayList<String>(); for (Class<? extends Change> aClass : domainReflections.getSubTypesOf(Change.class)) { if (Modifier.isPublic(aClass.getModifiers()) && !Modifier.isAbstract(aClass.getModifiers()) && !aClass.isAnonymousClass()) { Change c = aClass.newInstance(); try { factory.createXmlSerializer(c); } catch (StudyCalendarError sce) { errors.add(String.format("Failure with %s: %s", c, sce.getMessage())); }// w ww. jav a2 s . c o m } } if (!errors.isEmpty()) { fail(StringUtils.join(errors.iterator(), '\n')); } }
From source file:name.ikysil.beanpathdsl.codegen.Context.java
private boolean isExcluded(Class<?> clazz) { if (clazz.isPrimitive() || clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isInterface() || clazz.isSynthetic() || clazz.isEnum() || !Modifier.isPublic(clazz.getModifiers()) || (clazz.getPackage() == null)) { return true; }/*from www .j a v a 2 s . com*/ IncludedClass includedConfig = includedClasses.get(clazz); if (includedConfig != null) { return false; } ExcludedClass excludedConfig = excludedClasses.get(clazz); if (excludedConfig != null) { return true; } for (ExcludedPackage excludedPackage : excludedPackages) { if (excludedPackage.match(clazz.getPackage())) { return true; } } return false; }
From source file:org.makersoft.mvc.builder.PackageBasedUrlPathBuilder.java
/** * Interfaces, enums, annotations, and abstract classes cannot be instantiated. * //from w ww.j a va 2 s .co m * @param controllerClass * class to check * @return returns true if the class cannot be instantiated or should be ignored */ protected boolean cannotInstantiate(Class<?> controllerClass) { return controllerClass.isAnnotation() || controllerClass.isInterface() || controllerClass.isEnum() || (controllerClass.getModifiers() & Modifier.ABSTRACT) != 0 || controllerClass.isAnonymousClass(); }
From source file:com.liferay.portal.jsonwebservice.JSONWebServiceConfigurator.java
private boolean _isJSONWebServiceClass(Class<?> clazz) { if (!clazz.isAnonymousClass() && !clazz.isArray() && !clazz.isEnum() && !clazz.isLocalClass() && !clazz.isPrimitive() && !(clazz.isMemberClass() ^ Modifier.isStatic(clazz.getModifiers()))) { return true; }//from w w w . j av a 2 s . co m return false; }
From source file:org.evosuite.testcase.statements.FunctionalMockStatement.java
public static boolean canBeFunctionalMocked(Type type) { Class<?> rawClass = new GenericClass(type).getRawClass(); final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (Properties.hasTargetClassBeenLoaded() && (rawClass.equals(targetClass))) { return false; }/*from ww w . j a v a2s. c o m*/ if (EvoSuiteMock.class.isAssignableFrom(rawClass) || MockList.isAMockClass(rawClass.getName()) || rawClass.equals(Class.class) || rawClass.isArray() || rawClass.isPrimitive() || rawClass.isAnonymousClass() || rawClass.isEnum() || //note: Mockito can handle package-level classes, but we get all kinds of weird exceptions with instrumentation :( !Modifier.isPublic(rawClass.getModifiers())) { return false; } if (!InstrumentedClass.class.isAssignableFrom(rawClass) && Modifier.isFinal(rawClass.getModifiers())) { /* if a class has not been instrumented (eg because belonging to javax.*), then if it is final we cannot mock it :( recall that instrumentation does remove the final modifiers */ return false; } //FIXME: tmp fix to avoid mocking any class with package access methods try { for (Method m : rawClass.getDeclaredMethods()) { /* Unfortunately, it does not seem there is a "isPackageLevel" method, so we have to go by exclusion */ if (!Modifier.isPublic(m.getModifiers()) && !Modifier.isProtected(m.getModifiers()) && !Modifier.isPrivate(m.getModifiers()) && !m.isBridge() && !m.isSynthetic() && !m.getName().equals(ClassResetter.STATIC_RESET)) { return false; } } } catch (NoClassDefFoundError | Exception e) { //this could happen if we failed to load the class AtMostOnceLogger.warn(logger, "Failed to check if can mock class " + rawClass.getName() + ": " + e.getMessage()); return false; } //avoid cases of infinite recursions boolean onlySelfReturns = true; for (Method m : rawClass.getDeclaredMethods()) { if (!rawClass.equals(m.getReturnType())) { onlySelfReturns = false; break; } } if (onlySelfReturns && rawClass.getDeclaredMethods().length > 0) { //avoid weird cases like java.lang.Appendable return false; } //ad-hoc list of classes we should not really mock List<Class<?>> avoid = Arrays.asList( //add here if needed ); if (avoid.contains(rawClass)) { return false; } return true; }