public void visit(VirtualFile file) { if(file.isFile()) { accepts(file); } }
public boolean accepts(VirtualFile file) { String path = getFilePath(file); boolean accepts = false; try { accepts = file.isLeaf() == false && childPaths.contains(path) == false; } catch(Exception e) { } return accepts; }
try className = getClassName(file); Class<?> c = loader.loadClass(className); boolean hasAnnotations = hasAnnotations(c); boolean includeClass = false; if(clientClassName != null)
/** * Get the classes we want to scan. * * @param unit the deployment unit * @param mainClassName the main class name * @param classpath the classpath * @return possible classes containing metadata annotations * @throws IOException for any error */ protected Collection<Class<?>> getClasses(VFSDeploymentUnit unit, String mainClassName, VirtualFile classpath) throws IOException { AnnotatedClassFilter classVisitor = new AnnotatedClassFilter(unit, unit.getClassLoader(), classpath, mainClassName); classpath.visit(classVisitor); Map<VirtualFile, Class<?>> classes = classVisitor.getAnnotatedClasses(); if (classes != null && classes.size() > 0) { if(log.isTraceEnabled()) log.trace("Annotated classes: " + classes); } else { classes = new HashMap<VirtualFile, Class<?>>(); } return classes.values(); }
/** * Completely scan a class for annotations * @param cls * @return true if the class has annotations, false otherwise */ protected boolean hasAnnotations(Class<?> cls) { if(cls == null) return false; // Note: this also returns true if super class has annotations if(cls.getAnnotations().length > 0) return true; for(Method m : cls.getDeclaredMethods()) { if(m.getAnnotations().length > 0) return true; } for(Field f : cls.getDeclaredFields()) { if(f.getAnnotations().length > 0) return true; } return hasAnnotations(cls.getSuperclass()); }