本文整理汇总了Java中com.google.gwt.core.ext.typeinfo.JType.isEnum方法的典型用法代码示例。如果您正苦于以下问题:Java JType.isEnum方法的具体用法?Java JType.isEnum怎么用?Java JType.isEnum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gwt.core.ext.typeinfo.JType
的用法示例。
在下文中一共展示了JType.isEnum方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accept
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
public void accept(JType type, TypeVisitor tv){
if (type.isAnnotation() != null){
tv.visitAnnotationType(type.isAnnotation());
} else if (type.isArray() != null){
tv.visitArrayType(type.isArray());
}else if (type.isEnum() != null){
tv.visitEnumType(type.isEnum());
}else if (type.isGenericType() != null){
tv.visitGenericType(type.isGenericType());
}else if (type.isParameterized() != null){
tv.visitParameterizedType(type.isParameterized());
}else if (type.isPrimitive() != null){
tv.visitPrimitiveType(type.isPrimitive());
}else if (type.isRawType() != null){
tv.visitRawType(type.isRawType());
}else if (type.isTypeParameter() != null){
tv.visitTypeParameter(type.isTypeParameter());
}else if (type.isWildcard() != null){
tv.visitWildcardType(type.isWildcard());
}
}
示例2: createSubModels
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private void createSubModels(TreeLogger logger, GeneratorContext context) {
for (JType jType : this.imports) {
if (jType == null) {
continue;
}
if (jType.isEnum() != null) {
continue;
}
if (ModelCreator.DISCARD_MODEL_TYPES.contains(jType.getQualifiedSourceName())) {
continue;
}
if (jType instanceof JClassType) {
ModelCreator creator = new ModelCreator((JClassType) jType);
String subModelType = creator.create(logger, context);
this.subModels.put(jType, subModelType);
}
}
}
示例3: generateDeserializer
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private void generateDeserializer( SourceWriter sourceWriter, String methodName, JType type )
{
generateDeserializerBegin( sourceWriter, methodName, type );
if( type.getParameterizedQualifiedSourceName().equals( "java.lang.String" ) )
sourceWriter.println( "return json.isString().stringValue();" );
else if( type.getParameterizedQualifiedSourceName().equals( "java.lang.Integer" ) )
sourceWriter.println( "return (Integer) json.isNumber().doubleValue();" );
else if( type.getParameterizedQualifiedSourceName().equals( "int" ) )
sourceWriter.println( "return (int) json.isNumber().doubleValue();" );
else if( type.getParameterizedQualifiedSourceName().equals( "java.lang.Boolean" ) )
sourceWriter.println( "return (Boolean) json.isBoolean().booleanValue();" );
else if( type.getParameterizedQualifiedSourceName().equals( "boolean" ) )
sourceWriter.println( "return (boolean) json.isBoolean().booleanValue();" );
else if( type.getParameterizedQualifiedSourceName().equals( "java.util.Date" ) )
sourceWriter.println( "return new Date( json.isString().stringValue() );" );
else if( type.getQualifiedSourceName().equals( "java.util.List" ) )
{
JParameterizedType parametrizedType = type.isParameterized();
JClassType itemsType = parametrizedType.getTypeArgs()[0];
sourceWriter.println( "java.util.ArrayList res = new java.util.ArrayList();" );
sourceWriter.println( "JSONArray jsonArray = json.isArray();" );
sourceWriter.println( "for( int i=0; i<jsonArray.size(); i++ )" );
sourceWriter.indent();
sourceWriter.println( "res.add( " + getDeserializerMethodName( itemsType ) + "( jsonArray.get( i ) ) );" );
sourceWriter.outdent();
sourceWriter.println( "return res;" );
}
else if( type.isEnum() != null )
{
// JEnumType type.isEnum();
sourceWriter.println( "return " + type.getParameterizedQualifiedSourceName() + ".valueOf( json.isString().stringValue() );" );
}
else
{
sourceWriter.println( type.getParameterizedQualifiedSourceName() + " res = new " + type.getParameterizedQualifiedSourceName() + "();" );
JField fields[] = type.isClass().getFields();
for( int i = 0; i < fields.length; i++ )
{
JField field = fields[i];
String deserializerMethodName = getDeserializerMethodName( field.getType() );
sourceWriter.println( field.getType().getParameterizedQualifiedSourceName() + " " + field.getName() + " = " + deserializerMethodName + "( json.isObject().get( \"" + field.getName() + "\" ) );" );
sourceWriter.println( "res." + field.getName() + " = " + field.getName() + ";" );
}
sourceWriter.println( "return res;" );
}
generateDeserializerEnd( sourceWriter );
}
示例4: fromType
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
public String fromType(JType type, String innerExpression) {
if(type.isEnum() != null) {
return type.getQualifiedSourceName()+".valueOf("+innerExpression+".isString().stringValue())";
} else if (type.getQualifiedSourceName().equals(String.class.getCanonicalName())) {
return innerExpression + ".isString().stringValue()";
} else if (type.getQualifiedSourceName()
.equals(Double.class.getCanonicalName()) ||
((type.isPrimitive() != null) &&
JPrimitiveType.DOUBLE.equals(type.isPrimitive()))) {
return innerExpression + ".isNumber().doubleValue()";
} else if (type.getQualifiedSourceName()
.equals(Float.class.getCanonicalName()) ||
((type.isPrimitive() != null) &&
JPrimitiveType.FLOAT.equals(type.isPrimitive()))) {
return " (float) " + innerExpression + ".isNumber().doubleValue()";
} else if (type.getQualifiedSourceName()
.equals(Integer.class.getCanonicalName()) ||
((type.isPrimitive() != null) &&
JPrimitiveType.INT.equals(type.isPrimitive()))) {
return "Double.valueOf(" + innerExpression +
".isNumber().doubleValue()) .intValue()";
} else if (type.getQualifiedSourceName()
.equals(Short.class.getCanonicalName()) ||
((type.isPrimitive() != null) &&
JPrimitiveType.SHORT.equals(type.isPrimitive()))) {
return "Short.valueOf(" + innerExpression +
".isNumber().doubleValue()) .shortValue()";
} else if (type.getQualifiedSourceName()
.equals(Character.class.getCanonicalName()) ||
((type.isPrimitive() != null) &&
JPrimitiveType.CHAR.equals(type.isPrimitive()))) {
return "" + innerExpression +
".isString().stringValue().charAt(0)";
} else if (type.getQualifiedSourceName()
.equals(Long.class.getCanonicalName()) ||
((type.isPrimitive() != null) &&
JPrimitiveType.LONG.equals(type.isPrimitive()))) {
return "Double.valueOf( " + innerExpression +
".isNumber().doubleValue()).longValue()";
} else if (type.getQualifiedSourceName()
.equals(Boolean.class.getCanonicalName()) ||
((type.isPrimitive() != null) &&
JPrimitiveType.BOOLEAN.equals(type.isPrimitive()))) {
return innerExpression + ".isBoolean().booleanValue() ";
}
BeanResolver child = findType(type);
if (child != null) {
this.children.add(child);
return "CODEC_" +
child.getType().getQualifiedSourceName().replaceAll("\\.", "_") +
".deserializeFromJSONObject(" + innerExpression + ".isObject())";
}
throw new RuntimeException(""+type);
}
示例5: isCoreType
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private boolean isCoreType(JType type) {
return type.isEnum() != null || CORE_TYPES.contains(type.getQualifiedSourceName());
}
示例6: toType
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private String toType(JType type, String innerExpression) {
//System.out.println("toType " + type);
if ((type.isPrimitive() == JPrimitiveType.DOUBLE) ||
(type.isPrimitive() == JPrimitiveType.FLOAT) ||
(type.isPrimitive() == JPrimitiveType.LONG) ||
(type.isPrimitive() == JPrimitiveType.INT) ||
(type.isPrimitive() == JPrimitiveType.SHORT)) {
return " new JSONNumber( (double) " + innerExpression + ")";
} else if (type.isPrimitive() == JPrimitiveType.BOOLEAN) {
return " JSONBoolean.getInstance( " + innerExpression + " ) ";
} else if (type.isPrimitive() == JPrimitiveType.CHAR ){
return " new JSONString( Character.toString("+ innerExpression +") )";
}
StringBuilder sb = new StringBuilder(innerExpression +
" == null ? JSONNull.getInstance() : ");
if(type.isEnum() != null){
sb = sb.append(" new JSONString(( (Enum) "+innerExpression+").name()) ");
} else if (type.getQualifiedSourceName().equals("java.lang.String")) {
sb = sb.append(" new JSONString( " + innerExpression + " ) ");
} else if(type.getQualifiedSourceName().equals("java.lang.Character")){
sb = sb.append(" new JSONString( Character.toString(" + innerExpression + ") ) ");
}else if (type.isClassOrInterface() != null && type.isClassOrInterface().isAssignableTo(this.numberType)) {
sb = sb.append("new JSONNumber( ((Number) " + innerExpression +
").doubleValue())");
} else if (type.getQualifiedSourceName().equals("java.lang.Boolean")) {
sb.append(" JSONBoolean.getInstance( " + innerExpression + " ) ");
} else if(type.getQualifiedSourceName().equals(Serializable.class.getCanonicalName())){
sb.append(" dynamicType("+innerExpression+" )");
} else {
BeanResolver child = findType(type);
if (child == null) {
if(type.isTypeParameter() != null){
boolean found = false;
for(JClassType bound : type.isTypeParameter().getBounds()){
if(bound.getQualifiedSourceName().equals(Serializable.class.getCanonicalName())){
sb.append(" dynamicType("+innerExpression+" ) ");
found = true;
break;
}
}
if(!found){
throw new RuntimeException(type+" could not be mapped to JSON.");
}
}else {
throw new RuntimeException(type+" is not introspectable!");
}
} else {
this.children.add(child);
sb = sb.append("CODEC_" +
type.getQualifiedSourceName().replaceAll("\\.", "_") +
".serializeToJSONObject( " + innerExpression + " ) ");
}
}
return sb.toString();
}
示例7: isEnum
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
/**
* <p>isEnum</p>
*
* @param type a {@link com.google.gwt.core.ext.typeinfo.JType} object.
* @return a boolean.
*/
public boolean isEnum( JType type ) {
return null != type.isEnum();
}