private String getListType(JType jType) { final String typeName = jType.fullName(); return substringBeforeLast(substringAfter(typeName, "<"), ">"); }
private boolean isFinal(JType superType) { try { Class<?> javaClass = Class.forName(superType.fullName()); return Modifier.isFinal(javaClass.getModifiers()); } catch (ClassNotFoundException e) { return false; } }
private boolean isString(JType type){ return type.fullName().equals(String.class.getName()); }
private static void processFieldVarForSerializableSupport(JFieldVar fieldVar, DataOutputStream dataOutputStream) throws IOException { dataOutputStream.writeUTF(fieldVar.name()); dataOutputStream.writeInt(fieldVar.mods().getValue()); JType type = fieldVar.type(); dataOutputStream.writeUTF(type.fullName()); }
if (fieldType.fullName().equals(String.class.getName())) { return JExpr.lit(node.asText()); } else if (fieldType.fullName().equals(int.class.getName())) { return JExpr.lit(Integer.parseInt(node.asText())); } else if (fieldType.fullName().equals(BigInteger.class.getName())) { return JExpr._new(fieldType).arg(JExpr.lit(node.asText())); } else if (fieldType.fullName().equals(double.class.getName())) { return JExpr.lit(Double.parseDouble(node.asText())); } else if (fieldType.fullName().equals(BigDecimal.class.getName())) { return JExpr._new(fieldType).arg(JExpr.lit(node.asText())); } else if (fieldType.fullName().equals(boolean.class.getName())) { return JExpr.lit(Boolean.parseBoolean(node.asText())); } else if (fieldType.fullName().equals(DateTime.class.getName()) || fieldType.fullName().equals(Date.class.getName())) { long millisecs = parseDateToMillisecs(node.asText()); } else if (fieldType.fullName().equals(LocalDate.class.getName()) || fieldType.fullName().equals(LocalTime.class.getName())) { } else if (fieldType.fullName().equals(long.class.getName())) { return JExpr.lit(Long.parseLong(node.asText())); } else if (fieldType.fullName().equals(float.class.getName())) { return JExpr.lit(Float.parseFloat(node.asText()));
private static void processMethodCollectionForSerializableSupport(Iterator<JMethod> methods, DataOutputStream dataOutputStream) throws IOException { TreeMap<String, JMethod> sortedMethods = new TreeMap<>(); while (methods.hasNext()) { JMethod method = methods.next(); //Collect non-private methods if ((method.mods().getValue() & JMod.PRIVATE) != JMod.PRIVATE) { sortedMethods.put(method.name(), method); } } for (JMethod method : sortedMethods.values()) { dataOutputStream.writeUTF(method.name()); dataOutputStream.writeInt(method.mods().getValue()); if (method.type() != null) { dataOutputStream.writeUTF(method.type().fullName()); } for (JVar param : method.params()) { dataOutputStream.writeUTF(param.type().fullName()); } } }
@Override public void dateTimeField(JFieldVar field, JDefinedClass clazz, JsonNode node) { String timezone = node.has("customTimezone") ? node.get("customTimezone").asText() : "UTC"; String pattern = null; if (node.has("customDateTimePattern")) { pattern = node.get("customDateTimePattern").asText(); } else if (node.has("customPattern")) { pattern = node.get("customPattern").asText(); } else if (isNotEmpty(getGenerationConfig().getCustomDateTimePattern())) { pattern = getGenerationConfig().getCustomDateTimePattern(); } else if (getGenerationConfig().isFormatDateTimes()) { pattern = FormatRule.ISO_8601_DATETIME_FORMAT; } if (pattern != null && !field.type().fullName().equals("java.lang.String")) { field.annotate(JsonFormat.class).param("shape", JsonFormat.Shape.STRING).param("pattern", pattern).param("timezone", timezone); } } }
@Override public void dateField(JFieldVar field, JDefinedClass clazz, JsonNode node) { String pattern = null; if (node.has("customDatePattern")) { pattern = node.get("customDatePattern").asText(); } else if (node.has("customPattern")) { pattern = node.get("customPattern").asText(); } else if (isNotEmpty(getGenerationConfig().getCustomDatePattern())) { pattern = getGenerationConfig().getCustomDatePattern(); } else if (getGenerationConfig().isFormatDates()) { pattern = FormatRule.ISO_8601_DATE_FORMAT; } if (pattern != null && !field.type().fullName().equals("java.lang.String")) { field.annotate(JsonFormat.class).param("shape", JsonFormat.Shape.STRING).param("pattern", pattern); } }
@Override public void timeField(JFieldVar field, JDefinedClass clazz, JsonNode node) { String pattern = null; if (node.has("customTimePattern")) { pattern = node.get("customTimePattern").asText(); } else if (node.has("customPattern")) { pattern = node.get("customPattern").asText(); } else if (isNotEmpty(getGenerationConfig().getCustomTimePattern())) { pattern = getGenerationConfig().getCustomTimePattern(); } else if (getGenerationConfig().isFormatDates()) { pattern = FormatRule.ISO_8601_TIME_FORMAT; } if (pattern != null && !field.type().fullName().equals("java.lang.String")) { field.annotate(JsonFormat.class).param("shape", JsonFormat.Shape.STRING).param("pattern", pattern); } }
String fieldType = field.type().fullName();
private JInvocation illegalArgumentInvocation(JDefinedClass jclass, String propertyName, JType propertyType, JVar valueVar) { return _new(jclass.owner()._ref(IllegalArgumentException.class)) .arg(lit("property \"" + propertyName + "\" is of type \"" + propertyType.fullName() + "\", but got ") .plus(valueVar.invoke("getClass").invoke("toString"))); }
/** * Gets the binary name of the type. * * See http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#44909 * * @return * Name like "Foo$Bar", "int", "java.lang.String", "java.io.File[]". Never null. */ public String binaryName() { return fullName(); }
/** * Gets the binary name of the type. * * See http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#44909 * * @return * Name like "Foo$Bar", "int", "java.lang.String", "java.io.File[]". Never null. */ public String binaryName() { return fullName(); }
public JCMType(JCMTypeFactory factory, JT type) { this.factory = Validate.notNull(factory); this.type = Validate.notNull(type); this.fullName = type.fullName(); }
private void writeDefaultType(Writer writer, JType t, String path) throws IOException { String name = t.fullName(); writeDefaultType(writer, name, path); } private void writeDefaultType(Writer writer, String name, String path) throws IOException {
public static boolean isInstanceOfList(final JType type) { try { final String className = withoutGenerics(type.fullName()); final Class<?> clazz = Class.forName(className); return java.util.List.class.isAssignableFrom(clazz); } catch (final ClassNotFoundException exception) { return false; } }
private JavaReturn getReturnFromProperty(Property property, Part part) { JType t = property.type(); String targetNamespace = ProcessorUtil.resolvePartNamespace(part); if (targetNamespace == null) { targetNamespace = property.elementName().getNamespaceURI(); } JavaReturn returnType = new JavaReturn(property.name(), t.fullName(), targetNamespace); returnType.setQName(property.elementName()); returnType.setStyle(JavaType.Style.OUT); return returnType; }
private void createFluentFieldMethods(JFieldVar field, ClassOutline targetClass, ClassOutline fieldsFromClass) { print("createFluentFieldMethods for " + field.name() + " on " + targetClass.implClass.fullName() + " (from " + fieldsFromClass.implClass.fullName() + ")"); JMethod fluentSetter = createFluentSetter(field, targetClass, fieldsFromClass); createMethodStringVersion(field, targetClass, fluentSetter); // FIXME ugly hack - we create beginXYZ only for our own structures // TODO not for all! JType basicType = getContentType(field); if (basicType.fullName().startsWith("com.evolveum.") && isInstantiable(basicType)) { createFluentBegin(field, targetClass, fieldsFromClass, fluentSetter); } }
private JInvocation illegalArgumentInvocation(JDefinedClass jclass, String propertyName, JType propertyType, JVar valueVar) { return _new(jclass.owner()._ref(IllegalArgumentException.class)) .arg(lit("property \"" + propertyName + "\" is of type \"" + propertyType.fullName() + "\", but got ") .plus(valueVar.invoke("getClass").invoke("toString"))); }