本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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());
}
}
示例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());
}
}
示例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");
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
}
示例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());
}
示例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());
}
}
示例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());
}
}