Java Code Examples for com.sun.tools.xjc.outline.ClassOutline#getDeclaredFields()
The following examples show how to use
com.sun.tools.xjc.outline.ClassOutline#getDeclaredFields() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmbeddedAssociationMappingWrapper.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 6 votes |
private Collection<FieldOutline> getIdFieldsOutline( final ClassOutline classOutline) { final Collection<FieldOutline> idFieldOutlines = new ArrayList<FieldOutline>(); ClassOutline current = classOutline; while (current != null) { for (FieldOutline idFieldOutline : current.getDeclaredFields()) { final CPropertyInfo propertyInfo = idFieldOutline .getPropertyInfo(); if ((CustomizationUtils.containsCustomization(propertyInfo, Customizations.ID_ELEMENT_NAME) || CustomizationUtils .containsCustomization(propertyInfo, Customizations.EMBEDDED_ID_ELEMENT_NAME)) && !CustomizationUtils.containsCustomization( propertyInfo, Customizations.IGNORED_ELEMENT_NAME)) { idFieldOutlines.add(idFieldOutline); } } current = current.getSuperClass(); } return idFieldOutlines; }
Example 2
Source File: DefaultAssociationMapping.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 6 votes |
private Collection<FieldOutline> getIdFieldsOutline( final ClassOutline classOutline) { final Collection<FieldOutline> idFieldOutlines = new ArrayList<FieldOutline>(); ClassOutline current = classOutline; while (current != null) { for (FieldOutline idFieldOutline : current.getDeclaredFields()) { final CPropertyInfo propertyInfo = idFieldOutline .getPropertyInfo(); if ((CustomizationUtils.containsCustomization(propertyInfo, Customizations.ID_ELEMENT_NAME) || CustomizationUtils .containsCustomization(propertyInfo, Customizations.EMBEDDED_ID_ELEMENT_NAME)) && !CustomizationUtils.containsCustomization( propertyInfo, Customizations.IGNORED_ELEMENT_NAME)) { idFieldOutlines.add(idFieldOutline); } } current = current.getSuperClass(); } return idFieldOutlines; }
Example 3
Source File: EmbeddableAttributesMapping.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 6 votes |
public EmbeddableAttributes process(Mapping context, ClassOutline classOutline, Options options) { final EmbeddableAttributes attributes = new EmbeddableAttributes(); final FieldOutline[] fieldOutlines = classOutline.getDeclaredFields(); for (final FieldOutline fieldOutline : fieldOutlines) { final Object attributeMapping = getAttributeMapping(context, fieldOutline, options).process(context, fieldOutline, options); if (attributeMapping instanceof Basic) { attributes.getBasic().add((Basic) attributeMapping); } else if (attributeMapping instanceof Transient) { attributes.getTransient().add((Transient) attributeMapping); } } return attributes; }
Example 4
Source File: DefinedClassOutline.java From jaxb2-rich-contract-plugin with MIT License | 6 votes |
public DefinedClassOutline(final PluginContext pluginContext, final ClassOutline classOutline) { this.pluginContext = pluginContext; this.classOutline = classOutline; final List<DefinedPropertyOutline> properties = new ArrayList<>(classOutline.getDeclaredFields().length); for (final FieldOutline fieldOutline : classOutline.getDeclaredFields()) { properties.add(new DefinedPropertyOutline(fieldOutline)); } this.declaredFields = Collections.unmodifiableList(properties); if (this.classOutline.getSuperClass() != null) { this.superClass = new DefinedClassOutline(this.pluginContext, this.classOutline.getSuperClass()); } else { try { final Class<?> ungeneratedSuperClass = Class.forName(this.classOutline.implClass._extends().fullName()); if (Object.class.equals(ungeneratedSuperClass)) { this.superClass = null; } else { this.superClass = new ReferencedClassOutline(this.pluginContext.codeModel, ungeneratedSuperClass); } } catch (final Exception e) { throw new RuntimeException("Cannot find superclass of " + this.classOutline.target.getName() + ": " + this.classOutline.target.getLocator()); } } }
Example 5
Source File: MetaPlugin.java From jaxb2-rich-contract-plugin with MIT License | 6 votes |
private void generateMetaClass(final PluginContext pluginContext, final ClassOutline classOutline, final ErrorHandler errorHandler) throws SAXException { try { final JDefinedClass metaClass = classOutline.implClass._class(JMod.PUBLIC | JMod.STATIC, this.metaClassName); final JMethod visitMethod = generateVisitMethod(classOutline); for (final FieldOutline fieldOutline : classOutline.getDeclaredFields()) { if (this.extended) { generateExtendedMetaField(pluginContext, metaClass, visitMethod, fieldOutline); } else { generateNameOnlyMetaField(pluginContext, metaClass, fieldOutline); } } visitMethod.body()._return(JExpr._this()); } catch (final JClassAlreadyExistsException e) { errorHandler.error(new SAXParseException(getMessage("error.metaClassExists", classOutline.implClass.name(), this.metaClassName), classOutline.target.getLocator())); } }
Example 6
Source File: CustomizationUtils.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
public static FieldOutline findFieldWithCustomization(ClassOutline classOutline, final QName name) { for (final FieldOutline fieldOutline : classOutline.getDeclaredFields()) { final CCustomizations customizations = getCustomizations(fieldOutline); final CPluginCustomization customization = customizations.find(name.getNamespaceURI(), name.getLocalPart()); if (customization != null) return fieldOutline; } return null; }
Example 7
Source File: CustomizationUtils.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
public static FieldOutline findInheritedFieldWithCustomization(ClassOutline classOutline, final QName name) { for (final FieldOutline fieldOutline : classOutline.getDeclaredFields()) { if (containsCustomization(fieldOutline, name)) { return fieldOutline; } } final ClassOutline superClassOutline = classOutline.getSuperClass(); if (superClassOutline != null) { return findInheritedFieldWithCustomization(superClassOutline, name); } else { return null; } }
Example 8
Source File: FixJAXB1058Plugin.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { try { DummyListField_$get = new FieldAccessor<JMethod>( DummyListField.class, "$get", JMethod.class); IsSetField_core = new FieldAccessor<FieldOutline>(IsSetField.class, "core", FieldOutline.class); AbstractListField_field = new FieldAccessor<JFieldVar>( DummyListField.class.getSuperclass(), "field", JFieldVar.class); AbstractListField_listT = new FieldAccessor<JClass>( DummyListField.class.getSuperclass(), "listT", JClass.class); DummyListField_coreList = new FieldAccessor<JClass>( DummyListField.class, "coreList", JClass.class); } catch (Exception ex) { throw new SAXException("Could not create field accessors. " + "This plugin can not be used in this environment.", ex); } for (ClassOutline classOutline : outline.getClasses()) { for (FieldOutline fieldOutline : classOutline.getDeclaredFields()) { fixFieldOutline(fieldOutline); } } return false; }
Example 9
Source File: DefaultIgnoring.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 5 votes |
public void markAsAcknowledged(ClassOutline classOutline) { Customizations.markAsAcknowledged(classOutline.target); for (final FieldOutline fieldOutline : classOutline.getDeclaredFields()) { Customizations.markAsAcknowledged(fieldOutline.getPropertyInfo()); } }
Example 10
Source File: GroupInterfaceGenerator.java From jaxb2-rich-contract-plugin with MIT License | 5 votes |
private FieldOutline findField(final ClassOutline implClass, final PropertyUse propertyUse) throws SAXException { if (!propertyUse.isFixed()) { for (final FieldOutline field : implClass.getDeclaredFields()) { if (field.getPropertyInfo().getName(true).equals(propertyUse.getName())) { return field; } } this.pluginContext.errorHandler.error(new SAXParseException(MessageFormat.format(GroupInterfaceGenerator.RESOURCE_BUNDLE.getString("error.property-not-found"), propertyUse.declaration.toString(), propertyUse.getName(), implClass.implClass.fullName()), propertyUse.declaration.getLocator())); } return null; }
Example 11
Source File: AttributesMapping.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
public Attributes process(Mapping context, ClassOutline classOutline, Options options) { final Attributes attributes = new Attributes(); final FieldOutline[] fieldOutlines = classOutline.getDeclaredFields(); for (final FieldOutline fieldOutline : fieldOutlines) { final Object attributeMapping = getAttributeMapping(context, fieldOutline, options).process(context, fieldOutline, options); if (attributeMapping instanceof Id) { if (attributes.getEmbeddedId() == null) { attributes.getId().add((Id) attributeMapping); } else { logger.error("Could not add an id element to the attributes of the class [" + fieldOutline.parent().target.getName() + "] because they already contain an embedded-id element."); } } else if (attributeMapping instanceof EmbeddedId) { if (!attributes.getId().isEmpty()) { logger.error("Could not add an embedded-id element to the attributes of the class [" + fieldOutline.parent().target.getName() + "] because they already contain an id element."); } else if (attributes.getEmbeddedId() != null) { logger.error("Could not add an embedded-id element to the attributes of the class [" + fieldOutline.parent().target.getName() + "] because they already contain an embedded-id element."); } else { attributes.setEmbeddedId((EmbeddedId) attributeMapping); } } else if (attributeMapping instanceof Basic) { attributes.getBasic().add((Basic) attributeMapping); } else if (attributeMapping instanceof Version) { attributes.getVersion().add((Version) attributeMapping); } else if (attributeMapping instanceof ManyToOne) { attributes.getManyToOne().add((ManyToOne) attributeMapping); } else if (attributeMapping instanceof OneToMany) { attributes.getOneToMany().add((OneToMany) attributeMapping); } else if (attributeMapping instanceof OneToOne) { attributes.getOneToOne().add((OneToOne) attributeMapping); } else if (attributeMapping instanceof ManyToMany) { attributes.getManyToMany().add((ManyToMany) attributeMapping); } else if (attributeMapping instanceof ElementCollection) { attributes.getElementCollection().add( (ElementCollection) attributeMapping); } else if (attributeMapping instanceof Embedded) { attributes.getEmbedded().add((Embedded) attributeMapping); } else if (attributeMapping instanceof Transient) { attributes.getTransient().add((Transient) attributeMapping); } } return attributes; }
Example 12
Source File: BoundPropertiesPlugin.java From jaxb2-rich-contract-plugin with MIT License | 4 votes |
@Override public boolean run(final Outline outline, final Options opt, final ErrorHandler errorHandler) throws SAXException { if (!this.constrained && !this.bound) { return true; } final PluginContext pluginContext = PluginContext.get(outline, opt, errorHandler); final JCodeModel m = outline.getCodeModel(); if (this.generateTools) { // generate bound collection helper classes pluginContext.writeSourceFile(BoundList.class); pluginContext.writeSourceFile(BoundListProxy.class); pluginContext.writeSourceFile(CollectionChangeEventType.class); pluginContext.writeSourceFile(CollectionChangeEvent.class); pluginContext.writeSourceFile(CollectionChangeListener.class); pluginContext.writeSourceFile(VetoableCollectionChangeListener.class); } if(pluginContext.hasPlugin(ImmutablePlugin.class)) { errorHandler.error(new SAXParseException(getMessage("error.immutableAndConstrainedProperties"), outline.getModel().getLocator())); } final int setterAccess = JMod.PUBLIC; for (final ClassOutline classOutline : outline.getClasses()) { final JDefinedClass definedClass = classOutline.implClass; // Create bound collection proxies for (final FieldOutline fieldOutline : classOutline.getDeclaredFields()) { if (fieldOutline.getPropertyInfo().isCollection() && !definedClass.fields().get(fieldOutline.getPropertyInfo().getName(false)).type().isArray()) { generateProxyField(classOutline, fieldOutline); generateLazyProxyInitGetter(classOutline, fieldOutline); } } if (this.constrained && this.setterThrows) { for (final JMethod method : definedClass.methods()) { if (method.name().startsWith("with") && !"withVetoableChangeListener".equals(method.name()) && !"withPropertyChangeListener".equals(method.name()) ) { method._throws(PropertyVetoException.class); } } } if (this.constrained) createSupportProperty(outline, classOutline, VetoableChangeSupport.class, VetoableChangeListener.class, "vetoableChange"); if (this.bound) createSupportProperty(outline, classOutline, PropertyChangeSupport.class, PropertyChangeListener.class, "propertyChange"); for (final JFieldVar field : definedClass.fields().values()) { //final JFieldVar field = definedClass.fields().get(fieldOutline.getPropertyInfo().getName(false)); final JMethod oldSetter = definedClass.getMethod("set" + outline.getModel().getNameConverter().toPropertyName(field.name()), new JType[]{field.type()}); if (oldSetter != null && !field.type().isArray()) { definedClass.methods().remove(oldSetter); final JMethod setter = definedClass.method(setterAccess, m.VOID, "set" + outline.getModel().getNameConverter().toPropertyName(field.name())); final JVar setterArg = setter.param(JMod.FINAL, field.type(), "value"); final JBlock body = setter.body(); final JVar oldValueVar = body.decl(JMod.FINAL, field.type(), BoundPropertiesPlugin.OLD_VALUE_VAR_NAME, JExpr._this().ref(field)); if (this.constrained) { final JTryBlock tryBlock; final JBlock block; if (this.setterThrows) { block = body; setter._throws(PropertyVetoException.class); } else { tryBlock = body._try(); block = tryBlock.body(); final JCatchBlock catchBlock = tryBlock._catch(m.ref(PropertyVetoException.class)); final JVar exceptionVar = catchBlock.param("x"); catchBlock.body()._throw(JExpr._new(m.ref(RuntimeException.class)).arg(exceptionVar)); } invokeListener(block, field, oldValueVar, setterArg, "vetoableChange"); } body.assign(JExpr._this().ref(field), setterArg); if (this.bound) { invokeListener(body, field, oldValueVar, setterArg, "propertyChange"); } } } } return true; }
Example 13
Source File: AnnotatePlugin.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean run(Outline outline, Options options, ErrorHandler errorHandler){ JCodeModel codeModel = outline.getCodeModel(); Collection<? extends ClassOutline> classOutlines = outline.getClasses(); for(ClassOutline classOutline : classOutlines){ JDefinedClass beanClazz = classOutline.implClass; CPluginCustomization classCustomization = CustomizationUtils.findCustomization(classOutline, AnnotatePlugin.ANNOTATE_CLASS_QNAME); if(classCustomization != null){ annotate(codeModel, beanClazz, classCustomization); } Map<String, JFieldVar> fieldVars = beanClazz.fields(); FieldOutline[] fieldOutlines = classOutline.getDeclaredFields(); for(FieldOutline fieldOutline : fieldOutlines){ CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo(); List<CPluginCustomization> propertyCustomizations = CustomizationUtils.findPropertyCustomizationsInProperty(propertyInfo, AnnotatePlugin.ANNOTATE_PROPERTY_QNAME); for(CPluginCustomization propertyCustomization : propertyCustomizations){ JFieldVar fieldVar = fieldVars.get(propertyInfo.getName(false)); annotate(codeModel, fieldVar, propertyCustomization); } } } Collection<? extends EnumOutline> enumOutlines = outline.getEnums(); for(EnumOutline enumOutline : enumOutlines){ JDefinedClass clazz = enumOutline.clazz; CPluginCustomization enumCustomization = CustomizationUtils.findCustomization(enumOutline, AnnotatePlugin.ANNOTATE_ENUM_QNAME); if(enumCustomization != null){ annotate(codeModel, clazz, enumCustomization); } List<EnumConstantOutline> enumConstantOutlines = enumOutline.constants; for(EnumConstantOutline enumConstantOutline : enumConstantOutlines){ CCustomizations enumConstantCustomizations = enumConstantOutline.target.getCustomizations(); for(CPluginCustomization enumConstantCustomization : enumConstantCustomizations){ Element element = enumConstantCustomization.element; if((AnnotatePlugin.ANNOTATE_ENUM_CONSTANT_QNAME.getNamespaceURI()).equals(element.getNamespaceURI()) && (AnnotatePlugin.ANNOTATE_ENUM_CONSTANT_QNAME.getLocalPart()).equals(element.getLocalName())){ annotate(codeModel, enumConstantOutline.constRef, enumConstantCustomization); enumConstantCustomization.markAsAcknowledged(); } } } } return true; }