當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。