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


Java TypeMirror.toString方法代码示例

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


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

示例1: getViewStateClassFromAnnotationParams

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private String getViewStateClassFromAnnotationParams(TypeElement typeElement) {
	InjectViewState annotation = typeElement.getAnnotation(InjectViewState.class);
	String mvpViewStateClassName = "";

	if (annotation != null) {
		TypeMirror value;
		try {
			annotation.value();
		} catch (MirroredTypeException mte) {
			value = mte.getTypeMirror();
			mvpViewStateClassName = value.toString();
		}
	}

	if (mvpViewStateClassName.isEmpty() || DefaultViewState.class.getName().equals(mvpViewStateClassName)) {
		return null;
	}

	return mvpViewStateClassName;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:ViewStateProviderClassGenerator.java

示例2: jniMethodName

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
protected final String jniMethodName(ExecutableElement method, String cname,
                                     boolean longName)
            throws TypeSignature.SignatureException {
    String res = "Java_" + cname + "_" + method.getSimpleName();

    if (longName) {
        TypeMirror mType =  types.erasure(method.getReturnType());
        List<? extends VariableElement> params = method.getParameters();
        List<TypeMirror> argTypes = new ArrayList<TypeMirror>();
        for (VariableElement param: params) {
            argTypes.add(types.erasure(param.asType()));
        }

        res = res + "__";
        for (TypeMirror t: argTypes) {
            String tname = t.toString();
            TypeSignature newTypeSig = new TypeSignature(elems);
            String sig = newTypeSig.getTypeSignature(tname);
            res = res + nameToIdentifier(sig);
        }
    }
    return res;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:LLNI.java

示例3: jniMethodName

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
protected final String jniMethodName(ExecutableElement method, String cname,
                                     boolean longName)
            throws TypeSignature.SignatureException {
    String res = "Java_" + cname + "_" + method.getSimpleName();

    if (longName) {
        TypeMirror mType =  types.erasure(method.getReturnType());
        List<? extends VariableElement> params = method.getParameters();
        List<TypeMirror> argTypes = new ArrayList<>();
        for (VariableElement param: params) {
            argTypes.add(types.erasure(param.asType()));
        }

        res = res + "__";
        for (TypeMirror t: argTypes) {
            String tname = t.toString();
            TypeSignature newTypeSig = new TypeSignature(elems);
            String sig = newTypeSig.getTypeSignature(tname);
            res = res + nameToIdentifier(sig);
        }
    }
    return res;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:LLNI.java

示例4: getType

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private JType getType(TypeMirror typeMirror) {
        String type = typeMirror.toString();
        try {
//            System.out.println("typeName: "+typeName);
            return cm.parseType(type);
//            System.out.println("type: "+type);
        } catch (ClassNotFoundException e) {
            return cm.ref(type);
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:WebServiceWrapperGenerator.java

示例5: getParcelableClassName

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private String getParcelableClassName(TypeMirror typeMirror) {
    if (typeMirror.getKind() != TypeKind.ARRAY) {
        String pClassName = typeMirror.toString();
        int genericStartIndex = pClassName.indexOf('<');
        if (genericStartIndex != -1) {
            pClassName = pClassName.substring(0, genericStartIndex).trim();
        }
        return pClassName;
    } else {
        return getParcelableClassName(((ArrayType) typeMirror).getComponentType());
    }
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:13,代码来源:ParcellableParamBuilder.java

示例6: getTypeSimpleName

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private static String getTypeSimpleName(TypeMirror tm) {
    String name = tm.toString();
    int i = name.lastIndexOf('.');
    if (i > 0) {
        name = name.substring(i+1);
    }
    return name;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ElementCompletionItem.java

示例7: getRealTypeName

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private static String getRealTypeName(TypeMirror type, CompilationInfo ci) {
    final TypeMirror et = ci.getTypes().erasure(type);
    if (et.getKind() == TypeKind.DECLARED) {
        return ElementUtilities.getBinaryName((TypeElement)((DeclaredType)et).asElement());
    }
    if (et.getKind() == TypeKind.ARRAY) {
        return getRealTypeName(((ArrayType)et).getComponentType(), ci) + "[]";  // NOI18N
    }
    return et.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ElementUtilitiesEx.java

示例8: typeAsString

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
public static String typeAsString(TypeMirror type) {
    
    switch( type.getKind() ) {
        case DECLARED:
            return nameAsString(((DeclaredType)type).asElement());
        case ARRAY:
            return typeAsString(((ArrayType)type).getComponentType()) + "[]"; // NOI18N
        default:
            return type.toString();
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:BeanUtils.java

示例9: typeExchange

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
/**
 * Diagnostics out the true java type
 *
 * @param element Raw type
 * @return Type class of java
 */
public int typeExchange(Element element) {
    TypeMirror typeMirror = element.asType();

    // Primitive
    if (typeMirror.getKind().isPrimitive()) {
        return element.asType().getKind().ordinal();
    }

    switch (typeMirror.toString()) {
        case Constants.BYTE:
            return Type.BYTE.ordinal();
        case Constants.SHORT:
            return Type.SHORT.ordinal();
        case Constants.INTEGER:
            return Type.INT.ordinal();
        case Constants.LONG:
            return Type.LONG.ordinal();
        case Constants.FLOAT:
            return Type.FLOAT.ordinal();
        case Constants.DOUBEL:
            return Type.DOUBLE.ordinal();
        case Constants.BOOLEAN:
            return Type.BOOLEAN.ordinal();
        case Constants.STRING:
            return Type.STRING.ordinal();
        default:    // Other side, maybe the PARCELABLE or OBJECT.
            if (types.isSubtype(typeMirror, parcelableType)) {  // PARCELABLE
                return Type.PARCELABLE.ordinal();
            } else {    // For others
                return Type.OBJECT.ordinal();
            }
    }
}
 
开发者ID:luojilab,项目名称:DDComponentForAndroid,代码行数:40,代码来源:TypeUtils.java

示例10: getTypeBinaryName

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private static String getTypeBinaryName(TypeMirror t) {
    if (t instanceof ArrayType) {
        TypeMirror ct = ((ArrayType) t).getComponentType();
        return getTypeBinaryName(ct)+"[]";
    }
    if (t instanceof DeclaredType) {
        return ElementUtilities.getBinaryName((TypeElement) ((DeclaredType) t).asElement());
    }
    return t.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:EditorContextSupport.java

示例11: getSuperClassForDataBinding

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private TypeElement getSuperClassForDataBinding(TypeElement te) {
    TypeMirror superclass = te.getSuperclass();
    String superName = superclass.toString();
    if(superclass instanceof NoType){
        //no super.
    }else if(superName.startsWith("java.") || superName.startsWith("android.")){
        // no super too.
    }else{
        TypeElement newTe = new FieldData.TypeCompat(mContext.getTypes(), superclass).getElementAsType();
        DataBindingInfo info = mInfoMap.get(superName);
        if(info == null){
            //-------------- handle cross modules ------------
            //by class annotation
            if(hasDataBindingClassAnnotation(newTe)){
                return newTe;
            }
            //by field annotation
            List<VariableElement> elements = ElementFilter.fieldsIn(newTe.getEnclosedElements());
            if(elements.size() > 0){
                for(VariableElement ve: elements){
                    if(hasDataBindingFieldAnnotation(ve)){
                        return newTe;
                    }
                }
            }
            //may super's N class is using data-binding
            return getSuperClassForDataBinding(newTe);
        }else{
            //found
            return newTe;
        }
    }
    return null;
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:35,代码来源:DataBindingAnnotationProcessor.java

示例12: generate

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
public String generate(TypeMirror beanType, String packageName, Name beanName) {
    String generatedClassName = Type.deserializerName(packageName, beanName.toString());
    if (!TypeRegistry.containsDeserializer(beanType.toString())) {
        try {
            new AptDeserializerBuilder(beanType, filer)
                    .generate(beanName, packageName);
            TypeRegistry.registerDeserializer(beanType.toString(), ClassName.bestGuess(generatedClassName));
        } catch (IOException e) {
            throw new DeserializerGenerator.DeserializerGenerationFailedException(beanType.toString());
        }
    }
    return generatedClassName;
}
 
开发者ID:vegegoku,项目名称:gwt-jackson-apt,代码行数:14,代码来源:DeserializerGenerator.java

示例13: getBuilderForParam

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
/**
 * Returns the {@link ParamBuilder} that knows how to generate code for the given type of parameter
 */
ParamBuilder getBuilderForParam(TypeMirror typeMirror) {
    ParamBuilder paramBuilder = typeBuilderMap.get(typeMirror);
    if (paramBuilder == null) {
        switch (typeMirror.getKind()) {
            case BOOLEAN:
                paramBuilder = new BooleanParamBuilder(messager, null);
                break;
            case BYTE:
                paramBuilder = new ByteParamBuilder(messager, null);
                break;
            case CHAR:
                paramBuilder = new CharParamBuilder(messager, null);
                break;
            case DOUBLE:
                paramBuilder = new DoubleParamBuilder(messager, null);
                break;
            case FLOAT:
                paramBuilder = new FloatParamBuilder(messager, null);
                break;
            case INT:
                paramBuilder = new IntParamBuilder(messager, null);
                break;
            case LONG:
                paramBuilder = new LongParamBuilder(messager, null);
                break;
            case SHORT:
                paramBuilder = new ShortParamBuilder(messager, null);
                break;
            case ARRAY:
                paramBuilder = getBuilderForParam(((ArrayType) typeMirror).getComponentType());
                break;
            case DECLARED:
                TypeElement genericList = getGenericType(typeMirror);
                if (genericList != null) {
                    paramBuilder = new ListOfParcelerParamBuilder(messager, null, genericList);
                } else if (typeUtils.isAssignable(typeMirror, stringTypeMirror)) {
                    paramBuilder = new StringParamBuilder(messager, null);
                } else if (typeUtils.isAssignable(typeMirror, charSequenceTypeMirror)) {
                    paramBuilder = new CharSequenceParamBuilder(messager, null);
                } else if (typeUtils.isAssignable(typeMirror, listTypeMirror) || typeMirror.toString().equals("java.util.List<java.lang.String>")) {
                    paramBuilder = new ListParamBuilder(messager, null);
                } else if (typeUtils.isAssignable(typeMirror, mapTypeMirror)) {
                    paramBuilder = new MapParamBuilder(messager, null);
                } else if (typeUtils.isAssignable(typeMirror, parcellableTypeMirror)) {
                    paramBuilder = new ParcellableParamBuilder(messager, null);
                } else {
                    String typeName = typeMirror.toString();
                    int templateStart = typeName.indexOf('<');
                    if (templateStart != -1) {
                        typeName = typeName.substring(0, templateStart).trim();
                    }
                    TypeElement typeElement = elementUtils.getTypeElement(typeName);
                    if (typeElement != null) {
                        if (typeElement.getKind() == ElementKind.INTERFACE && typeElement.getAnnotation(Remoter.class) != null) {
                            paramBuilder = new BinderParamBuilder(messager, null);
                        } else if (parcelClass != null && typeElement.getAnnotation(parcelClass) != null) {
                            paramBuilder = new ParcelerParamBuilder(messager, null);
                        }
                    }
                }
                break;
        }
        if (paramBuilder != null) {
            paramBuilder.setBindingManager(this);
            typeBuilderMap.put(typeMirror, paramBuilder);
        } else {
            paramBuilder = new GenericParamBuilder(messager, null);
            paramBuilder.setBindingManager(this);
            typeBuilderMap.put(typeMirror, paramBuilder);
        }
    }
    return paramBuilder;
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:77,代码来源:BindingManager.java

示例14: jniType

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
protected final String jniType(TypeMirror t) throws Util.Exit {
    TypeElement throwable = elems.getTypeElement("java.lang.Throwable");
    TypeElement jClass = elems.getTypeElement("java.lang.Class");
    TypeElement jString = elems.getTypeElement("java.lang.String");
    Element tclassDoc = types.asElement(t);


    switch (t.getKind()) {
        case ARRAY: {
            TypeMirror ct = ((ArrayType) t).getComponentType();
            switch (ct.getKind()) {
                case BOOLEAN:  return "jbooleanArray";
                case BYTE:     return "jbyteArray";
                case CHAR:     return "jcharArray";
                case SHORT:    return "jshortArray";
                case INT:      return "jintArray";
                case LONG:     return "jlongArray";
                case FLOAT:    return "jfloatArray";
                case DOUBLE:   return "jdoubleArray";
                case ARRAY:
                case DECLARED: return "jobjectArray";
                default: throw new Error(ct.toString());
            }
        }

        case VOID:     return "void";
        case BOOLEAN:  return "jboolean";
        case BYTE:     return "jbyte";
        case CHAR:     return "jchar";
        case SHORT:    return "jshort";
        case INT:      return "jint";
        case LONG:     return "jlong";
        case FLOAT:    return "jfloat";
        case DOUBLE:   return "jdouble";

        case DECLARED: {
            if (tclassDoc.equals(jString))
                return "jstring";
            else if (types.isAssignable(t, throwable.asType()))
                return "jthrowable";
            else if (types.isAssignable(t, jClass.asType()))
                return "jclass";
            else
                return "jobject";
        }
    }

    util.bug("jni.unknown.type");
    return null; /* dead code. */
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:51,代码来源:JNI.java

示例15: getBundlerWrapper

import javax.lang.model.type.TypeMirror; //导入方法依赖的package包/类
private BundlerWrapper getBundlerWrapper(Element field) {
    for (AnnotationMirror annotationMirror : field.getAnnotationMirrors()) {
        if (!isStateAnnotation(annotationMirror)) {
            continue;
        }

        Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues();
        for (ExecutableElement executableElement : elementValues.keySet()) {
            if ("value".equals(executableElement.getSimpleName().toString())) {
                Object value = elementValues.get(executableElement).getValue(); // bundler class
                if (value == null) {
                    continue;
                }
                TypeName bundlerName = ClassName.get(mElementUtils.getTypeElement(value.toString()));
                TypeName genericName = null;

                try {
                    // gets the generic type Data from `class MyBundler implements Bundler<Data> {}`
                    List<? extends TypeMirror> interfaces = mElementUtils.getTypeElement(value.toString()).getInterfaces();
                    for (TypeMirror anInterface : interfaces) {
                        if (isAssignable(mTypeUtils.erasure(anInterface), Bundler.class)) {
                            List<? extends TypeMirror> typeArguments = ((DeclaredType) anInterface).getTypeArguments();
                            if (typeArguments != null && typeArguments.size() >= 1) {
                                TypeMirror genericTypeMirror = typeArguments.get(0);
                                String genericString = genericTypeMirror.toString();

                                // this check is necessary for returned types like: List<? extends String> -> remove "? extends"
                                if (genericString.contains("<? extends ")) {
                                    String innerType = genericString.substring(genericString.indexOf("<? extends ") + 11, genericString.length() - 1);

                                    // if it's a Parcelable, then we need to know the correct type for the bundler, e.g. List<ParcelableImpl> for parcelable list bundler
                                    if (PARCELABLE_CLASS_NAME.equals(innerType)) {
                                        InsertedTypeResult insertedType = getInsertedType(field, true);
                                        if (insertedType != null) {
                                            innerType = insertedType.mTypeMirror.toString();
                                        }
                                    }

                                    ClassName erasureClassName = ClassName.bestGuess(mTypeUtils.erasure(genericTypeMirror).toString());
                                    genericName = ParameterizedTypeName.get(erasureClassName, ClassName.bestGuess(innerType));
                                } else {
                                    genericName = ClassName.get(genericTypeMirror);
                                }
                            }
                        }
                    }
                } catch (Exception ignored) {
                }
                return new BundlerWrapper(bundlerName, genericName == null ? ClassName.get(Object.class) : genericName);
            }
        }
    }
    return null;
}
 
开发者ID:evernote,项目名称:android-state,代码行数:55,代码来源:StateProcessor.java


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