Java Code Examples for java.lang.reflect.Modifier#ABSTRACT

The following examples show how to use java.lang.reflect.Modifier#ABSTRACT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModifierUtil.java    From kalang with MIT License 6 votes vote down vote up
private static int parseSingleModfier(String s) throws InvalidModifierException {
    switch (s) {
        case "public":
            return Modifier.PUBLIC;
        case "protected":
            return Modifier.PROTECTED;
        case "private":
            return Modifier.PRIVATE;
        case "static":
            return Modifier.STATIC;
        case "final":
            return Modifier.FINAL;
        case "abstract":
            return Modifier.ABSTRACT;
        case "native":
            return Modifier.NATIVE;
        case "synchronized":
            return Modifier.SYNCHRONIZED;
        case "transient":
            return Modifier.TRANSIENT;
        case "volatile":
            return Modifier.VOLATILE;
        default:
            throw new InvalidModifierException("unrecognized modifier:" + s);
    }
}
 
Example 2
Source File: ObjectStreamClass.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 *
 * Copied from the Merlin java.io.ObjectStreamClass.
 */
private static Method getInheritableMethod(Class cl, String name,
                                           Class[] argTypes,
                                           Class returnType)
{
    Method meth = null;
    Class defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
Example 3
Source File: ObjectStreamClass.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 *
 * Copied from the Merlin java.io.ObjectStreamClass.
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
Example 4
Source File: ObjectStreamClass.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
Example 5
Source File: SerializableMethod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public SerializableMethod(Method method) {
    declaringClass = method.getDeclaringClass();
    methodName = method.getName();
    parameterTypes = method.getParameterTypes();
    returnType = method.getReturnType();
    exceptionTypes = method.getExceptionTypes();
    isVarArgs = method.isVarArgs();
    isAbstract = (method.getModifiers() & Modifier.ABSTRACT) != 0;
}
 
Example 6
Source File: ObjectStreamClass.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
Example 7
Source File: ObjectStreamClass.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
Example 8
Source File: InnerClassesInfo.java    From yGuard with MIT License 5 votes vote down vote up
public int getModifiers(){
  int mods = 0;
  if ((u2innerClassAccessFlags & 0x0001) == 0x0001) mods |= Modifier.PUBLIC;
  if ((u2innerClassAccessFlags & 0x0002) == 0x0002) mods |= Modifier.PRIVATE;
  if ((u2innerClassAccessFlags & 0x0004) == 0x0004) mods |= Modifier.PROTECTED;
  if ((u2innerClassAccessFlags & 0x0008) == 0x0008) mods |= Modifier.STATIC;
  if ((u2innerClassAccessFlags & 0x0010) == 0x0010) mods |= Modifier.FINAL;
  if ((u2innerClassAccessFlags & 0x0200) == 0x0200) mods |= Modifier.INTERFACE;
  if ((u2innerClassAccessFlags & 0x0400) == 0x0400) mods |= Modifier.ABSTRACT;
  return mods;
}
 
Example 9
Source File: ObjectStreamClass.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 *
 * Copied from the Merlin java.io.ObjectStreamClass.
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
Example 10
Source File: ObjectStreamClass.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
Example 11
Source File: ObjectStreamClass.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Returns non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * null if no match found.  Access checks are disabled on the returned
 * method (if any).
 */
private static Method getInheritableMethod(Class<?> cl, String name,
                                           Class<?>[] argTypes,
                                           Class<?> returnType)
{
    Method meth = null;
    Class<?> defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return null;
    }
    meth.setAccessible(true);
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return null;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return meth;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl) ? meth : null;
    } else {
        return packageEquals(cl, defCl) ? meth : null;
    }
}
 
Example 12
Source File: AutoSerializableManager.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if a non-static, non-abstract method with given signature provided it
 * is defined by or accessible (via inheritance) by the given class, or
 * false if no match found.
 */
private static boolean getInheritableMethod(Class cl, String name,
                                           Class[] argTypes,
                                           Class returnType)
{
    Method meth = null;
    Class defCl = cl;
    while (defCl != null) {
        try {
            meth = defCl.getDeclaredMethod(name, argTypes);
            break;
        } catch (NoSuchMethodException ex) {
            defCl = defCl.getSuperclass();
        }
    }

    if ((meth == null) || (meth.getReturnType() != returnType)) {
        return false;
    }
    int mods = meth.getModifiers();
    if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
        return false;
    } else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
        return true;
    } else if ((mods & Modifier.PRIVATE) != 0) {
        return (cl == defCl);
    } else {
        return packageEquals(cl, defCl);
    }
}
 
