当前位置: 首页>>代码示例>>Java>>正文


Java Modifier.STATIC属性代码示例

本文整理汇总了Java中java.lang.reflect.Modifier.STATIC属性的典型用法代码示例。如果您正苦于以下问题:Java Modifier.STATIC属性的具体用法?Java Modifier.STATIC怎么用?Java Modifier.STATIC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.lang.reflect.Modifier的用法示例。


在下文中一共展示了Modifier.STATIC属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllMethod

/**
 * 获取框架api类中所有符合要求的api
 *
 * @param injectedCls
 * @return
 * @throws Exception
 */
private static HashMap<String, Method> getAllMethod(Class injectedCls) throws Exception {
    HashMap<String, Method> mMethodsMap = new HashMap<>();
    Method[] methods = injectedCls.getDeclaredMethods();
    for (Method method : methods) {
        String name;
        if (method.getModifiers() != (Modifier.PUBLIC | Modifier.STATIC) || (name = method.getName()) == null) {
            continue;
        }
        Class[] parameters = method.getParameterTypes();
        if (null != parameters && parameters.length == 4) {
            if (parameters[1] == WebView.class && parameters[2] == JSONObject.class && parameters[3] == Callback.class) {
                mMethodsMap.put(name, method);
            }
        }
    }
    return mMethodsMap;
}
 
开发者ID:dailc,项目名称:hybrid-jsbridge-simple,代码行数:24,代码来源:JSBridge.java

示例2: ListenerSet

