当前位置: 首页>>代码示例>>Java>>正文


Java ArrayType.getComponentType方法代码示例

本文整理汇总了Java中javax.lang.model.type.ArrayType.getComponentType方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayType.getComponentType方法的具体用法?Java ArrayType.getComponentType怎么用?Java ArrayType.getComponentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.type.ArrayType的用法示例。


在下文中一共展示了ArrayType.getComponentType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: isMainMethod

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
/**
 * Returns true if the method is a main method
 * @param method to be checked
 * @return true when the method is a main method
 */
public static boolean isMainMethod (final ExecutableElement method) {
    if (!"main".contentEquals(method.getSimpleName())) {                //NOI18N
        return false;
    }
    long flags = ((Symbol.MethodSymbol)method).flags();                 //faster
    if (((flags & Flags.PUBLIC) == 0) || ((flags & Flags.STATIC) == 0)) {
        return false;
    }
    if (method.getReturnType().getKind() != TypeKind.VOID) {
        return false;
    }
    List<? extends VariableElement> params = method.getParameters();
    if (params.size() != 1) {
        return false;
    }
    TypeMirror param = params.get(0).asType();
    if (param.getKind() != TypeKind.ARRAY) {
        return false;
    }
    ArrayType array = (ArrayType) param;
    TypeMirror compound = array.getComponentType();
    if (compound.getKind() != TypeKind.DECLARED) {
        return false;
    }
    return "java.lang.String".contentEquals(((TypeElement)((DeclaredType)compound).asElement()).getQualifiedName());   //NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:SourceUtils.java

示例3: canContainArrays

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
/**
 * 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,代码行数:36,代码来源:ArrayStringConversions.java

示例4: isPrimitiveArray

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
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,代码行数:12,代码来源:TypeUtils.java

示例5: isParcelableArray

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
public static boolean isParcelableArray(Types typeUtils, Elements elementUtils, Element element) {
    if (element.asType().getKind() != TypeKind.ARRAY) {
        return false;
    }

    ArrayType arrayType = (ArrayType) element.asType();
    TypeMirror componentType = arrayType.getComponentType();

    TypeElement typeParcelable = elementUtils.getTypeElement(Parcelable.class.getName());
    return typeUtils.isSubtype(componentType, typeParcelable.asType());
}
 
开发者ID:srym,项目名称:vulture,代码行数:12,代码来源:TypeUtils.java

示例6: getPrimitiveArrayClassName

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
public static String getPrimitiveArrayClassName(Element element) {
    if (element.asType().getKind() != TypeKind.ARRAY) {
        throw new IllegalArgumentException("element is not array: " + element.toString());
    }

    ArrayType arrayType = (ArrayType) element.asType();
    TypeMirror componentType = arrayType.getComponentType();
    ClassName className = (ClassName) TypeName.get(componentType).box();
    return className.simpleName() + "Array";
}
 
开发者ID:srym,项目名称:vulture,代码行数:11,代码来源:TypeUtils.java

示例7: isArrayButNotByteArray

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
public boolean isArrayButNotByteArray(TypeMirror t) {
    if(!isArray(t))
        return false;

    ArrayType at = (ArrayType) t;
    TypeMirror ct = at.getComponentType();

    return !ct.equals(primitiveByte);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:ApNavigator.java

示例8: getComponentType

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
public TypeMirror getComponentType(TypeMirror t) {
    if (isArray(t)) {
        ArrayType at = (ArrayType) t;
        return at.getComponentType();
    }

    throw new IllegalArgumentException();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:ApNavigator.java

示例9: visitMethodInvocation

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
@Override
public Tree visitMethodInvocation(MethodInvocationTree node, Element p) {
    if (!refactoring.getReplace()) {
        return super.visitMethodInvocation(node, p);
    }
    TreePath currentPath = getCurrentPath();
    TypeMirror returnType = workingCopy.getTrees().getTypeMirror(currentPath);
    boolean fromArray = false;
    if (returnType != null && returnType.getKind() == TypeKind.ARRAY) {
        ArrayType array = (ArrayType) returnType;
        returnType = array.getComponentType();
        fromArray = true;
    }
    Element typeElement = workingCopy.getTypes().asElement(returnType);

    // TODO: Check if the method is in the scope, then skip it.
    if (p.equals(typeElement)) {
        if(willBeExtended(currentPath, node, returnType)) {
            return super.visitMethodInvocation(node, p);
        }
        ExpressionTree ident;

        DeclaredType declaredType = (DeclaredType) returnType;
        List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();

        List<ExpressionTree> types = new LinkedList<>();
        for (TypeMirror typeMirror : typeArguments) {
            types.add((ExpressionTree) make.Type(typeMirror));
        }
        ident = make.QualIdent(fqn);
        if (!types.isEmpty()) {
            ident = (ExpressionTree) make.ParameterizedType(ident, types);
        }

        Tree newClass;
        if(fromArray) {
            newClass = make.MethodInvocation(Collections.EMPTY_LIST, make.MemberSelect(ident, "wrap"), Collections.singletonList(node));
        } else {
            newClass = make.NewClass(null, Collections.EMPTY_LIST, ident, Collections.singletonList(node), null);
        }
        rewrite(node, newClass);
    }

    return super.visitMethodInvocation(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:IntroduceLocalExtensionTransformer.java

示例10: getAccessorType

import javax.lang.model.type.ArrayType; //导入方法依赖的package包/类
/**
 * Computes the string to append to 'get' or 'set' to get a valid Bundle method name.
 * For example, for the type int[], will return 'IntArray', which leads to the methods 'putIntArray' and 'getIntArray'
 *
 * @param typeMirror The type to access in the bundle
 * @return The string to append to 'get' or 'put'
 */
private String getAccessorType(TypeMirror typeMirror) {
    if (typeMirror instanceof PrimitiveType) {
        return typeMirror.toString().toUpperCase().charAt(0) + typeMirror.toString().substring(1);
    } else if (typeMirror instanceof DeclaredType) {
        Element element = ((DeclaredType) typeMirror).asElement();
        if (element instanceof TypeElement) {
            if (isSubtype(element, "java.util.List")) { // ArrayList
                List<? extends TypeMirror> typeArgs = ((DeclaredType) typeMirror).getTypeArguments();
                if (typeArgs != null && !typeArgs.isEmpty()) {
                    TypeMirror argType = typeArgs.get(0);
                    if (isSubtype(argType, "java.lang.Integer")) {
                        return "IntegerArrayList";
                    } else if (isSubtype(argType, "java.lang.String")) {
                        return "StringArrayList";
                    } else if (isSubtype(argType, "java.lang.CharSequence")) {
                        return "CharSequenceArrayList";
                    } else if (isSubtype(argType, "android.os.Parcelable")) {
                        return "ParcelableArrayList";
                    }
                }
            } else if (isSubtype(element, "android.os.Bundle")) {
                return "Bundle";
            } else if (isSubtype(element, "java.lang.String")) {
                return "String";
            } else if (isSubtype(element, "java.lang.CharSequence")) {
                return "CharSequence";
            } else if (isSubtype(element, "android.util.SparseArray")) {
                return "SparseParcelableArray";
            } else if (isSubtype(element, "android.os.Parcelable")) {
                return "Parcelable";
            } else if (isSubtype(element, "java.io.Serializable")) {
                return "Serializable";
            } else if (isSubtype(element, "android.os.IBinder")) {
                return "Binder";
            }
        }
    } else if (typeMirror instanceof ArrayType) {
        ArrayType arrayType = (ArrayType) typeMirror;
        TypeMirror compType = arrayType.getComponentType();
        if (compType instanceof PrimitiveType) {
            return compType.toString().toUpperCase().charAt(0) + compType.toString().substring(1) + "Array";
        } else if (compType instanceof DeclaredType) {
            Element compElement = ((DeclaredType) compType).asElement();
            if (compElement instanceof TypeElement) {
                if (isSubtype(compElement, "java.lang.String")) {
                    return "StringArray";
                } else if (isSubtype(compElement, "java.lang.CharSequence")) {
                    return "CharSequenceArray";
                } else if (isSubtype(compElement, "android.os.Parcelable")) {
                    return "ParcelableArray";
                }
                return null;
            }
        }
    }
    return null;
}
 
开发者ID:chenenyu,项目名称:Router,代码行数:65,代码来源:InjectParamProcessor.java


注:本文中的javax.lang.model.type.ArrayType.getComponentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。