use of java.lang.annotation.Annotation in project platformlayer by platformlayer.
the class GwtCodegenFileVisitor method processClassJso.
private void processClassJso(Class<?> clazz) throws MojoExecutionException {
Map<String, Object> model = new HashMap<String, Object>();
// ClassModel classModel = new ClassModel();
// classModel.className = clazz.getSimpleName();
// classModel.proxyClassName = classModel.className + "Proxy";
// classModel.serviceClassName = classModel.className + "GwtService";
// classModel.editorClassName = classModel.className + "Editor";
List<FieldModel> fields = Lists.newArrayList();
List<String> warnings = Lists.newArrayList();
String jsoClassName = clazz.getSimpleName();
String jsoBaseClassName = "com.google.gwt.core.client.JavaScriptObject";
Set<String> skipFields = Sets.newHashSet();
{
Class<?> c = clazz;
while (c != null) {
if (c.getName().equals("org.platformlayer.core.model.ItemBase")) {
jsoBaseClassName = "org.platformlayer.core.model.ItemBaseJs";
skipFields.add("key");
skipFields.add("tags");
break;
}
if (c.getName().equals("org.platformlayer.core.model.Action")) {
jsoBaseClassName = "org.platformlayer.core.model.ActionJs";
skipFields.add("type");
break;
}
if (c == Object.class) {
break;
} else {
c = c.getSuperclass();
}
}
}
for (Field field : clazz.getFields()) {
FieldModel fieldModel = new FieldModel();
Class<?> type = field.getType();
String fieldName = field.getName();
if (skipFields.contains(fieldName)) {
// These come in from the base class
continue;
}
String beanName = Utils.capitalize(fieldName);
Class<?> accessorType = type;
if (accessorType.isPrimitive()) {
accessorType = Utils.getBoxedType(accessorType);
}
if (type == Long.class || type.equals(long.class)) {
warnings.add("JSNI cannot map 'long " + fieldName + "'");
continue;
}
String mapped = null;
if (!isNativeType(type)) {
mapped = mapSpecialType(type);
if (mapped == null) {
String get = null;
String set = null;
if (type.equals(List.class)) {
Type genericType = field.getGenericType();
if (genericType instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) genericType;
Type[] actualTypeArguments = pt.getActualTypeArguments();
if (actualTypeArguments != null && actualTypeArguments.length == 1) {
Class<?> itemClass = (Class<?>) actualTypeArguments[0];
mapped = "java.util.List<" + itemClass.getName() + ">";
// public final
// List<org.platformlayer.service.certificates.model.PurchaseCertificateExample>
// getExamples() {
// return
// List<org.platformlayer.service.certificates.model.PurchaseCertificateExample>Js.get(this,
// "examples");
// }
//
// public final void
// setExamples(List<org.platformlayer.service.certificates.model.PurchaseCertificateExample>
// newValue) {
// List<org.platformlayer.service.certificates.model.PurchaseCertificateExample>Js.set(this,
// "examples", newValue);
// }
// Add imports??
get = "";
get += "public final java.util.List<{itemClass}> get{beanName}() {\n";
if (itemClass.equals(String.class)) {
get += " com.google.gwt.core.client.JsArrayString array0 = com.gwtreboot.client.JsHelpers.getObject0(this, \"{fieldName}\").cast();\n";
get += " return org.platformlayer.core.model.JsStringArrayToList.wrap(array0);\n";
} else {
get += " com.google.gwt.core.client.JsArray<{itemClass}> array0 = com.gwtreboot.client.JsHelpers.getObject0(this, \"{fieldName}\").cast();\n";
get += " return org.platformlayer.core.model.JsArrayToList.wrap(array0);\n";
}
get += "}\n";
set = "";
get = get.replace("{itemClass}", itemClass.getName());
set = set.replace("{itemClass}", itemClass.getName());
}
}
} else if (type.equals(String.class)) {
get = "";
get += "public final String get{beanName}() {\n";
get += " return com.gwtreboot.client.JsHelpers.getString0(this, \"{fieldName}\");\n";
get += "}\n";
set = "";
set += "public final void set{beanName}(String v) {\n";
set += " com.gwtreboot.client.JsHelpers.set0(this, \"{fieldName}\", v);\n";
set += "}\n";
mapped = "HACK";
} else if (type.equals(Boolean.class)) {
get = "";
get += "public final Boolean is{beanName}() {\n";
get += " return com.gwtreboot.client.JsHelpers.getBoolean0(this, \"{fieldName}\");\n";
get += "}\n";
set = "";
set += "public final void set{beanName}(String v) {\n";
set += " com.gwtreboot.client.JsHelpers.set0(this, \"{fieldName}\", v);\n";
set += "}\n";
mapped = "HACK";
} else if (type.equals(Float.class)) {
get = "";
get += "public final Float get{beanName}() {\n";
get += " return com.gwtreboot.client.JsHelpers.getFloat0(this, \"{fieldName}\");\n";
get += "}\n";
set = "";
set += "public final void set{beanName}(String v) {\n";
set += " com.gwtreboot.client.JsHelpers.set0(this, \"{fieldName}\", v);\n";
set += "}\n";
mapped = "HACK";
} else if (type.equals(Date.class)) {
get = "";
get += "public final java.util.Date get{beanName}() {\n";
get += " return com.gwtreboot.client.JsHelpers.getDate0(this, \"{fieldName}\");\n";
get += "}\n";
set = "";
set += "public final void set{beanName}(java.util.Date v) {\n";
set += " com.gwtreboot.client.JsHelpers.set0(this, \"{fieldName}\", v);\n";
set += "}\n";
mapped = "HACK";
} else {
boolean gwtSafe = false;
for (Annotation annotation : type.getAnnotations()) {
if (annotation.annotationType().getSimpleName().equals("GwtSafe")) {
gwtSafe = true;
}
}
if (gwtSafe) {
get = "";
get += "public final {field.type} get{beanName}() {\n";
get += " return com.gwtreboot.client.JsHelpers.getObject0(this, \"{fieldName}\").cast();\n";
get += "}\n";
set = "";
mapped = "HACK";
}
}
if (get != null) {
get = get.replace("{beanName}", beanName);
get = get.replace("{fieldName}", fieldName);
get = get.replace("{field.type}", type.getName());
fieldModel.customGet = get;
}
if (set != null) {
set = set.replace("{beanName}", beanName);
set = set.replace("{fieldName}", fieldName);
set = set.replace("{field.type}", type.getName());
fieldModel.customSet = set;
}
}
}
if (mapped != null) {
} else if (!isNativeType(type)) {
warnings.add("JSNI cannot map '" + type.getSimpleName() + " " + fieldName + "'");
continue;
}
fieldModel.type = mapped != null ? mapped : type.getName();
fieldModel.accessorType = mapped != null ? mapped : accessorType.getName();
fieldModel.beanName = beanName;
fieldModel.methodNameGet = "get" + beanName;
if (type.equals(boolean.class) || type.equals(Boolean.class)) {
fieldModel.methodNameGet = "is" + beanName;
}
fieldModel.name = fieldName;
fieldModel.custom = mapped != null;
fields.add(fieldModel);
}
// model.put("className", classModel.className);
model.put("jsoClassName", jsoClassName);
model.put("jsoBaseClassName", jsoBaseClassName);
// model.put("serviceClassName", classModel.serviceClassName);
// model.put("editorClassName", classModel.editorClassName);
model.put("fields", fields);
if (gwtBasePathComponents == null) {
throw new MojoExecutionException("Did not find .gwt.xml file above " + clazz);
}
// String gwtPackage = Joiner.on(".").join(gwtBasePathComponents);
String outputPackage = clazz.getPackage().getName();
model.put("package", outputPackage);
// File outputDir = new File(outDir, Joiner.on("/").join(gwtBasePathComponents));
// Utils.mkdirs(outputDir);
String outputPath = Joiner.on(".").join(gwtBasePathComponents) + ".translatable." + outputPackage;
File outputDir = new File(outDir, outputPath.replace('.', '/'));
Utils.mkdirs(outputDir);
model.put("warnings", warnings);
// String modelPackage = Joiner.on(".").join(getPathComponents());
// model.put("modelPackage", modelPackage);
//
// String editorPackage = gwtPackage + ".client";
// model.put("editorPackage", editorPackage);
runTemplate("jso/JsoObject.ftl", model, new File(outputDir, jsoClassName + ".java"));
}
use of java.lang.annotation.Annotation in project querydsl by querydsl.
the class EntitySerializer method introClassHeader.
@SuppressWarnings(UNCHECKED)
protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException {
Type queryType = typeMappings.getPathType(model, model, true);
TypeCategory category = model.getOriginalCategory();
Class<? extends Path> pathType;
if (model.getProperties().isEmpty()) {
switch(category) {
case COMPARABLE:
pathType = ComparablePath.class;
break;
case ENUM:
pathType = EnumPath.class;
break;
case DATE:
pathType = DatePath.class;
break;
case DATETIME:
pathType = DateTimePath.class;
break;
case TIME:
pathType = TimePath.class;
break;
case NUMERIC:
pathType = NumberPath.class;
break;
case STRING:
pathType = StringPath.class;
break;
case BOOLEAN:
pathType = BooleanPath.class;
break;
default:
pathType = EntityPathBase.class;
}
} else {
pathType = EntityPathBase.class;
}
for (Annotation annotation : model.getAnnotations()) {
writer.annotation(annotation);
}
writer.line("@Generated(\"", getClass().getName(), "\")");
if (category == TypeCategory.BOOLEAN || category == TypeCategory.STRING) {
writer.beginClass(queryType, new ClassType(pathType));
} else {
writer.beginClass(queryType, new ClassType(category, pathType, model));
}
// TODO : generate proper serialVersionUID here
long serialVersionUID = model.getFullName().hashCode();
writer.privateStaticFinal(Types.LONG_P, "serialVersionUID", serialVersionUID + "L");
}
use of java.lang.annotation.Annotation in project querydsl by querydsl.
the class TypeFactory method get.
public Type get(boolean entity, Class<?> cl, AnnotatedElement annotated, java.lang.reflect.Type genericType) {
ImmutableList.Builder<Object> keyBuilder = ImmutableList.builder().add(cl).add(genericType);
AnnotationHelper annotationHelper = null;
Annotation selectedAnnotation = null;
if (annotated != null) {
for (Annotation annotation : annotated.getDeclaredAnnotations()) {
for (AnnotationHelper helper : annotationHelpers) {
if (helper.isSupported(annotation.annotationType())) {
keyBuilder.add(annotation.annotationType());
selectedAnnotation = annotated.getAnnotation(annotation.annotationType());
annotationHelper = helper;
keyBuilder.add(helper.getCustomKey(selectedAnnotation));
break;
}
}
}
}
List<?> key = keyBuilder.build();
if (cache.containsKey(key)) {
Type value = cache.get(key);
if (entity && !(value instanceof EntityType)) {
value = new EntityType(value, variableNameFunction);
cache.put(key, value);
}
return value;
} else {
Type value = create(entity, cl, annotationHelper, selectedAnnotation, genericType, key);
cache.put(key, value);
return value;
}
}
use of java.lang.annotation.Annotation in project querydsl by querydsl.
the class MetaDataSerializer method introClassHeader.
@Override
protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException {
Type queryType = typeMappings.getPathType(model, model, true);
writer.line("@Generated(\"", getClass().getName(), "\")");
TypeCategory category = model.getOriginalCategory();
// serialize annotations only, if no bean types are used
if (model.equals(queryType)) {
for (Annotation annotation : model.getAnnotations()) {
writer.annotation(annotation);
}
}
writer.beginClass(queryType, new ClassType(category, entityPathType, model));
writer.privateStaticFinal(Types.LONG_P, "serialVersionUID", String.valueOf(model.hashCode()));
}
use of java.lang.annotation.Annotation in project randomizedtesting by randomizedtesting.
the class GroupEvaluator method collectGroups.
private HashMap<Class<? extends Annotation>, TestGroupInfo> collectGroups(List<TestCandidate> testCandidates) {
final HashMap<Class<? extends Annotation>, TestGroupInfo> groups = new HashMap<Class<? extends Annotation>, TestGroupInfo>();
// Collect all groups declared on methods and instance classes.
HashSet<Class<?>> clazzes = new HashSet<Class<?>>();
HashSet<Annotation> annotations = new HashSet<Annotation>();
for (TestCandidate c : testCandidates) {
final Class<?> testClass = c.getTestClass();
if (!clazzes.contains(testClass)) {
clazzes.add(testClass);
annotations.addAll(Arrays.asList(testClass.getAnnotations()));
}
annotations.addAll(Arrays.asList(c.method.getAnnotations()));
}
// Get TestGroup annotated annotations.
for (Annotation ann : annotations) {
Class<? extends Annotation> annType = ann.annotationType();
if (!groups.containsKey(ann) && annType.isAnnotationPresent(TestGroup.class)) {
groups.put(annType, new TestGroupInfo(annType));
}
}
return groups;
}
Aggregations