Example usage for java.lang.reflect Modifier isStatic

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

Introduction

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

Prototype

public static boolean isStatic(int mod) 

Source Link

Document

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

Usage

From source file:lapin.load.Loader.java

static private Object _impSymbols(Class clazz, Object export, Env env) throws IllegalAccessException {
    Lisp lisp = env.lisp();/* ww  w .  j av a2 s .  c  o  m*/
    Field[] fields = clazz.getFields();
    Class symClass = Symbol.class;
    for (int i = 0; i < fields.length; i++) {
        Field f = fields[i];
        int m = f.getModifiers();
        if (!Modifier.isStatic(m))
            continue;
        if (!symClass.isAssignableFrom(f.getType()))
            continue;
        Symbol sym = Data.symbol(f.get(null));
        lisp.getObarray().imp(sym.pkg(), sym);
        if (!Data.isNot(export))
            lisp.getObarray().exp(sym.pkg(), sym);
    }
    return Symbols.T;
}

From source file:com.dragome.compiler.parser.Parser.java

public void parseMethod(TypeDeclaration typeDecl, MethodDeclaration methodDecl, Method method) {
    Type[] types = method.getArgumentTypes();

    int offset;/*from  w w w .  j  ava2  s.  co  m*/
    if (Modifier.isStatic(methodDecl.getAccess())) {
        offset = 0;
    } else {

        offset = 1;
    }
    for (int i = 0; i < types.length; i++) {
        VariableDeclaration variableDecl = new VariableDeclaration(VariableDeclaration.LOCAL_PARAMETER);
        variableDecl.setName(VariableDeclaration.getLocalVariableName(method, offset, 0));
        variableDecl.setType(types[i]);
        methodDecl.addParameter(variableDecl);
        offset += types[i].getSize();
    }

    if (methodDecl.getCode() == null)
        return;

    Log.getLogger().debug("Parsing " + methodDecl.toString());
    Pass1 pass1 = new Pass1(jc);

    try {
        pass1.parse(method, methodDecl);
    } catch (Throwable ex) {
        if (ex instanceof UnhandledCompilerProblemException) {
            Pass1.setClassNotReversible(methodDecl);
        } else {
            ASTNode node = null;
            if (ex instanceof ParseException) {
                node = ((ParseException) ex).getAstNode();
            } else {
                node = Pass1.getCurrentNode();
            }

            if (DragomeJsCompiler.compiler.isFailOnError()) {
                throw Utils.generateException(ex, methodDecl, node);
            } else {
                fileUnit.addNotReversibleMethod(
                        Pass1.extractMethodNameSignature(methodDecl.getMethodBinding()));
                //String msg= Utils.generateExceptionMessage(methodDecl, node);
                //DragomeJsCompiler.errorCount++;
                //          Log.getLogger().error(msg + "\n" + Utils.stackTraceToString(ex));
            }

        }
        Block body = new Block();
        ThrowStatement throwStmt = new ThrowStatement();
        /*
        MethodBinding binding= MethodBinding.lookup("java.lang.RuntimeException", "<init>", "(java/lang/String)V;");
        ClassInstanceCreation cic= new ClassInstanceCreation(methodDecl, binding);
        cic.addArgument(new StringLiteral("Unresolved decompilation problem"));
        throwStmt.setExpression(cic);
        body.appendChild(throwStmt);*/
        methodDecl.setBody(body);

    }

    if (DragomeJsCompiler.compiler.optimize && methodDecl.getBody().getLastChild() instanceof ReturnStatement) {
        ReturnStatement ret = (ReturnStatement) methodDecl.getBody().getLastChild();
        if (ret.getExpression() == null) {
            methodDecl.getBody().removeChild(ret);
        }
    }

    //      Pass1.dump(methodDecl.getBody(), "Body of " + methodDecl.toString());

    return;
}

From source file:com.gatf.executor.core.AcceptanceTestContext.java

