Example usage for java.lang.reflect Modifier isPrivate

List of usage examples for java.lang.reflect Modifier isPrivate

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isPrivate.

Prototype

public static boolean isPrivate(int mod) 

Source Link

Document

Return true if the integer argument includes the private modifier, false otherwise.

Usage

From source file:ClassFigure.java

public ClassFigure(Class cls) {
    setLayoutManager(new ToolbarLayout());
    setBorder(new LineBorder(ColorConstants.black));
    setBackgroundColor(ColorConstants.yellow);
    setOpaque(true);/*  w  w w.  j a  v a2s. co m*/

    for (int i = 0; i < keys.length; i++)
        registry.put(keys[i], ImageDescriptor.createFromFile(null, "icons/java/" + keys[i] + ".gif"));

    Label title = new Label(cls.getName(), registry.get(KEY_CLASS));
    add(title);
    add(fieldBox);
    add(methodBox);

    // fields.
    Field[] fields = cls.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        Image image = null;
        if (Modifier.isPublic(field.getModifiers())) {
            image = registry.get(KEY_FIELD_PUBLIC);
        } else if (Modifier.isProtected(field.getModifiers())) {
            image = registry.get(KEY_FIELD_PROTECTED);
        } else if (Modifier.isPrivate(field.getModifiers())) {
            image = registry.get(KEY_FIELD_PRIVATE);
        } else {
            image = registry.get(KEY_FIELD_DEFAULT);
        }
        fieldBox.add(new Label(fields[i].getName(), image));
    }

    // fields.
    Method[] methods = cls.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        Image image = null;
        if (Modifier.isPublic(method.getModifiers())) {
            image = registry.get(KEY_METHOD_PUBLIC);
        } else if (Modifier.isProtected(method.getModifiers())) {
            image = registry.get(KEY_METHOD_PROTECTED);
        } else if (Modifier.isPrivate(method.getModifiers())) {
            image = registry.get(KEY_METHOD_PRIVATE);
        } else {
            image = registry.get(KEY_METHOD_DEFAULT);
        }
        methodBox.add(new Label(methods[i].getName(), image));
    }

}

From source file:com.happyblueduck.lembas.datastore.LembasEntity.java

/**
 * copies values from  lembasEntity to this entity. skip objectKey from that.
 * @param that/* w w  w .j a  v a2 s.  co m*/
 */
public void copy(LembasEntity that) {

    ArrayList<Field> fields = Lists.newArrayList(that.getClass().getFields());
    for (Field f : fields) {
        try {

            int modifiers = f.getModifiers();
            if (Modifier.isPrivate(modifiers))
                continue;
            if (Modifier.isStatic(modifiers))
                continue;
            if (Modifier.isTransient(modifiers))
                continue;
            if (Modifier.isFinal(modifiers))
                continue;
            if (Modifier.isVolatile(modifiers))
                continue;

            if (f.getName().equalsIgnoreCase(LembasUtil.objectKey))
                continue;

            Object value = f.get(that);
            if (value != null)
                this.setField(f, value);

        } catch (IllegalAccessException exception) {
            exception.printStackTrace();
        }
    }
}

From source file:objenome.util.bytecode.SgUtils.java

