Refine search
static private FieldOutline getIdField(ClassOutline clazz){ String name = "id"; FieldOutline[] fields = clazz.getDeclaredFields(); for(FieldOutline field : fields){ CPropertyInfo propertyInfo = field.getPropertyInfo(); String privateName = propertyInfo.getName(false); JType fieldType = field.getRawType(); if((name).equals(privateName) && ("java.lang.String").equals(fieldType.fullName())){ return field; } } return null; }
private void addNewBuilder(ClassOutline clazz, JDefinedClass builderClass) { boolean superClassWithSameName = false; ClassOutline superclass = clazz.getSuperClass(); while (superclass != null) { if (superclass.implClass.name().equals(clazz.implClass.name())) { superClassWithSameName = true; } superclass = superclass.getSuperClass(); } if (!superClassWithSameName) { JMethod method = clazz.implClass.method(JMod.PUBLIC | JMod.STATIC, builderClass, Introspector.decapitalize(clazz.implClass.name()) + "Builder"); method.body()._return(JExpr._new(builderClass)); } }
public static Set<JType> getPossibleTypes(FieldOutline fieldOutline, Aspect aspect) { Validate.notNull(fieldOutline); final ClassOutline classOutline = fieldOutline.parent(); final Outline outline = classOutline.parent(); final CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo(); final Set<JType> types = new HashSet<JType>(); if (propertyInfo.getAdapter() != null) { types.add(propertyInfo.getAdapter().customType.toType(fieldOutline .parent().parent(), aspect)); } else if (propertyInfo.baseType != null) { types.add(propertyInfo.baseType); } else { Collection<? extends CTypeInfo> typeInfos = propertyInfo.ref(); for (CTypeInfo typeInfo : typeInfos) { types.addAll(getPossibleTypes(outline, aspect, typeInfo)); } } return types; }
/** * Return all direct and inherited fields of the given class. * @return list of all fields */ protected List<FieldOutline> getAllDeclaredAndInheritedFields() { List<FieldOutline> fields = new LinkedList<FieldOutline>(); ClassOutline currentClassOutline = classOutline; while (currentClassOutline != null) { fields.addAll(Arrays.asList(currentClassOutline.getDeclaredFields())); currentClassOutline = currentClassOutline.getSuperClass(); } return fields; }
public boolean run( Outline outline, Options opt, ErrorHandler errorHandler ) { for( ClassOutline ci : outline.getClasses() ) { JDefinedClass impl = ci.implClass; if (ci.getSuperClass() == null) { JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName); $loc.annotate(XmlLocation.class); $loc.annotate(XmlTransient.class); impl._implements(Locatable.class); impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc); JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation"); JVar $newLoc = setter.param(Locator.class, "newLocator"); setter.body().assign($loc, $newLoc); } } return true; } }
protected JMethod generateHashCode$hashCode(ClassOutline classOutline, final JDefinedClass theClass) { ClassUtils._implements(theClass, theClass.owner().ref(HashCode.class)); final JMethod hashCode$hashCode = theClass.method(JMod.PUBLIC, theClass .owner().VOID, "hashCode"); { final JVar hashCodeBuilder = hashCode$hashCode.param( HashCodeBuilder.class, "hashCodeBuilder"); final JBlock body = hashCode$hashCode.body(); if (classOutline.getSuperClass() != null) { body.invoke(JExpr._super(), "hashCode").arg(hashCodeBuilder); } final FieldOutline[] fieldOutlines = classOutline .getDeclaredFields(); for (final FieldOutline fieldOutline : fieldOutlines) { final JBlock block = body.block(); final JVar theValue = block.decl(fieldOutline.getRawType(), "the" + fieldOutline.getPropertyInfo().getName(true)); FieldAccessorFactory.createFieldAccessor(fieldOutline, JExpr._this()).toRawValue(block, theValue); block.invoke(hashCodeBuilder, "append").arg(theValue); } } return hashCode$hashCode; } }
buf.append(cls.name()); Iterator itr = cls._implements(); while(itr.hasNext()) { if(first) { for( FieldOutline fo : ci.getDeclaredFields() ) { String type = printName(fo.getRawType()); println(type+' '+fo.getPropertyInfo().getName(true)+';');
private JMethod generateLazyProxyInitGetter(final ClassOutline classOutline, final FieldOutline fieldOutline) { final JCodeModel m = classOutline.parent().getCodeModel(); final JDefinedClass definedClass = classOutline.implClass; final String fieldName = fieldOutline.getPropertyInfo().getName(false); final String getterName = "get" + fieldOutline.getPropertyInfo().getName(true); final JFieldVar collectionField = definedClass.fields().get(fieldName); final JClass elementType = ((JClass) collectionField.type()).getTypeParameters().get(0); final JClass proxyFieldType = m.ref(BoundList.class).narrow(elementType); final JFieldRef collectionFieldRef = JExpr._this().ref(collectionField); final JFieldRef proxyField = JExpr._this().ref(collectionField.name() + BoundPropertiesPlugin.PROXY_SUFFIX); final JMethod oldGetter = definedClass.getMethod(getterName, new JType[0]); definedClass.methods().remove(oldGetter); final JMethod newGetter = definedClass.method(JMod.PUBLIC, proxyFieldType, getterName); newGetter.body()._if(collectionFieldRef.eq(JExpr._null()))._then().assign(collectionFieldRef, JExpr._new(m.ref(ArrayList.class).narrow(elementType))); final JBlock ifProxyNull = newGetter.body()._if(proxyField.eq(JExpr._null()))._then(); ifProxyNull.assign(proxyField, JExpr._new(m.ref(BoundListProxy.class).narrow(elementType)).arg(collectionFieldRef)); newGetter.body()._return(proxyField); return newGetter; }
void generateCopyConstructor(final boolean partial) { final JDefinedClass definedClass = this.classOutline.implClass; final JMethod constructor = definedClass.constructor(definedClass.isAbstract() ? JMod.PROTECTED : JMod.PUBLIC); final JVar otherParam = constructor.param(JMod.FINAL, this.classOutline.implClass, DeepCopyGenerator.OTHER_PARAM_NAME); final CopyGenerator cloneGenerator = this.pluginContext.createCopyGenerator(constructor, partial); final JDocComment docComment = constructor.javadoc(); docComment.append(getMessage("copyConstructor.javadoc.desc", definedClass.name())); docComment.addParam(otherParam).append(getMessage("copyConstructor.javadoc.param.other", definedClass.name())); if(partial) { docComment.addParam(cloneGenerator.getPropertyTreeParam()).append(getMessage("copyConstructor.javadoc.param.propertyPath", definedClass.name())); docComment.addParam(cloneGenerator.getPropertyTreeUseParam()).append(getMessage("copyConstructor.javadoc.param.propertyPathUse", definedClass.name())); } if (this.classOutline.getSuperClass() != null) { constructor.body().add(cloneGenerator.generatePartialArgs(this.pluginContext._super().arg(otherParam))); } final JBlock body = constructor.body(); generateFieldCopyExpressions(cloneGenerator, body, JExpr._this(), otherParam); }
private JMethod generateVisitMethod(final ClassOutline classOutline) { final JDefinedClass definedClass = classOutline.implClass; final JMethod visitMethod = definedClass.method(JMod.PUBLIC, definedClass, this.visitMethodName); final JCodeModel codeModel = definedClass.owner(); final JClass visitorType = codeModel.ref(PropertyVisitor.class); final JVar visitorParam = visitMethod.param(JMod.FINAL, visitorType, "_visitor_"); if (classOutline.getSuperClass() != null) { visitMethod.body().add(JExpr._super().invoke(this.visitMethodName).arg(visitorParam)); } else { visitMethod.body().add(visitorParam.invoke("visit").arg(JExpr._this())); } return visitMethod; }
private void replaceSetter(final ClassOutline co, final JFieldVar field, final JType setType) { // Create the method name final String methodName = OPERATION_SET_PREFIX + capitalizeFirstLetter(field.name()); // Create Date JType final JType dateType = co.parent().getCodeModel().ref(getReplaceableClass()); // Find and remove Old setter! final JMethod oldSetter = co.implClass.getMethod(methodName, new JType[] { dateType }); co.implClass.methods().remove(oldSetter); // Create New Setter final JMethod setter = co.implClass.method(JMod.PUBLIC, Void.TYPE, methodName); final JVar var = setter.param(JMod.FINAL, setType, PARAM_NAME); assignSetterValue(co.implClass, field, setter, var); }
private void replaceGetter(final ClassOutline co, final JFieldVar field, final JType setType) { // Create the method name final String methodName = OPERATION_GET_PREFIX + capitalizeFirstLetter(field.name()); // Find and remove Old Getter! final JMethod oldGetter = co.implClass.getMethod(methodName, new JType[0]); co.implClass.methods().remove(oldGetter); final JMethod getter = co.implClass.method(JMod.PUBLIC, setType, methodName); if (checkNull()) { final JType classType = co.parent().getCodeModel().ref(getImplementationClass()); getter.body()._if(JExpr.ref(field.name()).eq(JExpr._null()))._then().assign(field, JExpr._new(classType)); } getter.body()._return(JExpr.ref(field.name())); }
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) { for( ClassOutline co : model.getClasses() ) final FieldOutline[] fieldOutlineArray = co.getDeclaredFields(); final Collection<JMethod> allMethods = co.implClass.methods(); for (JMethod jMethod: allMethods) final String fieldName = ValidationUtils.getFieldNameFromGetterMethodName(jMethod.name()); if (fieldName != null) log.debug("Method name: {}",jMethod.name()); FieldOutline fieldOutline = null; for (FieldOutline fo : fieldOutlineArray) final String fname = ValidationUtils.getFieldNameWithJavaCase(fo.getPropertyInfo().getName(true)); if (fieldName.equals(fname)) final XSComponent xsxComponent = fieldOutline.getPropertyInfo().getSchemaComponent(); if (xsxComponent instanceof ParticleImpl)
private JFieldVar generateProxyField(final ClassOutline classOutline, final FieldOutline fieldOutline) { final JCodeModel m = classOutline.parent().getCodeModel(); final JDefinedClass definedClass = classOutline.implClass; final JFieldVar collectionField = definedClass.fields().get(fieldOutline.getPropertyInfo().getName(false)); final JClass elementType = ((JClass) collectionField.type()).getTypeParameters().get(0); return definedClass.field(JMod.PRIVATE | JMod.TRANSIENT, m.ref(BoundList.class).narrow(elementType), collectionField.name() + BoundPropertiesPlugin.PROXY_SUFFIX, JExpr._null()); }
@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; Map<String, JFieldVar> fieldVars = beanClazz.fields(); FieldOutline[] fieldOutlines = classOutline.getDeclaredFields(); for(FieldOutline fieldOutline : fieldOutlines){ CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo(); JFieldVar fieldVar = fieldVars.get(propertyInfo.getName(false)); Collection<? extends EnumOutline> enumOutlines = outline.getEnums(); for(EnumOutline enumOutline : enumOutlines){ JDefinedClass clazz = enumOutline.clazz;
private void removeDummyImplementation(final DefinedInterfaceOutline interfaceOutline) { final ClassOutline classToRemove = interfaceOutline.getClassOutline(); if (classToRemove != null) { final List<JMethod> methodsToRemove = new ArrayList<>(); for (final JMethod method : classToRemove._package().objectFactory().methods()) { if (method.name().equals("create" + classToRemove.implClass.name())) { methodsToRemove.add(method); } } for (final JMethod method : methodsToRemove) { classToRemove._package().objectFactory().methods().remove(method); } this.pluginContext.outline.getClasses().remove(classToRemove); } }
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())); } }
@Override public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { for (final ClassOutline classOutline : outline.getClasses()) { for (final CPluginCustomization pluginCustomization : classOutline.target .getCustomizations()) { pluginCustomization.markAsAcknowledged(); } final CClassInfo classInfo = classOutline.target; logger.debug("Class:" + classInfo.getName()); for (final FieldOutline fieldOutline : classOutline .getDeclaredFields()) { final CPropertyInfo propertyInfo = fieldOutline .getPropertyInfo(); logger.debug("Property:" + propertyInfo.getName(true)); for (final CPluginCustomization pluginCustomization : fieldOutline .getPropertyInfo().getCustomizations()) { pluginCustomization.markAsAcknowledged(); } } } return true; }
static private FieldOutline getContentField(ClassOutline clazz){ String name = clazz.implClass.name(); FieldOutline[] fields = clazz.getDeclaredFields(); for(FieldOutline field : fields){ CPropertyInfo propertyInfo = field.getPropertyInfo(); JType fieldType = field.getRawType(); if(propertyInfo.isCollection()){ JType elementType = CodeModelUtil.getElementType(fieldType); String elementName = elementType.name(); if((name).equals(elementName + "s") || (name).equals(JJavaName.getPluralForm(elementName))){ return field; } } } return null; } }
private boolean containsDefaultValue(Outline outline, FieldOutline field) { ClassOutline fClass = null; for (ClassOutline classOutline : outline.getClasses()) { if (classOutline.implClass == field.getRawType() && !classOutline.implClass.isAbstract()) { fClass = classOutline; break; } } if (fClass == null) { return false; } for (FieldOutline f : fClass.getDeclaredFields()) { if (f.getPropertyInfo().getSchemaComponent() instanceof XSParticle) { XSParticle particle = (XSParticle)f.getPropertyInfo().getSchemaComponent(); XSTerm term = particle.getTerm(); if (term.isElementDecl() && term.asElementDecl().getDefaultValue() != null) { return true; } } } return false; }