Example usage for java.lang.reflect Modifier PUBLIC

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

Introduction

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

Prototype

int PUBLIC

To view the source code for java.lang.reflect Modifier PUBLIC.

Click Source Link

Document

The int value representing the public modifier.

Usage

From source file:com.hihframework.core.utils.ReflectUtil.java

public static final String[] filterPublicMethodsName(Object obj, String prefix) {
    return getMethodsName(obj, Modifier.PUBLIC, prefix);
}

From source file:specminers.evaluation.PradelRefSpecsExtender.java

static Set<String> getAllMethodsViaJavaReflection(String fullClassName) {
    try {/* ww w .  j  a  v  a  2s  . c o  m*/
        Class<?> cls = Class.forName(fullClassName);
        //List<Method> classMethods = Arrays.asList(cls.getMethods());
        Set<Method> classMethods = ReflectionUtils.getAllMethods(cls,
                Predicates.not(withModifier(Modifier.PUBLIC)));

        Set<String> signatures = classMethods.stream()
                .map(m -> String.format("%s.%s()", fullClassName, m.getName())).collect(Collectors.toSet());

        return signatures;
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(JflapFileManipulator.class.getName()).log(Level.SEVERE, null, ex);
        // throw new RuntimeException(ex);
        return new HashSet<>();
    }
}

From source file:com.mollie.api.resource.BaseResource.java

/**
 * Convenience method to copy all public properties from a src object into
 * a dst object of the same type.//from  w ww  . j  a v  a 2 s  . co  m
 *
 * @param src Source object to copy properties from
 * @param dst Target object
 */
