Example usage for java.lang.reflect Modifier isFinal

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

Introduction

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

Prototype

public static boolean isFinal(int mod) 

Source Link

Document

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

Usage

From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java

/**
 * Make the given field accessible, explicitly setting it accessible if
 * necessary. The {@code setAccessible(true)} method is only called
 * when actually necessary, to avoid unnecessary conflicts with a JVM
 * SecurityManager (if active)./*  www .  j a v  a  2  s . c  o  m*/
 * @param field the field to make accessible
 * @see java.lang.reflect.Field#setAccessible
 */
public static void makeAccessible(Field field) {
    if ((!Modifier.isPublic(field.getModifiers())
            || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
            || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) {
        field.setAccessible(true);
    }
}

From source file:com.pwn9.pwnchat.config.ConfigObject.java

protected boolean doSkip(Field field) {
    return Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())
            || Modifier.isFinal(field.getModifiers()) || Modifier.isPrivate(field.getModifiers());
}

From source file:name.yumaa.ChromeLogger4J.java

/**
 * Returns a nicely formatted key of the field or method name
 * @param mod    .getModifiers()/*from  www.ja  va 2 s .co m*/
 * @param end    key ending
 * @return class member keys, converted to string
 */
private String getKey(int mod, String end) {
    StringBuilder key = new StringBuilder("");
    if (Modifier.isPublic(mod))
        key.append("public ");
    if (Modifier.isPrivate(mod))
        key.append("private ");
    if (Modifier.isProtected(mod))
        key.append("protected ");
    if (Modifier.isStatic(mod))
        key.append("static ");
    if (Modifier.isTransient(mod))
        key.append("transient ");
    if (Modifier.isVolatile(mod))
        key.append("volatile ");
    if (Modifier.isFinal(mod))
        key.append("final ");
    if (Modifier.isSynchronized(mod))
        key.append("synchronized ");
    return key.append(end).toString();
}

From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java

protected boolean doSkip(Field field) {
    return Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())
            || Modifier.isFinal(field.getModifiers()) || Modifier.isProtected(field.getModifiers())
            || Modifier.isPrivate(field.getModifiers());
}

From source file:adalid.core.Operation.java

private void finaliseFields() {
    String name;//from w w w  . ja v  a 2s  .  c om
    Class<?> type;
    int modifiers;
    boolean restricted;
    Class<?>[] classes = new Class<?>[] { Parameter.class, Expression.class };
    Object o;
    int depth = depth();
    int round = round();
    for (Class<?> c : classes) {
        for (Field field : XS1.getFields(getClass(), Operation.class)) { // getClass().getDeclaredFields()
            field.setAccessible(true);
            logger.trace(field);
            name = field.getName();
            type = field.getType();
            if (!c.isAssignableFrom(type)) {
                continue;
            }
            modifiers = field.getModifiers();
            restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers);
            if (restricted) {
                continue;
            }
            String errmsg = "failed to initialize field \"" + field + "\" at " + this;
            try {
                o = field.get(this);
                if (o == null) {
                    logger.debug(message(type, name, o, depth, round));
                } else if (o instanceof Parameter) {
                    finaliseParameter(field, (Parameter) o);
                } else if (o instanceof Expression) {
                    finaliseExpression(field, (Expression) o);
                }
            } catch (IllegalArgumentException | IllegalAccessException ex) {
                logger.error(errmsg, ThrowableUtils.getCause(ex));
                TLC.getProject().getParser().increaseErrorCount();
            }
        }
    }
}

From source file:ch.flashcard.HibernateDetachUtility.java

private static void nullOutFieldsByFieldAccess(Object object, Map<Integer, Object> checkedObjects,
        Map<Integer, List<Object>> checkedObjectCollisionMap, int depth, SerializationType serializationType)
        throws Exception {

    Class tmpClass = object.getClass();
    List<Field> fieldsToClean = new ArrayList<Field>();
    while (tmpClass != null && tmpClass != Object.class) {
        Field[] declaredFields = tmpClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            // do not process static final or transient fields since they won't be serialized anyway
            int modifiers = declaredField.getModifiers();
            if (!((Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers))
                    || Modifier.isTransient(modifiers))) {
                fieldsToClean.add(declaredField);
            }/*from   ww  w  .  j av  a 2s  .c  o  m*/
        }
        tmpClass = tmpClass.getSuperclass();
    }

    nullOutFieldsByFieldAccess(object, fieldsToClean, checkedObjects, checkedObjectCollisionMap, depth,
            serializationType);
}

From source file:com.microsoft.tfs.core.clients.build.internal.soapextensions.BuildEnumerationHelper.java

@SuppressWarnings("rawtypes")
public static String[] getDisplayTextValues(final Class enumType) {
    final List<String> displayValues = new ArrayList<String>();

    // Look for public static final fields in class that are same type as
    // the passed class.
    final Field[] fields = enumType.getFields();
    for (int i = 0; i < fields.length; i++) {
        if (fields[i].getType().equals(enumType) && Modifier.isPublic(fields[i].getModifiers())
                && Modifier.isFinal(fields[i].getModifiers()) && Modifier.isStatic(fields[i].getModifiers())) {
            try {
                displayValues.add(getDisplayText(fields[i].get(null)));
            } catch (final IllegalAccessException e) {
                throw new BuildException(
                        MessageFormat.format("IllegalAccessException calculating display values for {0}", //$NON-NLS-1$
                                enumType.getName()),
                        e);//from   w  w  w  .  j a v  a  2 s  . com
            }
        }
    }
    return displayValues.toArray(new String[displayValues.size()]);
}

