本文整理汇总了Java中com.helger.jcodemodel.AbstractJClass.narrow方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractJClass.narrow方法的具体用法?Java AbstractJClass.narrow怎么用?Java AbstractJClass.narrow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.helger.jcodemodel.AbstractJClass
的用法示例。
在下文中一共展示了AbstractJClass.narrow方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVisitorType
import com.helger.jcodemodel.AbstractJClass; //导入方法依赖的package包/类
public AbstractJClass getVisitorType() {
AbstractJClass result = jVisitor;
for (JTypeVar typeVariable: jVisitor.typeParams()) {
result = result.narrow(specialTypeVariables.substituteSpecialType(typeVariable, selfType, resultType, exceptionType));
}
return result;
}
示例2: substitute
import com.helger.jcodemodel.AbstractJClass; //导入方法依赖的package包/类
public static AbstractJType substitute(AbstractJType type, JTypeVar typeVariable, AbstractJType variableValue) {
if (type == typeVariable)
return variableValue;
else if (!(type instanceof AbstractJClass)) {
return type;
} else {
if (type.isArray())
return substitute(type.elementType(), typeVariable, variableValue).array();
else if (type instanceof JTypeWildcard) {
JTypeWildcard wildcard = (JTypeWildcard)type;
AbstractJClass bound = (AbstractJClass)substitute(wildcard.bound(), typeVariable, variableValue);
return bound.wildcard(wildcard.boundMode());
} else {
/*
* When we get type with type-parameters we should substitute
* type-parameters.
*/
AbstractJClass genericType = (AbstractJClass)type;
if (genericType.getTypeParameters().isEmpty()) {
return genericType;
} else {
AbstractJClass result = genericType.erasure();
for (AbstractJClass typeArgument: genericType.getTypeParameters()) {
result = result.narrow(substitute(typeArgument, typeVariable, variableValue));
}
return result;
}
}
}
}
示例3: parse
import com.helger.jcodemodel.AbstractJClass; //导入方法依赖的package包/类
public CblEntityHolder parse(Element cblEntityElement, Map<String, Element> allAnnotatedFields, JCodeModel model) throws ClassNotFoundException {
CblEntityHolder content = new CblEntityHolder();
content.setSourceClazz(model.directClass(cblEntityElement.toString()));
content.setSourceElement(cblEntityElement);
for (Element element : cblEntityElement.getEnclosedElements()) {
if (element.getKind() == ElementKind.FIELD) {
CblBaseFieldHolder fieldHolder = null;
List<String> baseTypeWithGenerics = ElementUtil.splitGenericIfNeeded(element.asType().toString());
AbstractJClass fieldType = model.directClass(baseTypeWithGenerics.get(0));
CblField annotation = element.getAnnotation(CblField.class);
CblConstant constant = element.getAnnotation(CblConstant.class);
if(annotation == null && constant == null){
continue;
}
if (annotation != null) {
CblFieldHolder cblFieldHolder = new CblFieldHolder();
cblFieldHolder.setAttachmentType(annotation.attachmentType());
cblFieldHolder.setDbField(annotation.value().equals("") ? element.getSimpleName().toString() : annotation.value());
if (allAnnotatedFields.containsKey(fieldType.name())) {
cblFieldHolder.setSubEntityName(fieldType.name()+ "Entity");
fieldType = model.directClass(fieldType.fullName()+ "Entity");
}
if (baseTypeWithGenerics.size() > 1) {
for (int i = 1; i < baseTypeWithGenerics.size(); i++) {
JDirectClass mClazz = model.directClass(baseTypeWithGenerics.get(i));
if (allAnnotatedFields.containsKey(mClazz.name())) {
cblFieldHolder.setSubEntityIsTypeParam(true);
cblFieldHolder.setSubEntityName(mClazz.name() + "Entity");
fieldType = fieldType.narrow(model.directClass(mClazz.fullName()+ "Entity"));
}else{
fieldType = fieldType.narrow(mClazz);
}
}
}
fieldHolder = cblFieldHolder;
}
if(constant != null){
CblConstantHolder holder = new CblConstantHolder();
holder.setConstantValue(constant.constant());
holder.setDbField(constant.value().equals("") ? element.getSimpleName().toString() : constant.value());
fieldHolder = holder;
}
fieldHolder.setType(fieldType);
fieldHolder.setClazzFieldName(element.toString());
fieldHolder.setFieldElement(element);
content.getFields().add(fieldHolder);
}
}
//Add Id Field
CblFieldHolder idHolder = new CblFieldHolder();
idHolder.setClazzFieldName("id");
idHolder.setDbField("_id");
idHolder.setType(model.directClass(String.class.getCanonicalName()));
content.getFields().add(idHolder);
return content;
}
示例4: narrowType
import com.helger.jcodemodel.AbstractJClass; //导入方法依赖的package包/类
public static AbstractJClass narrowType(AbstractJClass type, AbstractJClass[] typeParams) {
return typeParams.length == 0 ? type : type.narrow(typeParams);
}
示例5: resolveType
import com.helger.jcodemodel.AbstractJClass; //导入方法依赖的package包/类
private AbstractJClass resolveType(JDefinedClass container, Collection_map_valueContext cmp) {
//
// resolve primitive type or reference
//
if ( cmp.TYPE_LITERAL() != null )
return primitiveType( ProtoTypes.valueOf( cmp.TYPE_LITERAL().getText().toUpperCase() ) );
else if ( cmp.all_identifiers() != null )
return resolveType( container, cmp.all_identifiers() );
//
// resolve (set/list)
//
Collection_mapContext cmCtx = cmp.collection_map();
CollectionContext collectionCtx = cmCtx.collection();
if ( collectionCtx != null ) {
Collection_typeContext typeContext = collectionCtx.collection_type();
boolean isSet = "set".equalsIgnoreCase( collectionCtx.COLLECTION_LITERAL().getText() );
AbstractJClass collectionClass = isSet ? codeModel.ref( Set.class ) : codeModel.ref( List.class );
if ( typeContext.TYPE_LITERAL() != null )
return collectionClass.narrow( primitiveType( ProtoTypes.valueOf( typeContext.TYPE_LITERAL().getText().toUpperCase() ) ) );
return collectionClass.narrow( resolveType( container, typeContext.all_identifiers() ) );
}
//
// resolve map
//
MapContext mapCtx = cmCtx.map();
Map_keyContext map_key = mapCtx.map_key();
Map_valueContext map_value = mapCtx.map_value();
AbstractJClass keyClass;
AbstractJClass valueClass;
if ( map_key.TYPE_LITERAL() != null ) {
keyClass = primitiveType( ProtoTypes.valueOf( map_key.TYPE_LITERAL().getText().toUpperCase() ) );
}
else {
keyClass = resolveType( container, map_key.all_identifiers() );
}
if ( map_value.TYPE_LITERAL() != null ) {
valueClass = primitiveType( ProtoTypes.valueOf( map_value.TYPE_LITERAL().getText().toUpperCase() ) );
}
else {
valueClass = resolveType( container, map_value.all_identifiers() );
}
AbstractJClass mapClass = codeModel.ref( Map.class );
return mapClass.narrow( keyClass, valueClass );
}