List of usage examples for java.lang.reflect Modifier isStatic
public static boolean isStatic(int mod)
From source file:com.haulmont.cuba.core.config.type.TypeFactory.java
private static boolean isAcceptableMethod(Class<?> returnType, Method factoryMethod) { int modifiers = factoryMethod.getModifiers(); return Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && returnType.isAssignableFrom(factoryMethod.getReturnType()); }
From source file:ru.gkpromtech.exhibition.db.Table.java
protected Table(Class<T> entityClass, SQLiteOpenHelper sqlHelper) throws InvalidPropertiesFormatException { mEntityClass = entityClass;/* ww w . ja v a 2 s .com*/ mSqlHelper = sqlHelper; TableRef tableRef = entityClass.getAnnotation(TableRef.class); mTableName = tableRef.name(); // mTr = tableRef.tr(); List<Field> fields = new ArrayList<>(); for (Field field : mEntityClass.getFields()) if (!Modifier.isStatic(field.getModifiers())) fields.add(field); List<FkInfo> fks = new ArrayList<>(); mFields = fields.toArray(new Field[fields.size()]); mColumns = new String[mFields.length]; mType = new int[mFields.length]; for (int i = 0; i < mFields.length; ++i) { Field field = mFields[i]; mColumns[i] = field.getName(); switch (field.getType().getSimpleName()) { case "int": case "Integer": mType[i] = INTEGER; break; case "Short": case "short": mType[i] = SHORT; break; case "long": case "Long": mType[i] = LONG; break; case "float": case "Float": mType[i] = FLOAT; break; case "double": case "Double": mType[i] = DOUBLE; break; case "String": mType[i] = STRING; break; case "byte[]": mType[i] = BYTE_ARRAY; break; case "Date": mType[i] = DATE; break; case "boolean": mType[i] = BOOLEAN; break; default: throw new InvalidPropertiesFormatException( "Unsupported type: " + field.getType().getCanonicalName()); } FK fk = field.getAnnotation(FK.class); if (fk != null) fks.add(new FkInfo(fk.entity(), fk.field(), field.getName())); } mFks = fks.toArray(new FkInfo[fks.size()]); }
From source file:org.apache.dubbo.config.spring.beans.factory.annotation.CompatibleReferenceAnnotationBeanPostProcessor.java
/** * Finds {@link InjectionMetadata.InjectedElement} Metadata from annotated {@link Reference @Reference} fields * * @param beanClass The {@link Class} of Bean * @return non-null {@link List}/*from w w w. j a v a 2 s.c om*/ */ private List<ReferenceFieldElement> findFieldReferenceMetadata(final Class<?> beanClass) { final List<ReferenceFieldElement> elements = new LinkedList<ReferenceFieldElement>(); ReflectionUtils.doWithFields(beanClass, new ReflectionUtils.FieldCallback() { @Override public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { Reference reference = getAnnotation(field, Reference.class); if (reference != null) { if (Modifier.isStatic(field.getModifiers())) { if (logger.isWarnEnabled()) { logger.warn("@Reference annotation is not supported on static fields: " + field); } return; } elements.add(new ReferenceFieldElement(field, reference)); } } }); return elements; }
From source file:net.erdfelt.android.sdkfido.configer.Configer.java
private void findRawArgsMethod(Class<?> clazz) { for (Method method : clazz.getDeclaredMethods()) { ConfigArguments arg = method.getAnnotation(ConfigArguments.class); if (arg == null) { continue; // skip, not tagged }// w ww . ja v a 2 s. com int mods = method.getModifiers(); if (!Modifier.isPublic(mods)) { continue; // skip, not public } if (Modifier.isStatic(mods)) { continue; // skip, dont support static } Class<?>[] params = method.getParameterTypes(); if (params == null) { continue; // skip, needs params } if (params.length != 1) { continue; // skip, needs 1 param } if (!(params[0].equals(String.class))) { continue; // skip, param must be String } if (this.rawArgAdder != null) { StringBuilder err = new StringBuilder(); err.append("Not allowed to have multiple @ConfigArguments defined: "); err.append("\n Duplicate found at ").append(clazz.getName()).append("#").append(method.getName()); err.append("\n Original found at ").append(rawArgAdder.getDeclaringClass().getName()).append("#") .append(rawArgAdder.getName()); throw new IllegalStateException(err.toString()); } this.rawArgAdder = method; } }
From source file:com.geodevv.testing.irmina.IrminaContextLoader.java
private boolean isStaticNonPrivateAndNonFinal(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); int modifiers = clazz.getModifiers(); return (Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers)); }
From source file:com.qrmedia.commons.persistence.hibernate.clone.HibernateEntityBeanCloner.java
private static Collection<String> calculateTargetedFieldNames(Object entity, boolean preserveIdFields) { Collection<String> targetedFieldNames = new ArrayList<String>(); Class<?> entityClass = entity.getClass(); for (Field field : ClassUtils.getAllDeclaredFields(entityClass)) { String fieldName = field.getName(); // ignore static members and members without a valid getter and setter if (!Modifier.isStatic(field.getModifiers()) && PropertyUtils.isReadable(entity, fieldName) && PropertyUtils.isWriteable(entity, fieldName)) { targetedFieldNames.add(field.getName()); }/*ww w. ja va2s. c o m*/ } /* * Assume that, in accordance with recommendations, entities are using *either* JPA property * *or* field access. Guess the access type from the location of the @Id annotation, as * Hibernate does. */ Set<Method> idAnnotatedMethods = ClassUtils.getAnnotatedMethods(entityClass, Id.class); boolean usingFieldAccess = idAnnotatedMethods.isEmpty(); // ignore fields annotated with @Version and, optionally, @Id targetedFieldNames.removeAll(usingFieldAccess ? getFieldNames(ClassUtils.getAllAnnotatedDeclaredFields(entityClass, Version.class)) : getPropertyNames(ClassUtils.getAnnotatedMethods(entityClass, Version.class))); if (!preserveIdFields) { targetedFieldNames.removeAll(usingFieldAccess ? getFieldNames(ClassUtils.getAllAnnotatedDeclaredFields(entityClass, Id.class)) : getPropertyNames(idAnnotatedMethods)); } return targetedFieldNames; }
From source file:com.ankang.report.pool.AbstractReportAliasPool.java
private void mountPrams(LinkedHashMap<String, Class<?>> paramsType, Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); Annotation[][] annotations = method.getParameterAnnotations(); for (int i = 0; i < parameterTypes.length; i++) { if (annotations.length < i) { throw new ReportException( "Please add an effective note for the argument, such as: HTTPParam, RequestParam"); }/*from www . jav a 2 s . c o m*/ if ((ReportRequest.class.isAssignableFrom(parameterTypes[i])) || (!parameterTypes[i].isPrimitive() && !parameterTypes[i].toString().matches("^.+java\\..+$") && parameterTypes[i].toString().matches("^class.+$"))) { Field[] fields = parameterTypes[i].getDeclaredFields(); for (Field field : fields) { if (!Modifier.isFinal(field.getModifiers()) || !Modifier.isStatic(field.getModifiers())) { paramsType.put(field.getName(), field.getType()); } } } else { if (annotations.length >= i && annotations[i].length > 0) { paramsType.put(matchPrams(annotations[i][0]), parameterTypes[i]); } } } }
From source file:org.apache.syncope.client.console.panels.AnyTypesPanel.java
@Override protected List<IColumn<AnyTypeTO, String>> getColumns() { final List<IColumn<AnyTypeTO, String>> columns = new ArrayList<>(); for (Field field : AnyTypeTO.class.getDeclaredFields()) { if (field != null && !Modifier.isStatic(field.getModifiers())) { final String fieldName = field.getName(); if (field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()) || Map.class.isAssignableFrom(field.getType())) { columns.add(new PropertyColumn<>(new ResourceModel(field.getName()), field.getName())); } else if (field.getType().equals(boolean.class) || field.getType().equals(Boolean.class)) { columns.add(new BooleanPropertyColumn<>(new ResourceModel(field.getName()), field.getName(), field.getName())); } else { columns.add(new PropertyColumn<AnyTypeTO, String>(new ResourceModel(field.getName()), field.getName(), field.getName()) { private static final long serialVersionUID = -6902459669035442212L; @Override/*w w w . j a va 2 s. c o m*/ public String getCssClass() { String css = super.getCssClass(); if ("key".equals(fieldName)) { css = StringUtils.isBlank(css) ? "col-xs-1" : css + " col-xs-1"; } return css; } }); } } } return columns; }
From source file:org.apache.syncope.client.console.panels.AnyTypeClassesPanel.java
@Override protected List<IColumn<AnyTypeClassTO, String>> getColumns() { final List<IColumn<AnyTypeClassTO, String>> columns = new ArrayList<>(); for (Field field : AnyTypeClassTO.class.getDeclaredFields()) { if (field != null && !Modifier.isStatic(field.getModifiers())) { final String fieldName = field.getName(); if (field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()) || Map.class.isAssignableFrom(field.getType())) { columns.add(new PropertyColumn<>(new ResourceModel(field.getName()), field.getName())); } else if (field.getType().equals(boolean.class) || field.getType().equals(Boolean.class)) { columns.add(new BooleanPropertyColumn<>(new ResourceModel(field.getName()), field.getName(), field.getName())); } else { columns.add(new PropertyColumn<AnyTypeClassTO, String>(new ResourceModel(field.getName()), field.getName(), field.getName()) { private static final long serialVersionUID = -6902459669035442212L; @Override/*from www. java2 s . co m*/ public String getCssClass() { String css = super.getCssClass(); if ("key".equals(fieldName)) { css = StringUtils.isBlank(css) ? "col-xs-1" : css + " col-xs-1"; } return css; } }); } } } return columns; }
From source file:org.javelin.sws.ext.bind.internal.metadata.PropertyCallback.java
/** * <p>Reads class' metadata and returns a {@link XmlEventsPattern pattern of XML events} which may be used to marshal * an object of the analyzed class.<?p> * // w w w . jav a 2s. c o m * @return */ public TypedPattern<T> analyze() { TypedPattern<T> result = this.patternRegistry.findPatternByClass(this.clazz); if (result != null) return result; log.trace("Analyzing {} class with {} type name", this.clazz.getName(), this.typeName); // analyze fields ReflectionUtils.doWithFields(this.clazz, this, new FieldFilter() { @Override public boolean matches(Field field) { return !Modifier.isStatic(field.getModifiers()); } }); // analyze get/set methods - even private ones! ReflectionUtils.doWithMethods(this.clazz, this, new MethodFilter() { @Override public boolean matches(Method method) { boolean match = true; // is it getter? match &= method.getName().startsWith("get"); match &= method.getParameterTypes().length == 0; match &= method.getReturnType() != Void.class; // is there a setter? if (match) { Method setter = ReflectionUtils.findMethod(clazz, method.getName().replaceFirst("^get", "set"), method.getReturnType()); // TODO: maybe allow non-void returning setters as Spring-Framework already does? Now: yes match = setter != null || Collection.class.isAssignableFrom(method.getReturnType()); } return match; } }); if (this.valueMetadata != null && this.childElementMetadata.size() == 0 && this.childAttributeMetadata.size() == 0) { // we have a special case, where Java class becomes simpleType: // - formatting the analyzed class is really formatting the value // - the type information of the analyzed class is not changed! log.trace("Changing {} class' pattern to SimpleContentPattern", this.clazz.getName()); SimpleContentPattern<T> valuePattern = SimpleContentPattern.newValuePattern(this.typeName, this.clazz); SimpleContentPattern<?> simpleTypePattern = (SimpleContentPattern<?>) this.valueMetadata.getPattern(); valuePattern.setFormatter( PeelingFormatter.newPeelingFormatter(this.valueMetadata, simpleTypePattern.getFormatter())); result = valuePattern; } else { if (this.valueMetadata != null && this.childElementMetadata.size() > 0) { throw new RuntimeException("TODO: can't mix @XmlValue and @XmlElements"); } // we have complex type (possibly with simpleContent, when there's @XmlValue + one or more @XmlAttributes) // @XmlAttributes first. then @XmlElements this.childAttributeMetadata.addAll(this.childElementMetadata); if (this.valueMetadata != null) this.childAttributeMetadata.add(this.valueMetadata); result = ComplexTypePattern.newContentModelPattern(this.typeName, this.clazz, this.childAttributeMetadata); } if (log.isTraceEnabled()) log.trace("-> Class {} was mapped to {} with {} XSD type", this.clazz.getName(), result, this.typeName); return result; }