Java Code Examples for com.sun.codemodel.JType

The following examples show how to use com.sun.codemodel.JType. These examples are extracted from open source projects. 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 Project: Bats   Source File: ClassGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * declare a constant field for the class.
 * argument {@code function} holds the constant value which
 * returns a value holder must be set to the class field when the class instance created.
 * the class field innerClassField will be created if innerClassGenerator exists.
 *
 * @param prefix the prefix name of class field
 * @param t the type of class field
 * @param init init expression
 * @param function the function holds the constant value
 * @return the depth of nested class, class field
 */
public Pair<Integer, JVar> declareClassConstField(String prefix, JType t, JExpression init,
                                                  Function<DrillBuf, ? extends ValueHolder> function) {
  JVar var;
  int depth = 1;
  if (innerClassGenerator != null) {
    Pair<Integer, JVar> nested = innerClassGenerator.declareClassConstField(prefix, t, init, function);
    depth = nested.getKey() + 1;
    var = nested.getValue();
  } else {
    var = clazz.field(JMod.NONE, t, prefix + index++, init);
  }
  Pair<Integer, JVar> depthVar = Pair.of(depth, var);
  constantVars.put(depthVar, function);
  return depthVar;
}
 
Example 2
public EqualsArguments property(JBlock block, String propertyName,
		String propertyMethod, JType declarablePropertyType,
		JType propertyType, Collection<JType> possiblePropertyTypes) {
	final JVar leftPropertyValue = block.decl(JMod.FINAL,
			declarablePropertyType, leftValue().name() + propertyName,
			leftValue().invoke(propertyMethod));
	final JVar rightPropertyValue = block.decl(JMod.FINAL,
			declarablePropertyType, rightValue().name() + propertyName,
			rightValue().invoke(propertyMethod));
	// We assume that primitive properties are always set
	boolean isAlwaysSet = propertyType.isPrimitive();
	final JExpression leftPropertyHasSetValue = isAlwaysSet ? JExpr.TRUE
			: leftPropertyValue.ne(JExpr._null());
	final JExpression rightPropertyHasSetValue = isAlwaysSet ? JExpr.TRUE
			: rightPropertyValue.ne(JExpr._null());
	return spawn(leftPropertyValue, leftPropertyHasSetValue,
			rightPropertyValue, rightPropertyHasSetValue);
}
 
Example 3
@Override
public JType visit(PrimitiveType type, JCodeModel codeModel) {
	switch (type.getType()) {
	case Boolean:
		return codeModel.BOOLEAN;
	case Char:
		return codeModel.CHAR;
	case Byte:
		return codeModel.BYTE;
	case Short:
		return codeModel.SHORT;
	case Int:
		return codeModel.INT;
	case Long:
		return codeModel.LONG;
	case Float:
		return codeModel.FLOAT;
	case Double:
		return codeModel.DOUBLE;
	default:
		throw new AssertionError("Unknown primitive type ["
				+ type.getType() + "]");
	}
}
 
Example 4
@Override
public JType visit(WildcardType type, JCodeModel codeModel) {

	if (type.getExtends() != null) {
		final ReferenceType _extends = type.getExtends();
		final JType boundType = _extends.accept(this, codeModel);

		if (!(boundType instanceof JClass)) {
			throw new IllegalArgumentException("Bound type [" + _extends
					+ "]in the wildcard type must be class.");
		}

		final JClass boundClass = (JClass) boundType;
		return boundClass.wildcard();
	} else if (type.getSuper() != null) {
		// TODO
		throw new IllegalArgumentException(
				"Wildcard types with super clause are not supported at the moment.");
	} else {
		throw new IllegalArgumentException(
				"Wildcard type must have either extends or super clause.");
	}
}
 
