Java Code Examples for com.sun.tools.xjc.outline.FieldOutline#getRawType()

The following examples show how to use com.sun.tools.xjc.outline.FieldOutline#getRawType() . 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: FieldAccessorUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns the <code>setProperty(...)</code> method for the given field
 * outline or <code>null</code> if no such method exists.
 * 
 * @param fieldOutline
 *            field outline.
 * @return The <code>setProperty(...)</code> method for the given field
 *         outline or <code>null</code> if no such method exists.
 */
public static JMethod setter(FieldOutline fieldOutline) {

	final JMethod getter = getter(fieldOutline);
	final JType type = getter != null ? getter.type() : fieldOutline
			.getRawType();
	final JDefinedClass theClass = fieldOutline.parent().implClass;
	final String publicName = fieldOutline.getPropertyInfo().getName(true);
	final String name = "set" + publicName;
	return theClass.getMethod(name, new JType[] { type });
}
 
Example 2
Source File: SettersPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void generateSetters(ClassOutline classOutline,
		JDefinedClass theClass) {

	final FieldOutline[] declaredFields = FieldOutlineUtils.filter(
			classOutline.getDeclaredFields(), getIgnoring());

	for (final FieldOutline fieldOutline : declaredFields) {

		final String publicName = fieldOutline.getPropertyInfo().getName(
				true);

		final String getterName = "get" + publicName;

		final JMethod getter = theClass.getMethod(getterName, ABSENT);

		if (getter != null) {
			final JType type = getter.type();
			final JType rawType = fieldOutline.getRawType();
			final String setterName = "set" + publicName;
			final JMethod boxifiedSetter = theClass.getMethod(setterName,
					new JType[] { rawType.boxify() });
			final JMethod unboxifiedSetter = theClass.getMethod(setterName,
					new JType[] { rawType.unboxify() });
			final JMethod setter = boxifiedSetter != null ? boxifiedSetter
					: unboxifiedSetter;

			if (setter == null) {
				final JMethod generatedSetter = theClass.method(
						JMod.PUBLIC, theClass.owner().VOID, setterName);
				final JVar value = generatedSetter.param(type, "value");

				mode.generateSetter(fieldOutline, theClass,
						generatedSetter, value);
			}
		}
	}
}
 
Example 3
Source File: ClassDiscoverer.java    From jaxb-visitor with Apache License 2.0 5 votes vote down vote up
/**
 * Finds all external class references
 * @param outline root of the generated code
 * @param classes set of generated classes
 * @return set of external classes
 * @throws IllegalAccessException throw if there's an error introspecting the annotations
 */
static Set<JClass> discoverDirectClasses(Outline outline, Set<ClassOutline> classes) throws IllegalAccessException {

    Set<String> directClassNames = new LinkedHashSet<>();
    for(ClassOutline classOutline : classes) {
        // for each field, if it's a bean, then visit it
        List<FieldOutline> fields = findAllDeclaredAndInheritedFields(classOutline);
        for(FieldOutline fieldOutline : fields) {
            JType rawType = fieldOutline.getRawType();
            CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();
            boolean isCollection = propertyInfo.isCollection();
            if (isCollection) {
                JClass collClazz = (JClass) rawType;
                JClass collType = collClazz.getTypeParameters().get(0);
                addIfDirectClass(directClassNames, collType);
            } else {
                addIfDirectClass(directClassNames, rawType);
            }
            parseXmlAnnotations(outline, fieldOutline, directClassNames);
        }
    }

    Set<JClass> direct = directClassNames
            .stream()
            .map(cn -> outline.getCodeModel().directClass(cn))
            .collect(Collectors.toCollection(LinkedHashSet::new));

    return direct;

}
 
Example 4
Source File: PropertyFieldAccessorFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public PropertyFieldAccessor(final FieldOutline fieldOutline,
		JExpression targetObject) {
	super();
	this.fieldOutline = fieldOutline;
	this.targetObject = targetObject;
	this.fieldAccessor = fieldOutline.create(targetObject);
	final String publicName = fieldOutline.getPropertyInfo().getName(
			true);
	final String privateName = fieldOutline.getPropertyInfo().getName(
			false);
	this.theClass = fieldOutline.parent().implClass;
	final String setterName = "set" + publicName;
	final JMethod getGetter = theClass.getMethod("get" + publicName,
			ABSENT);
	final JMethod isGetter = theClass.getMethod("is" + publicName,
			ABSENT);
	final JFieldVar field = theClass.fields().get(privateName);
	this.field = field != null
			&& ((field.mods().getValue() & JMod.PROTECTED) != 0)
			&& ((field.mods().getValue() & JMod.STATIC) == 0)
			&& ((field.mods().getValue() & JMod.FINAL) == 0) ? field
			: null;
	this.getter = getGetter != null ? getGetter
			: (isGetter != null ? isGetter : null);
	this.type = this.getter != null ? this.getter.type() : fieldOutline
			.getRawType();
	this.fieldType = this.field != null ? this.field.type() : this.type;

	final JFieldVar constantField = theClass.fields().get(publicName);
	this.constantField = constantField != null
			&& ((constantField.mods().getValue() & JMod.PUBLIC) != 0)
			&& ((constantField.mods().getValue() & JMod.STATIC) != 0)
			&& ((constantField.mods().getValue() & JMod.FINAL) != 0) ? constantField
			: null;
	// fieldOutline.getRawType();
	final JType rawType = fieldOutline.getRawType();
	final JMethod boxifiedSetter = theClass.getMethod(setterName,
			new JType[] { rawType.boxify() });
	final JMethod unboxifiedSetter = theClass.getMethod(setterName,
			new JType[] { rawType.unboxify() });
	this.setter = boxifiedSetter != null ? boxifiedSetter
			: unboxifiedSetter;
	this.isSetter = theClass.getMethod("isSet" + publicName, ABSENT);
	this.unSetter = theClass.getMethod("unset" + publicName, ABSENT);
}