@SuppressWarnings("rawtypes")
public Class addTestCaseHooks(Method method) {
    Class claz = null;/*from   w w w  .  j  a v a  2  s. c o  m*/
    if (method != null && Modifier.isStatic(method.getModifiers())) {

        Annotation preHook = method.getAnnotation(PreTestCaseExecutionHook.class);
        Annotation postHook = method.getAnnotation(PostTestCaseExecutionHook.class);

        if (preHook != null) {
            PreTestCaseExecutionHook hook = (PreTestCaseExecutionHook) preHook;

            if (method.getParameterTypes().length != 1
                    || !method.getParameterTypes()[0].equals(TestCase.class)) {
                logger.severe("PreTestCaseExecutionHook annotated methods should "
                        + "confirm to the method signature - `public static void {methodName} ("
                        + "TestCase testCase)`");
                return claz;
            }

            if (hook.value() != null && hook.value().length > 0) {
                for (String testCaseName : hook.value()) {
                    if (testCaseName != null && !testCaseName.trim().isEmpty()) {
                        prePostTestCaseExecHooks.put("pre" + testCaseName, method);
                    }
                }
            } else {
                prePostTestCaseExecHooks.put("preAll", method);
            }
            claz = method.getDeclaringClass();
        }
        if (postHook != null) {
            PostTestCaseExecutionHook hook = (PostTestCaseExecutionHook) postHook;

            if (method.getParameterTypes().length != 1
                    || !method.getParameterTypes()[0].equals(TestCaseReport.class)) {
                logger.severe("PostTestCaseExecutionHook annotated methods should "
                        + "confirm to the method signature - `public static void {methodName} ("
                        + "TestCaseReport testCaseReport)`");
                return claz;
            }

            if (hook.value() != null && hook.value().length > 0) {
                for (String testCaseName : hook.value()) {
                    if (testCaseName != null && !testCaseName.trim().isEmpty()) {
                        prePostTestCaseExecHooks.put("post" + testCaseName, method);
                    }
                }
            } else {
                prePostTestCaseExecHooks.put("postAll", method);
            }
            claz = method.getDeclaringClass();
        }
    }
    return claz;
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@Test
public void defaultAccessMethodsWithStaticNativeOnly() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withAccess(AccessType.DEFAULT);
    memberCriteria.withModifiers(Modifier.STATIC | Modifier.NATIVE);
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    assertTrue(memberIterable.iterator().hasNext());
    for (Member member : memberIterable) {
        assertTrue("member must be a method", member instanceof Method);
        int modifiers = member.getModifiers();
        assertFalse(Modifier.isPublic(modifiers));
        assertFalse(Modifier.isProtected(modifiers));
        assertFalse(Modifier.isPrivate(modifiers));
        assertTrue(Modifier.isStatic(modifiers));
        assertTrue(Modifier.isNative(modifiers));
    }//  w ww.j a  v  a2 s  .c o  m
}

From source file:microsoft.exchange.webservices.data.core.service.schema.ServiceObjectSchema.java

/**
 * Initialize schema property names./*  www.ja  v a  2  s . c o  m*/
 */
public static void initializeSchemaPropertyNames() {
    synchronized (lockObject) {
        for (Class<?> type : ServiceObjectSchema.allSchemaTypes.getMember()) {
            Field[] fields = type.getDeclaredFields();
            for (Field field : fields) {
                int modifier = field.getModifiers();
                if (Modifier.isPublic(modifier) && Modifier.isStatic(modifier)) {
                    Object o;
                    try {
                        o = field.get(null);
                        if (o instanceof PropertyDefinition) {
                            PropertyDefinition propertyDefinition = (PropertyDefinition) o;
                            propertyDefinition.setName(field.getName());
                        }
                    } catch (IllegalArgumentException e) {
                        LOG.error(e);

                        // Skip the field
                    } catch (IllegalAccessException e) {
                        LOG.error(e);

                        // Skip the field
                    }
                }
            }
        }
    }
}

From source file:com.klwork.common.utils.ReflectionUtils.java

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

From source file:com.tongbanjie.tarzan.rpc.protocol.RpcCommand.java

private void customHeaderToMap() throws RpcCommandException {
    if (this.customHeader != null) {
        Field[] fields = getClazzFields(customHeader.getClass());
        if (null == this.customFields) {
            this.customFields = new HashMap<String, String>(8);
        }/*from   w w w .  j a  v a 2s.  c  o  m*/
        for (Field field : fields) {
            String fieldName = field.getName();
            Class clazz = field.getType();
            if (Modifier.isStatic(field.getModifiers()) || fieldName.startsWith("this")) {
                continue;
            }
            Object value;
            try {
                field.setAccessible(true);
                value = field.get(this.customHeader);
            } catch (Exception e) {
                throw new RpcCommandException(
                        "Encode the header failed, get the value of field <" + fieldName + "> error.", e);
            }
            if (value == null) {
                continue;
            }
            if (clazz.isEnum()) {
                this.customFields.put(fieldName, value.toString());
            } else {
                String type = getCanonicalName(clazz);
                String strValue = ClassUtils.simpleValueToString(type, value);
                if (strValue == null) {
                    throw new RpcCommandException("Encode the header failed, the field <" + fieldName
                            + "> type <" + getCanonicalName(clazz) + "> is not supported.");
                }
                this.customFields.put(fieldName, strValue);
            }
        }
    }
}

