Java Code Examples for com.sun.codemodel.JType#isArray()

The following examples show how to use com.sun.codemodel.JType#isArray() . 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: BuilderGenerator.java    From jaxb2-rich-contract-plugin with MIT License 6 votes vote down vote up
private BuilderOutline getReferencedBuilderOutline(final JType type) {
	BuilderOutline builderOutline = null;
	if (this.pluginContext.getClassOutline(type) == null && this.pluginContext.getEnumOutline(type) == null && type.isReference() && !type.isPrimitive() && !type.isArray() && type.fullName().contains(".")) {
		final Class<?> runtimeParentClass;
		try {
			runtimeParentClass = Class.forName(type.binaryName());
		} catch (final ClassNotFoundException e) {
			return null;
		}
		final JClass builderClass = reflectRuntimeInnerClass(runtimeParentClass, this.settings.getBuilderClassName());
		if (builderClass != null) {
			final ReferencedClassOutline referencedClassOutline = new ReferencedClassOutline(this.pluginContext.codeModel, runtimeParentClass);
			builderOutline = new BuilderOutline(referencedClassOutline, builderClass);
		}
	}
	return builderOutline;
}
 
Example 2
Source File: AbstractField.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns contents to be added to javadoc.
 */
protected final List<Object> listPossibleTypes( CPropertyInfo prop ) {
    List<Object> r = new ArrayList<Object>();
    for( CTypeInfo tt : prop.ref() ) {
        JType t = tt.getType().toType(outline.parent(),Aspect.EXPOSED);
        if( t.isPrimitive() || t.isArray() )
            r.add(t.fullName());
        else {
            r.add(t);
            r.add("\n");
        }
    }

    return r;
}
 
Example 3
Source File: ListCodeGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void generate(JBlock block, JType type,
		Collection<JType> possibleTypes, boolean isAlwaysSet, A arguments) {
	Validate.isInstanceOf(JClass.class, type);
	final JClass _class = (JClass) type;

	final JClass jaxbElementClass = getCodeModel().ref(JAXBElement.class);
	final Set<JType> arrays = new HashSet<JType>();
	final Collection<JClass> jaxbElements = new HashSet<JClass>();
	final Set<JType> otherTypes = new HashSet<JType>();
	for (final JType possibleType : possibleTypes) {
		if (possibleType.isArray()) {
			arrays.add(possibleType);
		} else if (possibleType instanceof JClass
				&& jaxbElementClass
						.isAssignableFrom(((JClass) possibleType).erasure())) {
			jaxbElements.add((JClass) possibleType);
		} else {
			otherTypes.add(possibleType);
		}
	}
	// If list items are not arrays or JAXBElements, just delegate to the
	// hashCode of the list
	if (arrays.isEmpty() && jaxbElements.isEmpty()) {
		getImplementor().onObject(arguments, block, false);
	} else {
		final JClass elementType = getElementType(_class);

		block = arguments.ifHasSetValue(block, isAlwaysSet, true);

		final A iterator = arguments.iterator(block, elementType);

		// while(e1.hasNext() && e2.hasNext()) {
		final JBlock whileBlock = iterator._while(block);
		// E o1 = e1.next();
		// Object o2 = e2.next();
		final boolean isElementAlwaysSet = elementType.isPrimitive();
		getCodeGenerator().generate(whileBlock, elementType, possibleTypes,
				isElementAlwaysSet,
				iterator.element(whileBlock, elementType));
		// }
		// return !(e1.hasNext() || e2.hasNext());
	}
}
 
Example 4
Source File: ObjectCodeGenerator.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void generate(final JBlock block, JType type,
		Collection<JType> possibleTypes, boolean isAlwaysSet, A arguments) {
	if (possibleTypes.size() <= 1) {
		getImplementor().onObject(arguments, block, isAlwaysSet);
	} else {
		final JClass jaxbElementClass = getCodeModel().ref(
				JAXBElement.class);
		final Set<JType> arrays = new HashSet<JType>();
		final Collection<JClass> jaxbElements = new HashSet<JClass>();
		final Set<JType> otherTypes = new HashSet<JType>();
		for (final JType possibleType : possibleTypes) {
			if (possibleType.isArray()) {
				arrays.add(possibleType);
			} else if (possibleType instanceof JClass
					&& jaxbElementClass
							.isAssignableFrom(((JClass) possibleType)
									.erasure())) {
				jaxbElements.add((JClass) possibleType);
			} else {
				otherTypes.add(possibleType);
			}
		}

		final JConditionable _if = new JConditionable() {

			private JConditional conditional = null;

			@Override
			public JBlock _ifThen(JExpression condition) {
				if (conditional == null) {
					conditional = block._if(condition);
				} else {
					conditional = conditional._elseif(condition);
				}
				return conditional._then();
			}

			@Override
			public JBlock _else() {
				if (conditional == null) {
					return block;
				} else {
					return conditional._else();
				}
			}
		};

		if (!jaxbElements.isEmpty()) {
			final Set<JType> valueTypes = getJAXBElementValueTypes(jaxbElements);
			final JType valueType = TypeUtil.getCommonBaseType(
					getCodeModel(), valueTypes);
			final JClass jaxbElementType = jaxbElementClass
					.narrow(valueType);

			final JBlock jaxbElementBlock = _if._ifThen(arguments
					._instanceof(jaxbElementClass));
			getCodeGenerator().generate(
					jaxbElementBlock,
					jaxbElementType,
					new HashSet<JType>(jaxbElements),
					true,
					arguments.cast("JAXBElement", jaxbElementBlock,
							jaxbElementType, true));

		}

		if (!arrays.isEmpty()) {
			for (JType arrayType : arrays) {
				final JBlock arrayBlock = _if._ifThen(arguments
						._instanceof(arrayType));
				getCodeGenerator().generate(
						arrayBlock,
						arrayType,
						Collections.singleton(arrayType),
						true,
						arguments.cast("Array", arrayBlock, arrayType,
								false));
			}
		}

		if (!otherTypes.isEmpty()) {
			getImplementor().onObject(arguments, _if._else(), false);
		}
	}
}