本文整理汇总了Java中javax.lang.model.type.TypeKind.ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java TypeKind.ARRAY属性的具体用法?Java TypeKind.ARRAY怎么用?Java TypeKind.ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.lang.model.type.TypeKind
的用法示例。
在下文中一共展示了TypeKind.ARRAY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveTypeName
/**
* uses FQNs where possible since javadoc does not match imports for
* parameter types
*/
private CharSequence resolveTypeName(TypeMirror asType, boolean isVarArgs) {
CharSequence ptype;
if (asType.getKind() == TypeKind.DECLARED) {
// snip generics
Element e = ((DeclaredType) asType).asElement();
ptype = e.getKind().isClass() || e.getKind().isInterface()
? ((TypeElement) e).getQualifiedName()
: e.getSimpleName();
} else if (asType.getKind() == TypeKind.TYPEVAR) {
do {
// Type Erasure JLS 4.6
asType = ((TypeVariable) asType).getUpperBound();
} while (asType.getKind() == TypeKind.TYPEVAR);
ptype = resolveTypeName(asType, isVarArgs);
} else if (isVarArgs && asType.getKind() == TypeKind.ARRAY) {
ptype = resolveTypeName(((ArrayType)asType).getComponentType(), false) + "..."; //NOI18N
} else {
ptype = asType.toString();
}
return ptype;
}
示例2: readResultsFromProxy
@Override
public void readResultsFromProxy(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
if (resultType.getKind() == TypeKind.ARRAY) {
methodBuilder.addStatement("result = reply.createBooleanArray()");
} else {
methodBuilder.addStatement("result = reply.readInt() == 1");
}
}
示例3: computeNewArray
private static List<? extends TypeMirror> computeNewArray(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
NewArrayTree nat = (NewArrayTree) parent.getLeaf();
if (nat.getType() == error) {
types.add(ElementKind.CLASS);
types.add(ElementKind.ENUM);
types.add(ElementKind.INTERFACE);
return null;
}
for (Tree dimension : nat.getDimensions()) {
if (dimension == error) {
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.INT));
}
}
for (Tree init : nat.getInitializers()) {
if (init == error) {
TypeMirror whole = info.getTrees().getTypeMirror(parent);
if (whole == null || whole.getKind() != TypeKind.ARRAY)
return null;
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return Collections.singletonList(((ArrayType) whole).getComponentType());
}
}
return null;
}
示例4: run
@Override
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
TreePath call = treePath;//.getParentPath();
if (call.getLeaf().getKind() != Kind.METHOD_INVOCATION) {
call = call.getParentPath();
if (call.getLeaf().getKind() != Kind.METHOD_INVOCATION) {
return null;
}
}
MethodInvocationTree mit = (MethodInvocationTree) call.getLeaf();
TypeMirror mType = info.getTrees().getTypeMirror(new TreePath(call, mit.getMethodSelect()));
if (mType == null || mType.getKind() != TypeKind.EXECUTABLE) {
return null;
}
ExecutableType methodType = (ExecutableType) mType;
if (methodType.getParameterTypes().isEmpty() || methodType.getParameterTypes().get(methodType.getParameterTypes().size() - 1).getKind() != TypeKind.ARRAY) {
return null;
}
ArrayType targetArray = (ArrayType) methodType.getParameterTypes().get(methodType.getParameterTypes().size() - 1);
TreePath target = new TreePath(call, mit.getArguments().get(mit.getArguments().size() - 1));
return Arrays.asList(new FixImpl(info, target, targetArray.getComponentType()).toEditorFix(),
new FixImpl(info, target, targetArray).toEditorFix());
}
示例5: getIterableGenericType
/**
*
* @param info context {@link CompilationInfo}
* @param iterable tested {@link TreePath}
* @return generic type of an {@link Iterable} or {@link ArrayType} at a TreePath
*/
public static TypeMirror getIterableGenericType(CompilationInfo info, TreePath iterable) {
TypeElement iterableElement = info.getElements().getTypeElement("java.lang.Iterable"); //NOI18N
if (iterableElement == null) {
return null;
}
TypeMirror iterableType = info.getTrees().getTypeMirror(iterable);
if (iterableType == null) {
return null;
}
TypeMirror designedType = null;
if (iterableType.getKind() == TypeKind.DECLARED) {
DeclaredType declaredType = (DeclaredType) iterableType;
if (!info.getTypes().isSubtype(info.getTypes().erasure(declaredType), info.getTypes().erasure(iterableElement.asType()))) {
return null;
}
ExecutableElement iteratorMethod = (ExecutableElement) iterableElement.getEnclosedElements().get(0);
ExecutableType iteratorMethodType = (ExecutableType) info.getTypes().asMemberOf(declaredType, iteratorMethod);
List<? extends TypeMirror> typeArguments = ((DeclaredType) iteratorMethodType.getReturnType()).getTypeArguments();
if (!typeArguments.isEmpty()) {
designedType = typeArguments.get(0);
} else {
TypeElement jlObject = info.getElements().getTypeElement("java.lang.Object");
if (jlObject != null) {
designedType = jlObject.asType();
}
}
} else if (iterableType.getKind() == TypeKind.ARRAY) {
designedType = ((ArrayType) iterableType).getComponentType();
}
if (designedType == null) {
return null;
}
return resolveTypeForDeclaration(info, designedType);
}
示例6: writeParamsToProxy
@Override
public void writeParamsToProxy(VariableElement param, ParamType paramType, MethodSpec.Builder methodBuilder) {
if (param.asType().getKind() == TypeKind.ARRAY) {
if (paramType == ParamType.OUT) {
writeArrayOutParamsToProxy(param, methodBuilder);
} else {
methodBuilder.addStatement("data.writeLongArray(" + param.getSimpleName() + ")");
}
} else {
methodBuilder.addStatement("data.writeLong(" + param.getSimpleName() + ")");
}
}
示例7: readResultsFromStub
@Override
public void readResultsFromStub(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
if (resultType.getKind() == TypeKind.ARRAY) {
methodBuilder.addStatement("reply.writeCharArray(result)");
} else {
methodBuilder.addStatement("reply.writeInt((int)result)");
}
}
示例8: readOutParamsFromProxy
@Override
public void readOutParamsFromProxy(VariableElement param, ParamType paramType, MethodSpec.Builder methodBuilder) {
if (paramType != ParamType.IN) {
if (param.asType().getKind() == TypeKind.ARRAY) {
methodBuilder.addStatement("int size_" + param.getSimpleName() + " = reply.readInt()");
methodBuilder.beginControlFlow("for(int i=0; i<size_" + param.getSimpleName() + "; i++)");
methodBuilder.addStatement(param.getSimpleName() + "[i] = ($T)getParcelerObject(reply.readString(), reply)", ((ArrayType) param.asType()).getComponentType());
methodBuilder.endControlFlow();
}
}
}
示例9: writeParamsToProxy
@Override
public void writeParamsToProxy(VariableElement param, ParamType paramType, MethodSpec.Builder methodBuilder) {
if (param.asType().getKind() == TypeKind.ARRAY) {
logError("List[] is not supported");
} else {
if (paramType != ParamType.OUT) {
if (isListOfStrings(param.asType())) {
methodBuilder.addStatement("data.writeStringList(" + param.getSimpleName() + ")");
} else {
methodBuilder.addStatement("data.writeList(" + param.getSimpleName() + ")");
}
}
}
}
示例10: readResultsFromProxy
@Override
public void readResultsFromProxy(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
if (resultType.getKind() == TypeKind.ARRAY) {
logError("short[] is not supported, use int[]");
methodBuilder.addStatement("result = null");
} else {
methodBuilder.addStatement("result = (short)reply.readInt()");
}
}
示例11: canContainArrays
/**
* Determines whether the array can contain other arrays. Checks if the component type is an array type.
* Otherwise, checks whether the component type is a declared one, and that it is an Object. Other declared
* types cannot hold array references.
*
* @param ci context
* @param tp path to the array expression
* @return true, if the expression (assuming array type) can hold other arrays as members
*/
static boolean canContainArrays(CompilationInfo ci, TreePath tp) {
TypeMirror tm = ci.getTrees().getTypeMirror(tp);
if (!Utilities.isValidType(tm)) {
return false;
}
tm = ci.getTypes().erasure(tm);
if (tm == null || tm.getKind() != TypeKind.ARRAY) {
return false;
}
ArrayType arrayType = (ArrayType)tm;
TypeMirror ct = arrayType.getComponentType();
boolean enableDeep = false;
if (ct.getKind() == TypeKind.ARRAY) {
// if the component kind is known to be an array, enable deepHash
enableDeep = true;
} else if (ct.getKind() == TypeKind.DECLARED) {
Element obj = ci.getElements().getTypeElement("java.lang.Object"); // NOI18N
if (obj == null) {
return false;
}
// other ref types than Object cannot hold array instances, deepHash is a nonsense
enableDeep = ci.getTypes().isSameType(obj.asType(), ct);
}
return enableDeep;
}
示例12: readResultsFromProxy
@Override
public void readResultsFromProxy(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
if (resultType.getKind() == TypeKind.ARRAY) {
logError("CharSequence[] cannot be marshalled");
} else {
methodBuilder.beginControlFlow("if(reply.readInt() != 0)");
methodBuilder.addStatement("result = android.text.TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(reply)");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement("result = null");
methodBuilder.endControlFlow();
}
}
示例13: writeParamsToStub
@Override
public void writeParamsToStub(VariableElement param, ParamType paramType, String paramName, MethodSpec.Builder methodBuilder) {
super.writeParamsToStub(param, paramType, paramName, methodBuilder);
if (param.asType().getKind() == TypeKind.ARRAY) {
if (paramType == ParamType.OUT) {
writeOutParamsToStub(param, paramType, paramName, methodBuilder);
} else {
methodBuilder.addStatement(paramName + " = data.createLongArray()");
}
} else {
methodBuilder.addStatement(paramName + " = data.readLong()");
}
}
示例14: writeParamsToStub
@Override
public void writeParamsToStub(VariableElement param, ParamType paramType, String paramName, MethodSpec.Builder methodBuilder) {
super.writeParamsToStub(param, paramType, paramName, methodBuilder);
if (param.asType().getKind() == TypeKind.ARRAY) {
logError("CharSequence[] cannot be marshalled");
} else {
methodBuilder.beginControlFlow("if(data.readInt() != 0)");
methodBuilder.addStatement(paramName + " = android.text.TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(data)");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement(paramName + " = null");
methodBuilder.endControlFlow();
}
}
示例15: isPrimitiveArray
public static boolean isPrimitiveArray(Element element) {
if (element.asType().getKind() != TypeKind.ARRAY) {
return false;
}
ArrayType arrayType = (ArrayType) element.asType();
TypeMirror componentType = arrayType.getComponentType();
TypeName typeName = TypeName.get(componentType);
return typeName.isPrimitive() || typeName.isBoxedPrimitive();
}