Java Code Examples for java.lang.reflect.Modifier.isStatic()

The following are Jave code examples for showing how to use isStatic() of the java.lang.reflect.Modifier class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javaide   File: AutoCompleteProvider.java   View Source Code Vote up 6 votes
@NonNull
private ArrayList<Description> getStaticAccess(String className) {
    ClassDescription classDescription = mClassLoader.getClassReader().readClassByName(className, null);
    ArrayList<Description> result = new ArrayList<>();
    if (classDescription != null) {
        for (FieldDescription fieldDescription : classDescription.getFields()) {
            if (Modifier.isStatic(fieldDescription.getModifiers())
                    && Modifier.isPublic(fieldDescription.getModifiers())) {
                result.add(fieldDescription);
            }
        }
        for (MethodDescription methodDescription : classDescription.getMethods()) {
            if (Modifier.isStatic(methodDescription.getModifiers())
                    && Modifier.isPublic(methodDescription.getModifiers())) {
                result.add(methodDescription);
            }
        }
    }
    return result;
}
 
Example 2
Project: TPlayer   File: Reflect.java   View Source Code Vote up 6 votes
/**
 * 取得一个Map,map中的key为字段名,value为字段对应的反射工具类
 *
 * @return Map
 */
public Map<String, Reflect> fields() {
    Map<String, Reflect> result = new LinkedHashMap<String, Reflect>();
    Class<?> type = type();

    do {
        for (Field field : type.getDeclaredFields()) {
            if (!isClass ^ Modifier.isStatic(field.getModifiers())) {
                String name = field.getName();

                if (!result.containsKey(name))
                    result.put(name, field(name));
            }
        }

        type = type.getSuperclass();
    } while (type != null);

    return result;
}
 
Example 3
Project: elasticsearch_my   File: PainlessDocGenerator.java   View Source Code Vote up 6 votes
private static void documentField(PrintStream stream, Field field) {
    stream.print("** [[");
    emitAnchor(stream, field);
    stream.print("]]");

    if (Modifier.isStatic(field.modifiers)) {
        stream.print("static ");
    }

    emitType(stream, field.type);
    stream.print(' ');

    String javadocRoot = javadocRoot(field);
    emitJavadocLink(stream, javadocRoot, field);
    stream.print('[');
    stream.print(field.name);
    stream.print(']');

    if (javadocRoot.equals("java8")) {
        stream.print(" (");
        emitJavadocLink(stream, "java9", field);
        stream.print("[java 9])");
    }

    stream.println();
}
 
Example 4
Project: Bytecoder   File: BytecoderUnitTestRunner.java   View Source Code Vote up 6 votes
public BytecoderUnitTestRunner(Class aClass) throws InitializationError {
    super(aClass);
    testClass = new TestClass(aClass);
    testMethods = new ArrayList<>();

    Method[] classMethods = aClass.getDeclaredMethods();
    for (Method classMethod : classMethods) {
        Class retClass = classMethod.getReturnType();
        int length = classMethod.getParameterTypes().length;
        int modifiers = classMethod.getModifiers();
        if (retClass == null || length != 0 || Modifier.isStatic(modifiers)
                || !Modifier.isPublic(modifiers) || Modifier.isInterface(modifiers)
                || Modifier.isAbstract(modifiers)) {
            continue;
        }
        String methodName = classMethod.getName();
        if (methodName.toUpperCase().startsWith("TEST")
                || classMethod.getAnnotation(Test.class) != null) {
            testMethods.add(new FrameworkMethod(classMethod));
        }
        if (classMethod.getAnnotation(Ignore.class) != null) {
            testMethods.remove(classMethod);
        }
    }
}
 
Example 5
Project: jdk8u-jdk   File: SwingTest.java   View Source Code Vote up 6 votes
private void start() throws Throwable {
    do {
        if ((this.method != null) && Modifier.isStatic(this.method.getModifiers())) {
            run(); // invoke static method on the current thread
        }
        else {
            SwingUtilities.invokeLater(this); // invoke on the event dispatch thread
        }
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            SunToolkit stk = (SunToolkit) tk;
            stk.realSync(); // wait until done
        }
    }
    while (this.frame != null);
    if (this.error != null) {
        throw this.error;
    }
}
 
