本文整理汇总了Java中java.lang.reflect.Modifier.PUBLIC属性的典型用法代码示例。如果您正苦于以下问题:Java Modifier.PUBLIC属性的具体用法?Java Modifier.PUBLIC怎么用?Java Modifier.PUBLIC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.lang.reflect.Modifier
的用法示例。
在下文中一共展示了Modifier.PUBLIC属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSerializableConstructor
/**
* Returns subclass-accessible no-arg constructor of first non-serializable
* superclass, or null if none found. Access checks are disabled on the
* returned constructor (if any).
*/
private static Constructor<?> getSerializableConstructor(Class<?> cl) {
Class<?> initCl = cl;
while (Serializable.class.isAssignableFrom(initCl)) {
if ((initCl = initCl.getSuperclass()) == null) {
return null;
}
}
try {
Constructor<?> cons = initCl.getDeclaredConstructor((Class<?>[]) null);
int mods = cons.getModifiers();
if ((mods & Modifier.PRIVATE) != 0 ||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
!packageEquals(cl, initCl)))
{
return null;
}
cons = reflFactory.newConstructorForSerialization(cl, cons);
cons.setAccessible(true);
return cons;
} catch (NoSuchMethodException ex) {
return null;
}
}
示例2: reflectProperties
private static Property[] reflectProperties(Class<? extends AbstractDao<?, ?>> daoClass)
throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException {
Class<?> propertiesClass = Class.forName(daoClass.getName() + "$Properties");
Field[] fields = propertiesClass.getDeclaredFields();
ArrayList<Property> propertyList = new ArrayList<Property>();
final int modifierMask = Modifier.STATIC | Modifier.PUBLIC;
for (Field field : fields) {
// There might be other fields introduced by some tools, just ignore them (see issue #28)
if ((field.getModifiers() & modifierMask) == modifierMask) {
Object fieldValue = field.get(null);
if (fieldValue instanceof Property) {
propertyList.add((Property) fieldValue);
}
}
}
Property[] properties = new Property[propertyList.size()];
for (Property property : propertyList) {
if (properties[property.ordinal] != null) {
throw new DaoException("Duplicate property ordinals");
}
properties[property.ordinal] = property;
}
return properties;
}
示例3: getSetMethod
/**
* @param type
* @param name
* @return Method
*/
public static Method getSetMethod(Class<?> type, String name) {
Method[] methods = type.getMethods();
String methodName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
for(Method method : methods) {
if(method.getModifiers() != Modifier.PUBLIC) {
continue;
}
if(method.getName().equals(methodName)) {
if(method.getParameterTypes().length == 1) {
return method;
}
}
}
return null;
}
示例4: 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;
}
}
示例5: isUsableCustomLayoutClass
private static boolean isUsableCustomLayoutClass(Class layoutClass) {
if ((layoutClass.getModifiers() & Modifier.PUBLIC) == 0) {
return false;
}
try {
if (layoutClass.getConstructor(new Class[0]) != null) {
return true; // has a public constructor without parameters
}
} catch (NoSuchMethodException ex) {
}
return CreationFactory.getDescriptor(layoutClass) != null;
}
示例6: resolveProxyClass
/**
* ObjectInputStream.resolveProxyClass has some funky way of using
* the incorrect class loader to resolve proxy classes, let's do it our way instead
*/
@Override
protected Class<?> resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException {
ClassLoader latestLoader;
if (classLoaders != null && classLoaders.length > 0) {
latestLoader = classLoaders[0];
} else {
latestLoader = null;
}
ClassLoader nonPublicLoader = null;
boolean hasNonPublicInterface = false;
// define proxy in class loader of non-public interface(s), if any
Class<?>[] classObjs = new Class[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
Class<?> cl = this.resolveClass(interfaces[i]);
if (latestLoader==null) latestLoader = cl.getClassLoader();
if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
if (hasNonPublicInterface) {
if (nonPublicLoader != cl.getClassLoader()) {
throw new IllegalAccessError(
"conflicting non-public interface class loaders");
}
} else {
nonPublicLoader = cl.getClassLoader();
hasNonPublicInterface = true;
}
}
classObjs[i] = cl;
}
try {
return Proxy.getProxyClass(hasNonPublicInterface ? nonPublicLoader
: latestLoader, classObjs);
} catch (IllegalArgumentException e) {
throw new ClassNotFoundException(null, e);
}
}
示例7: findClickMethods
private void findClickMethods(Method[] methods) {
for (Method method : methods) {
String methodName = method.getName();
if (!methodName.equals(ON_CLICK_METHOD_NAME) && methodName.startsWith(ON_CLICK_METHOD_NAME) ||
(methodName.startsWith(ON_CLICK_METHOD_PREFIX) && methodName.endsWith(ON_CLICK_METHOD_POSTFIX))) {
int modifiers = method.getModifiers();
if ((modifiers & Modifier.PUBLIC) != 0 && (modifiers & MODIFIERS_IGNORE) == 0) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 3 || parameterTypes.length == 4) {
Class<?> viewType = parameterTypes[0];
Class<?> cellType = parameterTypes[1];
Class<?> clickIntType = parameterTypes[2];
if (View.class.isAssignableFrom(viewType)
&& BaseCell.class.isAssignableFrom(cellType)
&& (clickIntType.equals(int.class) || clickIntType.equals(Integer.class))) {
if (parameterTypes.length == 4) {
Class<?> clickParamsType = parameterTypes[3];
if (Map.class.isAssignableFrom(clickParamsType)) {
mOnClickMethods.put(viewType, new OnClickMethod(4, method));
}
} else {
mOnClickMethods.put(viewType, new OnClickMethod(3, method));
}
}
}
}
}
}
}
示例8: resolveProxyClass
@Override
protected Class resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException {
ClassLoader nonPublicLoader = null;
boolean hasNonPublicInterface = false;
// define proxy in class loader of non-public
// interface(s), if any
Class[] classObjs = new Class[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
Class cl = getCachedClass(interfaces[i]);
if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
if (hasNonPublicInterface) {
if (nonPublicLoader != cl.getClassLoader()) {
String s = "conflicting non-public interface class loaders";
throw new IllegalAccessError(s);
}
} else {
nonPublicLoader = cl.getClassLoader();
hasNonPublicInterface = true;
}
}
classObjs[i] = cl;
}
try {
if (hasNonPublicInterface) {
return Proxy.getProxyClass(nonPublicLoader, classObjs);
} else {
return ClassPathLoader.getLatest().getProxyClass(classObjs);
}
} catch (IllegalArgumentException e) {
throw new ClassNotFoundException(null, e);
}
}
示例9: generateConstructors
private boolean generateConstructors() throws AdaptationException {
boolean gotCtor = false;
boolean canBeAutoConverted = false;
for (final Constructor<?> ctor: superClass.getDeclaredConstructors()) {
final int modifier = ctor.getModifiers();
if((modifier & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0 && !isCallerSensitive(ctor)) {
canBeAutoConverted = generateConstructors(ctor) | canBeAutoConverted;
gotCtor = true;
}
}
if(!gotCtor) {
throw new AdaptationException(ERROR_NO_ACCESSIBLE_CONSTRUCTOR, superClass.getCanonicalName());
}
return canBeAutoConverted;
}
示例10: createJava
public static String createJava(String zpackage, String name, int kind, int visibility, int modifier, boolean b) {
String m = "";
switch (modifier) {
case Modifier.ABSTRACT:
m = "abstract ";
break;
case Modifier.FINAL:
m = "final ";
break;
}
String v = "";
switch (visibility) {
case Modifier.PUBLIC:
v = "public ";
break;
}
String k = "class";
switch (kind) {
case 0:
k = "class";
break;
case 1:
k = "interface";
break;
case 2:
k = "enum";
break;
}
zpackage = zpackage.isEmpty() ? "" : "package " + zpackage + ";";
return String.format(JAVA_TEMPLATE, v, m, k, name, zpackage);
}
示例11: getMapperMethodsByClazz
private static void getMapperMethodsByClazz(final List<Method> result, final Class clazz) {
if (clazz != null && clazz.isAnnotationPresent(LuaViewLib.class)) {//XXXMapper
getMapperMethodsByClazz(result, clazz.getSuperclass());//处理super
final Method[] methods = clazz.getDeclaredMethods();
if (methods != null && methods.length > 0) {
for (final Method method : methods) {//add self
if (method.getModifiers() == Modifier.PUBLIC) {//public 方法才行
result.add(method);
}
}
}
}
}
示例12: translateModifiers
/**
* Convert modifier bits from private coding used by
* the compiler to that of java.lang.reflect.Modifier.
*/
static int translateModifiers(long flags) {
int result = 0;
if ((flags & Flags.ABSTRACT) != 0)
result |= Modifier.ABSTRACT;
if ((flags & Flags.FINAL) != 0)
result |= Modifier.FINAL;
if ((flags & Flags.INTERFACE) != 0)
result |= Modifier.INTERFACE;
if ((flags & Flags.NATIVE) != 0)
result |= Modifier.NATIVE;
if ((flags & Flags.PRIVATE) != 0)
result |= Modifier.PRIVATE;
if ((flags & Flags.PROTECTED) != 0)
result |= Modifier.PROTECTED;
if ((flags & Flags.PUBLIC) != 0)
result |= Modifier.PUBLIC;
if ((flags & Flags.STATIC) != 0)
result |= Modifier.STATIC;
if ((flags & Flags.SYNCHRONIZED) != 0)
result |= Modifier.SYNCHRONIZED;
if ((flags & Flags.TRANSIENT) != 0)
result |= Modifier.TRANSIENT;
if ((flags & Flags.VOLATILE) != 0)
result |= Modifier.VOLATILE;
return result;
}
示例13: resolveProxyClass
protected Class<?> resolveProxyClass(String[] interfaces) throws
IOException, ClassNotFoundException {
ClassLoader nonPublicLoader = null;
boolean hasNonPublicInterface = false;
// define proxy in class loader of non-public interface(s), if any
Class<?>[] classObjs = new Class<?>[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
Class<?> cl = Class.forName(interfaces[i], false, classLoader);
if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
if (hasNonPublicInterface) {
if (nonPublicLoader != cl.getClassLoader()) {
throw new IllegalAccessError(
"conflicting non-public interface class loaders");
}
} else {
nonPublicLoader = cl.getClassLoader();
hasNonPublicInterface = true;
}
}
classObjs[i] = cl;
}
try {
return Proxy.getProxyClass(hasNonPublicInterface ?
nonPublicLoader : classLoader, classObjs);
} catch (IllegalArgumentException e) {
throw new ClassNotFoundException(null, e);
}
}
示例14: isPublic
private boolean isPublic(Class<?> keyHandlerType)
{
return keyHandlerType.getModifiers() == Modifier.PUBLIC;
}
示例15: getModifiers
public static long getModifiers( PsiModifierList modifierList )
{
long modifiers = 0;
if( modifierList.hasExplicitModifier( PsiModifier.ABSTRACT ) )
{
modifiers |= Modifier.ABSTRACT;
}
if( modifierList.hasExplicitModifier( PsiModifier.DEFAULT ) )
{
modifiers |= 0x80000000000L; //Flags.DEFAULT;
}
if( modifierList.hasExplicitModifier( PsiModifier.FINAL ) )
{
modifiers |= Modifier.FINAL;
}
if( modifierList.hasExplicitModifier( PsiModifier.PRIVATE ) )
{
modifiers |= Modifier.PRIVATE;
}
if( modifierList.hasExplicitModifier( PsiModifier.PROTECTED ) )
{
modifiers |= Modifier.PROTECTED;
}
if( modifierList.hasExplicitModifier( PsiModifier.PUBLIC ) )
{
modifiers |= Modifier.PUBLIC;
}
if( modifierList.hasExplicitModifier( PsiModifier.STATIC ) )
{
modifiers |= Modifier.STATIC;
}
if( modifierList.hasExplicitModifier( PsiModifier.SYNCHRONIZED ) )
{
modifiers |= Modifier.SYNCHRONIZED;
}
if( modifierList.hasExplicitModifier( PsiModifier.TRANSIENT ) )
{
modifiers |= Modifier.TRANSIENT;
}
if( modifierList.hasExplicitModifier( PsiModifier.VOLATILE ) )
{
modifiers |= Modifier.VOLATILE;
}
return modifiers;
}