/** * Returns a parser for the given type(s). Accepts multiple types args to * allow requesting parsers for things like for pairs of ints. */ public AttributeParser getParser(JType... types) { if (types.length == 0) { throw new RuntimeException("Asked for attribute parser of no type"); } AttributeParser rtn = getForKey(getParametersKey(types)); if (rtn != null || types.length > 1) { return rtn; } /* Maybe it's an enum */ JEnumType enumType = types[0].isEnum(); if (enumType != null) { return new EnumAttributeParser(converter, enumType, logger); } /* * Dunno what it is, so let a StrictAttributeParser look for a * {field.reference} */ return new StrictAttributeParser(converter, logger, types[0]); }
/** * <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(); }
/** * Call {@link #processEnumType(JEnumType)} if {@code type} is a * {@link JEnumType}. */ private void maybeProcessEnumType(JType type) { assert type != null : "type == null"; JEnumType enumType = type.isEnum(); if (enumType != null) { processEnumType(enumType); } }
@Override public boolean isEnum() { return getEnclosedMetaObject().isEnum() != null; }
/** * Call {@link #processEnumType(JEnumType)} if {@code type} is a * {@link JEnumType}. */ private void maybeProcessEnumType(JType type) { assert type != null : "type == null"; JEnumType enumType = type.isEnum(); if (enumType != null) { processEnumType(enumType); } }
/** * Call {@link #processEnumType(JEnumType)} if {@code type} is a * {@link JEnumType}. */ private void maybeProcessEnumType(JType type) { assert type != null : "type == null"; JEnumType enumType = type.isEnum(); if (enumType != null) { processEnumType(enumType); } }
@Override public boolean isEnum() { return getEnclosedMetaObject().isEnum() != null; }
public static boolean isValueType(TypeOracle oracle, JType type) { JClassType classType = type.isClassOrInterface(); if (classType == null) { return true; } if (type.isEnum() != null) { return true; } for (String valueType : VALUE_TYPE_NAMES) { JClassType found = oracle.findType(valueType); // null check to accommodate limited mock CompilationStates if (found != null && found.equals(classType)) { return true; } } return false; }
public static boolean isValueType(TypeOracle oracle, JType type) { JClassType classType = type.isClassOrInterface(); if (classType == null) { return true; } if (type.isEnum() != null) { return true; } for (String valueType : VALUE_TYPE_NAMES) { JClassType found = oracle.findType(valueType); // null check to accommodate limited mock CompilationStates if (found != null && found.equals(classType)) { return true; } } return false; }
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); } } }
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); } } }
private List<MetaMethod> getSpecialTypeMethods() { final List<MetaMethod> meths = new ArrayList<>(); final JEnumType type = getEnclosedMetaObject().isEnum(); if (type != null) { meths.add(new GWTSpecialMethod(this, DefModifiers.none(), Scope.Public, String.class, "name")); meths.add(new GWTSpecialMethod(this, DefModifiers.none(), Scope.Public, Enum.class, "valueOf", Parameter.of( String.class, "p").getMetaParameter())); meths.add(new GWTSpecialMethod(this, DefModifiers.none(), Scope.Public, Enum[].class, "values")); } return meths; }
private List<MetaMethod> getSpecialTypeMethods() { final List<MetaMethod> meths = new ArrayList<>(); final JEnumType type = getEnclosedMetaObject().isEnum(); if (type != null) { meths.add(new GWTSpecialMethod(this, DefModifiers.none(), Scope.Public, String.class, "name")); meths.add(new GWTSpecialMethod(this, DefModifiers.none(), Scope.Public, Enum.class, "valueOf", Parameter.of( String.class, "p").getMetaParameter())); meths.add(new GWTSpecialMethod(this, DefModifiers.none(), Scope.Public, Enum[].class, "values")); } return meths; }
private boolean isNotBean(JType type) { JClassType collection = typeOracle.findType(Collection.class.getCanonicalName()); JClassType map = typeOracle.findType(Map.class.getCanonicalName()); JClassType number = typeOracle.findType(Number.class.getCanonicalName()); boolean isCollection = false, isMap = false, isNumber = false; if (type instanceof JClassType) { isCollection = ((JClassType) type).isAssignableTo(collection); isMap = ((JClassType) type).isAssignableTo(map); isNumber = ((JClassType) type).isAssignableTo(number); } return type.isPrimitive() != null || type.isEnum() != null || type.isArray() != null || isCollection || isNumber || isMap || type.getSimpleSourceName().equals("String") || type.getSimpleSourceName().equals("Byte") || type.getSimpleSourceName().equals("Short") || type.getSimpleSourceName().equals("Integer") || type.getSimpleSourceName().equals("Long") || type.getSimpleSourceName().equals("Boolean") || type.getSimpleSourceName().equals("Float") || type.getSimpleSourceName().equals("Double") || type.getSimpleSourceName().equals("Number") || type.getSimpleSourceName().equals("Character") || type.getSimpleSourceName().equals("Date") || type.getSimpleSourceName().equals("Timestamp"); }
/** * Returns a parser for the given type(s). Accepts multiple types args to * allow requesting parsers for things like for pairs of ints. */ public AttributeParser getParser(JType... types) { if (types.length == 0) { throw new RuntimeException("Asked for attribute parser of no type"); } AttributeParser rtn = getForKey(getParametersKey(types)); if (rtn != null || types.length > 1) { return rtn; } /* Maybe it's an enum */ JEnumType enumType = types[0].isEnum(); if (enumType != null) { return new EnumAttributeParser(converter, enumType, logger); } /* * Dunno what it is, so let a StrictAttributeParser look for a * {field.reference} */ return new StrictAttributeParser(converter, logger, types[0]); }
/** * Returns a parser for the given type(s). Accepts multiple types args to * allow requesting parsers for things like for pairs of ints. */ public AttributeParser getParser(JType... types) { if (types.length == 0) { throw new RuntimeException("Asked for attribute parser of no type"); } AttributeParser rtn = getForKey(getParametersKey(types)); if (rtn != null || types.length > 1) { return rtn; } /* Maybe it's an enum */ JEnumType enumType = types[0].isEnum(); if (enumType != null) { return new EnumAttributeParser(converter, enumType, logger); } /* * Dunno what it is, so let a StrictAttributeParser look for a * {field.reference} */ return new StrictAttributeParser(converter, logger, types[0]); }
public static boolean canContainId(JType type) { if (type != null) { return !(isBoolean(type) || isNumeric(type) || isCharacter(type) || isString(type) || type.isEnum() != null || isDate(type) || type.isArray() != null || isCollection(type) || isJavaType(type) || isGwtType(type)); } return false; }
protected String toFormStringExpression(JParameter argument, Style classStyle) throws UnableToCompleteException { JType type = argument.getType(); String expr = argument.getName(); if (type.isPrimitive() != null) { return "\"\"+" + expr; } if (STRING_TYPE == type) { return expr; } if (type.isClass() != null && isOverlayArrayType(type.isClass())) { return "(new " + JSON_ARRAY_CLASS + "(" + expr + ")).toString()"; } if (type.isClass() != null && OVERLAY_VALUE_TYPE.isAssignableFrom(type.isClass())) { return "(new " + JSON_OBJECT_CLASS + "(" + expr + ")).toString()"; } if ((!isThrowable(type) && type.getQualifiedBinaryName().startsWith("java.lang.")) || type.isEnum() != null) { return String.format("(%s != null ? %s.toString() : null)", expr, expr); } Json jsonAnnotation = getAnnotation(argument, Json.class); Style style = jsonAnnotation != null ? jsonAnnotation.style() : classStyle; return locator.encodeExpression(type, expr, style) + ".toString()"; }
protected String toFormStringExpression(JParameter argument, Style classStyle) throws UnableToCompleteException { JType type = argument.getType(); String expr = argument.getName(); if (type.isPrimitive() != null) { return "\"\"+" + expr; } if (STRING_TYPE == type) { return expr; } if (type.isClass() != null && isOverlayArrayType(type.isClass())) { return "(new " + JSON_ARRAY_CLASS + "(" + expr + ")).toString()"; } if (type.isClass() != null && OVERLAY_VALUE_TYPE.isAssignableFrom(type.isClass())) { return "(new " + JSON_OBJECT_CLASS + "(" + expr + ")).toString()"; } if ((!isThrowable(type) && type.getQualifiedBinaryName().startsWith("java.lang.")) || type.isEnum() != null) { return String.format("(%s != null ? %s.toString() : null)", expr, expr); } Json jsonAnnotation = getAnnotation(argument, Json.class); Style style = jsonAnnotation != null ? jsonAnnotation.style() : classStyle; return locator.encodeExpression(type, expr, style) + ".toString()"; }
public static MetaType fromType(final TypeOracle oracle, final JType t) { if (t.isTypeParameter() != null) { return new GWTTypeVariable(oracle, t.isTypeParameter()); } else if (t.isArray() != null && (t.isArray().getComponentType().isTypeParameter() != null || t.isArray().getComponentType().isWildcard() != null)) { return new GWTGenericArrayType(oracle, t.isArray()); } else if (t.isParameterized() != null) { return new GWTParameterizedType(oracle, t.isParameterized()); } else if (t.isWildcard() != null) { return new GWTWildcardType(oracle, t.isWildcard()); } else if (t.isClassOrInterface() != null || t.isEnum() != null || t.isPrimitive() != null || t.isRawType() != null || t.isArray() != null) { return GWTClass.newInstance(oracle, t); } else { throw new RuntimeException("Don't know how to make a MetaType from given JType " + t + " (which is a " + (t.getClass()) + ")"); } }