Example 6
Project: firebase-admin-java   File: CustomClassMapper.java   View Source Code Vote up 5 votes
private static boolean shouldIncludeGetter(Method method) {
  if (!method.getName().startsWith("get") && !method.getName().startsWith("is")) {
    return false;
  }
  // Exclude methods from Object.class
  if (method.getDeclaringClass().equals(Object.class)) {
    return false;
  }
  // Non-public methods
  if (!Modifier.isPublic(method.getModifiers())) {
    return false;
  }
  // Static methods
  if (Modifier.isStatic(method.getModifiers())) {
    return false;
  }
  // No return type
  if (method.getReturnType().equals(Void.TYPE)) {
    return false;
  }
  // Non-zero parameters
  if (method.getParameterTypes().length != 0) {
    return false;
  }
  // Excluded methods
  if (method.isAnnotationPresent(Exclude.class)) {
    return false;
  }
  return true;
}
 
Example 7
Project: X4J   File: BytecodeReadingParanamer.java   View Source Code Vote up 5 votes
private MethodCollector visitMethod(int access, String name, String desc) {
    // already found the method, skip any processing
    if (collector != null) {
        return null;
    }
    // not the same name
    if (!name.equals(methodName)) {
        return null;
    }
    Type[] argumentTypes = Type.getArgumentTypes(desc);
    int longOrDoubleQuantity = 0;
    for (Type t : argumentTypes) {
        if (t.getClassName().equals("long")
                || t.getClassName().equals("double")) {
            longOrDoubleQuantity++;
        }
    }
    int paramCount = argumentTypes.length;
    // not the same quantity of parameters
    if (paramCount != this.parameterTypes.length) {
        return null;
    }
    for (int i = 0; i < argumentTypes.length; i++) {
        if (!correctTypeName(argumentTypes, i).equals(
                this.parameterTypes[i].getName())) {
            return null;
        }
    }
    this.collector = new MethodCollector((Modifier.isStatic(access) ? 0 : 1),
            argumentTypes.length + longOrDoubleQuantity);
    return collector;
}
 
Example 8
Project: incubator-netbeans   File: Util.java   View Source Code Vote up 5 votes
public static Method getValueOfMethod(Class type) {
    try {
        Method method = type.getDeclaredMethod("valueOf", String.class);
        if (method == null || !Modifier.isStatic(method.getModifiers())) {
            return null;
        }
        return method;
    } catch (Exception e) {
        return null;
    }
}
 
Example 9
Project: openNaEF   File: ReflectionUtils.java   View Source Code Vote up 5 votes
public static List<Object> initializeStaticFinalFields(Class<?> klass) {
    List<Object> result = new ArrayList<Object>();
    for (Field f : klass.getDeclaredFields()) {
        if (Modifier.isStatic(f.getModifiers()) && Modifier.isFinal(f.getModifiers())) {
            try {
                f.setAccessible(true);
                result.add(f.get(null));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return result;
}
 
Example 10
Project: openjdk-jdk10   File: SEIStub.java   View Source Code Vote up 5 votes
private void validateInputs(Object proxy, Method method) {
    if (proxy == null || !Proxy.isProxyClass(proxy.getClass())) {
        throw new IllegalStateException("Passed object is not proxy!");
    }
    if (method == null || method.getDeclaringClass() == null
            || Modifier.isStatic(method.getModifiers())) {
        throw new IllegalStateException("Invoking static method is not allowed!");
    }
}
 
Example 11
Project: manifold-ij   File: ManAugmentProvider.java   View Source Code Vote up 5 votes
private boolean isExtensionMethod( AbstractSrcMethod method, String extendedType )
{
  if( !Modifier.isStatic( (int)method.getModifiers() ) || Modifier.isPrivate( (int)method.getModifiers() ) )
  {
    return false;
  }

  if( method.hasAnnotation( Extension.class ) )
  {
    return true;
  }

  return hasThisAnnotation( method, extendedType );
}
 
Example 12
Project: NyaaCore   File: IPCUtils.java   View Source Code Vote up 5 votes
/**
 * Register a method, the method must be static
 */
public static void registerMethod(String name, Method method) {
    name = name.toLowerCase();
    if (methodMap.containsKey(name)) {
        throw new IllegalArgumentException("duplicated method name");
    }
    if (!Modifier.isStatic(method.getModifiers())) {
        throw new IllegalArgumentException("method not static");
    }
    methodMap.put(name, method);
}
 
Example 13
Project: OpenJSharp   File: ObjectSizeCalculator.java   View Source Code Vote up 5 votes
public ClassSizeInfo(final Class<?> clazz) {
    long newFieldsSize = 0;
    final List<Field> newReferenceFields = new LinkedList<>();
    for (final Field f : clazz.getDeclaredFields()) {
        if (Modifier.isStatic(f.getModifiers())) {
            continue;
        }
        final Class<?> type = f.getType();
        if (type.isPrimitive()) {
            newFieldsSize += getPrimitiveFieldSize(type);
        } else {
            f.setAccessible(true);
            newReferenceFields.add(f);
            newFieldsSize += referenceSize;
        }
    }
    final Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        final ClassSizeInfo superClassInfo = getClassSizeInfo(superClass);
        newFieldsSize += roundTo(superClassInfo.fieldsSize, superclassFieldPadding);
        newReferenceFields.addAll(Arrays.asList(superClassInfo.referenceFields));
    }
    this.fieldsSize = newFieldsSize;
    this.objectSize = roundTo(objectHeaderSize + newFieldsSize, objectPadding);
    this.referenceFields = newReferenceFields.toArray(
            new Field[newReferenceFields.size()]);
}
 
Example 14
Project: OpenJSharp   File: CallerSensitiveDynamicMethod.java   View Source Code Vote up 5 votes
@Override
MethodHandle getTarget(final MethodHandles.Lookup lookup) {
    if(target instanceof Method) {
        final MethodHandle mh = Lookup.unreflect(lookup, (Method)target);
        if(Modifier.isStatic(((Member)target).getModifiers())) {
            return StaticClassIntrospector.editStaticMethodHandle(mh);
        }
        return mh;
    }
    return StaticClassIntrospector.editConstructorMethodHandle(Lookup.unreflectConstructor(lookup,
            (Constructor<?>)target));
}
 
Example 15
Project: jDialects   File: ReflectionUtils.java   View Source Code Vote up 4 votes
@Override
public boolean matches(Field field) {
	return !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()));
}
 
