Scans a single class for Swagger annotations - does not invoke ReaderListeners
435936
public Swagger read(Class<?> cls) {
        SwaggerDefinition swaggerDefinition = cls.getAnnotation(SwaggerDefinition.class);
        if (swaggerDefinition != null) {
            readSwaggerConfig(cls, swaggerDefinition);
        }

        return read(cls, "", null, false, new String[0], new String[0], new LinkedHashMap<>(), new ArrayList<>(), new HashSet<>());
    }
804377
@SuppressWarnings("unchecked")
    @VisibleForTesting
    Map<String, Class<? extends Service>> mapEventSources() throws IOException {

        /* Obtains all classpath's top level classes */
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Set<ClassPath.ClassInfo> classes = ClassPath.from(classLoader).getAllClasses();
        ClassLoaderRepository repository = new ClassLoaderRepository(classLoader);
        LOGGER.info("Scanning classpath for EventHandlers....");

        /* iterates over all classes, filter by HandlesEvent annotation and transforms stream to needed form */
        Map<String, Class<? extends Service>> collected = classes.parallelStream()
                /* loads class infos */
                .map(classInfo -> {
                    try {
                        /* sometimes exception occurs during class loading. Return empty/absent in this case */
                        return Optional.of(repository.loadClass(classInfo.getName()));
                    } catch (ClassNotFoundException e) {
                        LOGGER.trace("Class cannot be loaded: {}", classInfo.getName(), e);
                        return Optional.<JavaClass>empty();
                    }
                })
                /* filters classes which is present and marked with EventSource annotation */
                .filter(((Predicate<Optional<JavaClass>>) Optional::isPresent)
                        .and(javaClassOptional -> {
                            return Arrays.stream(javaClassOptional.get().getAnnotationEntries()).anyMatch(annotationEntry -> {
                                return Type.getType(annotationEntry.getAnnotationType()).toString().equals(EventSource.class.getCanonicalName());
                            });
                        })
                        .and(javaClassOptional -> {
                            try {
                                return Arrays.stream(javaClassOptional.get().getAllInterfaces()).anyMatch(iface -> {
                                    return iface.getClassName().equals(Service.class.getCanonicalName());
                                });
                            } catch (ClassNotFoundException e) {
                                LOGGER.trace("Class annotations cannot be loaded: {}", javaClassOptional.get().getClassName(), e);
                                return false;
                            }
                        }))
                /* transforms from Optional<JavaClass> to Class (obtaining values from Optionals) */
                .map(javaClassOptional -> {
                    try {
                        return (Class<? extends Service>) classLoader.loadClass(javaClassOptional.get().getClassName());
                    } catch (ClassNotFoundException e) {
                        LOGGER.trace("Class cannot be loaded: {}", javaClassOptional.get().getClassName(), e);
                        return null;
                    }
                })
                .filter(Objects::nonNull)
                .collect(Collectors.toMap(clazz -> clazz.getAnnotation(EventSource.class).value(), clazz -> clazz));

        LOGGER.info("Found {} event handlers", collected.size());
        return collected;
    }
488470
private Collection<KeyReader> findReader(final Class<? extends Saga> sagaClazz, final Class<?> messageClazz) {
        Saga saga = sagaProviderFactory.createProvider(sagaClazz).get();
        Collection<KeyReader> readers = saga.keyReaders();
        if (readers == null) {
            // return empty list in case saga returns null for any reason
            readers = new ArrayList<>();
        }

        return readers;
    }
962500
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
        GetField fields = in.readFields();
        classLoaderIdentifier = (String) fields.get(CLASS_LOADER_IDENTIFIER, null);

        // Note that further processing is required in JEEMetadataContextProviderImpl.deserializeThreadContext
        // in order to re-establish the thread context based on the metadata identifier if not defaulted.
    }
65157
private void introspect() {
    if (!listenerClass.isAnnotationPresent(EntityListener.class)) {
      String message = String.format(
          "Class %s must have %s annotation to be used as an EntityListener",
          listenerClass.getName(), EntityListener.class.getName());
      throw new EntityManagerException(message);
    }
    metadata = new ExternalListenerMetadata(listenerClass);
    processMethods();
  }
903588
@Override
    public void visit(SingleMemberAnnotationExpr anno, ControllerModel controller) {

        //org.wisdom.api.annotations.Path
        if(anno.getName().getName().equals(ANNOTATION_PATH)){
            controller.setBasePath(asString(anno.getMemberValue()));
        }
    }