private static void checkModifiers(int type, int modifiers) {
    for (int modifier = ABSTRACT; modifier <= STRICTFP; modifier++) {
        if (Modifier.isPrivate(modifiers) && !MODIFIERS_MATRIX[PRIVATE][type]) {
            throwIllegalArgument(type, PRIVATE);
        }/*from  ww  w  .  java  2s . c o m*/
        if (Modifier.isProtected(modifiers) && !MODIFIERS_MATRIX[PROTECTED][type]) {
            throwIllegalArgument(type, PROTECTED);
        }
        if (Modifier.isPublic(modifiers) && !MODIFIERS_MATRIX[PUBLIC][type]) {
            throwIllegalArgument(type, PUBLIC);
        }
        if (Modifier.isStatic(modifiers) && !MODIFIERS_MATRIX[STATIC][type]) {
            throwIllegalArgument(type, STATIC);
        }
        if (Modifier.isAbstract(modifiers) && !MODIFIERS_MATRIX[ABSTRACT][type]) {
            throwIllegalArgument(type, ABSTRACT);
        }
        if (Modifier.isFinal(modifiers) && !MODIFIERS_MATRIX[FINAL][type]) {
            throwIllegalArgument(type, FINAL);
        }
        if (Modifier.isNative(modifiers) && !MODIFIERS_MATRIX[NATIVE][type]) {
            throwIllegalArgument(type, NATIVE);
        }
        if (Modifier.isSynchronized(modifiers) && !MODIFIERS_MATRIX[SYNCHRONIZED][type]) {
            throwIllegalArgument(type, SYNCHRONIZED);
        }
        if (Modifier.isTransient(modifiers) && !MODIFIERS_MATRIX[TRANSIENT][type]) {
            throwIllegalArgument(type, TRANSIENT);
        }
        if (Modifier.isVolatile(modifiers) && !MODIFIERS_MATRIX[VOLATILE][type]) {
            throwIllegalArgument(type, VOLATILE);
        }
        if (Modifier.isStrict(modifiers) && !MODIFIERS_MATRIX[STRICTFP][type]) {
            throwIllegalArgument(type, STRICTFP);
        }
    }
}

From source file:org.apache.hawq.pxf.plugins.hdfs.WritableResolver.java

/**
 * Constructs a WritableResolver./*from   www .  ja  v  a2s  .c  o m*/
 *
 * @param input all input parameters coming from the client
 * @throws Exception if schema file is missing, cannot be found in
 *                   classpath or fails to instantiate
 */
public WritableResolver(InputData input) throws Exception {
    super(input);

    String schemaName = inputData.getUserProperty("DATA-SCHEMA");

    /** Testing that the schema name was supplied by the user - schema is an optional property. */
    if (schemaName == null) {
        throw new DataSchemaException(SCHEMA_NOT_INDICATED, this.getClass().getName());
    }

    /** Testing that the schema resource exists. */
    if (!isSchemaOnClasspath(schemaName)) {
        throw new DataSchemaException(SCHEMA_NOT_ON_CLASSPATH, schemaName);
    }

    userObject = Utilities.createAnyInstance(schemaName);
    fields = userObject.getClass().getDeclaredFields();
    recordkeyIndex = (inputData.getRecordkeyColumn() == null) ? RECORDKEY_UNDEFINED
            : inputData.getRecordkeyColumn().columnIndex();

    // fields details:
    if (LOG.isDebugEnabled()) {
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            String javaType = field.getType().getName();
            boolean isPrivate = Modifier.isPrivate(field.getModifiers());

            LOG.debug("Field #" + i + ", name: " + field.getName() + " type: " + javaType + ", "
                    + (isArray(javaType) ? "Array" : "Primitive") + ", "
                    + (isPrivate ? "Private" : "accessible") + " field");
        }
    }
}

From source file:CrossRef.java

/**
 * Print the fields and methods of one class.
 *//*w  w w .  j  av  a2  s  .  c  o  m*/
