private static String getVarName(Type type) { if (type instanceof TypeExtends) { return ((TypeExtends) type).getVarName(); } else if (type instanceof TypeSuper) { return ((TypeSuper) type).getVarName(); } else { return null; } }
public Type getQueryType(Type type, EntityType model, Type exprType, boolean raw, boolean rawParameters, boolean extend) { TypeCategory category = type.getCategory(); if (raw && category != TypeCategory.ENTITY && category != TypeCategory.CUSTOM) { return exprType; } else if (category == TypeCategory.STRING || category == TypeCategory.BOOLEAN) { return exprType; } else { if (rawParameters) { type = new SimpleType(type); } if (!type.isFinal() && extend) { type = new TypeExtends(type); } return new SimpleType(exprType, type); } }
@Override public String toString() { return delegateType.getFullName() + "." + name + " " + parameters; }
private Type createWithPackage(Type type) { String packageName = type.getPackageName(); String simpleName = prefix + normalizeName(type.getFullName() .substring(packageName.length() + 1)) + suffix; packageName = (packageName.startsWith("java") ? "ext." : "") + packageName + packageSuffix; return new SimpleType(type.getCategory(), packageName + "." + simpleName, packageName, simpleName, false, false); }
private Type createWithoutPackage(Type type) { String simpleName = prefix + normalizeName(type.getFullName()) + suffix; return new SimpleType(type.getCategory(), simpleName, "", simpleName, false, false); }
@Override public Parameter apply(Parameter p) { Type type; if (!asExpr) { type = typeMappings.getExprType( p.getType(), model, false, false, true); } else if (p.getType().isFinal()) { type = new ClassType(Expression.class, p.getType()); } else { type = new ClassType(Expression.class, new TypeExtends(p.getType())); } return new Parameter(p.getName(), type); } });
private Type getRaw(Type type) { if (type instanceof EntityType && type.getPackageName().startsWith("ext.java")) { return type; } else { return new SimpleType(type, type.getParameters()); } }
private Type asGeneric(Type type) { if (type.getParameters().size() == 0) { int count = type.getJavaClass().getTypeParameters().length; if (count > 0) { return new SimpleType(type, new Type[count]); } } return type; }
protected void listAccessor(EntityType model, Property field, CodeWriter writer) throws IOException { String escapedName = field.getEscapedName(); Type queryType = typeMappings.getPathType(field.getParameter(0), model, false); writer.beginPublicMethod(queryType, escapedName, new Parameter("index", Types.INT)); writer.line(RETURN + escapedName + ".get(index);").end(); writer.beginPublicMethod(queryType, escapedName, new Parameter("index", new ClassType(Expression.class, Types.INTEGER))); writer.line(RETURN + escapedName + ".get(index);").end(); }
private boolean hasPropertyWithType(TypeCategory category) { for (Property property : properties) { if (property.getType().getCategory() == category) { return true; } } return false; }
private Type getType(VariableElement element) { Type rv = typeFactory.getType(element.asType(), true); if (element.getAnnotation(QueryType.class) != null) { QueryType qt = element.getAnnotation(QueryType.class); if (qt.value() != PropertyType.NONE) { TypeCategory typeCategory = TypeCategory.valueOf(qt.value().name()); rv = rv.as(typeCategory); } } return rv; }
@Override public Type visitWildcard(WildcardType wildcardType, Boolean p) { if (wildcardType.getExtendsBound() != null) { Type type = visit(wildcardType.getExtendsBound(), p); return new TypeExtends(type); } else if (wildcardType.getSuperBound() != null) { Type type = visit(wildcardType.getSuperBound(), p); return new TypeSuper(type); } else { return null; } }
@Override public Parameter apply(Property input) { return new Parameter(input.getName(), input.getType()); } };
public TypeCategory getOriginalCategory() { return super.getCategory(); }
@Override public Type as(TypeCategory category) { if (getCategory() == category) { return this; } else { return super.as(category); } }
@Override public Parameter apply(Parameter p) { Type type; if (!asExpr) { type = typeMappings.getExprType(p.getType(), model, false, false, true); } else if (p.getType().isFinal()) { type = new ClassType(Expression.class, p.getType()); } else { type = new ClassType(Expression.class, new TypeExtends(p.getType())); } return new Parameter(p.getName(), type); } });
protected void mapAccessor(EntityType model, Property field, CodeWriter writer) throws IOException { String escapedName = field.getEscapedName(); Type queryType = typeMappings.getPathType(field.getParameter(1), model, false); writer.beginPublicMethod(queryType, escapedName, new Parameter("key", field.getParameter(0))); writer.line(RETURN + escapedName + ".get(key);").end(); writer.beginPublicMethod(queryType, escapedName, new Parameter("key", new ClassType(Expression.class, field.getParameter(0)))); writer.line(RETURN + escapedName + ".get(key);").end(); }
public boolean isRegistered(Type type) { return queryTypes.containsKey(type.getFullName()); } }
@Override public Type visitTypeVariable(TypeVariable typeVariable, Boolean p) { String varName = typeVariable.toString(); if (typeVariable.getUpperBound() != null) { Type type = visit(typeVariable.getUpperBound(), p); return new TypeExtends(varName, type); } else if (typeVariable.getLowerBound() != null && !(typeVariable.getLowerBound() instanceof NullType)) { Type type = visit(typeVariable.getLowerBound(), p); return new TypeSuper(varName, type); } else { return null; } }
public void register(Type type, Type queryType) { queryTypes.put(type.getFullName(), queryType); }