當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayType類代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:ButterKnifeProcessor.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:Constructor.java

示例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;
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:SourceAnalyzerFactory.java

示例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());
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:GeneratorUtilitiesTest.java

示例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()
        );
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:BeanModelBuilder.java

示例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
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:BiFeature.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:PluginGenerator.java

示例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;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:Utilities.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:JavadocCompletionItem.java

示例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);
	}
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:24,代碼來源:TimedMethodModel.java

示例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);
        }
    }
}
 
開發者ID:dleppik,項目名稱:EgTest,代碼行數:18,代碼來源:EgWriter.java

示例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();
    }
}
 
開發者ID:josesamuel,項目名稱:remoter,代碼行數:17,代碼來源:ParcelerParamBuilder.java

示例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();

    }
}
 
開發者ID:josesamuel,項目名稱:remoter,代碼行數:24,代碼來源:ParcelerParamBuilder.java

示例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;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:GeneratedPlugin.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:Mirrors.java


注:本文中的javax.lang.model.type.ArrayType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。