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


Java TypeKind.ARRAY屬性代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:JavadocCompletionItem.java

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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