List of usage examples for java.lang.reflect Modifier isStatic
public static boolean isStatic(int mod)
From source file:net.famzangl.minecraft.minebot.ai.command.CommandRegistry.java
private void getCommandsForClass(Class<?> commandClass, List<CommandDefinition> commands) { for (final Method m : commandClass.getMethods()) { if (Modifier.isStatic(m.getModifiers()) && m.isAnnotationPresent(AICommandInvocation.class)) { LOGGER.debug(MARKER_REGISTER, "Registering method: %s#%s()", commandClass.getCanonicalName(), m.getName());/* w w w. j a v a2 s .c om*/ commands.addAll(getCommandsForMethod(m)); } } }
From source file:com.yiji.openapi.sdk.util.Reflections.java
public static Set<String> getSimpleFieldNames(Class<?> pojoClass) { Set<String> propertyNames = new HashSet<String>(); Class<?> clazz = pojoClass; do {// w w w . ja v a 2 s .com Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (!Modifier.isStatic(field.getModifiers()) && (field.getType().isPrimitive() || isWrapClass(field.getType()) || field.getType().isAssignableFrom(Timestamp.class) || field.getType().isAssignableFrom(Date.class) || field.getType().isAssignableFrom(String.class) || field.getType().isAssignableFrom(Calendar.class))) { propertyNames.add(field.getName()); } } clazz = clazz.getSuperclass(); } while (clazz != null && !clazz.getSimpleName().equalsIgnoreCase("Object")); return propertyNames; }
From source file:com.baidu.jprotobuf.mojo.PreCompileMojo.java
/** * Execute goal./*from ww w . java2 s . c o m*/ * * @throws MojoExecutionException execution of the main class or one of the threads it generated failed. * @throws MojoFailureException something bad happened... */ public void execute() throws MojoExecutionException, MojoFailureException { if (isSkip()) { getLog().info("skipping execute as per configuraion"); return; } if (killAfter != -1) { getLog().warn("Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6."); } arguments = new String[] { outputParentDirectory.getAbsolutePath(), outputDirectory.getAbsolutePath(), filterClassPackage }; if (getLog().isDebugEnabled()) { StringBuffer msg = new StringBuffer("Invoking : "); msg.append(mainClass); msg.append(".main("); for (int i = 0; i < arguments.length; i++) { if (i > 0) { msg.append(", "); } msg.append(arguments[i]); } msg.append(")"); getLog().debug(msg); } final Log log = getLog(); IsolatedThreadGroup threadGroup = new IsolatedThreadGroup(mainClass /* name */); Thread bootstrapThread = new Thread(threadGroup, new Runnable() { public void run() { long current = System.currentTimeMillis(); try { Method main = Thread.currentThread().getContextClassLoader().loadClass(mainClass) .getMethod("main", new Class[] { String[].class }); if (!main.isAccessible()) { getLog().debug("Setting accessibility to true in order to invoke main()."); main.setAccessible(true); } if (!Modifier.isStatic(main.getModifiers())) { throw new MojoExecutionException( "Can't call main(String[])-method because it is not static."); } main.invoke(null, new Object[] { arguments }); } catch (NoSuchMethodException e) { // just pass it on Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), new Exception( "The specified mainClass doesn't contain a main method with appropriate signature.", e)); } catch (Exception e) { // just pass it on Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), e); } finally { log.info("JProtobuf pre compile done time took: " + (System.currentTimeMillis() - current) + "ms"); } } }, mainClass + ".main()"); bootstrapThread.setContextClassLoader(getClassLoader()); setSystemProperties(); bootstrapThread.start(); joinNonDaemonThreads(threadGroup); // It's plausible that spontaneously a non-daemon thread might be created as we try and shut down, // but it's too late since the termination condition (only daemon threads) has been triggered. if (keepAlive) { getLog().warn( "Warning: keepAlive is now deprecated and obsolete. Do you need it? Please comment on MEXEC-6."); waitFor(0); } if (cleanupDaemonThreads) { terminateThreads(threadGroup); try { threadGroup.destroy(); } catch (IllegalThreadStateException e) { getLog().warn("Couldn't destroy threadgroup " + threadGroup, e); } } if (originalSystemProperties != null) { System.setProperties(originalSystemProperties); } synchronized (threadGroup) { if (threadGroup.uncaughtException != null) { throw new MojoExecutionException("An exception occured while executing the Java class. " + threadGroup.uncaughtException.getMessage(), threadGroup.uncaughtException); } } registerSourceRoots(); }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void privateStaticFields() { 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); assertTrue(memberIterable.iterator().hasNext()); for (Member member : memberIterable) { assertTrue("member must be a field", member instanceof Field); int modifiers = member.getModifiers(); assertFalse(Modifier.isPublic(modifiers)); assertFalse(Modifier.isProtected(modifiers)); assertTrue(Modifier.isPrivate(modifiers)); assertTrue(Modifier.isStatic(modifiers)); }/*from w ww . j av a2 s . c o m*/ }
From source file:cn.webwheel.ActionSetter.java
public List<SetterInfo> parseSetters(Class cls) { List<SetterInfo> list = new ArrayList<SetterInfo>(); Field[] fields = cls.getFields(); for (int i = fields.length - 1; i >= 0; i--) { Field field = fields[i];//from w w w . j a va 2s . c om if (Modifier.isFinal(field.getModifiers())) continue; if (Modifier.isStatic(field.getModifiers())) continue; WebParam param = field.getAnnotation(WebParam.class); String name = field.getName(); if (field.getType().isArray()) name += "[]"; if (param != null && !param.value().isEmpty()) name = param.value(); SetterInfo si = getSetterInfo(field, name); if (si == null) { if (param != null) { logger.severe("wrong WebParam used at " + field); } continue; } list.add(si); } Method[] methods = cls.getMethods(); for (int i = methods.length - 1; i >= 0; i--) { Method method = methods[i]; WebParam param = method.getAnnotation(WebParam.class); String name = isSetter(method); if (name == null) { continue; } if (method.getParameterTypes()[0].isArray()) { name += "[]"; } if (param != null && !param.value().isEmpty()) { name = param.value(); } SetterInfo si = getSetterInfo(method, name); if (si == null) { if (param != null) { logger.severe("wrong WebParam used at " + method); } continue; } list.add(si); } return list; }
From source file:cn.webwheel.DefaultMain.java
private Action getAction(Class cls, Method method) { if (Modifier.isStatic(method.getModifiers())) { return method.getAnnotation(Action.class); }/* www. jav a 2 s. c o m*/ ArrayList<Action> actions = new ArrayList<Action>(); getActions(actions, new HashSet<Class>(), cls, method); if (actions.isEmpty()) return null; if (actions.get(0).disabled()) return null; if (actions.size() == 1) return actions.get(0); ActionImpl action = new ActionImpl(); for (Action act : actions) { if (action.merge(act)) { return action; } } return action; }
From source file:com.opengamma.language.external.ExternalFunctionHandler.java
/** * Creates a handler wrapper for a given class. * /*from ww w. ja va2s . c o m*/ * @param clazz the class containing external function methods */ public ExternalFunctionHandler(final Class<?> clazz) { final Constructor<?>[] constructors = clazz.getConstructors(); final Method[] methods = clazz.getMethods(); final ArrayList<PublishedFunction> functions = new ArrayList<PublishedFunction>( constructors.length + methods.length); // Only need an instance of the class if one or more annotated methods are not static. In this case, the same // instance will be re-used for each non-static method. If instantiation fails (e.g. no default constructor), just // skip instance methods and log warnings. Object sharedInstance = null; boolean instantiateFailed = false; for (Constructor<?> constructor : constructors) { if (!constructor.isAnnotationPresent(ExternalFunction.class)) { continue; } s_logger.debug("Found constructor {}", constructor); // If there is a constructor method, can only have static declarations instantiateFailed = true; functions.add(new ConstructorWrapper(constructor)); } for (Method method : methods) { if (!method.isAnnotationPresent(ExternalFunction.class)) { continue; } s_logger.debug("Found method {}", method); final Object instance; if (Modifier.isStatic(method.getModifiers())) { instance = null; } else { if (instantiateFailed) { s_logger.warn("Skipping method {}", method); continue; } else if (sharedInstance == null) { sharedInstance = tryGetInstance(clazz); if (sharedInstance == null) { s_logger.warn("Default instantiation failed for {}", clazz); s_logger.warn("Skipping method {}", method); instantiateFailed = true; continue; } } instance = sharedInstance; } functions.add(new MethodWrapper(method, instance)); } functions.trimToSize(); _functions = functions; }
From source file:net.jodah.typetools.TypeResolver.java
/** * Populates the {@code map} with variable/argument pairs for the {@code functionalInterface}. *//* w w w . ja va2 s . co m*/ private static void populateLambdaArgs(Class<?> functionalInterface, final Class<?> lambdaType, Map<TypeVariable<?>, Type> map) { if (GET_CONSTANT_POOL != null) { try { // Find SAM for (Method m : functionalInterface.getMethods()) { if (!m.isDefault() && !Modifier.isStatic(m.getModifiers()) && !m.isBridge()) { // Skip methods that override Object.class Method objectMethod = OBJECT_METHODS.get(m.getName()); if (objectMethod != null && Arrays.equals(m.getTypeParameters(), objectMethod.getTypeParameters())) continue; // Get functional interface's type params Type returnTypeVar = m.getGenericReturnType(); Type[] paramTypeVars = m.getGenericParameterTypes(); // Get lambda's type arguments ConstantPool constantPool = (ConstantPool) GET_CONSTANT_POOL.invoke(lambdaType); String[] methodRefInfo = constantPool.getMemberRefInfoAt( constantPool.getSize() - resolveMethodRefOffset(constantPool, lambdaType)); // Skip auto boxing methods if (methodRefInfo[1].equals("valueOf") && constantPool.getSize() > 22) { try { methodRefInfo = constantPool.getMemberRefInfoAt(constantPool.getSize() - resolveAutoboxedMethodRefOffset(constantPool, lambdaType)); } catch (MethodRefOffsetResolutionFailed ignore) { } } if (returnTypeVar instanceof TypeVariable) { Class<?> returnType = TypeDescriptor.getReturnType(methodRefInfo[2]) .getType(lambdaType.getClassLoader()); if (!returnType.equals(Void.class)) map.put((TypeVariable<?>) returnTypeVar, returnType); } TypeDescriptor[] arguments = TypeDescriptor.getArgumentTypes(methodRefInfo[2]); // Handle arbitrary object instance method references int paramOffset = 0; if (paramTypeVars[0] instanceof TypeVariable && paramTypeVars.length == arguments.length + 1) { Class<?> instanceType = TypeDescriptor.getObjectType(methodRefInfo[0]) .getType(lambdaType.getClassLoader()); map.put((TypeVariable<?>) paramTypeVars[0], instanceType); paramOffset = 1; } // Handle local final variables from context that are passed as arguments. int argOffset = 0; if (paramTypeVars.length < arguments.length) { argOffset = arguments.length - paramTypeVars.length; } for (int i = 0; i + argOffset < arguments.length; i++) { if (paramTypeVars[i] instanceof TypeVariable) { map.put((TypeVariable<?>) paramTypeVars[i + paramOffset], arguments[i + argOffset].getType(lambdaType.getClassLoader())); } } break; } } } catch (Exception ignore) { } } }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
public static void checkLegalCloudInvocationInfoDef(Object obj) { for (Field f : obj.getClass().getDeclaredFields()) { if (f.getAnnotation(CloudInvocationInfos.class) != null) { Type[] genericTypes = ((ParameterizedType) f.getGenericType()).getActualTypeArguments(); Class<?> typeParameter = (Class<?>) genericTypes[0]; if (!f.getType().equals(List.class) || genericTypes.length != 1 || !typeParameter.equals(InvocationInfo.class)) throw new IllegalDefinitionException("Illegal field type " + f.getType().getName() + " annotated with " + "@CloudInvocationInfos. You may only annotate java.util.List<InvocationInfo> fields."); if (Modifier.isStatic(f.getModifiers())) throw new IllegalDefinitionException("Illegal field " + f.getName() + " annotated with @CloudInvocationInfos. " + "Field has to be non-static."); }/*from w w w . j ava 2s . c o m*/ } }
From source file:org.teavm.flavour.json.emit.ClassInformationProvider.java
private void scanSetters(ClassInformation information, ReflectClass<?> cls) { for (ReflectMethod method : cls.getMethods()) { if (Modifier.isStatic(method.getModifiers())) { continue; }/*from w ww. j ava2 s. c om*/ if (isSetterName(method.getName()) && method.getParameterCount() == 1 && method.getReturnType() == context.findClass(void.class)) { if (hasExplicitPropertyDeclaration(method) || information.setterVisibility.match(method.getModifiers())) { String propertyName = decapitalize(method.getName().substring(3)); addSetter(information, propertyName, method); } } } }