Example 13
Source File: Ast2Class.java    From kalang with MIT License 5 votes vote down vote up
private void createInterfaceBridgeMethodIfNeed(MethodNode interfaceMethod,MethodNode implementMethod) {
    String desc = getMethodDescriptor(interfaceMethod);
    String implementDesc = getMethodDescriptor(implementMethod);
    if (desc.equals(implementDesc)) {
        return;
    }
    int access = interfaceMethod.getModifier() & ~Modifier.ABSTRACT;
    String name = interfaceMethod.getName();
    MethodVisitor methodVisitor = classWriter.visitMethod(access, name, desc, methodSignature(interfaceMethod), null);
    ParameterNode[] params = interfaceMethod.getParameters();
    for(ParameterNode p : params) {
        methodVisitor.visitParameter(p.getName(), p.getModifier());
    }
    ParameterNode[] implementedParams = implementMethod.getParameters();
    methodVisitor.visitVarInsn(ALOAD,0);
    int varIdx = 1;
    for(int i=0;i<params.length;i++) {
        Type implementedParamType = implementedParams[i].getType();
        Type interfaceParamType = params[i].getType();
        org.objectweb.asm.Type interfaceParamAsmType = asmType(interfaceParamType);
        methodVisitor.visitVarInsn(interfaceParamAsmType.getOpcode(ILOAD),varIdx);
        if (!implementedParamType.isAssignableFrom(interfaceParamType)) {
            methodVisitor.visitTypeInsn(CHECKCAST,internalName(implementedParamType));
        }
        varIdx += interfaceParamAsmType.getSize();
    }
    String owner = internalName(implementMethod.getClassNode());
    methodVisitor.visitMethodInsn(INVOKEVIRTUAL,owner,implementMethod.getName(),implementDesc,false);
    Type returnType = interfaceMethod.getType();
    if (VOID_TYPE.equals(returnType)) {
        methodVisitor.visitInsn(RETURN);
    } else {
        methodVisitor.visitInsn(asmType(returnType).getOpcode(IRETURN));
    }
    methodVisitor.visitMaxs(0,0);
    methodVisitor.visitEnd();
}
 
Example 14
Source File: StructUtils.java    From javastruct with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * is object accessible?
 *
 * @param obj Object
 * @throws StructException 
 */
public static void isAccessible(Object obj) throws StructException{
    int modifiers = obj.getClass().getModifiers();
    if ((modifiers & Modifier.PUBLIC) == 0)
        throw new StructException("Struct operations are only accessible for public classes. Class: " + obj.getClass().getName());
    if ((modifiers & (Modifier.INTERFACE | Modifier.ABSTRACT)) != 0)
        throw new StructException("Struct operations are not accessible for abstract classes and interfaces. Class: " + obj.getClass().getName());
}
 
Example 15
Source File: TestRunnerUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@TestOnly
public static boolean isJUnit4TestClass(final Class aClass) {
  final int modifiers = aClass.getModifiers();
  if ((modifiers & Modifier.ABSTRACT) != 0) return false;
  if ((modifiers & Modifier.PUBLIC) == 0) return false;
  if (aClass.getAnnotation(RunWith.class) != null) return true;
  for (Method method : aClass.getMethods()) {
    if (method.getAnnotation(Test.class) != null) return true;
  }
  return false;
}
 
Example 16
Source File: Class.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the Java language modifiers for this class or interface, encoded
 * in an integer. The modifiers consist of the Java Virtual Machine's
 * constants for {@code public}, {@code protected},
 * {@code private}, {@code final}, {@code static},
 * {@code abstract} and {@code interface}; they should be decoded
 * using the methods of class {@code Modifier}.
 *
 * <p> If the underlying class is an array class, then its
 * {@code public}, {@code private} and {@code protected}
 * modifiers are the same as those of its component type.  If this
 * {@code Class} represents a primitive type or void, its
 * {@code public} modifier is always {@code true}, and its
 * {@code protected} and {@code private} modifiers are always
 * {@code false}. If this object represents an array class, a
 * primitive type or void, then its {@code final} modifier is always
 * {@code true} and its interface modifier is always
 * {@code false}. The values of its other modifiers are not determined
 * by this specification.
 *
 * <p> The modifier encodings are defined in <em>The Java Virtual Machine
 * Specification</em>, table 4.1.
 *
 * @return the {@code int} representing the modifiers for this class
 * @see     java.lang.reflect.Modifier
 * @since JDK1.1
 */
public int getModifiers() {
    // Array classes inherit modifiers from their component types, but in the case of arrays
    // of an inner class, the class file may contain "fake" access flags because it's not valid
    // for a top-level class to private, say. The real access flags are stored in the InnerClass
    // attribute, so we need to make sure we drill down to the inner class: the accessFlags
    // field is not the value we want to return, and the synthesized array class does not itself
    // have an InnerClass attribute. https://code.google.com/p/android/issues/detail?id=56267
    if (isArray()) {
        int componentModifiers = getComponentType().getModifiers();
        if ((componentModifiers & Modifier.INTERFACE) != 0) {
            componentModifiers &= ~(Modifier.INTERFACE | Modifier.STATIC);
        }
        return Modifier.ABSTRACT | Modifier.FINAL | componentModifiers;
    }
    int JAVA_FLAGS_MASK = 0xffff;
    int modifiers = this.getInnerClassFlags(accessFlags & JAVA_FLAGS_MASK);
    return modifiers & JAVA_FLAGS_MASK;
}
 
Example 17
Source File: Code.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static boolean flagsRequireCode(int flags) {
    // A method's flags force it to have a Code attribute,
    // if the flags are neither native nor abstract.
    return (flags & (Modifier.NATIVE | Modifier.ABSTRACT)) == 0;
}
 
Example 18
Source File: Code.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static boolean flagsRequireCode(int flags) {
    // A method's flags force it to have a Code attribute,
    // if the flags are neither native nor abstract.
    return (flags & (Modifier.NATIVE | Modifier.ABSTRACT)) == 0;
}
 
Example 19
Source File: Code.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
static boolean flagsRequireCode(int flags) {
    // A method's flags force it to have a Code attribute,
    // if the flags are neither native nor abstract.
    return (flags & (Modifier.NATIVE | Modifier.ABSTRACT)) == 0;
}
 
Example 20
Source File: Code.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static boolean flagsRequireCode(int flags) {
    // A method's flags force it to have a Code attribute,
    // if the flags are neither native nor abstract.
    return (flags & (Modifier.NATIVE | Modifier.ABSTRACT)) == 0;
}