public ListenerSet() {
    eventTypes = new Vector<>();
    try {
        Class<?> eventClass = Class.forName("java.awt.AWTEvent");
        Field[] fields = eventClass.getFields();
        theWholeMask = 0;
        long eventMask;
        for (Field field : fields) {
            if ((field.getModifiers()
                    & (Modifier.PUBLIC | Modifier.STATIC)) != 0
                    && field.getType().equals(Long.TYPE)
                    && field.getName().endsWith("_EVENT_MASK")) {
                eventMask = (Long) field.get(null);
                eventTypes.add(new EventType(eventMask));
                theWholeMask = theWholeMask | eventMask;
            }
        }
    } catch (ClassNotFoundException | IllegalAccessException e) {
        JemmyProperties.getCurrentOutput().printStackTrace(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:EventTool.java

示例3: doClassStaticMethod

public static Object doClassStaticMethod(Class<?> belongClass,String method,Map<String,Object> paras) throws InvocationTargetException, IllegalAccessException {
    Method[] methods =belongClass.getMethods();
    String methodParaJson=null;
    if(paras!=null && paras.containsKey("req")){
        methodParaJson = String.valueOf(paras.get("req"));
    }
    for(Method m:methods){
        if(m.getName().equalsIgnoreCase(method) && (m.getModifiers()& Modifier.STATIC)== Modifier.STATIC){
            Type[] paraTypes = m.getParameterTypes();
            if(paraTypes.length==0 && methodParaJson==null){
                return m.invoke(null);
            }else if(paraTypes.length==1 && methodParaJson !=null){
                Gson gson = new Gson();
                return m.invoke(null,gson.fromJson(methodParaJson, paraTypes[0]));
            }
        }
    }
    return new NoSuchMethodException("no public static method "+method+" be found in"+belongClass.getName());
}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:19,代码来源:Tools.java

示例4: parseAndValidatateMetadata

@Override
public List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) {
  checkState(targetType.getTypeParameters().length == 0, "Parameterized types unsupported: %s",
             targetType.getSimpleName());
  checkState(targetType.getInterfaces().length <= 1, "Only single inheritance supported: %s",
             targetType.getSimpleName());
  if (targetType.getInterfaces().length == 1) {
    checkState(targetType.getInterfaces()[0].getInterfaces().length == 0,
               "Only single-level inheritance supported: %s",
               targetType.getSimpleName());
  }
  Map<String, MethodMetadata> result = new LinkedHashMap<String, MethodMetadata>();
  for (Method method : targetType.getMethods()) {
    if (method.getDeclaringClass() == Object.class ||
        (method.getModifiers() & Modifier.STATIC) != 0 ||
        Util.isDefault(method)) {
      continue;
    }
    MethodMetadata metadata = parseAndValidateMetadata(targetType, method);
    checkState(!result.containsKey(metadata.configKey()), "Overrides unsupported: %s",
               metadata.configKey());
    result.put(metadata.configKey(), metadata);
  }
  return new ArrayList<MethodMetadata>(result.values());
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:25,代码来源:Contract.java

示例5: assertStaticClassVarsAreFromPackage

private static boolean assertStaticClassVarsAreFromPackage() {
	//String packagename = System.getProperty("jawk.rtPackgeName", "org.jawk.jrt");
	String packagename = "org.jawk.jrt";
	if (packagename != null) {
		// use reflection to get all static Class definitions
		// and verify that they are members of the
		// runtime package
		Class c = AwkCompilerImpl.class;
		// foreach field in declared in the class...
		for (Field f : c.getDeclaredFields()) {
			int mod = f.getModifiers();
			// if a "private static final" member...
			if (       (mod & Modifier.PRIVATE) > 0
					&& (mod & Modifier.STATIC) > 0
					&& (mod & Modifier.FINAL) > 0
					&& f.getType() == Class.class)
			{
				try {
					// obtain the value of the field
					// and apply it here!
					Object o = f.get(null);
					Class cls = (Class) o;
					if (!cls.getPackage().getName().equals(packagename)) {
						throw new AssertionError("class " + c.toString() + " is not contained within '" + packagename + "' package. Field = " + f.toString());
					}
				} catch (IllegalAccessException iae) {
					throw new AssertionError(iae); // NOTE Thought there is an AssertionError#AssertionError(String, Throwable) ctor aswell, it was only introduced in Java 1.7, so we should not yet use it.
				}
			}
		}
	}
	// all's well
	return true;
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:34,代码来源:AwkCompilerImpl.java

示例6: main

public static void main(String[] args) throws Exception {

      // Check that all the lambda methods are private instance synthetic
      for (Class<?> k : new Class<?>[] { A.class, B.class, C.class }) {
         Method[] methods = k.getDeclaredMethods();
         int lambdaCount = 0;
         for(Method m : methods) {
            if (m.getName().startsWith("lambda$")) {
               ++lambdaCount;
               int mod = m.getModifiers();
               if ((mod & Modifier.PRIVATE) == 0) {
                  throw new Exception("Expected " + m + " to be private");
               }
               if (!m.isSynthetic()) {
                  throw new Exception("Expected " + m + " to be synthetic");
               }
               if ((mod & Modifier.STATIC) != 0) {
                  throw new Exception("Expected " + m + " to be instance method");
               }
            }
         }
         if (lambdaCount == 0) {
            throw new Exception("Expected at least one lambda method");
         }
      }

      /*
       * Unless the lambda methods are private, this will fail with:
       *  AbstractMethodError:
       *        Conflicting default methods: A.lambda$0 B.lambda$0 C.lambda$0
       */
      X x = new PrivateLambdas();
      if (!x.name().equals(" A B C")) {
         throw new Exception("Expected ' A B C' got: " + x.name());
      }
   }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:PrivateLambdas.java

示例7: getAllFields

public static List<Field> getAllFields(Class<?> clazz, Class<? extends Annotation> annotation,
        boolean excludeStaticField) throws Exception {
    // Precondition checking
    if (clazz == null) {
        return null;
    }

    List<Field> r = new LinkedList<Field>();
    Class<?> parent = clazz;
    while (parent != null) {
        for (Field f : parent.getDeclaredFields()) {
            f.setAccessible(true);

            if (excludeStaticField && (f.getModifiers() & Modifier.STATIC) != 0) {
                continue;
            }
            if (annotation != null && !f.isAnnotationPresent(annotation)) {
                continue;
            }

            r.add(f);
        }

        parent = parent.getSuperclass();
    }
    return r;
}
 
开发者ID:baidu,项目名称:dlock,代码行数:27,代码来源:ReflectionUtils.java

示例8: getDeclaredSUID

/**
 * 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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:ObjectStreamClass.java

示例9: isStaticInnerClass

/**
 * 是否为静态内部类
 *
 * @param cls
 * @return
 */
private static boolean isStaticInnerClass(Class cls) {
    if (cls != null && cls.isMemberClass()) {
        int modifiers = cls.getModifiers();
        if ((modifiers & Modifier.STATIC) == Modifier.STATIC) {
            return true;
        }
    }
    return false;
}
 
开发者ID:RockyQu,项目名称:Logg,代码行数:15,代码来源:Utils.java

示例10: isVarHandleMethodInvoke

public boolean isVarHandleMethodInvoke() {
    final int bits = MH_INVOKE_MODS &~ Modifier.PUBLIC;
    final int negs = Modifier.STATIC;
    if (testFlags(bits | negs, bits) &&
        clazz == VarHandle.class) {
        return isVarHandleMethodInvokeName(name);
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:MemberName.java

示例11: getInheritableMethod

/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 *
 * Copied from the Merlin java.io.ObjectStreamClass.
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:ObjectStreamClass.java

示例12: getDefaultSerialFields

/**
 * 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]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ObjectStreamClass.java

示例13: getInheritableMethod

/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:ObjectStreamClass.java

示例14: isDefault

/**
 * Identifies a method as a default instance method.
 */
public static boolean isDefault(Method method) {
  // Default methods are public non-abstract, non-synthetic, and non-static instance methods
  // declared in an interface.
  // method.isDefault() is not sufficient for our usage as it does not check
  // for synthetic methods.  As a result, it picks up overridden methods as well as actual default methods.
  final int SYNTHETIC = 0x00001000;
  return ((method.getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC | SYNTHETIC)) ==
          Modifier.PUBLIC) && method.getDeclaringClass().isInterface();
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:12,代码来源:Util.java

示例15: staticField

public HackedField<C, Object> staticField(String name)
        throws HackAssertionException {
    return new HackedField(this.mClass, name, Modifier.STATIC);
}
 
开发者ID:vipycm,项目名称:mao-android,代码行数:4,代码来源:Hack.java


注:本文中的java.lang.reflect.Modifier.STATIC属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。