• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TypeMirror类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.sun.mirror.type.TypeMirror的典型用法代码示例。如果您正苦于以下问题:Java TypeMirror类的具体用法?Java TypeMirror怎么用?Java TypeMirror使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: apply

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
public final T apply(TypeMirror type, P param) {
    if( type instanceof ArrayType)
        return onArrayType((ArrayType)type,param);
    if( type instanceof PrimitiveType)
        return onPrimitiveType((PrimitiveType)type,param);
    if (type instanceof ClassType )
        return onClassType((ClassType)type,param);
    if (type instanceof InterfaceType )
        return onInterfaceType((InterfaceType)type,param);
    if (type instanceof TypeVariable )
        return onTypeVariable((TypeVariable)type,param);
    if (type instanceof VoidType )
        return onVoidType((VoidType)type,param);
    if(type instanceof WildcardType)
        return onWildcard((WildcardType) type,param);
    assert false;
    throw new IllegalArgumentException();
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:19,代码来源:APTTypeVisitor.java


示例2: getSchemaGenerator

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
private synchronized XmlSchemaGenerator<TypeMirror, TypeDeclaration, FieldDeclaration, MethodDeclaration> getSchemaGenerator() {
    if(xsdgen==null) {
        xsdgen = new XmlSchemaGenerator<TypeMirror,TypeDeclaration,FieldDeclaration,MethodDeclaration>( types.getNavigator(), types );

        for (Map.Entry<QName, Reference> e : additionalElementDecls.entrySet()) {
            Reference value = e.getValue();
            if(value!=null) {
                NonElement<TypeMirror, TypeDeclaration> typeInfo = refMap.get(value);
                if(typeInfo==null)
                    throw new IllegalArgumentException(e.getValue()+" was not specified to JavaCompiler.bind");
                xsdgen.add(e.getKey(),!(value.type instanceof PrimitiveType),typeInfo);
            } else {
                xsdgen.add(e.getKey(),false,null);
            }
        }
    }
    return xsdgen;
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:19,代码来源:JAXBModelImpl.java


示例3: ref

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
public TypeMirror ref(Class c) {
    if(c.isArray())
        return env.getTypeUtils().getArrayType( ref(c.getComponentType()) );
    if(c.isPrimitive())
        return getPrimitive(c);
    TypeDeclaration t = env.getTypeDeclaration(getSourceClassName(c));
    // APT only operates on a set of classes used in the compilation,
    // and it won't recognize additional classes (even if they are visible from javac)
    // and return null.
    //
    // this is causing a problem where we check if a type is collection.
    // so until the problem is fixed in APT, work around the issue
    // by returning a dummy token
    if(t==null)
        return DUMMY;
    return env.getTypeUtils().getDeclaredType(t);
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:18,代码来源:APTNavigator.java


示例4: getClassValue

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
public TypeMirror getClassValue(Annotation a, String name) {
    try {
        a.annotationType().getMethod(name).invoke(a);
        assert false;
        throw new IllegalStateException("should throw a MirroredTypeException");
    } catch (IllegalAccessException e) {
        throw new IllegalAccessError(e.getMessage());
    } catch (InvocationTargetException e) {
        if( e.getCause() instanceof MirroredTypeException ) {
            MirroredTypeException me = (MirroredTypeException)e.getCause();
            return me.getTypeMirror();
        }
        // impossible
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new NoSuchMethodError(e.getMessage());
    }
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:19,代码来源:InlineAnnotationReaderImpl.java


示例5: getClassArrayValue

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
public TypeMirror[] getClassArrayValue(Annotation a, String name) {
    try {
        a.annotationType().getMethod(name).invoke(a);
        assert false;
        throw new IllegalStateException("should throw a MirroredTypesException");
    } catch (IllegalAccessException e) {
        throw new IllegalAccessError(e.getMessage());
    } catch (InvocationTargetException e) {
        if( e.getCause() instanceof MirroredTypesException ) {
            MirroredTypesException me = (MirroredTypesException)e.getCause();
            Collection<TypeMirror> r = me.getTypeMirrors();
            return r.toArray(new TypeMirror[r.size()]);
        }
        // impossible
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new NoSuchMethodError(e.getMessage());
    }
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:20,代码来源:InlineAnnotationReaderImpl.java


示例6: validateField

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
private static void validateField(FieldDeclaration field) {
	// Check if field is "public static final"
	Collection<Modifier> modifiers = field.getModifiers();
	if ( modifiers.size() != 3
	     || !modifiers.contains(Modifier.PUBLIC)
	     || !modifiers.contains(Modifier.STATIC)
	     || !modifiers.contains(Modifier.FINAL) ) {
		throw new RuntimeException("Field " + field.getSimpleName() + " is not declared public static final");
	}

	// Check suported types (int, long, float, String)
	TypeMirror field_type = field.getType();
	if ( field_type instanceof PrimitiveType ) {
		PrimitiveType field_type_prim = (PrimitiveType)field_type;
		PrimitiveType.Kind field_kind = field_type_prim.getKind();
		if ( field_kind != PrimitiveType.Kind.INT
		     && field_kind != PrimitiveType.Kind.LONG
		     && field_kind != PrimitiveType.Kind.FLOAT
		     && field_kind != PrimitiveType.Kind.BYTE ) {
			throw new RuntimeException("Field " + field.getSimpleName() + " is not of type 'int', 'long' or 'float'");
		}
	} else if ( "java.lang.String".equals(field_type.toString()) ) {
	} else {
		throw new RuntimeException("Field " + field.getSimpleName() + " is not a primitive type or String");
	}

	Object field_value = field.getConstantValue();
	if ( field_value == null ) {
		throw new RuntimeException("Field " + field.getSimpleName() + " has no initial value");
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:32,代码来源:FieldsGenerator.java


示例7: getMethodReturnType

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
public static TypeMirror getMethodReturnType(MethodDeclaration method) {
	TypeMirror result_type;
	ParameterDeclaration result_param = getResultParameter(method);
	if ( result_param != null ) {
		result_type = result_param.getType();
	} else
		result_type = method.getReturnType();
	return result_type;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:10,代码来源:Utils.java


示例8: getNIOBufferType

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
public static Class<?> getNIOBufferType(TypeMirror t) {
	Class<?> param_type = getJavaType(t);
	if ( Buffer.class.isAssignableFrom(param_type) )
		return param_type;
	else if ( param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class )
		return ByteBuffer.class;
	else
		return null;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:10,代码来源:Utils.java


示例9: visitConstructorDeclaration

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
/**
 * Stores information about constructors annotated with {@link Constructor},
 * particularly with the {@link ConstructorParameter} annotated parameters
 * and their required imports. The {@link SPAnnotationProcessor} takes this
 * information and generates
 * {@link SPPersisterHelper#commitObject(ca.sqlpower.dao.PersistedSPObject, Multimap, List, ca.sqlpower.dao.helper.SPPersisterHelperFactory)}
 * and
 * {@link SPPersisterHelper#persistObject(SPObject, int, SPPersister, ca.sqlpower.dao.session.SessionPersisterSuperConverter)}
 * methods.
 * 
 * @param d
 *            The {@link ConstructorDeclaration} of the constructor to
 *            visit.
 */
public void visitConstructorDeclaration(ConstructorDeclaration d) {
	
	if (!constructorFound && d.getAnnotation(Constructor.class) != null 
			&& d.getSimpleName().equals(typeDecl.getSimpleName())) {
		
		for (ParameterDeclaration pd : d.getParameters()) {
			ConstructorParameter cp = pd.getAnnotation(ConstructorParameter.class);
			if (cp != null) {
				try {
					TypeMirror type = pd.getType();
					Class<?> c = SPAnnotationProcessorUtils.convertTypeMirrorToClass(type);
					
					ParameterType property = cp.parameterType();
					String name;
					
					if (property.equals(ParameterType.PROPERTY)) {
						name = cp.propertyName();
					} else {
						name = pd.getSimpleName();
					}

					if (type instanceof PrimitiveType) {
						constructorParameters.add(
								new ConstructorParameterObject(property, c, name));

					} else if (type instanceof ClassType || type instanceof InterfaceType) {
						constructorParameters.add(
								new ConstructorParameterObject(property, c, name));
						constructorImports.add(c.getName());
					}
				} catch (ClassNotFoundException e) {
					valid = false;
					e.printStackTrace();
				}
			}
		}
		constructorFound = true;
	}
}
 
开发者ID:SQLPower,项目名称:sqlpower-library,代码行数:54,代码来源:SPClassVisitor.java


示例10: visitArray

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
public void visitArray(Attribute.Array a) {
    Type elemtype = env.jctypes.elemtype(a.type);

    if (elemtype.tsym == env.symtab.classType.tsym) {   // Class[]
        // Construct a proxy for a MirroredTypesException
        ArrayList<TypeMirror> elems = new ArrayList<TypeMirror>();
        for (int i = 0; i < a.values.length; i++) {
            Type elem = ((Attribute.Class) a.values[i]).type;
            elems.add(env.typeMaker.getType(elem));
        }
        value = new MirroredTypesExceptionProxy(elems);

    } else {
        int len = a.values.length;
        Class<?> runtimeTypeSaved = runtimeType;
        runtimeType = runtimeType.getComponentType();
        try {
            Object res = Array.newInstance(runtimeType, len);
            for (int i = 0; i < len; i++) {
                a.values[i].accept(this);
                if (value == null || value instanceof ExceptionProxy) {
                    return;
                }
                try {
                    Array.set(res, i, value);
                } catch (IllegalArgumentException e) {
                    value = null;       // indicates a type mismatch
                    return;
                }
            }
            value = res;
        } finally {
            runtimeType = runtimeTypeSaved;
        }
    }
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:37,代码来源:AnnotationProxyMaker.java


示例11: equals

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
public boolean equals(Object obj) {
    TypeMirror t = ex.getTypeMirror();
    return t != null &&
           obj instanceof MirroredTypeExceptionProxy &&
           t.equals(
                ((MirroredTypeExceptionProxy) obj).ex.getTypeMirror());
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:8,代码来源:AnnotationProxyMaker.java


示例12: append

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
/**
 * Appends a constant whose type is not statically known
 * by dispatching to the appropriate overloaded append method.
 */
void append(Object val) {
    if (val instanceof String) {
        append((String) val);
    } else if (val instanceof Character) {
        append((Character) val);
    } else if (val instanceof Boolean) {
        append((Boolean) val);
    } else if (val instanceof Byte) {
        append((Byte) val);
    } else if (val instanceof Short) {
        append((Short) val);
    } else if (val instanceof Integer) {
        append((Integer) val);
    } else if (val instanceof Long) {
        append((Long) val);
    } else if (val instanceof Float) {
        append((Float) val);
    } else if (val instanceof Double) {
        append((Double) val);
    } else if (val instanceof TypeMirror) {
        append((TypeMirrorImpl) val);
    } else if (val instanceof EnumConstantDeclaration) {
        append((EnumConstantDeclarationImpl) val);
    } else if (val instanceof AnnotationMirror) {
        append((AnnotationMirrorImpl) val);
    } else if (val instanceof Collection) {
        append((Collection) val);
    } else {
        appendUnquoted(val.toString());
    }
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:36,代码来源:Constants.java


示例13: append

import com.sun.mirror.type.TypeMirror; //导入依赖的package包/类
/**
 * Appends a constant whose type is not statically known
 * by dispatching to the appropriate overloaded append method.
 */
void append(Object val) {
    if (val instanceof String) {
        append((String) val);
    } else if (val instanceof Character) {
        append((Character) val);
    } else if (val instanceof Boolean) {
        append((Boolean) val);
    } else if (val instanceof Byte) {
        append((Byte) val);
    } else if (val instanceof Short) {
        append((Short) val);
    } else if (val instanceof Integer) {
        append((Integer) val);
    } else if (val instanceof Long) {
        append((Long) val);
    } else if (val instanceof Float) {
        append((Float) val);
    } else if (val instanceof Double) {
        append((Double) val);
    } else if (val instanceof TypeMirror) {
        append((TypeMirrorImpl) val);
    } else if (val instanceof EnumConstantDeclaration) {
        append((EnumConstantDeclarationImpl) val);
    } else if (val instanceof AnnotationMirror) {
        append((AnnotationMirrorImpl) val);
    } else if (val instanceof Collection<?>) {
        append((Collection<?>) val);
    } else {
        appendUnquoted(val.toString());
    }
}
 
开发者ID:aducode,项目名称:openjdk-source-code-learn,代码行数:36,代码来源:Constants.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OioSocketChannel类代码示例发布时间:2022-05-21
下一篇:
Java CompletableEmitter类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap