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


Java Modifier.PRIVATE属性代码示例

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


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

示例1: getModifiers

private static int getModifiers(ClassInfo ci, int mIndex) {
    int modifiers = 0;
    if (ci.isMethodAbstract(mIndex)) {
        modifiers += Modifier.ABSTRACT;
    }
    if (ci.isMethodPrivate(mIndex)) {
        modifiers += Modifier.PRIVATE;
    }
    if (ci.isMethodProtected(mIndex)) {
        modifiers += Modifier.PROTECTED;
    }
    if (ci.isMethodPublic(mIndex)) {
        modifiers += Modifier.PUBLIC;
    }
    if (ci.isMethodFinal(mIndex)) {
        modifiers += Modifier.FINAL;
    }
    if (ci.isMethodStatic(mIndex)) {
        modifiers += Modifier.STATIC;
    }
    if (ci.isMethodNative(mIndex)) {
        modifiers += Modifier.NATIVE;
    }
    return modifiers;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ExternalPackages.java

示例2: 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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:ObjectStreamClass.java

示例3: newConstructorForSerialization

/**
 * Returns an accessible no-arg constructor for a class.
 * The no-arg constructor is found searching the class and its supertypes.
 *
 * @param cl the class to instantiate
 * @return a no-arg constructor for the class or {@code null} if
 *     the class or supertypes do not have a suitable no-arg constructor
 */
public final Constructor<?> newConstructorForSerialization(Class<?> cl) {
    Class<?> initCl = cl;
    while (Serializable.class.isAssignableFrom(initCl)) {
        if ((initCl = initCl.getSuperclass()) == null) {
            return null;
        }
    }
    Constructor<?> constructorToCall;
    try {
        constructorToCall = initCl.getDeclaredConstructor();
        int mods = constructorToCall.getModifiers();
        if ((mods & Modifier.PRIVATE) != 0 ||
                ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
                        !packageEquals(cl, initCl))) {
            return null;
        }
    } catch (NoSuchMethodException ex) {
        return null;
    }
    return generateConstructor(cl, constructorToCall);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:ReflectionFactory.java

示例4: main

public static void main(String[] args) throws Exception {
    /* We are not testing for the ACC_SUPER bug, so strip we strip
     * synchorized. */

    int m = 0;

    m = Inner.class.getModifiers() & (~Modifier.SYNCHRONIZED);
    if (m != Modifier.PRIVATE)
        throw new Exception("Access bits for innerclass not from " +
                            "InnerClasses attribute");

    m = Protected.class.getModifiers() & (~Modifier.SYNCHRONIZED);
    if (m != Modifier.PROTECTED)
        throw new Exception("Protected inner class wronged modifiers");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ForInnerClass.java

示例5: fireChanged

private void fireChanged() {
    FormLoaderSettings options = FormLoaderSettings.getInstance();
    boolean isChanged = false;
    if (rbGenerateFields.isSelected()) {
        switch (cbModifier.getSelectedIndex()) {
            case 0:
                isChanged = options.getVariablesModifier() != Modifier.PUBLIC;
                break;
            case 1:
                isChanged = options.getVariablesModifier() != 0;
                break;
            case 2:
                isChanged = options.getVariablesModifier() != Modifier.PROTECTED;
                break;
            case 3:
                isChanged = options.getVariablesModifier() != Modifier.PRIVATE;
                break;
        }
    }
    try {
        changed = isChanged || options.getFoldGeneratedCode() != cbFold.isSelected()
                || options.getAssistantShown() != cbAssistant.isSelected()
                || options.getGenerateFQN() != cbFQN.isSelected()
                || options.getListenerGenerationStyle() != cbListenerStyle.getSelectedIndex()
                || options.getLayoutCodeTarget() != cbLayoutStyle.getSelectedIndex()
                || options.getAutoSetComponentName() != cbComponentNames.getSelectedIndex()
                || options.getI18nAutoMode() != cbAutoI18n.getSelectedIndex()
                || options.getVariablesLocal() != rbGenerateLocals.isSelected()
                || options.getGridX() != (Integer) spGridSize.getValue()
                || options.getGridY() != (Integer) spGridSize.getValue()
                || !options.getGuidingLineColor().equals(guideLineColorProperty.getValue())
                || !options.getSelectionBorderColor().equals(selectionBorderColorProperty.getValue())
                || options.getPaintAdvancedLayoutInfo() != (cbPaintLayout.isSelected() ? 3 : 0);
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:FormEditorCustomizer.java

示例6: isAccessable

public static boolean isAccessable(final Package subclassPackage, final Package superclassPackage,
		final int superMemberModifiers) {
	if (subclassPackage.equals(superclassPackage)) {
		switch (superMemberModifiers) {
		case Modifier.PRIVATE:
			return false;

		case Modifier.PROTECTED:
			return true;

		case Modifier.PUBLIC:
			return true;

		default:
			return true;
		}
	} else {
		switch (superMemberModifiers) {
		case Modifier.PRIVATE:
			return false;

		case Modifier.PROTECTED:
			return true;

		case Modifier.PUBLIC:
			return true;

		default:
			return false;
		}
	}
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:32,代码来源:Reflections.java

示例7: getPersistFields

/**
 * 获取持久化模型的持久属性,判断根据是:
 * 1. Field的Modifiers==Private
 * 2. Field的Type属于基本类型
 * 
 * @param clazz
 * @return
 */
public static <T> Field[] getPersistFields(Class<T> clazz) {
    Field[] fields = getFields(clazz);

    List<Field> result = Lists.newArrayList();

    for (int i = 0; i < fields.length; i++) {
        if (fields[i].getModifiers() != Modifier.PRIVATE) {
            continue;
        }
        result.add(fields[i]);
    }

    return result.toArray(new Field[]{});
}
 
开发者ID:lemon-china,项目名称:lemon-framework,代码行数:22,代码来源:ReflectUtil.java

示例8: 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:DocEnv.java

示例9: 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).
 *
 * Copied from the Merlin java.io.ObjectStreamClass.
 */
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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:ObjectStreamClass.java

示例10: 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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:ObjectStreamClass.java

示例11: assertStaticClassVarsAreFromPackage

private static boolean assertStaticClassVarsAreFromPackage() {
	//String packagename = System.getProperty("jawk.rtPackgeName", "org.jawk.jrt");
	String packagename = "org.jawk.jrt";
	if (packagename != null) {
		// use reflection to get all static Class definitions
		// and verify that they are members of the
		// runtime package
		Class c = AwkCompilerImpl.class;
		// foreach field in declared in the class...
		for (Field f : c.getDeclaredFields()) {
			int mod = f.getModifiers();
			// if a "private static final" member...
			if (       (mod & Modifier.PRIVATE) > 0
					&& (mod & Modifier.STATIC) > 0
					&& (mod & Modifier.FINAL) > 0
					&& f.getType() == Class.class)
			{
				try {
					// obtain the value of the field
					// and apply it here!
					Object o = f.get(null);
					Class cls = (Class) o;
					if (!cls.getPackage().getName().equals(packagename)) {
						throw new AssertionError("class " + c.toString() + " is not contained within '" + packagename + "' package. Field = " + f.toString());
					}
				} catch (IllegalAccessException iae) {
					throw new AssertionError(iae); // NOTE Thought there is an AssertionError#AssertionError(String, Throwable) ctor aswell, it was only introduced in Java 1.7, so we should not yet use it.
				}
			}
		}
	}
	// all's well
	return true;
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:34,代码来源:AwkCompilerImpl.java

示例12: main

public static void main(String[] args) throws Exception {

      // Check that all the lambda methods are private instance synthetic
      for (Class<?> k : new Class<?>[] { A.class, B.class, C.class }) {
         Method[] methods = k.getDeclaredMethods();
         int lambdaCount = 0;
         for(Method m : methods) {
            if (m.getName().startsWith("lambda$")) {
               ++lambdaCount;
               int mod = m.getModifiers();
               if ((mod & Modifier.PRIVATE) == 0) {
                  throw new Exception("Expected " + m + " to be private");
               }
               if (!m.isSynthetic()) {
                  throw new Exception("Expected " + m + " to be synthetic");
               }
               if ((mod & Modifier.STATIC) != 0) {
                  throw new Exception("Expected " + m + " to be instance method");
               }
            }
         }
         if (lambdaCount == 0) {
            throw new Exception("Expected at least one lambda method");
         }
      }

      /*
       * Unless the lambda methods are private, this will fail with:
       *  AbstractMethodError:
       *        Conflicting default methods: A.lambda$0 B.lambda$0 C.lambda$0
       */
      X x = new PrivateLambdas();
      if (!x.name().equals(" A B C")) {
         throw new Exception("Expected ' A B C' got: " + x.name());
      }
   }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:PrivateLambdas.java

示例13: getInheritableMethod

/**
 * Returns true if a non-static, non-abstract method with given signature provided it is defined
 * by or accessible (via inheritance) by the given class, or false if no match found.
 */
private static boolean 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 false;
  }
  int mods = meth.getModifiers();
  if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
    return false;
  } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
    return true;
  } else if ((mods & Modifier.PRIVATE) != 0) {
    return (cl == defCl);
  } else {
    return packageEquals(cl, defCl);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:31,代码来源:AutoSerializableManager.java

示例14: getPrivateMethod

/**
 * Returns true if a non-static private method with given signature defined by given class, or
 * false if none found.
 */
private static boolean getPrivateMethod(Class cl, String name, Class[] argTypes,
    Class returnType) {
  try {
    Method meth = cl.getDeclaredMethod(name, argTypes);
    int mods = meth.getModifiers();
    return ((meth.getReturnType() == returnType) && ((mods & Modifier.STATIC) == 0)
        && ((mods & Modifier.PRIVATE) != 0));
  } catch (NoSuchMethodException ex) {
    return false;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:15,代码来源:AutoSerializableManager.java

示例15: setCodeData

void setCodeData(String componentName, CustomCodeData codeData, FileObject srcFile, int[] positions) {
    if (this.codeData != null) { // clean up
        initCodeEditor.getDocument().removeDocumentListener(docListener);
        declareCodeEditor.getDocument().removeDocumentListener(docListener);

        initGutter.removeAll();
        declareGutter.removeAll();

        revalidate();
        repaint();
    }

    if (editBlockInfos != null) {
        editBlockInfos.clear();
        guardBlockInfos.clear();
    }
    else {
        editBlockInfos = new HashMap<CodeCategory, EditBlockInfo[]>();
        guardBlockInfos = new HashMap<CodeCategory, GuardBlockInfo[]>();
    }

    FormUtils.setupEditorPane(initCodeEditor, srcFile, positions[0]);
    FormUtils.setupEditorPane(declareCodeEditor, srcFile, positions[1]);

    this.codeData = codeData;
    selectInComboBox(componentCombo, componentName);

    buildCodeView(CodeCategory.CREATE_AND_INIT);
    buildCodeView(CodeCategory.DECLARATION);

    Object um = initCodeEditor.getDocument().getProperty(UNDO_MANAGER_PROP);
    if (um instanceof UndoManager) {
        ((UndoManager)um).discardAllEdits();
    }
    um = declareCodeEditor.getDocument().getProperty(UNDO_MANAGER_PROP);
    if (um instanceof UndoManager) {
        ((UndoManager)um).discardAllEdits();
    }

    VariableDeclaration decl = codeData.getDeclarationData();
    boolean local = decl.local;
    for (int i=0; i < variableValues.length; i++) {
        if (variableValues[i] == local) {
            selectInComboBox(variableCombo, variableStrings[i]);
            break;
        }
    }
    int modifiers = decl.modifiers;
    int access = modifiers & (Modifier.PRIVATE|Modifier.PROTECTED|Modifier.PUBLIC);
    for (int i=0; i < accessValues.length; i++) {
        if (accessValues[i] == access) {
            selectInComboBox(accessCombo, accessStrings[i]);
            break;
        }
    }
    staticCheckBox.setSelected((modifiers & Modifier.STATIC) == Modifier.STATIC);
    finalCheckBox.setSelected((modifiers & Modifier.FINAL) == Modifier.FINAL);
    transientCheckBox.setSelected((modifiers & Modifier.TRANSIENT) == Modifier.TRANSIENT);
    volatileCheckBox.setSelected((modifiers & Modifier.VOLATILE) == Modifier.VOLATILE);
    accessCombo.setEnabled(!local);
    staticCheckBox.setEnabled(!local);
    transientCheckBox.setEnabled(!local);
    volatileCheckBox.setEnabled(!local);

    if (local)
        lastLocalModifiers = modifiers;
    else
        lastFieldModifiers = modifiers;

    changed = false;

    if (docListener == null)
        docListener = new DocumentL();
    initCodeEditor.getDocument().addDocumentListener(docListener);
    declareCodeEditor.getDocument().addDocumentListener(docListener);

    initCodeEditor.setCaretPosition(0);
    declareCodeEditor.setCaretPosition(0);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:79,代码来源:CustomCodeView.java


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