/** * @param javaType * @return */ private FieldSource<JavaClassSource> getOrCreateSerialVersionUID(JavaClassSource javaType) { FieldSource<JavaClassSource> field = javaType.getField(SERIAL_VERSION_FIELD_NAME); if (field == null) { // private static final long serialVersionUID = 1L; field = javaType.addField().setPrivate().setStatic(true).setFinal(true).setType(long.class) .setName(SERIAL_VERSION_FIELD_NAME); } return field; }
@Override public List<PropertySource<O>> getProperties(Class<?> type) { final Set<String> propertyNames = new LinkedHashSet<>(); for (MethodSource<O> method : getMethods()) { if ((isAccessor(method) || isMutator(method)) && method.getReturnType().getQualifiedName().equals(type.getCanonicalName())) { propertyNames.add(extractPropertyName(method)); } } for (FieldSource<O> field : getFields()) { if (!field.isStatic() && field.getType().getQualifiedName().equals(type.getCanonicalName())) { propertyNames.add(field.getName()); } } final List<PropertySource<O>> result = new ArrayList<>(propertyNames.size()); for (String name : propertyNames) { result.add(new PropertyImpl<>(name, getOrigin())); } return result; }
private void addArquillianResourceEnricher(JavaClassSource test) { if (asClient.hasValue()) { test.addImport("org.jboss.arquillian.test.api.ArquillianResource"); final FieldSource<JavaClassSource> urlField = test.addField(); urlField .setName("url") .setType(URL.class) .setPrivate(); urlField.addAnnotation("ArquillianResource"); } }
public boolean isManagedField(FieldSource<JavaClassSource> field, ClassTypeResolver classTypeResolver) throws Exception { if (!field.isFinal() && !field.isStatic()) { //finally we can check if the field type is a managed type. //if not, the field should remain untouched return DriverUtils.isManagedType(field.getType(), classTypeResolver); } return false; }
protected void addPropertyChangeSupport(JavaClassSource type, ClassPlan plan) { // property change listeners type.addField() .setName("pcs") .setType(PropertyChangeSupport.class) .setPrivate(); final MethodSource<JavaClassSource> listenerAdd = type.addMethod(); listenerAdd.getJavaDoc().setText("Adds a property change listener"); listenerAdd.setPublic() .setName("addPropertyChangeListener") .addParameter(PropertyChangeListener.class, "listener"); listenerAdd.setBody("if(null==this.pcs) this.pcs = new PropertyChangeSupport(this);\n" + "this.pcs.addPropertyChangeListener(listener);"); final MethodSource<JavaClassSource> listenerRemove = type.addMethod(); listenerRemove.getJavaDoc().setText("Removes a property change listener"); listenerRemove.setPublic() .setName("removePropertyChangeListener") .addParameter(PropertyChangeListener.class, "listener"); listenerRemove.setBody("if(this.pcs!=null) this.pcs.removePropertyChangeListener(listener);"); }
FieldSource<JavaClassSource> field = subresourceClass.addField(); field.setName(propName) .setType(propType) .setPrivate() .setLiteralInitializer("new java.util.ArrayList<>();") .getJavaDoc().setText(resourceText); AnnotationSource attributeAnnotation = field.addAnnotation(); attributeAnnotation.setName(ResourceDocumentation.class.getSimpleName()); attributeAnnotation.setStringValue(resourceText); field.addAnnotation(SubresourceInfo.class).setStringValue(singularName);
.setPublic() .setStatic(true) .setFinal(true) .setType(Class.class) .setName("CAMEL_NESTED_CLASS") .setLiteralInitializer(nestedType.getCanonicalName() + ".class"); && !optionClass.isAnnotation() && !Modifier.isAbstract(optionClass.getModifiers())) { prop.getField().addAnnotation(NestedConfigurationProperty.class); prop.getField().addAnnotation(Deprecated.class); prop.getAccessor().addAnnotation(Deprecated.class); prop.getMutator().addAnnotation(Deprecated.class); description = mutator.getJavaDoc().getFullText(); } else if (sourceProp.hasField()) { description = sourceProp.getField().getJavaDoc().getFullText(); prop.getField().getJavaDoc().setFullText(description); optionName = sourceProp.hasField() ? sourceProp.getField().getName() : null; prop.getField().getJavaDoc().setFullText(description); prop.getField().setLiteralInitializer(value); } else if ("integer".equals(type) || "boolean".equals(type)) { prop.getField().setLiteralInitializer(defaultValue); } else if ("string".equals(type)) {
@Override public FieldSource<O> createField() { Assert.isFalse(getOrigin().isInterface(), "An interface cannot declare a nonstatic field"); Assert.isTrue(getField() == null, "Field already exists"); final FieldSource<O> result = getOrigin().addField().setVisibility(Visibility.PRIVATE).setType(typeName()) .setName(name); if (getOrigin().isEnum()) { result.setFinal(true); } if (isAccessible() && !getAccessor().isAbstract()) { removeAccessor(); createAccessor(); } if (isMutable() && !getMutator().isAbstract()) { removeMutator(); createMutator(); } return result; }
private void writeProperty(final JavaClassSource javaClass, final Property propDef) { if (!javaClass.hasField(propDef.getPropertyName())) { final StringBuilder javadoc = new StringBuilder(); javadoc .append("The property for ") .append(propDef.name()); final FieldSource<?> method = javaClass.addField() .setType(propDef.getPropertyType()) .setName(propDef.getPropertyName()) .setPrivate(); method.getJavaDoc().setFullText(javadoc.toString()); } else { // javaClass.getMethod(propDef.getName()).setBody(javaClass.getMethod(propDef.getName()).getBody() // + body.toString()); } }
prop.getField().getJavaDoc().setFullText(option.getDescription()); prop.getField().setStringInitializer(option.getDefaultValue()); } else if ("long".equals(type) || "java.lang.Long".equals(type)) { prop.getField().setLiteralInitializer(value); } else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) { prop.getField().setLiteralInitializer(option.getDefaultValue()); } else if (!Strings.isBlank(option.getEnums())) { String enumShortName = type.substring(type.lastIndexOf(".") + 1); prop.getField().setLiteralInitializer(enumShortName + "." + option.getDefaultValue()); commonClass.addImport(model.getJavaType()); .setName("enabled") .setType(boolean.class) .setPrivate() .setLiteralInitializer("true") .getJavaDoc().setFullText("Enable the component"); configClass.addField("Map<String, " + commonName + "> configurations = new HashMap<>()") .setPrivate() .getJavaDoc().setFullText("Define additional configuration definitions");
final FieldSource<JavaClassSource> field = source.addField(); field.setName(normalizedKey).setStringInitializer(key); field.setType("String").setPublic().setStatic(true).setFinal(true); field.getJavaDoc().setFullText("Message: " + value);
setProtected(). setType("KubernetesClient"). setName("kubernetes"). addAnnotation("ArquillianResource"); setProtected(). setType("Session"). setName("session"). addAnnotation("ArquillianResource");
Type oldType = field.getType(); field.setName(property.getName()); if (DriverUtils.isManagedType(field.getType(), classTypeResolver) && !DriverUtils.equalsType(field.getType(), property.getClassName(), property.isMultiple(), field.setType(newClassName); if (field.getLiteralInitializer() != null) { newClassName); } else { field.setLiteralInitializer(null);
bogus.getField().getJavaDoc().setText("Whether to enable auto configuration of the " + model.getName() + " language. This is enabled by default."); bogus.removeAccessor(); bogus.removeMutator(); prop.getField().addAnnotation(Deprecated.class); prop.getAccessor().addAnnotation(Deprecated.class); prop.getMutator().addAnnotation(Deprecated.class); prop.getField().getJavaDoc().setFullText(desc); prop.getField().setStringInitializer(option.getDefaultValue()); } else if ("long".equals(option.getJavaType()) || "java.lang.Long".equals(option.getJavaType())) { prop.getField().setLiteralInitializer(value); } else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) { prop.getField().setLiteralInitializer(option.getDefaultValue()); } else if (!Strings.isBlank(option.getEnumValues())) { String enumShortName = type.substring(type.lastIndexOf(".") + 1); prop.getField().setLiteralInitializer(enumShortName + "." + option.getDefaultValue()); javaClass.addImport(model.getJavaType());
/** * Generates a getXXX and setXXX method for the supplied field * * @param clazz * @param field */ public static void createGetterAndSetter(final JavaClassSource clazz, final FieldSource<JavaClassSource> field) { if (!clazz.hasField(field)) { throw new IllegalArgumentException("Entity did not contain the given field [" + field + "]"); } clazz.getMethods(); String fieldName = field.getName(); String methodNameSuffix = Strings.capitalize(fieldName); clazz.addMethod().setReturnType(field.getType().toString()).setName("get" + methodNameSuffix) .setPublic() .setBody("return this." + fieldName + ";"); if (!field.isFinal()) { clazz.addMethod().setReturnTypeVoid().setName("set" + methodNameSuffix).setPublic() .setParameters("final " + field.getType().toString() + " " + fieldName) .setBody("this." + fieldName + " = " + fieldName + ";"); } }
public List<ObjectProperty> parseManagedTypesProperties(JavaClassSource javaClassSource, ClassTypeResolver classTypeResolver) throws ModelDriverException { List<FieldSource<JavaClassSource>> fields = javaClassSource.getFields(); List<ObjectProperty> properties = new ArrayList<ObjectProperty>(); ObjectProperty property; for (FieldSource<JavaClassSource> field : fields) { if (DriverUtils.isManagedType(field.getType(), classTypeResolver)) { property = parseProperty(field, classTypeResolver); properties.add(property); } else { logger.debug("field: " + field + "with fieldName: " + field.getName() + " won't be loaded by the diver because type: " + field.getType().getName() + " isn't a managed type."); } } return properties; }
ObjectProperty property; Visibility visibility = DriverUtils.buildVisibility(field.getVisibility()); type = field.getType(); if (type.isPrimitive()) { className = type.getName(); property = new ObjectPropertyImpl(field.getName(), className, multiple, bag, visibility, field.isStatic(), field.isFinal()); List<AnnotationSource<JavaClassSource>> annotations = field.getAnnotations(); if (annotations != null) { for (AnnotationSource annotation : annotations) { field.getName(), field.getOrigin().getName()), e); throw new ModelDriverException(errorMessage(DATA_OBJECT_FIELD_LOAD_ERROR, field.getName(), field.getOrigin().getName()), e);
@Override public FieldSource<Body> getField(final String name) { for (FieldSource<Body> field : getFields()) { if (field.getName().equals(name)) { return field; } } return null; }
public void visit(FieldSource<? extends JavaSource> fieldSource) { Type fieldType = fieldSource.getType(); String fieldClassName; String fieldName = fieldSource.getName(); resParts.addPart(fieldName, PartType.FIELD); for (AnnotationSource annoSource : fieldSource.getAnnotations()) { visit(annoSource);
if (fields != null) { for (FieldSource<JavaClassSource> field : fields) { if (DriverUtils.isManagedType(field.getType(), classTypeResolver)) { addProperty(dataObject, classTypeResolver); } else { logger.debug("field: " + field + "with fieldName: " + field.getName() + " won't be loaded by the diver because type: " + field.getType().getName() + " isn't a managed type."); unmanagedProperties.add(new ObjectPropertyImpl(field.getName(), field.getType().toString(), false, DriverUtils.buildVisibility(field.getVisibility()), field.isStatic(), field.isFinal()));