Example 16
Project: MaxSim   File: Inheritance1.java   View Source Code Vote up 4 votes
public static boolean isStatic(Field field) {
    return Modifier.isStatic(field.getModifiers());
}
 
Example 17
Project: gitplex-mit   File: ReflectionUtils.java   View Source Code Vote up 4 votes
/**
 * Invoke specified method with specified parameters. Parameter types 
 * of invoked method should be compatible with types of specified 
 * parameters. The method will be searched in specified class and all 
 * its super classes in turn. 
 * <p>
 * @param clazz
 * 			class to invoke method in. Method will be searched 
 * 			in super classes if not found in specified class 
 * @param methodName
 * 			name of the method
 * @param params
 * 			parameters to be passed to the method
 * @return
 * 			return value of invoked method
 * @throws
 * 			RuntimeException if no method matching specified name and parameters
 */
public static Object invokeMethod(Object object, String methodName, Object...params) {
	Class<?>[] paramTypes = new Class<?>[params.length];
	
	for (int i = 0; i < params.length; i++) 
		paramTypes[i] = params[i].getClass();
	
	Method method = getMethod(object.getClass(), methodName, paramTypes);
    if (Modifier.isStatic(method.getModifiers())) {
        throw new RuntimeException("Method '" + methodName + "' should not be a static method.");
    }
    method.setAccessible(true);
       try {
		return method.invoke(object, params);
	} catch (Exception e) {
		throw ExceptionUtils.unchecked(e);
	}
}
 
Example 18
Project: azeroth   File: ReflectUtils.java   View Source Code Vote up 4 votes
public static boolean isPublicInstanceField(Field field) {
    return Modifier.isPublic(field.getModifiers())
            && !Modifier.isStatic(field.getModifiers())
            && !Modifier.isFinal(field.getModifiers())
            && !field.isSynthetic();
}
 
Example 19
Project: lams   File: FieldUtils.java   View Source Code Vote up 3 votes
/**
 * Write a static Field.
 * @param field to write
 * @param value to set
 * @param forceAccess  whether to break scope restrictions using the
 *  <code>setAccessible</code> method. <code>False</code> will only
 *  match public fields.
 * @throws IllegalArgumentException if the field is null or not static
 * @throws IllegalAccessException if the field is not made accessible or is final
 */
public static void writeStaticField(Field field, Object value, boolean forceAccess) throws IllegalAccessException {
    if (field == null) {
        throw new IllegalArgumentException("The field must not be null");
    }
    if (!Modifier.isStatic(field.getModifiers())) {
        throw new IllegalArgumentException("The field '" + field.getName() + "' is not static");
    }
    writeField(field, (Object) null, value, forceAccess);
}
 
Example 20
Project: jetfuel   File: AspectMember.java   View Source Code Vote up 2 votes
/**
 * Tells whether the aspect member is static or not;
 * 
 * @return
 */
public final boolean isStatic() {
	return Modifier.isStatic(getModifiers());
}