List of usage examples for java.lang.reflect Modifier isStatic
public static boolean isStatic(int mod)
From source file:org.ajax4jsf.renderkit.compiler.MethodCallElement.java
private Method provideMethod(Map methods, Class cls, Object object, MethodCacheState state) { if (state.method != null) return state.method; if (methods.size() > 0) { for (int i = 0; i < state.signatures.length; i++) { state.method = (Method) methods.get(getClassesKey(state.signatures[i].arguments)); if (state.method != null) { state.current = state.signatures[i]; return state.method; }/*w ww.j a v a2 s. c o m*/ } } if (cls == null && object != null) cls = object.getClass(); Method[] ms = cls.getMethods(); for (int m = 0; m < ms.length; m++) { if (!ms[m].getName().equals(methodName)) continue; if (object == null && !Modifier.isStatic(ms[m].getModifiers())) continue; Class[] cs = ms[m].getParameterTypes(); Signature s = getMatchingArguments(cs, state.signatures); if (s == null) continue; state.current = s; state.method = ms[m]; methods.put(getClassesKey(s.arguments), ms[m]); return state.method; } return null; }
From source file:de.ks.flatadocdb.metamodel.Parser.java
protected boolean filterField(Field f) { int modifiers = f.getModifiers(); return !Modifier.isStatic(modifiers); }
From source file:com.github.mbenson.privileged.weaver.PrivilegedMethodWeaver.java
private CtClass createAction(CtClass type, CtMethod impl, Class<?> iface) throws NotFoundException, CannotCompileException, IOException { final boolean exc = impl.getExceptionTypes().length > 0; final CtClass actionType = classPool.get(iface.getName()); final String simpleName = generateActionClassname(impl); debug("Creating action type %s for method %s", simpleName, toString(impl)); final CtClass result = type.makeNestedClass(simpleName, true); result.addInterface(actionType);//from w w w. jav a 2 s . c o m final CtField owner; if (Modifier.isStatic(impl.getModifiers())) { owner = null; } else { owner = new CtField(type, generateName("owner"), result); owner.setModifiers(Modifier.PRIVATE | Modifier.FINAL); debug("Adding owner field %s to %s", owner.getName(), simpleName); result.addField(owner); } final List<String> propagatedParameters = new ArrayList<String>(); int index = -1; for (final CtClass param : impl.getParameterTypes()) { final String f = String.format("arg%s", Integer.valueOf(++index)); final CtField fld = new CtField(param, f, result); fld.setModifiers(Modifier.PRIVATE | Modifier.FINAL); debug("Copying parameter %s from %s to %s.%s", index, toString(impl), simpleName, f); result.addField(fld); propagatedParameters.add(f); } { final StrBuilder constructor = new StrBuilder(simpleName).append('('); boolean sep = false; final Body body = new Body(); for (final CtField fld : result.getDeclaredFields()) { if (sep) { constructor.append(", "); } else { sep = true; } constructor.append(fld.getType().getName()).append(' ').append(fld.getName()); body.appendLine("this.%1$s = %1$s;", fld.getName()); } constructor.append(") ").append(body.complete()); final String c = constructor.toString(); debug("Creating action constructor:"); debug(c); result.addConstructor(CtNewConstructor.make(c, result)); } { final StrBuilder run = new StrBuilder("public Object run() "); if (exc) { run.append("throws Exception "); } final Body body = new Body(); final CtClass rt = impl.getReturnType(); final boolean isVoid = rt.equals(CtClass.voidType); if (!isVoid) { body.append("return "); } final String deref = Modifier.isStatic(impl.getModifiers()) ? type.getName() : owner.getName(); final String call = String.format("%s.%s(%s)", deref, impl.getName(), StringUtils.join(propagatedParameters, ", ")); if (!isVoid && rt.isPrimitive()) { body.appendLine("%2$s.valueOf(%1$s);", call, ((CtPrimitiveType) rt).getWrapperName()); } else { body.append(call).append(';').appendNewLine(); if (isVoid) { body.appendLine("return null;"); } } run.append(body.complete()); final String r = run.toString(); debug("Creating run method:"); debug(r); result.addMethod(CtNewMethod.make(r, result)); } getClassFileWriter().write(result); debug("Returning action type %s", result); return result; }
From source file:org.apache.hadoop.fs.TestFilterFileSystem.java
@Test public void testFilterFileSystem() throws Exception { for (Method m : FileSystem.class.getDeclaredMethods()) { if (Modifier.isStatic(m.getModifiers())) continue; if (Modifier.isPrivate(m.getModifiers())) continue; if (Modifier.isFinal(m.getModifiers())) continue; try {//w w w. j a v a2 s . com DontCheck.class.getMethod(m.getName(), m.getParameterTypes()); LOG.info("Skipping " + m); } catch (NoSuchMethodException exc) { LOG.info("Testing " + m); try { FilterFileSystem.class.getDeclaredMethod(m.getName(), m.getParameterTypes()); } catch (NoSuchMethodException exc2) { LOG.error("FilterFileSystem doesn't implement " + m); throw exc2; } } } }
From source file:edu.umich.flowfence.sandbox.ResolvedQM.java
private InstanceMethodData resolveInstance(Class<?> definingClass, String methodName, Class<?>[] paramClasses, boolean bestMatch) throws Exception { if (localLOGD) { Log.d(TAG, "Resolving as instance"); }/*from w ww.j a v a2s . c o m*/ final Method method = definingClass.getMethod(methodName, paramClasses); if (Modifier.isStatic(method.getModifiers())) { throw new NoSuchMethodException("Method is static, but was resolved as instance"); } return new InstanceMethodData(method); }
From source file:com.opensource.frameworks.processframework.utils.MethodInvoker.java
/** * Invoke the specified method./*from w ww. j av a 2 s . co m*/ * <p>The invoker needs to have been prepared before. * @return the object (possibly null) returned by the method invocation, * or <code>null</code> if the method has a void return type * @throws InvocationTargetException if the target method threw an exception * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ public Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be <code>null</code>. Object targetObject = getTargetObject(); Method preparedMethod = getPreparedMethod(); if (targetObject == null && !Modifier.isStatic(preparedMethod.getModifiers())) { throw new IllegalArgumentException("Target method must not be non-static without a target"); } ReflectionUtils.makeAccessible(preparedMethod); return preparedMethod.invoke(targetObject, getArguments()); }
From source file:com.xiongyingqi.util.MethodInvoker.java
/** * Invoke the specified method./*from w w w . j a va 2 s. com*/ * <p>The invoker needs to have been prepared before. * * @return the object (possibly null) returned by the method invocation, * or {@code null} if the method has a void return type * @throws java.lang.reflect.InvocationTargetException if the target method threw an exception * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ public Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be {@code null}. Object targetObject = getTargetObject(); Method preparedMethod = getPreparedMethod(); if (targetObject == null && !Modifier.isStatic(preparedMethod.getModifiers())) { throw new IllegalArgumentException("Target method must not be non-static without a target"); } ReflectionUtils.makeAccessible(preparedMethod); return preparedMethod.invoke(targetObject, getArguments()); }
From source file:org.apache.openjpa.enhance.PCSubclassValidator.java
private void checkMethodIsSubclassable(Method meth, FieldMetaData fmd) { String className = fmd.getDefiningMetaData().getDescribedType().getName(); if (!(Modifier.isProtected(meth.getModifiers()) || Modifier.isPublic(meth.getModifiers()))) addError(loc.get("subclasser-private-accessors-unsupported", className, meth.getName()), fmd); if (Modifier.isFinal(meth.getModifiers())) addError(loc.get("subclasser-final-methods-not-allowed", className, meth.getName()), fmd); if (Modifier.isNative(meth.getModifiers())) addContractViolation(loc.get("subclasser-native-methods-not-allowed", className, meth.getName()), fmd); if (Modifier.isStatic(meth.getModifiers())) addError(loc.get("subclasser-static-methods-not-supported", className, meth.getName()), fmd); }
From source file:com.founder.e5.config.ConfigReader.java
/** * /*from ww w . ja va 2 s . c o m*/ * configcontext */ private void initRestart() throws Exception { InfoRestart[] infos = (InfoRestart[]) listRestart.toArray(new InfoRestart[0]); if (infos == null) return; //Restart init for (int i = 0; i < infos.length; i++) { Class myClass = Class.forName(infos[i].getInvokeClass()); Method method = myClass.getMethod(infos[i].getInvokeMethod(), null); if (Modifier.isStatic(method.getModifiers())) method.invoke(null, null); else method.invoke(myClass.newInstance(), null); } //DBSession Init for (int i = 0; i < listDBSession.size(); i++) { InfoDBSession db = (InfoDBSession) getDBSessions().get(i); DBSessionFactory.registerDB(db.getName(), db.getImplementation()); } //ID Init for (int i = 0; i < listID.size(); i++) { InfoID id = (InfoID) getIDs().get(i); EUID.registerID(id.getName(), id.getType(), id.getParam()); } }
From source file:edu.umich.flowfence.sandbox.ResolvedQM.java
private MethodData resolveStatic(Class<?> definingClass, String methodName, Class<?>[] paramClasses, boolean bestMatch) throws Exception { if (localLOGD) { Log.d(TAG, "Resolving as static"); }//from w w w .j a va 2 s. c om final Method method = definingClass.getMethod(methodName, paramClasses); if (!Modifier.isStatic(method.getModifiers())) { throw new NoSuchMethodException("Method is instance, but was resolved as static"); } return new MethodData(method); }