Example 5
private JType getOrGeneratePojoFromJsonSchema(JCodeModel cm, String resourcePath, MimeType mimeType, String className) throws IOException {
    JType type = null;

    if (StringUtils.isNotBlank(mimeType.getSchema())) {
        if (globalTypes.containsKey(mimeType.getSchema())) {
            type = globalTypes.get(mimeType.getSchema());
        } else {
            type = generatePojoFromSchema(cm, className, getModelPackage(resourcePath), mimeType.getSchema(), mimeType.getSchemaPath(), SourceType.JSONSCHEMA);
        }
    } else if (StringUtils.isNotBlank(mimeType.getExample())) {
        type = generatePojoFromSchema(cm, className, getModelPackage(resourcePath), mimeType.getExample(), SourceType.JSON);
    }

    if (type != null && type.fullName().equals("java.lang.Object") && StringUtils.isNotBlank(mimeType.getExample())) {
        type = generatePojoFromSchema(cm, className, getModelPackage(resourcePath), mimeType.getExample(), SourceType.JSON);
    }

    if (type == null) {
        type = cm.ref(Object.class);
    }

    return type;
}
 
Example 6
Source Project: hyperjaxb3   Source File: AnnotateOutline.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void processAttributeWildcard(ClassOutline classOutline) {
	logger.debug("The class ["
			+ OutlineUtils.getClassName(classOutline)
			+ "] declares an attribute wildcard which will be made transient.");
	String FIELD_NAME = "otherAttributes";
	String METHOD_SEED = classOutline.parent().getModel()
			.getNameConverter().toClassName(FIELD_NAME);

	final JMethod getOtherAttributesMethod = classOutline.ref.getMethod(
			"get" + METHOD_SEED, new JType[0]);

	if (getOtherAttributesMethod == null) {
		logger.error("Could not find the attribute wildcard method in the class ["
				+ OutlineUtils.getClassName(classOutline) + "].");
	} else {
		getOtherAttributesMethod.annotate(Transient.class);
	}
}
 
Example 7
Source Project: hyperjaxb3   Source File: JTypeUtils.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static JType[] getBasicTypes(final JCodeModel codeModel) {
	final JType[] basicTypes = new JType[] { codeModel.BOOLEAN,
			codeModel.BOOLEAN.boxify(), codeModel.BYTE,
			codeModel.BYTE.boxify(), codeModel.CHAR,
			codeModel.CHAR.boxify(), codeModel.DOUBLE,
			codeModel.DOUBLE.boxify(), codeModel.FLOAT,
			codeModel.FLOAT.boxify(), codeModel.INT,
			codeModel.INT.boxify(), codeModel.LONG,
			codeModel.LONG.boxify(), codeModel.SHORT,
			codeModel.SHORT.boxify(), codeModel.ref(String.class),
			codeModel.ref(BigInteger.class),
			codeModel.ref(BigDecimal.class),
			codeModel.ref(java.util.Date.class),
			codeModel.ref(java.util.Calendar.class),
			codeModel.ref(java.sql.Date.class),
			codeModel.ref(java.sql.Time.class),
			codeModel.ref(java.sql.Timestamp.class),
			codeModel.BYTE.array(),	codeModel.BYTE.boxify().array(),
			codeModel.CHAR.array(),	codeModel.CHAR.boxify().array() }

	;
	return basicTypes;
}
 
Example 8
@Override
protected JExpression unwrap(JExpression source) {

	final JType declaredType = getDeclaredType();

	final JClass elementClass = codeModel.ref(JAXBElement.class).narrow(
			declaredType.boxify().wildcard());

	// TODO remove if cast is not necessary
	final JExpression value = JExpr.cast(elementClass, source);

	if (xmlAdapterClass == null) {
		return XmlAdapterXjcUtils.unmarshallJAXBElement(codeModel, value);

	} else {
		return XmlAdapterXjcUtils.unmarshallJAXBElement(codeModel,
				xmlAdapterClass, value);
	}

}
 
