本文整理汇总了Java中javax.lang.model.type.ReferenceType类的典型用法代码示例。如果您正苦于以下问题:Java ReferenceType类的具体用法?Java ReferenceType怎么用?Java ReferenceType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReferenceType类属于javax.lang.model.type包,在下文中一共展示了ReferenceType类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGenericTypeForContainer
import javax.lang.model.type.ReferenceType; //导入依赖的package包/类
public static ReferenceType getGenericTypeForContainer(VariableElement field) {
TypeMirror fieldType = field.asType();
TypeKind kind = fieldType.getKind();
if (kind != TypeKind.DECLARED) { return null; }
List<? extends TypeMirror> args = ((DeclaredType) fieldType).getTypeArguments();
if (args.size() <= 0) { return null; }
fieldType = args.get(0);
kind = fieldType.getKind();
// We also support RealmList<byte[]>
if (kind != TypeKind.DECLARED && kind != TypeKind.ARRAY) { return null; }
return (ReferenceType) fieldType;
}
示例2: getRealmResultsType
import javax.lang.model.type.ReferenceType; //导入依赖的package包/类
public static String getRealmResultsType(VariableElement field) {
if (!Utils.isRealmResults(field)) { return null; }
ReferenceType type = getGenericTypeForContainer(field);
if (null == type) { return null; }
return type.toString();
}
示例3: getRealmListType
import javax.lang.model.type.ReferenceType; //导入依赖的package包/类
public static String getRealmListType(VariableElement field) {
if (!Utils.isRealmList(field)) { return null; }
ReferenceType type = getGenericTypeForContainer(field);
if (null == type) { return null; }
return type.toString();
}
示例4: getFieldTypeSimpleName
import javax.lang.model.type.ReferenceType; //导入依赖的package包/类
/**
* @return the simple type name for a field.
*/
public static String getFieldTypeSimpleName(ReferenceType type) {
return (null == type) ? null : getFieldTypeSimpleName(type.toString());
}
示例5: commonConvert
import javax.lang.model.type.ReferenceType; //导入依赖的package包/类
/**
* Assignment conversion and method invocation conversion are almost
* identical, except that assignment conversion allows narrowing. We
* factor out the common logic here.
*
* @param node
* a Node producing a value
* @param varType
* the type of a variable
* @param contextAllowsNarrowing
* whether to allow narrowing (for assignment conversion) or
* not (for method invocation conversion)
* @return a Node with the value converted to the type of the variable,
* which may be the input node itself
*/
protected Node commonConvert(Node node, TypeMirror varType,
boolean contextAllowsNarrowing) {
// For assignment conversion, see JLS 5.2
// For method invocation conversion, see JLS 5.3
// Check for identical types or "identity conversion"
TypeMirror nodeType = node.getType();
boolean isSameType = types.isSameType(nodeType, varType);
if (isSameType) {
return node;
}
boolean isRightNumeric = TypesUtils.isNumeric(nodeType);
boolean isRightPrimitive = TypesUtils.isPrimitive(nodeType);
boolean isRightBoxed = TypesUtils.isBoxedPrimitive(nodeType);
boolean isRightReference = nodeType instanceof ReferenceType;
boolean isLeftNumeric = TypesUtils.isNumeric(varType);
boolean isLeftPrimitive = TypesUtils.isPrimitive(varType);
// boolean isLeftBoxed = TypesUtils.isBoxedPrimitive(varType);
boolean isLeftReference = varType instanceof ReferenceType;
boolean isSubtype = types.isSubtype(nodeType, varType);
if (isRightNumeric && isLeftNumeric && isSubtype) {
node = widen(node, varType);
nodeType = node.getType();
} else if (isRightReference && isLeftReference && isSubtype) {
// widening reference conversion is a no-op, but if it
// applies, then later conversions do not.
} else if (isRightPrimitive && isLeftReference) {
if (contextAllowsNarrowing && conversionRequiresNarrowing(varType, node)) {
node = narrowAndBox(node, varType);
nodeType = node.getType();
} else {
node = box(node);
nodeType = node.getType();
}
} else if (isRightBoxed && isLeftPrimitive) {
node = unbox(node);
nodeType = node.getType();
if (types.isSubtype(nodeType, varType)
&& !types.isSameType(nodeType, varType)) {
node = widen(node, varType);
nodeType = node.getType();
}
} else if (isRightPrimitive && isLeftPrimitive) {
if (contextAllowsNarrowing && conversionRequiresNarrowing(varType, node)) {
node = narrow(node, varType);
nodeType = node.getType();
}
}
// TODO: if checkers need to know about null references of
// a particular type, add logic for them here.
return node;
}
示例6: commonConvert
import javax.lang.model.type.ReferenceType; //导入依赖的package包/类
/**
* Assignment conversion and method invocation conversion are almost identical, except that
* assignment conversion allows narrowing. We factor out the common logic here.
*
* @param node a Node producing a value
* @param varType the type of a variable
* @param contextAllowsNarrowing whether to allow narrowing (for assignment conversion) or
* not (for method invocation conversion)
* @return a Node with the value converted to the type of the variable, which may be the
* input node itself
*/
protected Node commonConvert(
Node node, TypeMirror varType, boolean contextAllowsNarrowing) {
// For assignment conversion, see JLS 5.2
// For method invocation conversion, see JLS 5.3
// Check for identical types or "identity conversion"
TypeMirror nodeType = node.getType();
boolean isSameType = types.isSameType(nodeType, varType);
if (isSameType) {
return node;
}
boolean isRightNumeric = TypesUtils.isNumeric(nodeType);
boolean isRightPrimitive = TypesUtils.isPrimitive(nodeType);
boolean isRightBoxed = TypesUtils.isBoxedPrimitive(nodeType);
boolean isRightReference = nodeType instanceof ReferenceType;
boolean isLeftNumeric = TypesUtils.isNumeric(varType);
boolean isLeftPrimitive = TypesUtils.isPrimitive(varType);
// boolean isLeftBoxed = TypesUtils.isBoxedPrimitive(varType);
boolean isLeftReference = varType instanceof ReferenceType;
boolean isSubtype = types.isSubtype(nodeType, varType);
if (isRightNumeric && isLeftNumeric && isSubtype) {
node = widen(node, varType);
nodeType = node.getType();
} else if (isRightReference && isLeftReference && isSubtype) {
// widening reference conversion is a no-op, but if it
// applies, then later conversions do not.
} else if (isRightPrimitive && isLeftReference) {
if (contextAllowsNarrowing && conversionRequiresNarrowing(varType, node)) {
node = narrowAndBox(node, varType);
nodeType = node.getType();
} else {
node = box(node);
nodeType = node.getType();
}
} else if (isRightBoxed && isLeftPrimitive) {
node = unbox(node);
nodeType = node.getType();
if (types.isSubtype(nodeType, varType) && !types.isSameType(nodeType, varType)) {
node = widen(node, varType);
nodeType = node.getType();
}
} else if (isRightPrimitive && isLeftPrimitive) {
if (contextAllowsNarrowing && conversionRequiresNarrowing(varType, node)) {
node = narrow(node, varType);
nodeType = node.getType();
}
}
// TODO: if checkers need to know about null references of
// a particular type, add logic for them here.
return node;
}