protected void copyInto(T src, T dst) {
    Field[] fromFields = returnedClass().getDeclaredFields();
    Object value = null;

    try {
        for (Field field : fromFields) {
            int modifiers = field.getModifiers();

            if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC
                    && (modifiers & Modifier.FINAL) != Modifier.FINAL
                    && (modifiers & Modifier.STATIC) != Modifier.STATIC) {
                value = field.get(src);
                field.set(dst, value);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.ops4j.gaderian.service.impl.LoggingInterceptorFactory.java

protected void addServiceMethodImplementation(ClassFab classFab, MethodSignature sig) {
    Class returnType = sig.getReturnType();
    String methodName = sig.getName();

    boolean isVoid = (returnType == void.class);

    BodyBuilder builder = new BodyBuilder();

    builder.begin();//  w  w w.  j a v  a  2  s.co m
    builder.addln("boolean debug = _log.isDebugEnabled();");

    builder.addln("if (debug)");
    builder.add("  org.ops4j.gaderian.service.impl.LoggingUtils.entry(_log, ");
    builder.addQuoted(methodName);
    builder.addln(", $args);");

    if (!isVoid) {
        builder.add(ClassFabUtils.getJavaClassName(returnType));
        builder.add(" result = ");
    }

    builder.add("_delegate.");
    builder.add(methodName);
    builder.addln("($$);");

    if (isVoid) {
        builder.addln("if (debug)");
        builder.add("  org.ops4j.gaderian.service.impl.LoggingUtils.voidExit(_log, ");
        builder.addQuoted(methodName);
        builder.addln(");");
    } else {
        builder.addln("if (debug)");
        builder.add("  org.ops4j.gaderian.service.impl.LoggingUtils.exit(_log, ");
        builder.addQuoted(methodName);
        builder.addln(", ($w)result);");
        builder.addln("return result;");
    }

    builder.end();

    MethodFab methodFab = classFab.addMethod(Modifier.PUBLIC, sig, builder.toString());

    builder.clear();

    builder.begin();
    builder.add("org.ops4j.gaderian.service.impl.LoggingUtils.exception(_log, ");
    builder.addQuoted(methodName);
    builder.addln(", $e);");
    builder.addln("throw $e;");
    builder.end();

    String body = builder.toString();

    Class[] exceptions = sig.getExceptionTypes();

    int count = exceptions.length;

    for (int i = 0; i < count; i++) {
        methodFab.addCatch(exceptions[i], body);
    }

    // Catch and log any other exception, in addition to the
    // checked exceptions.
    methodFab.addCatch(Throwable.class, body);
}

From source file:de.micromata.tpsb.doc.parser.japa.ParserUtil.java

public static boolean ignoreMethod(FileInfo fi, MethodInfo mi) {
    if (TpsbEnvUtils.getAnnotation(fi, TpsbIgnore.class.getSimpleName()) != null) {
        return true;
    }//w  w w. j av a 2 s. c o  m
    if (TpsbEnvUtils.getAnnotation(mi, TpsbIgnore.class.getSimpleName()) != null) {
        return true;
    }
    if ((mi.getModifier() & Modifier.STATIC) == Modifier.STATIC) {
        return true;
    }
    if ((mi.getModifier() & Modifier.PUBLIC) != Modifier.PUBLIC) {
        return true;
    }
    return false;
}

From source file:se.vgregion.portal.innovatinosslussen.domain.TypesBeanTest.java

void doGetterSetterValuesMatch(Class... typeInPackage)
        throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    for (Class item : typeInPackage)
        for (Class type : getTypes(item)) {
            if (!type.isEnum()) {
                if (type.getDeclaredConstructors()[0].getModifiers() == Modifier.PUBLIC) {
                    doGetterSetterValuesMatch(type.newInstance());
                }//from   ww  w . j  a  v a  2 s. c  o m
            }
        }
}

From source file:org.gvnix.addon.jpa.addon.batch.JpaBatchOperationsImpl.java

/** {@inheritDoc} */
@Override/* ww  w .  j  av a 2s .  co m*/
public void create(JavaType entity, JavaType target) {
    Validate.notNull(entity, "Entity required");
    if (target == null) {
        target = generateJavaType(entity, null);
    }

    Validate.isTrue(!JdkJavaType.isPartOfJavaLang(target.getSimpleTypeName()),
            "Target name '%s' must not be part of java.lang", target.getSimpleTypeName());

    int modifier = Modifier.PUBLIC;

    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(target,
            pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
    File targetFile = new File(typeLocationService.getPhysicalTypeCanonicalPath(declaredByMetadataId));
    Validate.isTrue(!targetFile.exists(), "Type '%s' already exists", target);

    // Prepare class builder
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
            declaredByMetadataId, modifier, target, PhysicalTypeCategory.CLASS);

    // Prepare annotations array
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(2);

    // Add @Service annotations
    annotations.add(new AnnotationMetadataBuilder(SpringJavaType.SERVICE));

    // Add @GvNIXJpaBatch annotation
    AnnotationMetadataBuilder jpaBatchAnnotation = new AnnotationMetadataBuilder(
            new JavaType(GvNIXJpaBatch.class));
    jpaBatchAnnotation.addClassAttribute("entity", entity);
    annotations.add(jpaBatchAnnotation);

    // Set annotations
    cidBuilder.setAnnotations(annotations);

    typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}

From source file:org.codehaus.groovy.grails.compiler.injection.DefaultGrailsDomainClassInjector.java

private Collection createPropertiesForBelongsToExpression(Expression e, ClassNode classNode) {
    List properties = new ArrayList();
    if (e instanceof MapExpression) {
        MapExpression me = (MapExpression) e;
        List mapEntries = me.getMapEntryExpressions();
        for (Iterator i = mapEntries.iterator(); i.hasNext();) {
            MapEntryExpression mme = (MapEntryExpression) i.next();
            String key = mme.getKeyExpression().getText();

            String type = mme.getValueExpression().getText();

            properties.add(new PropertyNode(key, Modifier.PUBLIC, ClassHelper.make(type), classNode, null, null,
                    null));//  w  w w . j  a  va2 s  .c  om
        }
    }

    return properties;
}

From source file:org.python.pydev.core.REF.java

/**
 * @return the value of some attribute in the given object
 *//*from w w w .j av a2  s  .c om*/
public static Object getAttrObj(Class<? extends Object> c, Object o, String attr,
        boolean raiseExceptionIfNotAvailable) {
    try {
        Field field = REF.getAttrFromClass(c, attr);
        if (field != null) {
            //get it even if it's not public!
            if ((field.getModifiers() & Modifier.PUBLIC) == 0) {
                field.setAccessible(true);
            }
            Object obj = field.get(o);
            return obj;
        }
    } catch (Exception e) {
        //ignore
        if (raiseExceptionIfNotAvailable) {
            throw new RuntimeException(e);
        }
    }
    return null;
}

From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderUserAuthorityMetadata.java

public SafeSecurityProviderUserAuthorityMetadata(String identifier, JavaType aspectName,
        PhysicalTypeMetadata governorPhysicalTypeMetadata) {
    super(identifier, aspectName, governorPhysicalTypeMetadata);
    /*Validate.isTrue(isValid(identifier), "Metadata identification string '"
        + identifier + "' does not appear to be a valid");*/

    // Helper itd generation
    this.helper = new ItdBuilderHelper(this, governorPhysicalTypeMetadata,
            builder.getImportRegistrationResolver());

    // Adding Fields
    builder.addField(getField("serialVersionUID", "-2443806778851127910L", JavaType.LONG_PRIMITIVE,
            Modifier.PRIVATE + Modifier.STATIC + Modifier.FINAL));

    builder.addField(getField("authority", null, JAVA_TYPE_STRING, Modifier.PRIVATE));

    // User Details
    builder.addField(getField("nif", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("usrtipo", null, JAVA_TYPE_STRING, Modifier.PRIVATE));
    builder.addField(getField("idgrupo", null, JAVA_TYPE_STRING, Modifier.PUBLIC));
    builder.addField(getField("idrol", null, JAVA_TYPE_STRING, Modifier.PUBLIC));
    builder.addField(getField("idaplicacion", null, JAVA_TYPE_STRING, Modifier.PUBLIC));

    // Creating getters and setters
    builder.addMethod(getGetterMethod("authority", JavaType.STRING));
    builder.addMethod(getSetterMethod("authority", JavaType.STRING));
    builder.addMethod(getGetterMethod("nif", JavaType.STRING));
    builder.addMethod(getSetterMethod("nif", JavaType.STRING));
    builder.addMethod(getGetterMethod("usrtipo", JavaType.STRING));
    builder.addMethod(getSetterMethod("usrtipo", JavaType.STRING));
    builder.addMethod(getGetterMethod("idgrupo", JavaType.STRING));
    builder.addMethod(getSetterMethod("idgrupo", JavaType.STRING));
    builder.addMethod(getGetterMethod("idrol", JavaType.STRING));
    builder.addMethod(getSetterMethod("idrol", JavaType.STRING));
    builder.addMethod(getGetterMethod("idaplicacion", JavaType.STRING));
    builder.addMethod(getSetterMethod("idaplicacion", JavaType.STRING));

    // Creating methods
    builder.addMethod(getHashCodeMethod());
    builder.addMethod(getEqualsMethod());

    // Create a representation of the desired output ITD
    itdTypeDetails = builder.build();//w w w  .jav  a2  s.c o  m
}