本文整理汇总了Java中javax.lang.model.type.ArrayType类的典型用法代码示例。如果您正苦于以下问题:Java ArrayType类的具体用法?Java ArrayType怎么用?Java ArrayType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayType类属于javax.lang.model.type包,在下文中一共展示了ArrayType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getArrayResourceMethodName
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
/**
* Returns a method name from the {@link android.content.res.Resources} class for array resource
* binding, null if the element type is not supported.
*/
private static FieldResourceBinding.Type getArrayResourceMethodName(Element element) {
TypeMirror typeMirror = element.asType();
if (TYPED_ARRAY_TYPE.equals(typeMirror.toString())) {
return FieldResourceBinding.Type.TYPED_ARRAY;
}
if (TypeKind.ARRAY.equals(typeMirror.getKind())) {
ArrayType arrayType = (ArrayType) typeMirror;
String componentType = arrayType.getComponentType().toString();
if (STRING_TYPE.equals(componentType)) {
return FieldResourceBinding.Type.STRING_ARRAY;
} else if ("int".equals(componentType)) {
return FieldResourceBinding.Type.INT_ARRAY;
} else if ("java.lang.CharSequence".equals(componentType)) {
return FieldResourceBinding.Type.TEXT_ARRAY;
}
}
return null;
}
示例2: typeToTypeDeclaration
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
private TypeDeclaration typeToTypeDeclaration(TypeMirror tMirror){
int dimension = 0;
TypeMirror aType = tMirror;
ITypeDeclaration[] generics = null;
if(tMirror.getKind() == TypeKind.ARRAY){
for(;aType.getKind() == TypeKind.ARRAY; aType = ((ArrayType)tMirror).getComponentType()) {
dimension++;
}
}
if(aType.getKind() == TypeKind.DECLARED){
DeclaredType dType = (DeclaredType) aType;
List<? extends TypeMirror> parameters = dType.getTypeArguments();
if( parameters!=null && parameters.size()>0){
generics = new ITypeDeclaration[parameters.size()];
int i=0;
for(TypeMirror gType: parameters){
generics[i] = typeToTypeDeclaration(gType);
i++;
}
}
}
return new TypeDeclaration(owner, generics, dimension);
}
示例3: recordTypeUsage
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
private void recordTypeUsage(
final TypeMirror type,
final Map<Pair<BinaryName, String>, UsagesData<String>> p) {
List<TypeMirror> types = new LinkedList<TypeMirror>();
types.add(type);
while (!types.isEmpty()) {
TypeMirror currentType = types.remove(0);
if (currentType == null) continue;
switch (currentType.getKind()) {
case DECLARED:
final Symbol typeSym = ((Type) currentType).tsym;
if (typeSym != null && (typeSym.getKind().isClass() || typeSym.getKind().isInterface())) {
addUsage (typeSym, activeClass.peek(), p, ClassIndexImpl.UsageType.TYPE_REFERENCE);
}
types.addAll(((DeclaredType) currentType).getTypeArguments());
break;
case ARRAY:
types.add(((ArrayType) currentType).getComponentType());
break;
}
}
}
示例4: testOverrideMethods5
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
public void testOverrideMethods5() throws Exception {
performTest("package test;\npublic class Test extends XX<Number> {\npublic Test(){\n} }\nclass XX<T> {\npublic void test(T ... a) {}}", new OverrideMethodsTask(30), new Validator() {
public void validate(CompilationInfo info) {
TypeElement clazz = info.getElements().getTypeElement("test.Test");
ExecutableElement method = ElementFilter.methodsIn(clazz.getEnclosedElements()).get(0);
assertTrue(method.getSimpleName().contentEquals("test"));
TypeElement te = info.getElements().getTypeElement("java.lang.Number");
assertEquals(1, method.getParameters().size());
TypeMirror paramType = method.getParameters().get(0).asType();
assertNotNull(paramType);
assertTrue(paramType.getKind() == TypeKind.ARRAY);
assertTrue(info.getTypes().isSameType(te.asType(), ((ArrayType)paramType).getComponentType()));
assertTrue(method.isVarArgs());
}
});
}
示例5: addDependency
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
private void addDependency(TypeMirror tm) {
if (tm.getKind() == TypeKind.ARRAY) {
addDependency(((ArrayType)tm).getComponentType());
} else if (tm.getKind() == TypeKind.WILDCARD) {
WildcardType wt = (WildcardType)tm;
TypeMirror bound = wt.getSuperBound();
if (bound == null) {
bound = wt.getExtendsBound();
}
addDependency(bound);
} else if (tm.getKind() == TypeKind.DECLARED) {
addDependency(
((TypeElement)compilationInfo.getTypes().asElement(tm)).getQualifiedName().toString()
);
}
}
示例6: getTypeClass
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
private static String getTypeClass(TypeMirror type, CompilationInfo javac) {
TypeKind kind = type.getKind();
if (kind.isPrimitive()) {
return type.toString();
} else if (kind == TypeKind.ARRAY) {
return resolveArrayClass((ArrayType) type, javac);
} else if (kind == TypeKind.DECLARED) {
return ((TypeElement) ((DeclaredType) type).asElement()).getQualifiedName().toString();
} else if (kind == TypeKind.ERROR) {
return type.toString();
} else if (kind == TypeKind.TYPEVAR) {
return javac.getTypes().erasure(type).toString();
} else {
throw new IllegalStateException("Unknown type: " + type + ", " + type.getKind()); // NOI18N
}
}
示例7: appendSimpleTypeName
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
private static void appendSimpleTypeName(StringBuilder ret, TypeMirror type) {
switch (type.getKind()) {
case DECLARED:
DeclaredType declared = (DeclaredType) type;
TypeElement element = (TypeElement) declared.asElement();
ret.append(element.getSimpleName());
break;
case TYPEVAR:
appendSimpleTypeName(ret, ((TypeVariable) type).getUpperBound());
break;
case WILDCARD:
appendSimpleTypeName(ret, ((WildcardType) type).getExtendsBound());
break;
case ARRAY:
appendSimpleTypeName(ret, ((ArrayType) type).getComponentType());
ret.append("Array");
break;
default:
ret.append(type);
}
}
示例8: containedTypevarsRecursively
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
private static void containedTypevarsRecursively(@NonNull TypeMirror tm, @NonNull Collection<TypeVariable> typeVars) {
switch (tm.getKind()) {
case TYPEVAR:
typeVars.add((TypeVariable) tm);
break;
case DECLARED:
DeclaredType type = (DeclaredType) tm;
for (TypeMirror t : type.getTypeArguments()) {
containedTypevarsRecursively(t, typeVars);
}
break;
case ARRAY:
containedTypevarsRecursively(((ArrayType) tm).getComponentType(), typeVars);
break;
case WILDCARD:
if (((WildcardType) tm).getExtendsBound() != null) {
containedTypevarsRecursively(((WildcardType) tm).getExtendsBound(), typeVars);
}
if (((WildcardType) tm).getSuperBound() != null) {
containedTypevarsRecursively(((WildcardType) tm).getSuperBound(), typeVars);
}
break;
}
}
示例9: resolveTypeName
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
/**
* 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;
}
示例10: checkPublicType
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
private void checkPublicType(ModelContext ctx, TypeMirror type, ExecutableElement method, boolean acceptVoid, String msg) throws ModelException {
TypeKind kind = type.getKind();
if (kind.isPrimitive()) {
return;
}
switch (kind) {
case ARRAY:
checkPublicType(ctx, ((ArrayType) type).getComponentType(), method, false, msg);
return;
case DECLARED:
if (ctx.isPublic(type) || ctx.isProtected(type)) {
return;
}
throw new ModelException(msg + ": " + type + " is not public or protected");
case VOID:
if (acceptVoid) {
return;
}
throw new ModelException(msg + ": unsupported type " + type);
default:
throw new ModelException(msg + ": unsupported type " + type);
}
}
示例11: addVarArgs
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
private void addVarArgs(MethodSpec.Builder specBuilder,
LanguageInjector languageInjector,
String[] arguments,
List<? extends VariableElement> parameters,
VariableElement param)
{
if (parameters.size() <= arguments.length) {
ArrayType varargType = (ArrayType) param.asType();
TypeMirror type = varargType.getComponentType();
for (int argPos = parameters.size()-1; argPos < arguments.length; argPos++) {
if (argPos > 0)
specBuilder.addCode(", ");
String argument = arguments[argPos];
languageInjector.add(specBuilder, type, argument);
}
}
}
示例12: readOutResultsFromStub
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
@Override
public void readOutResultsFromStub(VariableElement param, ParamType paramType, String paramName, MethodSpec.Builder methodBuilder) {
if (param.asType().getKind() == TypeKind.ARRAY) {
methodBuilder.beginControlFlow("if (" + paramName + " != null)");
methodBuilder.addStatement("reply.writeInt(" + paramName + ".length)");
methodBuilder.beginControlFlow("for($T item:" + paramName + " )", ((ArrayType) param.asType()).getComponentType());
methodBuilder.addStatement("Class pClass = getParcelerClass(item)");
methodBuilder.addStatement("reply.writeString(pClass.getName())");
methodBuilder.addStatement("org.parceler.Parcels.wrap(pClass, item).writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE)");
methodBuilder.endControlFlow();
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement("reply.writeInt(-1)");
methodBuilder.endControlFlow();
}
}
示例13: readResultsFromProxy
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
@Override
public void readResultsFromProxy(TypeMirror resultType, MethodSpec.Builder methodBuilder) {
if (resultType.getKind() == TypeKind.ARRAY) {
methodBuilder.addStatement("int size_result = reply.readInt()");
methodBuilder.beginControlFlow("if (size_result >= 0)");
methodBuilder.addStatement("result = new $T[size_result]", ((ArrayType) resultType).getComponentType());
methodBuilder.beginControlFlow("for(int i=0; i<size_result; i++)");
methodBuilder.addStatement("result[i]= ($T)getParcelerObject(reply.readString(), reply)", ((ArrayType) resultType).getComponentType());
methodBuilder.endControlFlow();
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement("result = null");
methodBuilder.endControlFlow();
} else {
methodBuilder.beginControlFlow("if (reply.readInt() != 0)");
methodBuilder.addStatement("result = ($T)getParcelerObject(reply.readString(), reply)", resultType);
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement("result = null");
methodBuilder.endControlFlow();
}
}
示例14: hasUncheckedWarning
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
static boolean hasUncheckedWarning(TypeMirror type) {
switch (type.getKind()) {
case DECLARED:
DeclaredType declared = (DeclaredType) type;
for (TypeMirror typeParam : declared.getTypeArguments()) {
if (hasUncheckedWarning(typeParam)) {
return true;
}
}
return false;
case TYPEVAR:
return true;
case WILDCARD:
return ((WildcardType) type).getExtendsBound() != null;
case ARRAY:
return hasUncheckedWarning(((ArrayType) type).getComponentType());
default:
return false;
}
}
示例15: AttributeModel
import javax.lang.model.type.ArrayType; //导入依赖的package包/类
AttributeModel(ExecutableElement element) {
this.element = element;
this.name = element.getSimpleName().toString();
TypeMirror type = element.getReturnType();
this.isArray = type.getKind() == TypeKind.ARRAY;
this.type = this.isArray ? ((ArrayType) type).getComponentType() : type;
this.kind = AttributeTypeKind.from(this.type);
this.suffix = this.isArray ? "[]" : "";
this.mirrorModel = getMirrorModelIfAnnotation();
}