What is the role of ClassOutline / JClass / CClass in CodeModel?

后端 未结 2 1232
南笙
南笙 2020-11-28 12:07

My question concerns writing JAXB plugins, in particular JAXB codemodel.

What is the role of ClassOutline (and it\'s companions) and JClass

2条回答
  •  粉色の甜心
    2020-11-28 12:59

    (This is to answer your further questions.)

    Yes, it is possible to check customizations. Here is a class I am using to access customizations.

    The trick is that reference properties don't have own customizations, customizations are placed in the referenced element properties.

    public static CCustomizations getCustomizations(
            final CPropertyInfo propertyInfo) {
    
        final CCustomizations main = new CCustomizations(
                propertyInfo.getCustomizations());
    
        final Collection elementCustomizations = propertyInfo
                .accept(new CPropertyVisitor>() {
                    public Collection onAttribute(
                            CAttributePropertyInfo info) {
                        return Collections.emptyList();
                    }
    
                    public Collection onElement(
                            CElementPropertyInfo arg0) {
                        return Collections.emptyList();
                    }
    
                    public Collection onReference(
                            CReferencePropertyInfo info) {
    
                        final List elementCustomizations = new ArrayList(
                                info.getElements().size());
    
                        for (CElement element : info.getElements()) {
                            if (!(element instanceof CElementInfo && ((CElementInfo) element)
                                    .hasClass())) {
                                elementCustomizations.add(element
                                        .getCustomizations());
                            }
                        }
    
                        return elementCustomizations;
                    }
    
                    public Collection onValue(
                            CValuePropertyInfo arg0) {
                        return Collections.emptyList();
                    };
    
                });
    
        CCustomizations customizations = main;
    
        for (CCustomizations e : elementCustomizations) {
            main.addAll(e);
        }
    
        return customizations;
    }
    

    I'd say users@jaxb.java.net is a good place for such discussions.

提交回复
热议问题