Example 9
Source Project: immutable-xjc   Source File: PluginImpl.java    License: MIT License 6 votes vote down vote up
private JExpression getDefensiveCopyExpression(JCodeModel codeModel, JType jType, JVar param) {
    List<JClass> typeParams = ((JClass) jType).getTypeParameters();
    JClass typeParameter = null;
    if (typeParams.iterator().hasNext()) {
        typeParameter = typeParams.iterator().next();
    }

    JClass newClass = null;
    if (param.type().erasure().equals(codeModel.ref(Collection.class))) {
        newClass = codeModel.ref(ArrayList.class);
    } else if (param.type().erasure().equals(codeModel.ref(List.class))) {
        newClass = codeModel.ref(ArrayList.class);
    } else if (param.type().erasure().equals(codeModel.ref(Map.class))) {
        newClass = codeModel.ref(HashMap.class);
    } else if (param.type().erasure().equals(codeModel.ref(Set.class))) {
        newClass = codeModel.ref(HashSet.class);
    } else if (param.type().erasure().equals(codeModel.ref(SortedMap.class))) {
        newClass = codeModel.ref(TreeMap.class);
    } else if (param.type().erasure().equals(codeModel.ref(SortedSet.class))) {
        newClass = codeModel.ref(TreeSet.class);
    }
    if (newClass != null && typeParameter != null) {
        newClass = newClass.narrow(typeParameter);
    }
    return newClass == null ? JExpr._null() : JExpr._new(newClass).arg(param);
}
 
Example 10
public static JMethod getMethod(JDefinedClass theClass, String name,
		JType[] arguments) {
	final JMethod method = theClass.getMethod(name, arguments);
	if (method != null) {
		return method;
	} else {
		final JClass draftSuperClass = theClass._extends();
		if (draftSuperClass == null
				|| !(draftSuperClass instanceof JDefinedClass)) {
			return null;
		} else {
			final JDefinedClass superClass = (JDefinedClass) draftSuperClass;
			return getMethod(superClass, name, arguments);
		}
	}
}
 
Example 11
Source Project: Bats   Source File: EvaluationVisitor.java    License: Apache License 2.0 5 votes vote down vote up
private HoldingContainer getHoldingContainer(ClassGenerator<?> generator,
                                             MajorType majorType,
                                             Function<DrillBuf, ? extends ValueHolder> function) {
  JType holderType = generator.getHolderType(majorType);
  Pair<Integer, JVar> depthVar = generator.declareClassConstField("const", holderType, function);
  JFieldRef outputSet = null;
  JVar var = depthVar.getValue();
  if (majorType.getMode() == TypeProtos.DataMode.OPTIONAL) {
    outputSet = var.ref("isSet");
  }
  return new HoldingContainer(majorType, var, var.ref("value"), outputSet);
}
 
Example 12
Source Project: jaxb2-rich-contract-plugin   Source File: BuilderGenerator.java    License: MIT License 5 votes vote down vote up
void generateArrayProperty(final JBlock initBody, final JVar productParam, final PropertyOutline fieldOutline, final JType elementType, final JType builderType) {
	final String fieldName = fieldOutline.getFieldName();
	final String propertyName = fieldOutline.getBaseName();
	final JType fieldType = fieldOutline.getRawType();
	final JMethod withVarargsMethod = this.builderClass.raw.method(JMod.PUBLIC, builderType, PluginContext.WITH_METHOD_PREFIX + propertyName);
	final JVar withVarargsParam = withVarargsMethod.varParam(elementType, fieldName);
	if (this.implement) {
		final JFieldVar builderField = this.builderClass.raw.field(JMod.PRIVATE, fieldType, fieldName, JExpr._null());
		withVarargsMethod.body().assign(JExpr._this().ref(builderField), withVarargsParam);
		withVarargsMethod.body()._return(JExpr._this());
		initBody.assign(productParam.ref(fieldName), JExpr._this().ref(builderField));
	}
}
 
Example 13
Source Project: jaxb2-rich-contract-plugin   Source File: MetaPlugin.java    License: MIT License 5 votes vote down vote up
private JExpression dotClass(final JType cl) {
	if (cl instanceof JClass) {
		return ((JClass)cl).dotclass();
	} else {
		return new JExpressionImpl() {
			public void generate(final JFormatter f) {
				f.g(cl).p(".class");
			}
		};
	}
}
 
