Java Code Examples for java.lang.reflect.Modifier#STATIC
The following examples show how to use
java.lang.reflect.Modifier#STATIC .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalPackages.java From netbeans with Apache License 2.0 | 6 votes |
private static int getModifiers(ClassInfo ci, int mIndex) { int modifiers = 0; if (ci.isMethodAbstract(mIndex)) { modifiers += Modifier.ABSTRACT; } if (ci.isMethodPrivate(mIndex)) { modifiers += Modifier.PRIVATE; } if (ci.isMethodProtected(mIndex)) { modifiers += Modifier.PROTECTED; } if (ci.isMethodPublic(mIndex)) { modifiers += Modifier.PUBLIC; } if (ci.isMethodFinal(mIndex)) { modifiers += Modifier.FINAL; } if (ci.isMethodStatic(mIndex)) { modifiers += Modifier.STATIC; } if (ci.isMethodNative(mIndex)) { modifiers += Modifier.NATIVE; } return modifiers; }
Example 2
Source File: BeansAccessBuilder.java From json-smart-v2 with Apache License 2.0 | 6 votes |
public void addConversion(Class<?> conv) { if (conv == null) return; for (Method mtd : conv.getMethods()) { if ((mtd.getModifiers() & Modifier.STATIC) == 0) continue; Class<?>[] param = mtd.getParameterTypes(); if (param.length != 1) continue; if (!param[0].equals(Object.class)) continue; Class<?> rType = mtd.getReturnType(); if (rType.equals(Void.TYPE)) continue; convMtds.put(rType, mtd); } }
Example 3
Source File: Constructor.java From jdk-1.7-annotated with Apache License 2.0 | 5 votes |
/** * Returns an array of arrays that represent the annotations on the formal * parameters, in declaration order, of the method represented by * this {@code Constructor} object. (Returns an array of length zero if the * underlying method is parameterless. If the method has one or more * parameters, a nested array of length zero is returned for each parameter * with no annotations.) The annotation objects contained in the returned * arrays are serializable. The caller of this method is free to modify * the returned arrays; it will have no effect on the arrays returned to * other callers. * * @return an array of arrays that represent the annotations on the formal * parameters, in declaration order, of the method represented by this * Constructor object * @since 1.5 */ public Annotation[][] getParameterAnnotations() { int numParameters = parameterTypes.length; if (parameterAnnotations == null) return new Annotation[numParameters][0]; Annotation[][] result = AnnotationParser.parseParameterAnnotations( parameterAnnotations, sun.misc.SharedSecrets.getJavaLangAccess(). getConstantPool(getDeclaringClass()), getDeclaringClass()); if (result.length != numParameters) { Class<?> declaringClass = getDeclaringClass(); if (declaringClass.isEnum() || declaringClass.isAnonymousClass() || declaringClass.isLocalClass() ) ; // Can't do reliable parameter counting else { if (!declaringClass.isMemberClass() || // top-level // Check for the enclosing instance parameter for // non-static member classes (declaringClass.isMemberClass() && ((declaringClass.getModifiers() & Modifier.STATIC) == 0) && result.length + 1 != numParameters) ) { throw new AnnotationFormatError( "Parameter annotations don't match number of parameters"); } } } return result; }
Example 4
Source File: ObjectStreamClass.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Returns explicit serial version UID value declared by given class, or * null if none. */ private static Long getDeclaredSUID(Class<?> cl) { try { Field f = cl.getDeclaredField("serialVersionUID"); int mask = Modifier.STATIC | Modifier.FINAL; if ((f.getModifiers() & mask) == mask) { f.setAccessible(true); return Long.valueOf(f.getLong(null)); } } catch (Exception ex) { } return null; }
Example 5
Source File: LocalMinecraftInterface.java From amidst with GNU General Public License v3.0 | 5 votes |
private void stopAllExecutors() throws IllegalArgumentException, IllegalAccessException { Class<?> clazz = utilClass.getClazz(); for (Field field: clazz.getDeclaredFields()) { if ((field.getModifiers() & Modifier.STATIC) > 0 && field.getType().equals(ExecutorService.class)) { field.setAccessible(true); ExecutorService exec = (ExecutorService) field.get(null); exec.shutdownNow(); } } }
Example 6
Source File: BytecodeCreatorImpl.java From gizmo with Apache License 2.0 | 5 votes |
@Override public ResultHandle getMethodParam(int methodNo) { int count = (method.getModifiers() & Modifier.STATIC) != 0 ? 0 : 1; for (int i = 0; i < methodNo; ++i) { String s = getMethod().getMethodDescriptor().getParameterTypes()[i]; if (s.equals("J") || s.equals("D")) { count += 2; } else { count++; } } ResultHandle resultHandle = new ResultHandle(getMethod().getMethodDescriptor().getParameterTypes()[methodNo], this); resultHandle.setNo(count); return resultHandle; }
Example 7
Source File: RealFunctionValidation.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns a {@link Method} with specified signature. * * @param className The fully qualified name of the class to which the * method belongs. * @param methodName The name of the method. * @param signature The signature of the method, as a list of parameter * types. * @return the method * @throws SecurityException * @throws ClassNotFoundException */ public static Method findStaticMethod(final String className, final String methodName, final List<Class<?>> signature) throws SecurityException, ClassNotFoundException { final int n = signature.size(); final Method[] methods = Class.forName(className).getMethods(); for (Method method : methods) { if (method.getName().equals(methodName)) { final Class<?>[] parameters = method.getParameterTypes(); boolean sameSignature = true; if (parameters.length == n) { for (int i = 0; i < n; i++) { sameSignature &= signature.get(i) .equals(parameters[i]); } if (sameSignature) { final int modifiers = method.getModifiers(); if ((modifiers & Modifier.STATIC) != 0) { return method; } else { final String msg = "method must be static"; throw new IllegalArgumentException(msg); } } } } } throw new IllegalArgumentException("method not found"); }
Example 8
Source File: ObjectStreamClass.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns explicit serial version UID value declared by given class, or * null if none. */ private static Long getDeclaredSUID(Class<?> cl) { try { Field f = cl.getDeclaredField("serialVersionUID"); int mask = Modifier.STATIC | Modifier.FINAL; if ((f.getModifiers() & mask) == mask) { f.setAccessible(true); return Long.valueOf(f.getLong(null)); } } catch (Exception ex) { } return null; }
Example 9
Source File: RealFunctionValidation.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns a {@link Method} with specified signature. * * @param className The fully qualified name of the class to which the * method belongs. * @param methodName The name of the method. * @param signature The signature of the method, as a list of parameter * types. * @return the method * @throws SecurityException * @throws ClassNotFoundException */ public static Method findStaticMethod(final String className, final String methodName, final List<Class<?>> signature) throws SecurityException, ClassNotFoundException { final int n = signature.size(); final Method[] methods = Class.forName(className).getMethods(); for (Method method : methods) { if (method.getName().equals(methodName)) { final Class<?>[] parameters = method.getParameterTypes(); boolean sameSignature = true; if (parameters.length == n) { for (int i = 0; i < n; i++) { sameSignature &= signature.get(i) .equals(parameters[i]); } if (sameSignature) { final int modifiers = method.getModifiers(); if ((modifiers & Modifier.STATIC) != 0) { return method; } else { final String msg = "method must be static"; throw new IllegalArgumentException(msg); } } } } } throw new IllegalArgumentException("method not found"); }
Example 10
Source File: ObjectStreamClass.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Returns explicit serial version UID value declared by given class, or * null if none. */ private static Long getDeclaredSUID(Class<?> cl) { try { Field f = cl.getDeclaredField("serialVersionUID"); int mask = Modifier.STATIC | Modifier.FINAL; if ((f.getModifiers() & mask) == mask) { f.setAccessible(true); return Long.valueOf(f.getLong(null)); } } catch (Exception ex) { } return null; }
Example 11
Source File: NLS.java From lucene-solr with Apache License 2.0 | 5 votes |
private static void loadfieldValue(Field field, Class<? extends NLS> clazz) { int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC; int MOD_MASK = MOD_EXPECTED | Modifier.FINAL; if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED) return; // Set a value for this empty field. try { field.set(null, field.getName()); validateMessage(field.getName(), clazz); } catch (IllegalArgumentException | IllegalAccessException e) { // should not happen } }
Example 12
Source File: ObjectStreamClass.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns array of ObjectStreamFields corresponding to all non-static * non-transient fields declared by given class. Each ObjectStreamField * contains a Field object for the field it represents. If no default * serializable fields exist, NO_FIELDS is returned. */ private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) { Field[] clFields = cl.getDeclaredFields(); ArrayList<ObjectStreamField> list = new ArrayList<>(); int mask = Modifier.STATIC | Modifier.TRANSIENT; for (int i = 0; i < clFields.length; i++) { if ((clFields[i].getModifiers() & mask) == 0) { list.add(new ObjectStreamField(clFields[i], false, true)); } } int size = list.size(); return (size == 0) ? NO_FIELDS : list.toArray(new ObjectStreamField[size]); }
Example 13
Source File: AbsTLApiTest.java From kotlogram with MIT License | 5 votes |
public <T extends TLObject> T randomize(T object) { Class<? extends TLObject> clazz = object.getClass(); // Get class + superclass fields List<Field> fields = new ArrayList<>(); Collections.addAll(fields, clazz.getDeclaredFields()); if (clazz.getSuperclass() != TLObject.class) { Collections.addAll(fields, clazz.getSuperclass().getDeclaredFields()); } for (Field field : fields) { if (field.getName().equalsIgnoreCase("flags")) { continue; } if (!(((field.getModifiers() & Modifier.TRANSIENT) == 0))) { continue; } if (!((field.getModifiers() & Modifier.STATIC) == 0)) { continue; } if (!((field.getModifiers() & Modifier.FINAL) == 0)) { continue; } field.setAccessible(true); try { field.set(object, getRandom(field.getType(), field)); } catch (Exception e) { throw new RuntimeException(e); } } return object; }
Example 14
Source File: ReflectUtils.java From spring-analysis-note with MIT License | 5 votes |
public Object run() throws Exception { Method[] methods = Object.class.getDeclaredMethods(); for (Method method : methods) { if ("finalize".equals(method.getName()) || (method.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) > 0) { continue; } OBJECT_METHODS.add(method); } return null; }
Example 15
Source File: ObjectStreamClass.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns array of ObjectStreamFields corresponding to all non-static * non-transient fields declared by given class. Each ObjectStreamField * contains a Field object for the field it represents. If no default * serializable fields exist, NO_FIELDS is returned. */ private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) { Field[] clFields = cl.getDeclaredFields(); ArrayList<ObjectStreamField> list = new ArrayList<>(); int mask = Modifier.STATIC | Modifier.TRANSIENT; for (int i = 0; i < clFields.length; i++) { if ((clFields[i].getModifiers() & mask) == 0) { list.add(new ObjectStreamField(clFields[i], false, true)); } } int size = list.size(); return (size == 0) ? NO_FIELDS : list.toArray(new ObjectStreamField[size]); }
Example 16
Source File: AbstractOptions.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
private boolean isOptionField(Field field) { return ((field.getModifiers() & Modifier.STATIC) == 0) && (!field.getName().equals("metaClass")) && (!excludeFromAntProperties(field.getName())); }
Example 17
Source File: ClosureStaticMetaMethod.java From groovy with Apache License 2.0 | 4 votes |
public int getModifiers() { return Modifier.PUBLIC | Modifier.STATIC; }
Example 18
Source File: BCMethod.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
BCMethod(ClassBuilder cb, String returnType, String methodName, int modifiers, String[] parms, BCJava factory) { this.cb = (BCClass) cb; modClass = this.cb.modify(); myReturnType = returnType; myName = methodName; if (SanityManager.DEBUG) { this.cb.validateType(returnType); } // if the method is not static, allocate for "this". if ((modifiers & Modifier.STATIC) == 0 ) currentVarNum = 1; String[] vmParamterTypes; if (parms != null && parms.length != 0) { int len = parms.length; vmParamterTypes = new String[len]; parameters = new BCLocalField[len]; for (int i = 0; i < len; i++) { Type t = factory.type(parms[i]); parameters[i] = new BCLocalField(t, currentVarNum); currentVarNum += t.width(); // convert to vmname for the BCMethodDescriptor.get() call vmParamterTypes[i] = t.vmName(); } } else vmParamterTypes = BCMethodDescriptor.EMPTY; // create a code attribute String sig = BCMethodDescriptor.get(vmParamterTypes, factory.type(returnType).vmName(), factory); // stuff the completed information into the class. myEntry = modClass.addMember(methodName, sig, modifiers); // get code chunk myCode = new CodeChunk(this.cb); parameterTypes = parms; }
Example 19
Source File: Hack.java From deagle with Apache License 2.0 | 4 votes |
public @CheckResult <T> StaticFieldToHack<C> staticField(final @NonNull String name) { return new StaticFieldToHack<>(this, name, Modifier.STATIC); }
Example 20
Source File: NSManager.java From cxf with Apache License 2.0 | 4 votes |
private boolean isPulicStaticFinal(final Field field) { return field.getModifiers() == (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL); }