List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
From source file:org.ireland.jnetty.dispatch.servlet.ServletConfigImpl.java
/** * Checks the class constructor for the public-zero arg. Class??public *///from w w w . j ava2 s. c o m public void checkConstructor() throws ServletException { Constructor[] constructors = _servletClass.getDeclaredConstructors(); Constructor zeroArg = null; for (int i = 0; i < constructors.length; i++) { if (constructors[i].getParameterTypes().length == 0) { zeroArg = constructors[i]; break; } } if (zeroArg == null) throw error(_servletClassName + " | must have a zero arg constructor. Servlets must have public zero-arg constructors.\n" + (constructors != null ? constructors[0] : null) + " is not a valid constructor."); if (!Modifier.isPublic(zeroArg.getModifiers())) throw error(zeroArg + " | must be public. '" + _servletClassName + "' must have a public, zero-arg constructor."); }
From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java
/** * Make the given constructor accessible, explicitly setting it accessible * if necessary. The {@code setAccessible(true)} method is only called * when actually necessary, to avoid unnecessary conflicts with a JVM * SecurityManager (if active).// www .ja v a 2s. c o m * @param ctor the constructor to make accessible * @see java.lang.reflect.Constructor#setAccessible */ public static void makeAccessible(Constructor<?> ctor) { if ((!Modifier.isPublic(ctor.getModifiers()) || !Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) { ctor.setAccessible(true); } }
From source file:com.microsoft.tfs.core.clients.build.internal.soapextensions.BuildEnumerationHelper.java
@SuppressWarnings("rawtypes") public static String[] getDisplayTextValues(final Class enumType) { final List<String> displayValues = new ArrayList<String>(); // Look for public static final fields in class that are same type as // the passed class. final Field[] fields = enumType.getFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].getType().equals(enumType) && Modifier.isPublic(fields[i].getModifiers()) && Modifier.isFinal(fields[i].getModifiers()) && Modifier.isStatic(fields[i].getModifiers())) { try { displayValues.add(getDisplayText(fields[i].get(null))); } catch (final IllegalAccessException e) { throw new BuildException( MessageFormat.format("IllegalAccessException calculating display values for {0}", //$NON-NLS-1$ enumType.getName()), e);//from w w w.j a v a 2 s. com } } } return displayValues.toArray(new String[displayValues.size()]); }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
private boolean isCandidate(Class<?> clazz) { if (clazz.isAnnotationPresent(Ignored.class)) { if (logger.isDebugEnabled()) { logger.debug("Ignores bean definition because it's present by @Ignored : " + clazz.getName()); }//from w w w . j a v a2 s .c om return false; } if (!Modifier.isPublic(clazz.getModifiers())) { if (logger.isDebugEnabled()) { logger.debug("Ignores bean definition because it's not a public class: " + clazz.getName()); } return false; } if (Modifier.isAbstract(clazz.getModifiers())) { if (logger.isDebugEnabled()) { logger.debug("Ignores bean definition because it's a abstract class: " + clazz.getName()); } return false; } if (clazz.getDeclaringClass() != null) { if (logger.isDebugEnabled()) { logger.debug("Ignores bean definition because it's a inner class: " + clazz.getName()); } return false; } return true; }
From source file:com.liferay.cli.support.util.ReflectionUtils.java
/** * Determine whether the given field is a "public static final" constant. * /*from www . ja v a 2s . co m*/ * @param field the field to check */ public static boolean isPublicStaticFinal(final Field field) { final int modifiers = field.getModifiers(); return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers); }
From source file:com.tmind.framework.pub.utils.MethodUtils.java
/** * <p>Return an accessible method (that is, one that can be invoked via * reflection) that implements the specified Method. If no such method * can be found, return <code>null</code>.</p> * * @param method The method that we wish to call *///from ww w. ja v a 2 s.com public static Method getAccessibleMethod(Method method) { // Make sure we have a method to check if (method == null) { return (null); } // If the requested method is not public we cannot call it if (!Modifier.isPublic(method.getModifiers())) { return (null); } // If the declaring class is public, we are done Class clazz = method.getDeclaringClass(); if (Modifier.isPublic(clazz.getModifiers())) { return (method); } // Check the implemented interfaces and subinterfaces method = getAccessibleMethodFromInterfaceNest(clazz, method.getName(), method.getParameterTypes()); return (method); }
From source file:es.caib.zkib.jxpath.util.ValueUtils.java
/** * Return an accessible method (that is, one that can be invoked via * reflection) that implements the specified method, by scanning through * all implemented interfaces and subinterfaces. If no such Method * can be found, return <code>null</code>. * * @param clazz Parent class for the interfaces to be checked * @param methodName Method name of the method we wish to call * @param parameterTypes The parameter type signatures * @return Method//from w w w. j a va 2 s . c om */ private static Method getAccessibleMethodFromInterfaceNest(Class clazz, String methodName, Class[] parameterTypes) { Method method = null; // Check the implemented interfaces of the parent class Class[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { // Is this interface public? if (!Modifier.isPublic(interfaces[i].getModifiers())) { continue; } // Does the method exist on this interface? try { method = interfaces[i].getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { //NOPMD //ignore } if (method != null) { break; } // Recursively check our parent interfaces method = getAccessibleMethodFromInterfaceNest(interfaces[i], methodName, parameterTypes); if (method != null) { break; } } // Return whatever we have found return (method); }
From source file:com.android.camera2.its.ItsSerializer.java
@SuppressWarnings("unchecked") public static JSONObject serialize(CameraMetadata md) throws ItsException { JSONObject jsonObj = new JSONObject(); Field[] allFields = md.getClass().getDeclaredFields(); if (md.getClass() == TotalCaptureResult.class) { allFields = CaptureResult.class.getDeclaredFields(); }/*from w w w . ja va2 s . co m*/ for (Field field : allFields) { if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()) && (field.getType() == CaptureRequest.Key.class || field.getType() == CaptureResult.Key.class || field.getType() == TotalCaptureResult.Key.class || field.getType() == CameraCharacteristics.Key.class) && field.getGenericType() instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) field.getGenericType(); Type[] argTypes = paramType.getActualTypeArguments(); if (argTypes.length > 0) { try { Type keyType = argTypes[0]; Object keyObj = field.get(md); MetadataEntry entry; if (keyType instanceof GenericArrayType) { entry = serializeArrayEntry(keyType, keyObj, md); } else { entry = serializeEntry(keyType, keyObj, md); } // TODO: Figure this weird case out. // There is a weird case where the entry is non-null but the toString // of the entry is null, and if this happens, the null-ness spreads like // a virus and makes the whole JSON object null from the top level down. // Not sure if it's a bug in the library or I'm just not using it right. // Workaround by checking for this case explicitly and not adding the // value to the jsonObj when it is detected. if (entry != null && entry.key != null && entry.value != null && entry.value.toString() == null) { Logt.w(TAG, "Error encountered serializing value for key: " + entry.key); } else if (entry != null) { jsonObj.put(entry.key, entry.value); } else { // Ignore. } } catch (IllegalAccessException e) { throw new ItsException("Access error for field: " + field + ": ", e); } catch (org.json.JSONException e) { throw new ItsException("JSON error for field: " + field + ": ", e); } } } } return jsonObj; }
From source file:com.snaplogic.snaps.firstdata.Create.java
static boolean isSetter(Method method) { return Modifier.isPublic(method.getModifiers()) && method.getReturnType().equals(void.class) && method.getParameterTypes().length == 1 && method.getName().matches(REGEX_SET); }
From source file:org.ebayopensource.turmeric.tools.errorlibrary.ErrorLibraryGeneratorTest.java
@Test public void validateContentOfErrorConstants() throws Exception { String errorConstantsClassName = "org.ebayopensource.turmeric.test.errorlibrary.turmericruntime.ErrorConstants"; String sampleErrorName = "svc_factory_custom_ser_no_bound_type"; // Initialize testing paths MavenTestingUtils.ensureEmpty(testingdir); File rootDir = TestResourceUtil.copyResourceRootDir("errorLibrary/TestErrorLibrary", testingdir); File binDir = new File(rootDir, "bin"); File gensrcDir = new File(rootDir, "gen-src"); MavenTestingUtils.ensureDirExists(binDir); MavenTestingUtils.ensureDirExists(gensrcDir); // @formatter:off String pluginParameters[] = { "-gentype", "genTypeConstants", "-pr", rootDir.getAbsolutePath(), "-domain", "TurmericRuntime", "-errorlibname", "TestErrorLibrary" }; // @formatter:on performDirectCodeGen(pluginParameters); Class<?> errConstant = compileGeneratedFile(errorConstantsClassName, gensrcDir, binDir); Assert.assertThat("errConstant", errConstant, notNullValue()); Assert.assertThat(errConstant.getName(), is(errorConstantsClassName)); Field member = errConstant.getField(sampleErrorName.toUpperCase()); Assert.assertThat("member", member, notNullValue()); Assert.assertThat("member.type", member.getType().getName(), is(String.class.getName())); Assert.assertThat("member.isFinal", Modifier.isFinal(member.getModifiers()), is(true)); Assert.assertThat("member.isPublic", Modifier.isPublic(member.getModifiers()), is(true)); Assert.assertThat("member.isStatic", Modifier.isStatic(member.getModifiers()), is(true)); Assert.assertThat("member.get(null)", (String) member.get(null), is(sampleErrorName)); }