Example 14
Source Project: jaxb2-rich-contract-plugin   Source File: MetaPlugin.java    License: MIT License 5 votes vote down vote up
private void generateAccessors(final FieldOutline fieldOutline, final String propertyName, final JType returnType, final JDefinedClass declaringClass, final F1<JExpression, JVar> getMaker, final F3<JExpression, JBlock, JVar, JVar> setMaker) {
	final String constantName = getConstantName(fieldOutline);
	final JMethod getMethod = declaringClass.method(JMod.PUBLIC, returnType, "get");
	getMethod.annotate(Override.class);
	final JVar instanceParam = getMethod.param(JMod.FINAL, fieldOutline.parent().implClass, "_instance_");
	getMethod.body()._return(JOp.cond(instanceParam.eq(JExpr._null()), JExpr._null(), getMaker.f(instanceParam)));
	final JMethod setMethod = declaringClass.method(JMod.PUBLIC, void.class, "set");
	setMethod.annotate(Override.class);
	final JVar setInstanceParam = setMethod.param(JMod.FINAL, fieldOutline.parent().implClass, "_instance_");
	final JVar valueParam = setMethod.param(JMod.FINAL, returnType, "_value_");
	if (constantName == null) {
		final JConditional ifNotNull = setMethod.body()._if(setInstanceParam.ne(JExpr._null()));
		setMaker.f(ifNotNull._then(), setInstanceParam, valueParam);
	}
}
 
Example 15
@Override
public JType getElementType() {
	if (isCollection() && !getRawType().isArray()) {
		return ((JClass) getRawType()).getTypeParameters().get(0);
	} else {
		return getRawType();
	}
}
 