From source file:com.liferay.cli.support.util.ReflectionUtils.java

/**
 * Determine whether the given field is a "public static final" constant.
 * //from w  ww  . j  a v  a  2  s . c o  m
 * @param field the field to check
 */
public static boolean isPublicStaticFinal(final Field field) {
    final int modifiers = field.getModifiers();
    return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);
}

From source file:org.ebayopensource.turmeric.tools.errorlibrary.ErrorLibraryGeneratorTest.java

@Test
public void validateContentOfErrorConstants() throws Exception {
    String errorConstantsClassName = "org.ebayopensource.turmeric.test.errorlibrary.turmericruntime.ErrorConstants";
    String sampleErrorName = "svc_factory_custom_ser_no_bound_type";

    // Initialize testing paths
    MavenTestingUtils.ensureEmpty(testingdir);
    File rootDir = TestResourceUtil.copyResourceRootDir("errorLibrary/TestErrorLibrary", testingdir);
    File binDir = new File(rootDir, "bin");
    File gensrcDir = new File(rootDir, "gen-src");

    MavenTestingUtils.ensureDirExists(binDir);
    MavenTestingUtils.ensureDirExists(gensrcDir);

    // @formatter:off
    String pluginParameters[] = { "-gentype", "genTypeConstants", "-pr", rootDir.getAbsolutePath(), "-domain",
            "TurmericRuntime", "-errorlibname", "TestErrorLibrary" };
    // @formatter:on

    performDirectCodeGen(pluginParameters);

    Class<?> errConstant = compileGeneratedFile(errorConstantsClassName, gensrcDir, binDir);
    Assert.assertThat("errConstant", errConstant, notNullValue());
    Assert.assertThat(errConstant.getName(), is(errorConstantsClassName));

    Field member = errConstant.getField(sampleErrorName.toUpperCase());
    Assert.assertThat("member", member, notNullValue());
    Assert.assertThat("member.type", member.getType().getName(), is(String.class.getName()));
    Assert.assertThat("member.isFinal", Modifier.isFinal(member.getModifiers()), is(true));
    Assert.assertThat("member.isPublic", Modifier.isPublic(member.getModifiers()), is(true));
    Assert.assertThat("member.isStatic", Modifier.isStatic(member.getModifiers()), is(true));
    Assert.assertThat("member.get(null)", (String) member.get(null), is(sampleErrorName));
}

From source file:adalid.core.EntityAtlas.java

private void finaliseFields() {
    String name;//from w  w  w  . ja va 2 s .  c  o m
    Class<?> type;
    int modifiers;
    boolean restricted;
    Object o;
    int depth = _declaringArtifact.depth();
    int round = _declaringArtifact.round();
    int index = _declaringArtifact.getStartWith();
    Class<?>[] classes = new Class<?>[] { Property.class, Key.class, Tab.class, View.class, Instance.class,
            NamedValue.class, Expression.class, Transition.class, Operation.class, Trigger.class };
    Class<?> dac = _declaringArtifact.getClass();
    Class<?> top = Entity.class;
    for (Class<?> c : classes) {
        for (Field field : XS1.getFields(dac, top)) {
            field.setAccessible(true);
            logger.trace(field);
            name = field.getName();
            type = field.getType();
            if (!c.isAssignableFrom(type)) {
                continue;
            }
            if (c.equals(Expression.class) && Property.class.isAssignableFrom(type)) {
                continue;
            }
            modifiers = field.getModifiers();
            restricted = Modifier.isPrivate(modifiers);
            if (restricted) {
                continue;
            }
            restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers);
            if (restricted) {
                continue;
            }
            String errmsg = "failed to initialize field \"" + field + "\" at " + _declaringArtifact;
            try {
                o = field.get(_declaringArtifact);
                if (o == null) {
                    logger.debug(message(type, name, o, depth, round));
                } else if (o instanceof Property) {
                    finaliseProperty(field, (Property) o);
                } else if (o instanceof Key) {
                    finaliseKey(field, (Key) o);
                } else if (o instanceof Tab) {
                    finaliseTab(field, (Tab) o);
                } else if (o instanceof View) {
                    finaliseView(field, (View) o);
                } else if (o instanceof Instance) {
                    finaliseInstance(field, (Instance) o, index++);
                } else if (o instanceof NamedValue) {
                    finaliseNamedValue(field, (NamedValue) o);
                } else if (o instanceof Expression) {
                    finaliseExpression(field, (Expression) o);
                } else if (o instanceof Transition) {
                    finaliseTransition(field, (Transition) o);
                } else if (o instanceof Operation) {
                    finaliseOperation(field, (Operation) o);
                } else if (o instanceof Trigger) {
                    finaliseTrigger(field, (Trigger) o);
                }
            } catch (IllegalArgumentException | IllegalAccessException ex) {
                logger.error(errmsg, ThrowableUtils.getCause(ex));
                TLC.getProject().getParser().increaseErrorCount();
            }
        }
    }
}