protected void doClass(Class c) {
    int i, mods;
    startClass(c);
    try {
        Field[] fields = c.getDeclaredFields();
        Arrays.sort(fields, new Comparator() {
            public int compare(Object o1, Object o2) {
                return ((Field) o1).getName().compareTo(((Field) o2).getName());
            }
        });
        for (i = 0; i < fields.length; i++) {
            Field field = (Field) fields[i];
            if (!Modifier.isPrivate(field.getModifiers()))
                putField(field, c);
            // else System.err.println("private field ignored: " + field);
        }

        Method methods[] = c.getDeclaredMethods();
        // Arrays.sort(methods);
        for (i = 0; i < methods.length; i++) {
            if (!Modifier.isPrivate(methods[i].getModifiers()))
                putMethod(methods[i], c);
            // else System.err.println("pvt: " + methods[i]);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    endClass();
}

From source file:AccessibleFieldIterator.java

protected void addMoreFields() {
    boolean needMoreFields = true;
    while (needMoreFields) {

        for (Field field : this.currentClass.getDeclaredFields()) {

            if (!(field.isSynthetic() || Modifier.isPrivate(field.getModifiers())
                    || this.visibleFieldNames.contains(field.getName()))) {
                try {
                    field.setAccessible(true);
                    this.fieldQueueIterator.add(field);
                    this.visibleFieldNames.add(field.getName());
                    needMoreFields = false;
                } catch (SecurityException e) {
                    // ignore fields that cannot be set accessible
                }//from  ww  w .  ja  va2  s .co m
            }
        }

        if (needMoreFields) {
            // found no accessible fields in the current class
            this.currentClass = this.currentClass.getSuperclass();
            if (this.currentClass == null) {
                // no more fields
                return;
            }
        }
    }
}

From source file:org.springframework.test.context.support.AnnotationConfigContextLoaderUtils.java

private static boolean isStaticNonPrivateAndNonFinal(Class<?> clazz) {
    Assert.notNull(clazz, "Class must not be null");
    int modifiers = clazz.getModifiers();
    return (Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers));
}

From source file:com.tlabs.android.evanova.mvp.PresenterLifeCycle.java

private void addAnnotatedPresenter(Object source) {
    for (Field field : source.getClass().getDeclaredFields()) {
        if (field.isAnnotationPresent(Presenter.class)) {
            if (Modifier.isPrivate(field.getModifiers())) {
                throw new NotAccessibleException("presenter on " + field.getName() + " canot be private");
            } else {
                try {
                    field.setAccessible(true);
                    ViewPresenter presenter = (ViewPresenter) field.get(source);
                    registerPresenter(presenter);
                    field.setAccessible(false);
                } catch (IllegalAccessException e) {
                    NotAccessibleException exception = new NotAccessibleException(field.getName(), e);
                    throw exception;
                }//from w  ww  .  ja  va2 s.c o m
            }
        }
    }
}

From source file:com.github.jknack.handlebars.context.MemberValueResolver.java

/**
 * True if the member is private./* w  w w .  ja va 2  s .  com*/
 *
 * @param member The member object.
 * @return True if the member is private.
 */
protected boolean isPrivate(final M member) {
    return Modifier.isPrivate(member.getModifiers());
}

From source file:org.apache.openjpa.enhance.PCSubclassValidator.java

public void assertCanSubclass() {
    Class superclass = meta.getDescribedType();
    String name = superclass.getName();
    if (superclass.isInterface())
        addError(loc.get("subclasser-no-ifaces", name), meta);
    if (Modifier.isFinal(superclass.getModifiers()))
        addError(loc.get("subclasser-no-final-classes", name), meta);
    if (Modifier.isPrivate(superclass.getModifiers()))
        addError(loc.get("subclasser-no-private-classes", name), meta);
    if (PersistenceCapable.class.isAssignableFrom(superclass))
        addError(loc.get("subclasser-super-already-pc", name), meta);

    try {// w  w  w .  ja  v a 2 s .co  m
        Constructor c = superclass.getDeclaredConstructor(new Class[0]);
        if (!(Modifier.isProtected(c.getModifiers()) || Modifier.isPublic(c.getModifiers())))
            addError(loc.get("subclasser-private-ctor", name), meta);
    } catch (NoSuchMethodException e) {
        addError(loc.get("subclasser-no-void-ctor", name), meta);
    }

    // if the BCClass we loaded is already pc and the superclass is not,
    // then we should never get here, so let's make sure that the
    // calling context is caching correctly by throwing an exception.
    if (pc.isInstanceOf(PersistenceCapable.class) && !PersistenceCapable.class.isAssignableFrom(superclass))
        throw new InternalException(loc.get("subclasser-class-already-pc", name));

    if (AccessCode.isProperty(meta.getAccessType()))
        checkPropertiesAreInterceptable();

    if (errors != null && !errors.isEmpty())
        throw new UserException(errors.toString());
    else if (contractViolations != null && !contractViolations.isEmpty() && log.isWarnEnabled())
        log.warn(contractViolations.toString());
}