public void first(Set<String> classNames) throws NotFoundException, ClassNotFoundException { // 扫描注册 ClassPool classPool = ClassPool.getDefault(); String tempClassName = null; Class register = Register.class; CtClass clazz; Object isRegister; Iterator<String> it = classNames.iterator(); while (it.hasNext()) { tempClassName = it.next(); clazz = classPool.get(tempClassName); isRegister = clazz.getAnnotation(register); AnnotationsAttribute a = (AnnotationsAttribute) clazz.getClassFile2().getAttribute(AnnotationsAttribute.visibleTag); Annotation[] as = a.getAnnotations(); for (Annotation an : as) { // System.out.println(String.format("MemberNames:%s ", an.getMemberNames())); Set anSet = an.getMemberNames(); Iterator anit = anSet.iterator(); while (anit.hasNext()) { System.out.println("type:" + anit.next().getClass()); } // AnnotationsAttribute a = (AnnotationsAttribute) // clazz.getClassFile().getAttribute(AnnotationsAttribute.visibleTag); // for() } System.err.println(a); System.err.println(a); // System.err.println(a.getName()); if (null != isRegister) System.out.println(isRegister); } }
/** * Constructs a list of Dialog objects based on Classes annotated by Component annotations. Scans * the provided list of classes constructing a Dialog object for each one annotated with the * Component annotation. Any classes provided in the class list which are not thusly annotated are * ignored. * * @param classList * @param zipOutputStream * @param reservedNames * @param xtypeMap * @param classLoader * @param classPool * @return A list of constructed Dialog objects * @throws InvalidComponentClassException * @throws InvalidComponentFieldException * @throws OutputFailureException * @throws IOException * @throws ParserConfigurationException * @throws TransformerException * @throws ClassNotFoundException * @throws CannotCompileException * @throws NotFoundException * @throws SecurityException * @throws NoSuchFieldException * @throws IllegalArgumentException * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws InstantiationException */ public static List<Dialog> buildDialogsFromClassList( ComponentNameTransformer transformer, List<CtClass> classList, ZipArchiveOutputStream zipOutputStream, Set<String> reservedNames, WidgetRegistry widgetRegistry, ClassLoader classLoader, ClassPool classPool, File buildDirectory, String componentPathBase, String defaultComponentPathSuffix) throws InvalidComponentClassException, InvalidComponentFieldException, OutputFailureException, IOException, ParserConfigurationException, TransformerException, ClassNotFoundException, CannotCompileException, NotFoundException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException { final List<Dialog> dialogList = new ArrayList<Dialog>(); for (CtClass curClass : classList) { ComponentMojoUtil.getLog().debug("Checking class for Component annotation " + curClass); boolean hasDialogFieldOrCQIncludeTab = false; for (CtField curField : ComponentMojoUtil.collectFields(curClass)) { if (curField.hasAnnotation(DialogField.class)) { hasDialogFieldOrCQIncludeTab = true; break; } } if (!hasDialogFieldOrCQIncludeTab) { for (CtMethod curMethod : ComponentMojoUtil.collectMethods(curClass)) { if (curMethod.hasAnnotation(DialogField.class)) { hasDialogFieldOrCQIncludeTab = true; break; } } } if (!hasDialogFieldOrCQIncludeTab) { Component componentAnnotation = (Component) curClass.getAnnotation(Component.class); for (Tab tab : componentAnnotation.tabs()) { if (StringUtils.isNotEmpty(tab.path())) { hasDialogFieldOrCQIncludeTab = true; break; } } } if (hasDialogFieldOrCQIncludeTab) { ComponentMojoUtil.getLog().debug("Processing Component Class " + curClass); Dialog builtDialog = DialogFactory.make(curClass, widgetRegistry, classLoader, classPool); dialogList.add(builtDialog); File dialogFile = writeDialogToFile( transformer, builtDialog, curClass, buildDirectory, componentPathBase, defaultComponentPathSuffix); writeDialogToArchiveFile( transformer, dialogFile, curClass, zipOutputStream, reservedNames, componentPathBase, defaultComponentPathSuffix); } } return dialogList; }