当前位置: 首页>>代码示例>>Java>>正文


Java Modifier.isPrivate方法代码示例

本文整理汇总了Java中java.lang.reflect.Modifier.isPrivate方法的典型用法代码示例。如果您正苦于以下问题:Java Modifier.isPrivate方法的具体用法?Java Modifier.isPrivate怎么用?Java Modifier.isPrivate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Modifier的用法示例。


在下文中一共展示了Modifier.isPrivate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkUtilityClass

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Check utility class well defined: is final, has only one private constructor and all methods are static
 * @param clazz Class to check
 */
public static void checkUtilityClass(final Class<?> clazz) {
	try {
		Assert.assertTrue("class must be final", Modifier.isFinal(clazz.getModifiers()));
		Assert.assertEquals("There must be only one constructor", 1, clazz.getDeclaredConstructors().length);
		final Constructor<?> constructor = clazz.getDeclaredConstructor();
		if (constructor.isAccessible() || !Modifier.isPrivate(constructor.getModifiers())) {
			Assert.fail("constructor is not private");
		}
		constructor.setAccessible(true);
		constructor.newInstance();
		constructor.setAccessible(false);
		for (final Method method : clazz.getMethods()) {
			if (!Modifier.isStatic(method.getModifiers()) && method.getDeclaringClass().equals(clazz)) {
				Assert.fail("there exists a non-static method:" + method);
			}
		}
	} catch (SecurityException | NoSuchMethodException | InstantiationException | IllegalAccessException
			| IllegalArgumentException | InvocationTargetException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:26,代码来源:TestUtils.java

示例2: mostAccessible

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private Symbol.MethodSymbol mostAccessible( Symbol.MethodSymbol ctor, Symbol.MethodSymbol sym )
{
  int ctorMods = (int)ctor.flags();
  int symMods = (int)sym.flags();
  if( Modifier.isPublic( ctorMods ) )
  {
    return ctor;
  }
  if( Modifier.isPublic( symMods ) )
  {
    return sym;
  }
  if( Modifier.isProtected( ctorMods ) )
  {
    return ctor;
  }
  if( Modifier.isProtected( symMods ) )
  {
    return sym;
  }
  if( Modifier.isPrivate( ctorMods ) )
  {
    return Modifier.isPrivate( symMods ) ? ctor : sym;
  }
  return ctor;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:27,代码来源:SrcClassUtil.java

示例3: accessFailedMessage

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
String accessFailedMessage(Class<?> refc, MemberName m) {
    Class<?> defc = m.getDeclaringClass();
    int mods = m.getModifiers();
    // check the class first:
    boolean classOK = (Modifier.isPublic(defc.getModifiers()) &&
                       (defc == refc ||
                        Modifier.isPublic(refc.getModifiers())));
    if (!classOK && (allowedModes & PACKAGE) != 0) {
        classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), FULL_POWER_MODES) &&
                   (defc == refc ||
                    VerifyAccess.isClassAccessible(refc, lookupClass(), FULL_POWER_MODES)));
    }
    if (!classOK)
        return "class is not public";
    if (Modifier.isPublic(mods))
        return "access to public member failed";  // (how?, module not readable?)
    if (Modifier.isPrivate(mods))
        return "member is private";
    if (Modifier.isProtected(mods))
        return "member is protected";
    return "member is private to package";
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:MethodHandles.java

示例4: getReplaceResolveForSerialization

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Lookup readResolve or writeReplace on a class with specified
 * signature constraints.
 * @param cl a serializable class
 * @param methodName the method name to find
 * @returns a MethodHandle for the method or {@code null} if not found or
 *       has the wrong signature.
 */
private MethodHandle getReplaceResolveForSerialization(Class<?> cl,
                                                       String methodName) {
    if (!Serializable.class.isAssignableFrom(cl)) {
        return null;
    }

    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            Method m = defCl.getDeclaredMethod(methodName);
            if (m.getReturnType() != Object.class) {
                return null;
            }
            int mods = m.getModifiers();
            if (Modifier.isStatic(mods) | Modifier.isAbstract(mods)) {
                return null;
            } else if (Modifier.isPublic(mods) | Modifier.isProtected(mods)) {
                // fall through
            } else if (Modifier.isPrivate(mods) && (cl != defCl)) {
                return null;
            } else if (!packageEquals(cl, defCl)) {
                return null;
            }
            try {
                // Normal return
                m.setAccessible(true);
                return MethodHandles.lookup().unreflect(m);
            } catch (IllegalAccessException ex0) {
                // setAccessible should prevent IAE
                throw new InternalError("Error", ex0);
            }
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:ReflectionFactory.java

示例5: validateClass

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private void validateClass(Class<?> source, RuleSourceValidationProblemCollector problems) {
    int modifiers = source.getModifiers();

    if (Modifier.isInterface(modifiers)) {
        problems.add("Must be a class, not an interface");
    }

    if (source.getEnclosingClass() != null) {
        if (Modifier.isStatic(modifiers)) {
            if (Modifier.isPrivate(modifiers)) {
                problems.add("Class cannot be private");
            }
        } else {
            problems.add("Enclosed classes must be static and non private");
        }
    }

    Constructor<?>[] constructors = source.getDeclaredConstructors();
    for (Constructor<?> constructor : constructors) {
        if (constructor.getParameterTypes().length > 0) {
            problems.add("Cannot declare a constructor that takes arguments");
            break;
        }
    }

    Field[] fields = source.getDeclaredFields();
    for (Field field : fields) {
        int fieldModifiers = field.getModifiers();
        if (!field.isSynthetic() && !(Modifier.isStatic(fieldModifiers) && Modifier.isFinal(fieldModifiers))) {
            problems.add(field, "Fields must be static final.");
        }
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:34,代码来源:ModelRuleExtractor.java

示例6: overrides

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Returns true if a overrides b. Assumes signatures of a and b are the same and a's declaring
 * class is a subclass of b's declaring class.
 */
private static boolean overrides(Method a, Method b) {
  // See JLS section 8.4.8.1
  int modifiers = b.getModifiers();
  if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) {
    return true;
  }
  if (Modifier.isPrivate(modifiers)) {
    return false;
  }
  // b must be package-private
  return a.getDeclaringClass().getPackage().equals(b.getDeclaringClass().getPackage());
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:17,代码来源:InjectionPoint.java

示例7: modifier

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private static String modifier(int mod)
{
	if( Modifier.isPublic(mod) ) return "public";
	if( Modifier.isProtected(mod) ) return "protected";
	if( Modifier.isPrivate(mod) ) return "private";
	return "";
}
 
开发者ID:zhangxin23,项目名称:zookeeper-sandbox,代码行数:8,代码来源:ClassGenerator.java

示例8: keepPublicConcreteClasses

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private static void keepPublicConcreteClasses(final Collection<Class> classes) {
    if (null != classes) {
        final Iterator<Class> itr = classes.iterator();
        for (Class clazz = null; itr.hasNext(); clazz = itr.next()) {
            if (null != clazz) {
                final int modifiers = clazz.getModifiers();
                if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
                    itr.remove();
                }
            }
        }
    }
}
 
开发者ID:gchq,项目名称:gaffer-doc,代码行数:14,代码来源:PropertiesWalkthrough.java

示例9: getMigratorAnalyzeResult

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private static MigratorAnalyzeResult getMigratorAnalyzeResult(Class<?> migrator) {
	MigratorAnalyzeResult migratorAnalyzeResult = 
		migratorAnalyzeResults.get(migrator.getName());
	if (migratorAnalyzeResult == null) {
		final MigratorAnalyzeResult newMigratorAnalyzeResult = 
			new MigratorAnalyzeResult();

		Method[] methods = migrator.getDeclaredMethods();
		for (int i=0; i<methods.length; i++) {
			Method method = methods[i];
			int migrateVersion = getVersion(method);
			if (migrateVersion != 0) { 
				if (Modifier.isPrivate(method.getModifiers()) && 
						!Modifier.isStatic(method.getModifiers())) {
					method.setAccessible(true);
					newMigratorAnalyzeResult.getMigrateVersions()
							.put(method.getName(), migrateVersion);
					newMigratorAnalyzeResult.getMigrateMethods().add(method);
				} else {
					throw new RuntimeException("Migrate method should be declared " +
							"as a private non-static method.");
				}
			}
		}

		Collections.sort(newMigratorAnalyzeResult.getMigrateMethods(), 
				new Comparator<Method>() {

			public int compare(Method migrate_x, Method migrate_y) {
				return newMigratorAnalyzeResult.getMigrateVersions().get(migrate_x.getName()) - 
						newMigratorAnalyzeResult.getMigrateVersions().get(migrate_y.getName());
			}
			
		});
		migratorAnalyzeResults.put(migrator.getName(), newMigratorAnalyzeResult);
		return newMigratorAnalyzeResult;
	} else {
		return migratorAnalyzeResult;
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:41,代码来源:MigrationHelper.java

示例10: isInstanceExtensionMethod

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private boolean isInstanceExtensionMethod( AbstractSrcMethod method, String extendedType )
{
  if( !Modifier.isStatic( (int)method.getModifiers() ) || Modifier.isPrivate( (int)method.getModifiers() ) )
  {
    return false;
  }

  return hasThisAnnotation( method, extendedType );
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:10,代码来源:ManAugmentProvider.java

示例11: isPrivate

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
 * Return true if the field includes the {@code private} modifier.
 */
public boolean isPrivate() {
    return Modifier.isPrivate(field.getModifiers());
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:7,代码来源:Field.java

示例12: validateNonRuleMethod

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private void validateNonRuleMethod(Method method, RuleSourceValidationProblemCollector problems) {
    if (!Modifier.isPrivate(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && !method.isSynthetic() && !GroovyMethods.isObjectMethod(method)) {
        problems.add(method, "A method that is not annotated as a rule must be private");
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:6,代码来源:ModelRuleExtractor.java

示例13: isAllModifiersContainSpecificModifier

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public static boolean isAllModifiersContainSpecificModifier(int allModifiers, int specificModifier) {
    if (Modifier.isAbstract(allModifiers) && Modifier.isAbstract(specificModifier))
        return true;

    if (Modifier.isFinal(allModifiers) && Modifier.isFinal(specificModifier))
        return true;

    if (Modifier.isInterface(allModifiers) && Modifier.isInterface(specificModifier))
        return true;

    if (Modifier.isNative(allModifiers) && Modifier.isNative(specificModifier))
        return true;

    if (Modifier.isPrivate(allModifiers) && Modifier.isPrivate(specificModifier))
        return true;

    if (Modifier.isProtected(allModifiers) && Modifier.isProtected(specificModifier))
        return true;

    if (Modifier.isPublic(allModifiers) && Modifier.isPublic(specificModifier))
        return true;

    if (Modifier.isStatic(allModifiers) && Modifier.isStatic(specificModifier))
        return true;

    if (Modifier.isStrict(allModifiers) && Modifier.isStrict(specificModifier))
        return true;

    if (Modifier.isSynchronized(allModifiers) && Modifier.isSynchronized(specificModifier))
        return true;

    if (Modifier.isTransient(allModifiers) && Modifier.isTransient(specificModifier))
        return true;

    if (Modifier.isVolatile(allModifiers) && Modifier.isVolatile(specificModifier))
        return true;

    if (Modifier.isVolatile(allModifiers) && Modifier.isVolatile(specificModifier))
        return true;

    return false;
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:43,代码来源:Solution.java

示例14: isVisible

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
@Override boolean isVisible(int modifiers) {
  return !Modifier.isPrivate(modifiers);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:4,代码来源:NullPointerTester.java

示例15: isPrivate

import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/** Return true if the field includes the {@code private} modifier. */
public boolean isPrivate () {
	return Modifier.isPrivate(field.getModifiers());
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:5,代码来源:Field.java


注:本文中的java.lang.reflect.Modifier.isPrivate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。