Java Code Examples for com.sun.codemodel.JDefinedClass#fields()
The following examples show how to use
com.sun.codemodel.JDefinedClass#fields() .
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: PluginImpl.java From immutable-xjc with MIT License | 6 votes |
private ClassField[] getSuperclassFields(JDefinedClass clazz) { List<JDefinedClass> superclasses = getSuperClasses(clazz); // get all fields in class reverse order List<ClassField> superclassFields = new ArrayList<>(); Collections.reverse(superclasses); for (JDefinedClass classOutline : superclasses) { Map<String, JFieldVar> fields = classOutline.fields(); for (JFieldVar jFieldVar : fields.values()) { if (!(isStatic(jFieldVar) && isFinal(jFieldVar))) { superclassFields.add(new ClassField(classOutline, jFieldVar)); } } } return superclassFields.toArray(new ClassField[0]); }
Example 2
Source File: ImplementationBuilder.java From aem-component-generator with Apache License 2.0 | 5 votes |
/** * adds getters to all the fields available in the java class. * * @param jc */ private void addGetters(JDefinedClass jc) { Map<String, JFieldVar> fieldVars = jc.fields(); if (!fieldVars.isEmpty()) { for (Map.Entry<String, JFieldVar> entry : fieldVars.entrySet()) { if (entry.getValue() != null) { addGetter(jc, entry.getValue()); } } } }
Example 3
Source File: WSDLImporter.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void importStructure(Mapping mapping) { QName qname = mapping.getElement(); JDefinedClass theClass = (JDefinedClass) mapping.getType().getTypeClass(); SimpleStructureDefinition structure = (SimpleStructureDefinition) this.structures.get(this.namespace + qname.getLocalPart()); Map<String, JFieldVar> fields = theClass.fields(); int index = 0; for (Entry<String, JFieldVar> entry : fields.entrySet()) { Class<?> fieldClass = ReflectUtil.loadClass(entry.getValue().type().boxify().fullName()); structure.setFieldName(index, entry.getKey(), fieldClass); index++; } }
Example 4
Source File: WSDLImporter.java From flowable-engine with Apache License 2.0 | 4 votes |
protected void importStructure(Mapping mapping) { QName qname = mapping.getElement(); JDefinedClass theClass = (JDefinedClass) mapping.getType().getTypeClass(); SimpleStructureDefinition structure = (SimpleStructureDefinition) this.structures.get(this.namespace + qname.getLocalPart()); Map<String, JFieldVar> fields = theClass.fields(); int index = 0; for (Entry<String, JFieldVar> entry : fields.entrySet()) { final JType fieldType = entry.getValue().type(); final Class<?> fieldClass = ReflectUtil.loadClass(fieldType.boxify().fullName()); final Class<?> fieldParameterClass; if (fieldType instanceof JClass) { final JClass fieldClassType = (JClass) fieldType; final List<JClass> fieldTypeParameters = fieldClassType.getTypeParameters(); if (fieldTypeParameters.size() > 1) { throw new FlowableException( String.format("Field type '%s' with more than one parameter is not supported: %S", fieldClassType, fieldTypeParameters)); } else if (fieldTypeParameters.isEmpty()) { fieldParameterClass = null; } else { final JClass fieldParameterType = fieldTypeParameters.get(0); // Hack because JClass.fullname() doesn't return the right class fullname for a nested class to be // loaded from classloader. It should be contain "$" instead of "." as separator boolean isFieldParameterTypeNeestedClass = false; final Iterator<JDefinedClass> theClassNeestedClassIt = theClass.classes(); do { final JDefinedClass neestedType = theClassNeestedClassIt.next(); if (neestedType.name().equals(fieldParameterType.name())) { isFieldParameterTypeNeestedClass = true; } } while (!isFieldParameterTypeNeestedClass); if (isFieldParameterTypeNeestedClass) { // The parameter type is a nested class fieldParameterClass = ReflectUtil .loadClass(theClass.erasure().fullName() + "$" + fieldParameterType.name()); } else { // The parameter type is not a nested class fieldParameterClass = ReflectUtil.loadClass(fieldParameterType.erasure().fullName()); } } } else { fieldParameterClass = null; } structure.setFieldName(index, entry.getKey(), fieldClass, fieldParameterClass); index++; } }
Example 5
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; }