List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
From source file:com.github.rinde.rinsim.scenario.measure.Metrics.java
/** * Computes the number of occurrences of each event type in the specified * {@link Scenario}./*w w w . jav a 2s .co m*/ * @param s The scenario to check. * @return A {@link ImmutableMultiset} of event types. */ public static ImmutableMultiset<Class<?>> getEventTypeCounts(Scenario s) { final Multiset<Class<?>> set = LinkedHashMultiset.create(); for (final TimedEvent te : s.getEvents()) { set.add(te.getClass()); } final List<Class<?>> toMove = new ArrayList<>(); for (final Class<?> c : set.elementSet()) { if (!Modifier.isPublic(c.getModifiers()) && TimedEvent.class.isAssignableFrom(c.getSuperclass()) && !set.contains(c.getSuperclass())) { toMove.add(c); } } for (final Class<?> c : toMove) { set.add(c.getSuperclass(), set.count(c)); set.remove(c, set.count(c)); } return ImmutableMultiset.copyOf(set); }
From source file:org.hisp.dhis.webwork.configuration.UrlXmlConfigurationProvider.java
protected boolean verifyAction(String className, String name, Location loc) { try {/*from www . j a v a 2 s .c om*/ Class clazz = ObjectFactory.getObjectFactory().getClassInstance(className); if (ObjectFactory.getObjectFactory().isNoArgConstructorRequired()) { if (!Modifier.isPublic(clazz.getModifiers())) { LOG.error("Action class [" + className + "] is not public, skipping action [" + name + "]"); return false; } clazz.getConstructor(new Class[] {}); } return true; } catch (ClassNotFoundException e) { LOG.error("Action class [" + className + "] not found, skipping action [" + name + "] at " + loc, e); return false; } catch (NoSuchMethodException e) { LOG.error("Action class [" + className + "] does not have a public no-arg constructor," + " skipping action [" + name + "] at " + loc, e); return false; } catch (Exception ex) { throw new ConfigurationException(ex, loc); } }
From source file:com.weibo.api.motan.core.extension.ExtensionLoader.java
private void checkClassPublic(Class<T> clz) { if (!Modifier.isPublic(clz.getModifiers())) { failThrows(clz, "Error is not a public class"); }//from w w w.ja v a2 s . c o m }
From source file:com.google.code.siren4j.util.ReflectionUtils.java
/** * Determine if the method is a setter./* w w w . j a va2 s.c o m*/ * * @param method * @return */ public static boolean isSetter(Method method) { String name = method.getName(); String[] splitname = StringUtils.splitByCharacterTypeCamelCase(name); return method.getReturnType().equals(void.class) && Modifier.isPublic(method.getModifiers()) && splitname[0].equals(SETTER_PREFIX); }
From source file:org.geomajas.internal.service.DtoConverterServiceImpl.java
private Object getBeanProperty(Object bean, String property) throws GeomajasException { PropertyDescriptor d = BeanUtils.getPropertyDescriptor(bean.getClass(), property); if (d != null) { Method m = d.getReadMethod(); if (m != null) { if (!Modifier.isPublic(m.getDeclaringClass().getModifiers())) { m.setAccessible(true);//from w ww . j av a 2s . c o m } Object value; try { value = m.invoke(bean); } catch (Exception e) { // NOSONAR throw new GeomajasException(e); } return value; } } return null; }
From source file:net.minecraftforge.common.config.ConfigManager.java
private static void sync(Configuration cfg, Class<?> cls, String modid, String category, boolean loading, Object instance) {/* www . j av a2 s . c o m*/ for (Field f : cls.getDeclaredFields()) { if (!Modifier.isPublic(f.getModifiers())) continue; //Only the root class may have static fields. Otherwise category tree nodes of the same type would share the //contained value messing up the sync if (Modifier.isStatic(f.getModifiers()) != (instance == null)) continue; if (f.isAnnotationPresent(Config.Ignore.class)) continue; String comment = null; Comment ca = f.getAnnotation(Comment.class); if (ca != null) comment = NEW_LINE.join(ca.value()); String langKey = modid + "." + (category.isEmpty() ? "" : category + Configuration.CATEGORY_SPLITTER) + f.getName().toLowerCase(Locale.ENGLISH); LangKey la = f.getAnnotation(LangKey.class); if (la != null) langKey = la.value(); boolean requiresMcRestart = f.isAnnotationPresent(Config.RequiresMcRestart.class); boolean requiresWorldRestart = f.isAnnotationPresent(Config.RequiresWorldRestart.class); if (FieldWrapper.hasWrapperFor(f)) //Wrappers exist for primitives, enums, maps and arrays { if (Strings.isNullOrEmpty(category)) throw new RuntimeException( "An empty category may not contain anything but objects representing categories!"); try { IFieldWrapper wrapper = FieldWrapper.get(instance, f, category); ITypeAdapter adapt = wrapper.getTypeAdapter(); Property.Type propType = adapt.getType(); for (String key : wrapper.getKeys()) //Iterate the fully qualified property names the field provides { String suffix = StringUtils.replaceOnce(key, wrapper.getCategory() + Configuration.CATEGORY_SPLITTER, ""); boolean existed = exists(cfg, wrapper.getCategory(), suffix); if (!existed || loading) //Creates keys in category specified by the wrapper if new ones are programaticaly added { Property property = property(cfg, wrapper.getCategory(), suffix, propType, adapt.isArrayAdapter()); adapt.setDefaultValue(property, wrapper.getValue(key)); if (!existed) adapt.setValue(property, wrapper.getValue(key)); else wrapper.setValue(key, adapt.getValue(property)); } else //If the key is not new, sync according to shouldReadFromVar() { Property property = property(cfg, wrapper.getCategory(), suffix, propType, adapt.isArrayAdapter()); Object propVal = adapt.getValue(property); Object mapVal = wrapper.getValue(key); if (shouldReadFromVar(property, propVal, mapVal)) adapt.setValue(property, mapVal); else wrapper.setValue(key, propVal); } } ConfigCategory confCat = cfg.getCategory(wrapper.getCategory()); for (Property property : confCat.getOrderedValues()) //Iterate the properties to check for new data from the config side { String key = confCat.getQualifiedName() + Configuration.CATEGORY_SPLITTER + property.getName(); if (!wrapper.handlesKey(key)) continue; if (loading || !wrapper.hasKey(key)) { Object value = wrapper.getTypeAdapter().getValue(property); wrapper.setValue(key, value); } } if (loading) wrapper.setupConfiguration(cfg, comment, langKey, requiresMcRestart, requiresWorldRestart); } catch (Exception e) { String format = "Error syncing field '%s' of class '%s'!"; String error = String.format(format, f.getName(), cls.getName()); throw new RuntimeException(error, e); } } else if (f.getType().getSuperclass() != null && f.getType().getSuperclass().equals(Object.class)) { //If the field extends Object directly, descend the object tree and access the objects members Object newInstance = null; try { newInstance = f.get(instance); } catch (IllegalAccessException e) { throw new RuntimeException(e); } //Setup the sub category with its respective name, comment, language key, etc. String sub = (category.isEmpty() ? "" : category + Configuration.CATEGORY_SPLITTER) + getName(f).toLowerCase(Locale.ENGLISH); ConfigCategory confCat = cfg.getCategory(sub); confCat.setComment(comment); confCat.setLanguageKey(langKey); confCat.setRequiresMcRestart(requiresMcRestart); confCat.setRequiresWorldRestart(requiresWorldRestart); sync(cfg, f.getType(), modid, sub, loading, newInstance); } else { String format = "Can't handle field '%s' of class '%s': Unknown type."; String error = String.format(format, f.getName(), cls.getCanonicalName()); throw new RuntimeException(error); } } }
From source file:gemlite.core.util.Util.java
public final static boolean isPublicFunction(Class<?> c) { int modifiers = c.getModifiers(); return Modifier.isPublic(modifiers); }
From source file:com.kelveden.rastajax.core.ResourceClassLoader.java
private List<ResourceClassMethod> loadMethods(final Class<?> candidateResourceClass) { final List<ResourceClassMethod> methodsOnResource = new ArrayList<ResourceClassMethod>(); Method[] methods;/*from w w w. j a v a 2 s . c om*/ try { methods = candidateResourceClass.getDeclaredMethods(); } catch (NoClassDefFoundError e) { LOGGER.warn( "Could not process candidate resource class {} as a class referenced in it could not be found.", candidateResourceClass.getName(), e); return methodsOnResource; } for (Method method : methods) { if (Modifier.isPublic(method.getModifiers())) { final ResourceClassMethod methodOnResource = loadMethod(candidateResourceClass, method); if (methodOnResource != null) { methodsOnResource.add(methodOnResource); } } } return methodsOnResource; }
From source file:com.duy.pascal.interperter.libraries.PascalLibraryManager.java
public static ArrayList<DescriptionImpl> getAllMethodDescription(Class<?>... classes) { ArrayList<DescriptionImpl> suggestItems = new ArrayList<>(); for (Class<?> aClass : classes) { Method[] methods = aClass.getDeclaredMethods(); for (Method method : methods) { if (AndroidLibraryUtils.getSdkVersion() >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (method.getAnnotation(PascalMethod.class) != null) { PascalMethod annotation = method.getAnnotation(PascalMethod.class); String description = annotation.description(); // TODO: 17-Aug-17 // suggestItems.add(new FunctionDescription(StructureType.TYPE_FUNCTION, // Name.create(method.getName()), description, method.)); }/* w w w . ja v a 2 s .c o m*/ } else { if (Modifier.isPublic(method.getModifiers())) { suggestItems.add(new DescriptionImpl(StructureType.TYPE_FUNCTION, method.getName())); } } } } return suggestItems; }
From source file:net.servicefixture.util.ReflectionUtils.java
/** * Returns true if it is an enumeration type. * /*w ww . java 2 s .c om*/ * @param type * @return */ public static boolean isEnumarationPatternClass(Class type) { try { //JDK1.4 Enumeration Pattern Constructor[] constructors = type.getConstructors(); for (int i = 0; i < constructors.length; i++) { if (Modifier.isPublic(constructors[i].getModifiers())) { return false; } } type.getMethod("fromString", new Class[] { String.class }); return true; } catch (SecurityException e) { } catch (NoSuchMethodException e) { } return false; }