Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.*;

public class Main {
    /**
     * @deprecated since 1.9, use variant that takes second argument
     */
    @Deprecated
    public static String isLocalType(Class<?> type) {
        return isLocalType(type, false);
    }

    /**
     * @since 1.9
     */
    public static String isLocalType(Class<?> type, boolean allowNonStatic) {
        /* As per [JACKSON-187], GAE seems to throw SecurityExceptions
         * here and there... and GAE itself has a bug, too
         * (see []). Bah. So we need to catch some wayward exceptions on GAE
         */
        try {
            // one more: method locals, anonymous, are not good:
            if (type.getEnclosingMethod() != null) {
                return "local/anonymous";
            }

            /* But how about non-static inner classes? Can't construct
             * easily (theoretically, we could try to check if parent
             * happens to be enclosing... but that gets convoluted)
             */
            if (!allowNonStatic) {
                if (type.getEnclosingClass() != null) {
                    if (!Modifier.isStatic(type.getModifiers())) {
                        return "non-static member class";
                    }
                }
            }
        } catch (SecurityException e) {
        } catch (NullPointerException e) {
        }
        return null;
    }
}