From source file:com.gwtcx.server.servlet.FileUploadServlet.java

@SuppressWarnings("rawtypes")
private Object createNestedEntity(Class entity, Field[] fields, String[] nextLine) {

    Log.debug("createNestedEntity()");

    try {//from   w w  w.  j a  va 2 s.c  om
        Object object = entity.newInstance();

        for (Field field : fields) {
            Class type = field.getType();

            // ignore Static fields
            if (Modifier.isStatic(field.getModifiers())) {
                continue;
            }

            if (type.getSimpleName().equals("String")) {
                Integer index = fieldNames.get(field.getName());
                if (index != null) {
                    field.set(object, nextLine[index].trim());
                    Log.debug("Field name: " + field.getName() + " index[" + index + "] = " + nextLine[index]);
                }
            }
        }

        return object;
    } catch (Exception e) {
        Log.error("Error encountered while creating nested entity", e);
    }

    return null;
}

From source file:ch.ifocusit.plantuml.classdiagram.ClassDiagramBuilder.java

public ClassAttribute[] readFields(Class aClass) {
    return Stream.of(aClass.getDeclaredFields())
            // exclude inner class
            .filter(field -> !field.getName().startsWith(DOLLAR))
            // exclude static fields
            .filter(field -> field.getDeclaringClass().isEnum() || !Modifier.isStatic(field.getModifiers()))
            .map(this::createClassAttribute)
            // excludes specific fields
            .filter(filterFields()).toArray(ClassAttribute[]::new);
}

From source file:com.metaparadigm.jsonrpc.JSONRPCBridge.java

private static ClassData analyzeClass(Class clazz) {
    log.info("analyzing " + clazz.getName());
    Method methods[] = clazz.getMethods();
    ClassData cd = new ClassData();
    cd.clazz = clazz;/*from w  ww  .j  a v a 2  s .  c o  m*/

    // Create temporary method map
    HashMap staticMethodMap = new HashMap();
    HashMap methodMap = new HashMap();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getDeclaringClass() == Object.class)
            continue;
        int mod = methods[i].getModifiers();
        if (!Modifier.isPublic(mod))
            continue;
        Class param[] = method.getParameterTypes();

        // don't count locally resolved args
        int argCount = 0;
        synchronized (localArgResolverMap) {
            for (int n = 0; n < param.length; n++) {
                HashSet resolvers = (HashSet) localArgResolverMap.get(param[n]);
                if (resolvers != null)
                    continue;
                argCount++;
            }
        }

        MethodKey mk = new MethodKey(method.getName(), argCount);
        ArrayList marr = (ArrayList) methodMap.get(mk);
        if (marr == null) {
            marr = new ArrayList();
            methodMap.put(mk, marr);
        }
        marr.add(method);
        if (Modifier.isStatic(mod)) {
            marr = (ArrayList) staticMethodMap.get(mk);
            if (marr == null) {
                marr = new ArrayList();
                staticMethodMap.put(mk, marr);
            }
            marr.add(method);
        }
    }
    cd.methodMap = new HashMap();
    cd.staticMethodMap = new HashMap();
    // Convert ArrayLists to arrays
    Iterator i = methodMap.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        MethodKey mk = (MethodKey) entry.getKey();
        ArrayList marr = (ArrayList) entry.getValue();
        if (marr.size() == 1) {
            cd.methodMap.put(mk, marr.get(0));
        } else {
            cd.methodMap.put(mk, marr.toArray(new Method[0]));
        }
    }
    i = staticMethodMap.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        MethodKey mk = (MethodKey) entry.getKey();
        ArrayList marr = (ArrayList) entry.getValue();
        if (marr.size() == 1) {
            cd.staticMethodMap.put(mk, marr.get(0));
        } else {
            cd.staticMethodMap.put(mk, marr.toArray(new Method[0]));
        }
    }
    return cd;
}