628032
def get_swagger_view(title=None, url=None, generator_class=SchemaGenerator):
    
    return schemas.get_schema_view(
        title=title,
        url=url,
        renderer_classes=[
            CoreJSONRenderer,
            renderers.OpenAPIRenderer,
            renderers.SwaggerUIRenderer],
        generator_class=generator_class)
40631
private static List<ModuleRef> findModuleRefsFromCallstack(final Class<?>[] callStack, final ScanSpec scanSpec,
            final LogNode log) {
        final LinkedHashSet<Object> layers = new LinkedHashSet<>();
        if (callStack != null) {
            for (final Class<?> stackFrameClass : callStack) {
                final Object /* Module */ module = ReflectionUtils.invokeMethod(stackFrameClass, "getModule",
                        /* throwException = */ false);
                if (module != null) {
                    final Object /* ModuleLayer */ layer = ReflectionUtils.invokeMethod(module, "getLayer",
                            /* throwException = */ true);
                    // getLayer() returns null for unnamed modules -- have to get their classes from java.class.path 
                    if (layer != null) {
                        layers.add(layer);
                    }
                }
            }
        }
        // Add system modules from boot layer, if they weren't already found in stacktrace
        Class<?> moduleLayerClass = null;
        try {
            moduleLayerClass = Class.forName("java.lang.ModuleLayer");
        } catch (ClassNotFoundException | LinkageError e) {
            // Ignored
        }
        if (moduleLayerClass != null) {
            final Object /* ModuleLayer */ bootLayer = ReflectionUtils.invokeStaticMethod(moduleLayerClass, "boot",
                    /* throwException = */ false);
            if (bootLayer != null) {
                layers.add(bootLayer);
            }
        }
        return findModuleRefs(layers, scanSpec, log);
    }
905071
public ScanListener getScanListener()
    {
    	if (m_listener == null)
    	{
    		String strClassName = this.getProperty(LISTENER_CLASS);
    		if (strClassName == null)
    			strClassName = ReplaceScanListener.class.getName();
			m_listener = (ScanListener)ClassServiceUtility.getClassService().makeObjectFromClassName(strClassName);
			if (m_listener != null)
				((BaseScanListener)m_listener).init(this, null);
			else
				System.exit(0);
    	}
    	return m_listener;
    }
1230107
public static List<String> scanAsList(final Class<? extends Annotation> clas, final String... basePackage) {
		final List<String> classes = new ArrayList<>();
		scan(clas, basePackage, new AnnotationHandler() {

			@Override
			public void handleAnnotationFound(String className) {
				classes.add(className);
			}
		});
		return classes;
	}
1206812
private void readJSR303Annotations(UIComponent component) {
		coreExpression = ELTools.getCoreValueExpression(component);
		Annotation[] annotations = ELTools.readAnnotations(component);
		if (null != annotations) {
			for (Annotation a : annotations) {
				if (a instanceof Max) {
					long maximum = ((Max) a).value();
					max = maximum;
					hasMax = true;
				} else if (a instanceof Min) {
					long minimum = ((Min) a).value();
					hasMin = true;
					min = minimum;
				} else if (a instanceof Size) {
					maxSize = ((Size) a).max();
					hasMaxSize = maxSize > 0;
					minSize = ((Size) a).min();
					hasMinSize = minSize > 0;
				} else if (a instanceof NotNull) {
					isRequired = true;
				}
			}
		}

		clazz = ELTools.getType(component);
		if ((clazz == Integer.class) || (clazz == int.class)
				|| (clazz == Byte.class) || (clazz == byte.class)
				|| (clazz == Short.class) || (clazz == short.class)
				|| (clazz == Long.class) || (clazz == long.class)) {
			isInteger = true;
			isNumeric = true;
		} else if ((clazz == Double.class) || (clazz == double.class)
				|| (clazz == Float.class) || (clazz == float.class)) {
			isFloat = true;
			isNumeric = true;
		} else if ((clazz==Date.class) || (clazz==java.util.Date.class)) {
			isDate=true;
		}
	}
1049545
static ClassInfoList getAllStandardClasses(final Collection<ClassInfo> classes, final ScanSpec scanSpec) {
        return new ClassInfoList(ClassInfo.filterClassInfo(classes, scanSpec, /* strictWhitelist = */ true,
                ClassType.STANDARD_CLASS), /* sortByName = */ true);
    }