Example 16
Source Project: dremio-oss   Source File: EvaluationVisitor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public HoldingContainer visitQuotedStringConstant(QuotedString e, ClassGenerator<?> generator)
    throws RuntimeException {
  CompleteType completeType = CompleteType.VARCHAR;
  JBlock setup = generator.getBlock(BlockType.SETUP);
  JType holderType = CodeModelArrowHelper.getHolderType(completeType, generator.getModel());
  JVar var = generator.declareClassField("string", holderType);
  JExpression stringLiteral = JExpr.lit(e.value);
  JExpression buffer = JExpr.direct("context").invoke("getManagedBuffer");
  setup.assign(var,
      generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getNullableVarCharHolder").arg(buffer).arg(stringLiteral));
  return new HoldingContainer((completeType), var, var.ref("value"), var.ref("isSet"));
}
 
Example 17
Source Project: jaxb2-rich-contract-plugin   Source File: SelectorGenerator.java    License: MIT License 5 votes vote down vote up
public void generateMetaFields() {
	if(this.classOutline.getSuperClass() != null) {
		this.selectorClass._extends(this.selectorGenerator.getInfoClass(this.classOutline.getSuperClass().implClass).selectorClass.narrow(this.rootTypeParam).narrow(this.parentTypeParam));
	}
	for (final FieldOutline fieldOutline : this.classOutline.getDeclaredFields()) {
		final JFieldVar definedField = PluginUtil.getDeclaredField(fieldOutline);
		if (definedField != null) {
			final JType elementType = PluginUtil.getElementType(fieldOutline);
			if (elementType.isReference()) {
				final ClassOutline modelClass = this.selectorGenerator.getPluginContext().getClassOutline(elementType);
				final JClass returnType;
				if (modelClass != null) {
					returnType = this.selectorGenerator.getInfoClass(modelClass.implClass).selectorClass.narrow(this.rootTypeParam).narrow(this.selectorClass.narrow(this.rootTypeParam).narrow(this.parentTypeParam));
				} else {
					returnType = this.selectorGenerator.getPluginContext().codeModel.ref(this.selectorGenerator.selectorBaseClass).narrow(this.rootTypeParam).narrow(this.selectorClass.narrow(this.rootTypeParam).narrow(this.parentTypeParam));
				}
				final JFieldVar includeField = this.selectorClass.field(JMod.PRIVATE, returnType, definedField.name(), JExpr._null());
				final JFieldRef fieldRef = JExpr._this().ref(includeField);
				final JMethod includeMethod = this.selectorClass.method(JMod.PUBLIC, returnType, definedField.name());
				if(this.selectorGenerator.selectorParamName != null) {
					final JVar includeParam = includeMethod.param(JMod.FINAL, this.selectorGenerator.getSelectorParamType(this.classOutline.implClass, elementType), this.selectorGenerator.selectorParamName);
					includeMethod.body()._return(JOp.cond(fieldRef.eq(JExpr._null()), fieldRef.assign(JExpr._new(returnType).arg(JExpr._this().ref("_root")).arg(JExpr._this()).arg(JExpr.lit(definedField.name())).arg(includeParam)), fieldRef));
				} else {
					includeMethod.body()._return(JOp.cond(fieldRef.eq(JExpr._null()), fieldRef.assign(JExpr._new(returnType).arg(JExpr._this().ref("_root")).arg(JExpr._this()).arg(JExpr.lit(definedField.name()))), fieldRef));
				}

				this.buildChildrenMethod.body()._if(fieldRef.ne(JExpr._null()))._then().add(this.productMapVar.invoke("put").arg(JExpr.lit(definedField.name())).arg(fieldRef.invoke("init")));
			}
		}
	}
	this.buildChildrenMethod.body()._return(this.productMapVar);
}
 
Example 18
Source Project: groovy-cps   Source File: Translator.java    License: Apache License 2.0 5 votes vote down vote up
private JType primitive(Object src, TypeKind k) {
    switch (k) {
    case BOOLEAN:   return codeModel.BOOLEAN;
    case BYTE:      return codeModel.BYTE;
    case SHORT:     return codeModel.SHORT;
    case INT:       return codeModel.INT;
    case LONG:      return codeModel.LONG;
    case CHAR:      return codeModel.CHAR;
    case FLOAT:     return codeModel.FLOAT;
    case DOUBLE:    return codeModel.DOUBLE;
    case VOID:      return codeModel.VOID;
    }
    throw new UnsupportedOperationException(src.toString());
}
 
Example 19
Source Project: dremio-oss   Source File: BaseFunctionHolder.java    License: Apache License 2.0 5 votes vote down vote up
protected void addProtectedBlock(ClassGenerator<?> g, JBlock sub, String body, HoldingContainer[] inputVariables,
    JVar[] workspaceJVars, boolean decConstInputOnly) {
  if (inputVariables != null) {
    for (int i = 0; i < inputVariables.length; i++) {
      if (decConstInputOnly && !inputVariables[i].isConstant()) {
        continue;
      }

      ValueReference parameter = parameters[i];
      HoldingContainer inputVariable = inputVariables[i];
      if (parameter.isFieldReader && !inputVariable.isReader() && inputVariable.getCompleteType().isScalar()) {
        JType singularReaderClass = g.getModel()._ref(TypeHelper.getHolderReaderImpl(getArrowMinorType(inputVariable.getCompleteType().toMinorType())));
        JType fieldReadClass = g.getModel()._ref(FieldReader.class);
        sub.decl(fieldReadClass, parameter.name, JExpr._new(singularReaderClass).arg(inputVariable.getHolder()));
      } else {
        sub.decl(inputVariable.getHolder().type(), parameter.name, inputVariable.getHolder());
      }
    }
  }

  JVar[] internalVars = new JVar[workspaceJVars.length];
  for (int i = 0; i < workspaceJVars.length; i++) {
    if (decConstInputOnly) {
      internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
    } else {
      internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
    }

  }

  Preconditions.checkNotNull(body);
  sub.directStatement(body);

  // reassign workspace variables back to global space.
  for (int i = 0; i < workspaceJVars.length; i++) {
    sub.assign(workspaceJVars[i], internalVars[i]);
  }
}
 
Example 20
Source Project: mxjc   Source File: ClassModelBuilder.java    License: MIT License 5 votes vote down vote up
/**
 * Build class name to element name mapping
 * 
 * @param outline, JAXB schema/code model
 * @return class name to element name map
 */
private static Map<String, QName> buildClass2ElementMapping(Outline outline) {
	Map<String, QName> mapping = new HashMap<String, QName>();
	for(CElementInfo ei : outline.getModel().getAllElements()) {
        JType exposedType = ei.getContentInMemoryType().toType(outline,Aspect.EXPOSED);
        mapping.put(exposedType.fullName(), ei.getElementName());
	}
	return mapping;
}
 
Example 21
Source Project: groovy-cps   Source File: Translator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JType visitParameterizedType(ParameterizedTypeTree pt, Void __) {
    JClass base = (JClass)visit(pt.getType());
    List<JClass> args = new ArrayList<>();
    for (Tree arg : pt.getTypeArguments()) {
        args.add((JClass)visit(arg));
    }
    return base.narrow(args);
}
 
Example 22
public HashCodeArguments element(JBlock subBlock, JType elementType) {
	final JVar elementValue = subBlock.decl(JMod.FINAL, elementType,
			value().name() + "Element", value().invoke("next"));
	final boolean isElementAlwaysSet = elementType.isPrimitive();
	final JExpression elementHasSetValue = isElementAlwaysSet ? JExpr.TRUE
			: elementValue.ne(JExpr._null());
	return spawn(elementValue, elementHasSetValue);

}
 
Example 23
@Override
public JType visit(ReferenceType type, JCodeModel codeModel) {
	final JType referencedType = type.getType().accept(this, codeModel);

	JType referencedTypeArray = referencedType;
	for (int index = 0; index < type.getArrayCount(); index++) {
		referencedTypeArray = referencedTypeArray.array();
	}
	return referencedTypeArray;
}
 
Example 24
Source Project: hyperjaxb3   Source File: AbstractField.java    License: 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 25
Source Project: mxjc   Source File: ClassModelBuilder.java    License: MIT License 5 votes vote down vote up
private static boolean isNestClass(JType type) {
	if (type instanceof JClass) {
		JClass clazz = (JClass)type;
		JClass out = clazz.outer();
		if (out == null) {
			return false;
		}
		if (out instanceof JClass) {
			return true;
		}
	}
	return false;
}
 
Example 26
static
private JType toType(JCodeModel codeModel, TypeMirror typeMirror){
	String name = typeMirror.toString();

	if(name.endsWith("Value<?>")){
		name = name.substring(0, name.length() - "Value<?>".length()) + "Value<? extends java.lang.Number>";
	}

	try {
		return codeModel.parseType(name);
	} catch(ClassNotFoundException cnfe){
		throw new RuntimeException(cnfe);
	}
}
 
Example 27
@Override
public JMethod apply(ApiActionMetadata endpointMetadata, JDefinedClass generatableType) {
	JType responseType = responseTypeRule.apply(endpointMetadata, generatableType);
	JMethod jMethod = generatableType.method(JMod.PUBLIC, responseType, endpointMetadata.getName());
	jMethod = paramsRule.apply(endpointMetadata, ext(jMethod, generatableType.owner()));
	return jMethod;
}
 
Example 28
Source Project: jaxb2-rich-contract-plugin   Source File: SelectorGenerator.java    License: MIT License 5 votes vote down vote up
JType getSelectorParamType(final JClass instanceType, final JType propertyType) {
	if(this.selectorParamType.isReference()) {
		return ((JClass)this.selectorParamType).narrow(instanceType).narrow(propertyType);
	} else {
		return this.selectorParamType;
	}
}
 
Example 29
Source Project: immutable-xjc   Source File: PluginImpl.java    License: MIT License 5 votes vote down vote up
private JVar addProperty(JDefinedClass clazz, JFieldVar field) {
    JType jType = getJavaType(field);
    int builderFieldVisibility = builderInheritance ? JMod.PROTECTED : JMod.PRIVATE;
    if (isCollection(field)) {
        return clazz.field(builderFieldVisibility, jType, field.name(),
                getNewCollectionExpression(field.type().owner(), jType));
    } else {
        return clazz.field(builderFieldVisibility, jType, field.name());
    }
}
 
Example 30
Source Project: jaxb-visitor   Source File: ClassDiscoverer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the type is a JAXBElement. In the case of JAXBElements, we want to traverse its
 * underlying value as opposed to the JAXBElement.
 * @param type element type to test to see if its a JAXBElement
 * @return true if the type is a JAXBElement
 */
static boolean isJAXBElement(JType type) {
    //noinspection RedundantIfStatement
    if (type.fullName().startsWith(JAXBElement.class.getName())) {
        return true;
    }
    return false;
}