List of usage examples for java.lang.reflect Modifier STATIC
int STATIC
To view the source code for java.lang.reflect Modifier STATIC.
Click Source Link
From source file:com.mobile.system.db.abatis.AbatisService.java
public Object parseToObject(Class beanClass, Cursor cur) throws IllegalAccessException, InstantiationException, SecurityException, NoSuchMethodException { Object obj = null;/*w w w . j a v a 2 s. c o m*/ Field[] props = beanClass.getDeclaredFields(); if (props == null || props.length == 0) { Log.d(TAG, "Class" + beanClass.getName() + " has no fields"); return null; } // Create instance of this Bean class obj = beanClass.newInstance(); // Set value of each member variable of this object for (int i = 0; i < props.length; i++) { String fieldName = props[i].getName(); if (props[i].getModifiers() == (Modifier.PUBLIC | Modifier.STATIC)) { continue; } Class type = props[i].getType(); String typeName = type.getName(); // Check for Custom type Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { int curIdx = cur.getColumnIndex(fieldName); if (curIdx != -1) { int nDotIdx = typeName.lastIndexOf("."); if (nDotIdx >= 0) { typeName = typeName.substring(nDotIdx); } if (typeName.equals("int")) { m.invoke(obj, cur.getInt(curIdx)); } else if (typeName.equals("double")) { m.invoke(obj, cur.getDouble(curIdx)); } else if (typeName.equals("String")) { m.invoke(obj, cur.getString(curIdx)); } else if (typeName.equals("long")) { m.invoke(obj, cur.getLong(curIdx)); } else if (typeName.equals("float")) { m.invoke(obj, cur.getFloat(curIdx)); } else if (typeName.equals("Date")) { m.invoke(obj, cur.getString(curIdx)); } else if (typeName.equals("byte[]") || typeName.equals("[B")) { m.invoke(obj, cur.getBlob(curIdx)); } else { m.invoke(obj, cur.getString(curIdx)); } } } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } return obj; }
From source file:autocorrelator.apps.SDFGroovy.java
private static void exitWithHelp(String msg, Options options) { System.err.println(msg);/*from www . j a va 2 s . c o m*/ HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(INTROText, options); StringBuilder sb = new StringBuilder(); Class<SDFGroovyHelper> helper = SDFGroovyHelper.class; for (Method m : helper.getMethods()) { if ((m.getModifiers() & Modifier.STATIC) == 0 || (m.getModifiers() & Modifier.PUBLIC) == 0) continue; String meth = m.toString(); meth = meth.replaceAll("public static final ", ""); meth = meth.replaceAll("java\\.lang\\.", ""); meth = meth.replaceAll("java\\.math\\.", ""); meth = meth.replaceAll("autocorrelator\\.apps\\.SDFGroovyHelper.", ""); sb.append('\t').append(meth).append('\n'); } System.out.println("Imported internal functions:"); System.out.println(sb); System.exit(1); }
From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java
/** * @return gets or creates getProperty(name,beanWrapper) *///w w w .j ava2s. c o m private MethodMetadata getPropertyMethodWithWrapper() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(JavaType.STRING, BEAN_WRAPPER_IMPL); // Check if a method exist in type final MethodMetadata method = helper.methodExists(GET_PROPERTY_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method return method; } // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = helper.toSymbolName("name", "beanWrapper"); // Create the method body InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder(); buildGetPropertyMethodWithWrapper(body, helper, context.getEntity()); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(context.getMetadataId(), Modifier.PUBLIC + Modifier.STATIC, GET_PROPERTY_METHOD, AUDIT_PROPERTY_GENERIC, parameterTypes, parameterNames, body); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteria.java
/** * Set the criterion that selects only {@link Member}s that exactly have the * specified modifiers. The access modifiers are set separately. Use * {@link #withAccess(AccessType...)} to set access modifiers. * * @param modifiers//from w w w . j a v a2 s . c o m * @since 1.0.0.0 */ public void withModifiers(int modifiers) { if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers)) { throw new IllegalArgumentException( "access modifiers are not allowed as argument. Use withAccess() instead."); } int allowedModifiers = Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT | Modifier.VOLATILE | Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT | Modifier.INTERFACE; if ((modifiers & allowedModifiers) == 0) { throw new IllegalArgumentException( "modifiers must be one of [" + Modifier.toString(allowedModifiers) + "]"); } this.modifiers = modifiers; }
From source file:org.gradle.build.docs.dsl.source.SourceMetaDataVisitor.java
private int extractModifiers(GroovySourceAST ast) { GroovySourceAST modifiers = ast.childOfType(MODIFIERS); if (modifiers == null) { return 0; }// w w w. j av a 2 s. c o m int modifierFlags = 0; for (GroovySourceAST child = (GroovySourceAST) modifiers .getFirstChild(); child != null; child = (GroovySourceAST) child.getNextSibling()) { switch (child.getType()) { case LITERAL_private: modifierFlags |= Modifier.PRIVATE; break; case LITERAL_protected: modifierFlags |= Modifier.PROTECTED; break; case LITERAL_public: modifierFlags |= Modifier.PUBLIC; break; case FINAL: modifierFlags |= Modifier.FINAL; break; case LITERAL_static: modifierFlags |= Modifier.STATIC; break; } } return modifierFlags; }
From source file:com.all.app.BeanStatisticsWriter.java
private List<CSVColumn> auto(Object object) { List<CSVColumn> columns = new ArrayList<CSVColumn>(); Method[] declaredMethods = object.getClass().getDeclaredMethods(); for (Method method : declaredMethods) { boolean noArguments = method.getParameterTypes().length == 0; boolean isVoid = method.getReturnType().equals(void.class); boolean isPublic = (method.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC; boolean isNotStatic = (method.getModifiers() & Modifier.STATIC) != Modifier.STATIC; boolean isGetter = method.getName().startsWith("get"); if (isGetter && noArguments && isPublic && isNotStatic && !isVoid) { columns.add(new CSVColumnMethodReflected(method.getName(), method.getName())); }/*from w w w . java 2 s .c o m*/ } return columns; }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test(expected = IllegalStateException.class) public void iteratorRemove() { memberCriteria.membersOfType(Field.class); memberCriteria.withAccess(AccessType.PRIVATE); memberCriteria.withModifiers(Modifier.STATIC); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); Iterator<Member> iterator = memberIterable.iterator(); assertTrue(iterator.hasNext());/*from w w w. j a v a 2s . c o m*/ iterator.remove(); }
From source file:org.eclipse.buildship.docs.source.SourceMetaDataVisitor.java
private int extractModifiers(GroovySourceAST ast) { GroovySourceAST modifiers = ast.childOfType(MODIFIERS); if (modifiers == null) { return 0; }/* ww w.j a va 2s . c o m*/ int modifierFlags = 0; for (GroovySourceAST child = (GroovySourceAST) modifiers .getFirstChild(); child != null; child = (GroovySourceAST) child.getNextSibling()) { switch (child.getType()) { case LITERAL_private: modifierFlags |= Modifier.PRIVATE; break; case LITERAL_protected: modifierFlags |= Modifier.PROTECTED; break; case LITERAL_public: modifierFlags |= Modifier.PUBLIC; break; case FINAL: modifierFlags |= Modifier.FINAL; break; case LITERAL_static: modifierFlags |= Modifier.STATIC; break; case ABSTRACT: modifierFlags |= Modifier.ABSTRACT; break; } } return modifierFlags; }
From source file:org.bitpipeline.lib.friendlyjson.JSONEntity.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static Object fromJson(Class<?> clazz, Object json) throws JSONMappingException { if (json == null) return null; Object fromJson = null;//from ww w. jav a 2s.c o m if (clazz == null) { try { fromJson = JSONEntity.fromJson(json); } catch (JSONException e) { e.printStackTrace(); throw new JSONMappingException(e); } } else { Constructor<?> constructor; ; if (JSONEntity.class.isAssignableFrom(clazz)) { // A JSON Entity. Class<?> enclosingClass = clazz.getEnclosingClass(); if (enclosingClass != null && (clazz.getModifiers() & Modifier.STATIC) == 0) { // it's a non static inner class try { constructor = clazz.getDeclaredConstructor(enclosingClass, JSONObject.class); } catch (Exception e) { throw new JSONMappingException(clazz.getName() + JSONEntity.MSG_MUST_HAVE_CONSTRUCTOR, e); } try { /* we actually don't know the enclosing object... * this will be a problem with inner classes that * reference the enclosing class instance at * constructor time... although with json entities * that should not happen. */ fromJson = constructor.newInstance(null, json); } catch (Exception e) { throw new JSONMappingException(e); } } else { // static inner class try { constructor = clazz.getDeclaredConstructor(JSONObject.class); } catch (Exception e) { throw new JSONMappingException(clazz.getName() + JSONEntity.MSG_MUST_HAVE_CONSTRUCTOR, e); } try { fromJson = constructor.newInstance(json); } catch (Exception e) { throw new JSONMappingException("clazz = " + clazz.getName() + "; json = " + json.toString(), e); } } } else if (clazz.isEnum()) { try { fromJson = Enum.valueOf((Class<Enum>) clazz, json.toString()); } catch (Exception e) { fromJson = null; } } else { try { fromJson = JSONEntity.fromJson(json); } catch (JSONException e) { e.printStackTrace(); } } } if (clazz != null && !clazz.isAssignableFrom(fromJson.getClass())) throw new JSONMappingException("Was expeting a " + clazz.getName() + " but received a " + fromJson.getClass().getName() + " instead."); return fromJson; }
From source file:org.gvnix.addon.jpa.addon.geo.providers.hibernatespatial.GvNIXEntityMapLayerMetadata.java
/** * Create a generic method to filter by all geometric fields from an entity * //from ww w . j a v a 2 s . co m * @param entity * @param plural * @param geoFieldNames * @return */ private MethodMetadata getfindAllTheEntityByAllGeoms(JavaType entity, String plural, Map<JavaSymbolName, AnnotationAttributeValue<Integer>> geoFields) { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); // Adding param types parameterTypes.add(AnnotatedJavaType .convertFromJavaType(new JavaType("org.gvnix.jpa.geo.hibernatespatial.util.GeometryFilter"))); parameterTypes.add(AnnotatedJavaType.convertFromJavaType( new JavaType("java.lang.Class", 0, DataType.TYPE, null, Arrays.asList(new JavaType("T"))))); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(new JavaType(MAP.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(JavaType.STRING, JavaType.OBJECT)))); parameterTypes.add(AnnotatedJavaType.convertFromJavaType( new JavaType("java.lang.Iterable", 0, DataType.TYPE, null, Arrays.asList(JavaType.STRING)))); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.STRING)); // Getting method name JavaSymbolName methodName = new JavaSymbolName(String.format("findAll%sByGeoFilter", plural)); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(methodName, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); // Adding parameter names parameterNames.add(new JavaSymbolName("geomFilter")); parameterNames.add(new JavaSymbolName("klass")); parameterNames.add(new JavaSymbolName("hints")); parameterNames.add(new JavaSymbolName("fields")); parameterNames.add(new JavaSymbolName("scale")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildfindAllTheEntityByAllGeomMethodBody(entity, plural, bodyBuilder, geoFields); // Return type: ResponseEntity<List<T>> JavaType responseEntityJavaType = new JavaType(new JavaType("java.util.List").getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(new JavaType("T"))); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC, methodName, responseEntityJavaType, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); methodBuilder.setGenericDefinition("T"); return methodBuilder.build(); // Build and return a MethodMetadata // instance }