1098469
public static Builder from(Reader swaggerReader) {
        Validate.notNull(swaggerReader, "swaggerReader must not be null");
        Swagger swagger;
        try {
            swagger = new SwaggerParser().parse(IOUtils.toString(swaggerReader));
        } catch (IOException e) {
            throw new RuntimeException("Swagger source can not be parsed", e);
        }
        if (swagger == null)
            throw new IllegalArgumentException("Swagger source is in a wrong format");

        return new Builder(swagger);
    }
299376
public void scan(String classNamePattern, SaveHandler saveHandler) throws IOException {
        if (classNamePattern == null) {
            throw new IllegalArgumentException("classNamePattern must not be null");
        }

        classNamePattern = classNamePattern.replace(PACKAGE_SEPARATOR_CHAR, REGULAR_FILE_SEPARATOR_CHAR);
        String basePackageName = determineBasePackageName(classNamePattern);
        if (basePackageName == null) {
            return;
        }

        String subPattern;
        if (classNamePattern.length() > basePackageName.length()) {
            subPattern = classNamePattern.substring(basePackageName.length());
        } else {
            subPattern = StringUtils.EMPTY;
        }

        WildcardPattern pattern = WildcardPattern.compile(subPattern, REGULAR_FILE_SEPARATOR_CHAR);
        WildcardMatcher matcher = new WildcardMatcher(pattern);

        Enumeration<URL> resources = classLoader.getResources(basePackageName);

        if (!StringUtils.endsWith(basePackageName, REGULAR_FILE_SEPARATOR_CHAR)) {
            basePackageName += REGULAR_FILE_SEPARATOR_CHAR;
        }

        while (resources.hasMoreElements()) {
            URL resource = resources.nextElement();

            if (log.isDebugEnabled()) {
                log.debug("Scanning for components in path: " + resource.getFile());
            }

            if (isJarResource(resource)) {
                scanFromJarResource(resource, matcher, saveHandler);
            } else {
                scan(resource.getFile(), basePackageName, null, matcher, saveHandler);
            }
        }
    }
