List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:com.eviware.x.form.support.ADialogBuilder.java
public static XFormDialog buildDialog(Class<? extends Object> formClass, ActionList actions, FormLayout layout) {/*from ww w . j a v a 2 s . com*/ AForm formAnnotation = formClass.getAnnotation(AForm.class); if (formAnnotation == null) { throw new RuntimeException("formClass is not annotated correctly.."); } MessageSupport messages = MessageSupport.getMessages(formClass); XFormDialogBuilder builder = XFormFactory.createDialogBuilder(messages.get(formAnnotation.name())); XForm form = createForm(builder, layout); for (Field field : formClass.getFields()) { AField fieldAnnotation = field.getAnnotation(AField.class); if (fieldAnnotation != null) { try { addFormField(form, field, fieldAnnotation, messages); } catch (Exception e) { e.printStackTrace(); } } } ActionList defaultActions = StringUtils.isBlank(formAnnotation.helpUrl()) ? builder.buildOkCancelActions() : builder.buildOkCancelHelpActions(formAnnotation.helpUrl()); if (actions == null) { actions = defaultActions; } else { actions.addActions(defaultActions); } XFormDialog dialog = builder.buildDialog(actions, messages.get(formAnnotation.description()), UISupport.createImageIcon(formAnnotation.icon())); return dialog; }
From source file:org.mybatisorm.annotation.handler.TableHandler.java
public static boolean hasAnnotation(Class<?> clazz) { return clazz.getAnnotation(Table.class) != null; }
From source file:com.eucalyptus.upgrade.TestHarness.java
@SuppressWarnings("unchecked") private static String getDescription(Object o) { Class c = null; Method m = null;/*from www.j a va 2s . com*/ if (o instanceof Class && ((c = (Class) o).getAnnotation(TestDescription.class)) != null) { return ((TestDescription) c.getAnnotation(TestDescription.class)).value(); } else if (o instanceof Method && ((m = (Method) o).getAnnotation(TestDescription.class)) != null) { StringBuffer sb = new StringBuffer(); for (Class a : Lists.newArrayList(Before.class, After.class, Test.class, Ignore.class, Parameters.class)) { if (m.getAnnotation(a) != null) sb.append(" @").append(String.format("%-9.9s", a.getSimpleName())).append(" "); } return sb.append(" ").append(((TestDescription) m.getAnnotation(TestDescription.class)).value()) .toString(); } return ""; }
From source file:com.helpinput.propertyeditors.PropertyEditorRegister.java
public static PropertyEditor newProtertyEditor(Class<? extends PropertyEditor> propertyEditorType, Class<?>... targetType) { final Class<?> theTargetType = getTargetType(propertyEditorType, targetType); if (theTargetType == null) return null; Map<Method, Object> setMethodAndValues = null; Properties propertiesAnn = propertyEditorType.getAnnotation(Properties.class); if (propertiesAnn != null) { Property[] properties = propertiesAnn.value(); if (Utils.hasLength(properties)) { setMethodAndValues = new HashMap<>(properties.length + 1); for (Property property : properties) { if (!addProperty(propertyEditorType, property, setMethodAndValues)) return null; }/*from www .j av a 2 s . c o m*/ } } Property propertyAnn = propertyEditorType.getAnnotation(Property.class); if (propertyAnn != null) { if (setMethodAndValues == null) setMethodAndValues = new HashMap<>(1); if (!addProperty(propertyEditorType, propertyAnn, setMethodAndValues)) return null; } PropertyEditor propertyEditor; try { propertyEditor = propertyEditorType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); return null; } if (Utils.hasLength(setMethodAndValues)) { for (Entry<Method, Object> entry : setMethodAndValues.entrySet()) { try { Utils.InvokedMethod(propertyEditor, entry.getKey(), entry.getValue()); } catch (Exception e) { e.printStackTrace(); return null; } } } return propertyEditor; }
From source file:com.crosstreelabs.junited.elasticsearch.ElasticsearchRule.java
protected static List<ElasticSetup> getAnnotations(final Description description) { Class<?> testClass = description.getTestClass(); String methodName = description.getMethodName(); List<ElasticSetup> result = new ArrayList<>(); if (testClass.isAnnotationPresent(ElasticSetup.class)) { result.add(testClass.getAnnotation(ElasticSetup.class)); }//from ww w . java 2 s . co m if (testClass.isAnnotationPresent(ElasticSetups.class)) { result.addAll(Arrays.asList(testClass.getAnnotation(ElasticSetups.class).value())); } if (methodName == null) { return result; } try { Method method = testClass.getDeclaredMethod(methodName); if (method.isAnnotationPresent(ElasticSetup.class)) { result.add(method.getAnnotation(ElasticSetup.class)); } if (method.isAnnotationPresent(ElasticSetups.class)) { result.addAll(Arrays.asList(method.getAnnotation(ElasticSetups.class).value())); } } catch (NoSuchMethodException | SecurityException ex) { } return result; }
From source file:com.spotify.heroic.shell.Tasks.java
public static String taskUsage(final Class<? extends ShellTask> task) { final TaskUsage u = task.getAnnotation(TaskUsage.class); if (u != null) { return u.value(); }/*from w w w. j a va 2s . c o m*/ return String.format("<no @ShellTaskUsage annotation for %s>", task.getCanonicalName()); }
From source file:com.spotify.heroic.shell.Tasks.java
public static String name(final Class<? extends ShellTask> task) { final TaskName n = task.getAnnotation(TaskName.class); if (n != null) { return n.value(); }/* w w w.j av a 2s. c o m*/ throw new IllegalStateException( String.format("No name configured with @TaskName on %s", task.getCanonicalName())); }
From source file:com.spotify.heroic.shell.Tasks.java
public static List<String> aliases(final Class<? extends ShellTask> task) { final TaskName n = task.getAnnotation(TaskName.class); final List<String> names = new ArrayList<>(); if (n != null) { for (final String alias : n.aliases()) { names.add(alias);// w ww . j a v a2 s . co m } } return names; }
From source file:com.sqewd.open.dal.services.EntitySchema.java
public static EntitySchema loadSchema(StructEntityReflect enref) throws Exception { EntitySchema entity = new EntitySchema(); Class<?> type = Class.forName(enref.Class); entity.name = enref.Entity;//from w ww .j a v a 2s . co m AbstractPersister pers = DataManager.get().getPersister(type); entity.persister = pers.getClass().getCanonicalName(); entity.classname = type.getCanonicalName(); if (type.isAnnotationPresent(JsonRootName.class)) { JsonRootName re = type.getAnnotation(JsonRootName.class); entity.jsonname = re.value(); } entity.properties = new ArrayList<PropertySchema>(); for (StructAttributeReflect attr : enref.Attributes) { PropertySchema pdef = PropertySchema.load(type, attr.Field.getName()); if (pdef != null) entity.properties.add(pdef); } return entity; }
From source file:com.spotify.heroic.shell.Tasks.java
public static List<String> allNames(final Class<? extends ShellTask> task) { final TaskName n = task.getAnnotation(TaskName.class); final List<String> names = new ArrayList<>(); if (n != null) { names.add(n.value());// ww w . j av a2 s. c om for (final String alias : n.aliases()) { names.add(alias); } } if (names.isEmpty()) { throw new IllegalStateException( String.format("No name configured with @TaskName on %s", task.getCanonicalName())); } return names; }