372522
protected void initEventAdaptors()
    {
        if ( _clientDecl == null || _clientDecl.getMethods() == null )
            return;
        
        for (MethodDeclaration clientMethod : _clientDecl.getMethods())
        {
            //
            // Do a quick check for the presence of the EventHandler annotation on methods
            //
            if (clientMethod.getAnnotation(EventHandler.class) == null ||
                clientMethod.toString().equals("<clinit>()"))
                continue;

            //
            // EventHandler annotations on private methods cause compilation error.
            //
            if (isPrivateMethod(clientMethod))
            {
                _ap.printError( clientMethod, "eventhandler.method.is.private");
                continue;
            }

            //
            // If found, we must actually read the value using an AnnotationMirror, since it
            // contains a Class element (eventSet) that cannot be loaded
            //
            AnnotationMirror handlerMirror = null;
            for (AnnotationMirror annot : clientMethod.getAnnotationMirrors())
            {
                if ( annot == null ||
                    annot.getAnnotationType() == null ||
                    annot.getAnnotationType().getDeclaration() == null ||
                    annot.getAnnotationType().getDeclaration().getQualifiedName() == null )
                    return;

                if ( annot.getAnnotationType().getDeclaration().getQualifiedName().equals(
                        "org.apache.beehive.controls.api.events.EventHandler"))
                {
                    handlerMirror = annot;
                    break;
                }
            }
            if (handlerMirror == null)
            {
                throw new CodeGenerationException("Unable to find EventHandler annotation on " +
                                                  clientMethod);
            }

            AptAnnotationHelper handlerAnnot = new AptAnnotationHelper(handlerMirror);

            //
            // Locate the EventField based upon the field element value
            //
            String fieldName = (String)handlerAnnot.getObjectValue("field");
            AptEventField eventField = (AptEventField)getField(fieldName);
            if (eventField == null)
            {
                // Deliberately not issuing a diagnostic if an event handler specifies
                // a field that isn't a control.  Other annotation processors also
                // handle event handlers, so delegate diagnostic responsibility to them.
                continue;
            }

            //
            // Locate the EventSet based upon the eventSet element value
            //
            Object tmo = handlerAnnot.getObjectValue("eventSet");
            if (!(tmo instanceof TypeMirror))
                continue;
            
            TypeMirror tm = (TypeMirror)tmo;
            String setName = tm.toString();

            AptControlInterface controlIntf = eventField.getControlInterface();
            AptEventSet eventSet = controlIntf.getEventSet(setName);

            // todo: remove workaround once bug has been resolved.
            /* Workaround JIRA issue BEEHIVE-1143, eventset name may
               contain a '$' seperator between the outer class and inner class.
               Should be a '.' seperator. Only applies to Eclipse APT. This
               workaround is also present in AptControlImplementation.initEventAdapters
             */
            if (tm.getClass().getName().startsWith("org.eclipse.")) {
                setName = setName.replace('$', '.');
            }
            // end of workaround

            if (eventSet == null)
            {
                _ap.printError( clientMethod, "eventhandler.eventset.not.found", setName );
                continue;
            }

            //
            // Register a new EventAdaptor for the EventSet, if none exists already
            //
            EventAdaptor adaptor = eventField.getEventAdaptor(eventSet);
            if (adaptor == null)
            {
                adaptor = new EventAdaptor(eventField, eventSet);
                eventField.addEventAdaptor(eventSet, adaptor);
            }

            //
            // Locate the EventSet method based upon the eventName element value.  Once
            // found, add a new AptEventHandler to the adaptor for this event.
            //
            boolean found = false;
            String eventName = (String)handlerAnnot.getObjectValue("eventName");
            AptMethod handlerMethod = new AptMethod(clientMethod, _ap);

            //
            // Will start at the currrent event set and look up through any ones it
            // extends to try and find a matching event
            //
            while (eventSet != null)
            {
                for (AptEvent controlEvent : eventSet.getEvents())
                {
                    if (controlEvent == null || 
                        controlEvent.getName() == null || 
                        !controlEvent.getName().equals(eventName))
                        continue;

                    if ( controlEvent.getArgTypes() == null )
                        continue;

                    //
                    // BUGBUG: If the arguments are parameterized, then the event handler
                    // might declare a specific bound version of the type, so a direct
                    // comparison will fail.  If parameterized, we don't validate.
                    //
                    if (controlEvent.hasParameterizedArguments() ||
                        (controlEvent.getArgTypes().equals(handlerMethod.getArgTypes()) &&
                         controlEvent.getReturnType().equals(handlerMethod.getReturnType())
                        )
                       )
                    {
                        HashSet<String> throwSet = new HashSet<String>(controlEvent.getThrowsList());
                        ArrayList<String> handlerThrows = handlerMethod.getThrowsList();
                        boolean throwsMatches = true;
                        for ( String t : handlerThrows )
                        {
                            if ( !throwSet.contains(t) )
                                throwsMatches = false;
                        }
                    
                        if ( !throwsMatches )
                        {
                            _ap.printError( clientMethod, "eventhandler.throws.mismatch", handlerMethod.getName() );
                        }

                        adaptor.addHandler(controlEvent, 
                                       new AptEventHandler(controlEvent, clientMethod, _ap ));
                        found = true;
                        break;
                    }
                }
                if (found)  // outer loop too
                    break;

                //
                // Look up on the super event set if not found at the current level
                //
                eventSet = eventSet.getSuperEventSet();
            }
            if (!found)
            {
                _ap.printError( clientMethod, "eventhandler.method.not.found", setName );
            }
        } 
    }
605863
private void scanClasses0(String basePackage)
            throws IOException, ClassNotFoundException, FileNotFoundException {
        File packageDirectory = null;
        ClassLoader cld = getLoader();
        String basePackagePath = basePackage.replace('.', '/');
        Enumeration<URL> basePackageUrls = cld.getResources(basePackagePath);
        if (basePackageUrls == null || !basePackageUrls.hasMoreElements()) {
            throw new ClassNotFoundException("Base package path not found: [" + basePackagePath
                    + "]");
        }
        while (basePackageUrls.hasMoreElements()) {
            String packagePath = basePackageUrls.nextElement().getFile();
            if (packagePath.contains(JAR_FILE_PATTERN)) {
                scanJarFile(basePackagePath, packagePath);
            } else {
                packageDirectory = new File(packagePath);
                scanDirectory(basePackage, packageDirectory);
            }
        }
    }
895627
public static void scan(final Class<? extends Annotation> clas, final String[] basePackage, final AnnotationHandler handler) {
		final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
		scanner.setResourceLoader(new PathMatchingResourcePatternResolver(Thread.currentThread().getContextClassLoader()));
		scanner.addIncludeFilter(new AnnotationTypeFilter(clas));
		for (final String pck : basePackage) {
			for (final BeanDefinition bd : scanner.findCandidateComponents(pck)) {
				handler.handleAnnotationFound(bd.getBeanClassName());
			}
		}
	}