Example usage for org.objectweb.asm Opcodes ACC_NATIVE

List of usage examples for org.objectweb.asm Opcodes ACC_NATIVE

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACC_NATIVE.

Prototype

int ACC_NATIVE

To view the source code for org.objectweb.asm Opcodes ACC_NATIVE.

Click Source Link

Usage

From source file:org.freud.analysed.classbytecode.parser.asm.AsmMethod.java

License:Apache License

@Override
public boolean isNative() {
    return isAccessModifier(Opcodes.ACC_NATIVE);
}

From source file:org.jboss.byteman.agent.adapter.AccessCheckAdapter.java

License:Open Source License

public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
        final String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    if ((access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_SYNTHETIC)) == 0
            && matchTargetMethod(name, desc)) {
        setVisited();/*from w w  w. j  a v a 2  s.  c o m*/
        return new AccessCheckMethodAdapter(mv, getTransformContext(), access, name, desc, signature,
                exceptions);
    }

    return mv;
}

From source file:org.jboss.byteman.agent.TransformContext.java

License:Open Source License

public boolean matchTargetMethod(int access, String name, String desc) {
    return ((access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_SYNTHETIC)) == 0
            && targetMethodName.equals(name)
            && (targetDescriptor.equals("") || TypeHelper.equalDescriptors(targetDescriptor, desc)));
}

From source file:org.osjava.jardiff.Tools.java

License:Apache License

/**
 * Returns whether a method's newAccess is incompatible with oldAccess
 * following <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html">Java Language Specification, Java SE 7 Edition</a>:
 * <ul>/*w w  w .  ja  va2 s  .co m*/
 *   <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.9">13.4.7 Access to Members and Constructors</a><ul>
 *     <li>Changing the declared access of a member or constructor to permit less access
 *        <b>may break compatibility</b> with pre-existing binaries, causing a linkage error to be thrown when these binaries are resolved.
 *     </li>
 *     <li>The binary format is defined so that changing a member or constructor to be more accessible does not cause a
 *         linkage error when a subclass (already) defines a method to have less access.
 *     </li>
 *     </ul></li>
 *   <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.16">13.4.16 abstract Methods</a><ul>
 *     <li>Changing a method that is declared abstract to no longer be declared abstract
 *         <b>does not break compatibility</b> with pre-existing binaries.</li>
 *     <li>Changing a method that is not declared abstract to be declared abstract
 *         <b>will break compatibility</b> with pre-existing binaries that previously invoked the method, causing an AbstractMethodError.</li>
 *     </ul></li>
 *   <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.17">13.4.17 final</a><ul>
 *     <li>Changing a method that is declared final to no longer be declared final
 *         <b>does not break compatibility</b> with pre-existing binaries.</li>
 *     <li>Changing an instance method that is not declared final to be declared final
 *         <b>may break compatibility</b> with existing binaries that depend on the ability to override the method.</li>
 *     <li>Changing a class (static) method that is not declared final to be declared final
 *         <b>does not break compatibility</b> with existing binaries, because the method could not have been overridden.</li>
 *     </ul></li>
 *   <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.18">13.4.18 native Methods</a><ul>
 *     <li>Adding or deleting a native modifier of a method
 *         <b>does not break compatibility</b> with pre-existing binaries.</li>
 *     </ul></li>
 *   <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.19">13.4.19 static Methods</a><ul>
 *     <li>If a method that is not declared private is also declared static (that is, a class method)
 *         and is changed to not be declared static (that is, to an instance method), or vice versa,
 *         then <i>compatibility with pre-existing binaries may be broken</i>, resulting in a linkage time error,
 *         namely an IncompatibleClassChangeError, if these methods are used by the pre-existing binaries.
 *         Such changes <b>break functional backward compatibility</b>!</li>
 *     </ul></li>
 *   <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.20">13.4.20 synchronized Methods</a><ul>
 *     <li>Adding or deleting a synchronized modifier of a method
 *         <b>does not break compatibility</b> with pre-existing binaries.</li>
 *   </ul></li>
 *   <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.21">13.4.21 Method and Constructor Throws</a><ul>
 *     <li>Changes to the throws clause of methods or constructors
 *         <b>do not break compatibility</b> with pre-existing binaries; these clauses are checked only at compile time.</li>
 *   </ul></li>
 * </ul>
 *
 * @param oldAccess
 * @param newAccess
 * @return
 */
public static boolean isMethodAccessChange(final int oldAccess, final int newAccess) {
    if (isAccessIncompatible(oldAccess, newAccess)) {
        return true; // 13.4.7
    }
    if (not(oldAccess, Opcodes.ACC_ABSTRACT) && has(newAccess, Opcodes.ACC_ABSTRACT)) {
        return true; // 13.4.16 #2
    } else if (not(oldAccess, Opcodes.ACC_FINAL) && not(oldAccess, Opcodes.ACC_STATIC)
            && has(newAccess, Opcodes.ACC_FINAL)) {
        return true; // 13.4.17 #2 excluding and #3
    } else {
        final int compatibleChanges = Opcodes.ACC_ABSTRACT | // 13.4.16 #1
                Opcodes.ACC_FINAL | // 13.4.17 #1
                Opcodes.ACC_NATIVE | // 13.4.18 #1
                Opcodes.ACC_SYNCHRONIZED; // 13.4.20 #1
        final int accessPermissions = Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE;
        final int oldAccess2 = oldAccess & ~compatibleChanges & ~accessPermissions;
        final int newAccess2 = newAccess & ~compatibleChanges & ~accessPermissions;
        return oldAccess2 != newAccess2;
    }
}

From source file:org.osjava.jardiff.ToolsTest.java

License:Apache License

@Test
public void isMethodAccessChange() {
    // A non-static method can't become final.
    assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_FINAL));
    assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL));
    // ... but can become non-final.
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_FINAL, 0));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC));
    // ... but a static method can become final!
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_STATIC, Opcodes.ACC_STATIC + Opcodes.ACC_FINAL));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC,
            Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL));

    // A method can become more accessible
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PUBLIC));
    assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_PUBLIC));
    assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_PROTECTED));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PUBLIC));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PROTECTED));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, 0));
    // ...but can't become less accessible
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, 0));
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PROTECTED));
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PRIVATE));
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, 0));
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PRIVATE));
    assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_PRIVATE));

    // A class or method can become concrete.
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_ABSTRACT, 0));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC));
    assertFalse(/*w w  w. j  av  a2  s . c  om*/
            Tools.isMethodAccessChange(Opcodes.ACC_ABSTRACT + Opcodes.ACC_PROTECTED, Opcodes.ACC_PROTECTED));
    // ...but can't become abstract
    assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_ABSTRACT));
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT));
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PROTECTED + Opcodes.ACC_ABSTRACT));

    // A method can't change static
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_STATIC, 0));
    assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC));

    // A method can change synchronized
    assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_SYNCHRONIZED));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC + Opcodes.ACC_SYNCHRONIZED));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_SYNCHRONIZED, 0));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC + Opcodes.ACC_SYNCHRONIZED, Opcodes.ACC_PUBLIC));

    // A method can change native
    assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_NATIVE));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC + Opcodes.ACC_NATIVE));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_NATIVE, 0));
    assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC + Opcodes.ACC_NATIVE, Opcodes.ACC_PUBLIC));
}

From source file:org.rascalmpl.library.lang.java.m3.internal.JarConverter.java

License:Open Source License

private IConstructor mapFieldAccesCode(int code, int where) {
    // Check the original M3 implementation for possible IConstructor types.
    switch (code) {
    case Opcodes.ACC_PUBLIC:
        return constructModifierNode("public");
    case Opcodes.ACC_PRIVATE:
        return constructModifierNode("private");
    case Opcodes.ACC_PROTECTED:
        return constructModifierNode("protected");
    case Opcodes.ACC_STATIC:
        return constructModifierNode("static");
    case Opcodes.ACC_FINAL:
        return constructModifierNode("final");
    case Opcodes.ACC_SYNCHRONIZED:
        if (where == CLASSE)
            return null;
        return constructModifierNode("synchronized");
    case Opcodes.ACC_ABSTRACT:
        return constructModifierNode("abstract");
    case Opcodes.ACC_VOLATILE:
        return constructModifierNode("volatile");
    case Opcodes.ACC_TRANSIENT:
        return constructModifierNode("transient");
    case Opcodes.ACC_NATIVE:
        return constructModifierNode("native");

    // TODO: GIT PULL/MERGE ORIGINAL RASCAL VERSION < 2013-11-30 (Shahin commit)
    // case Opcodes.ACC_DEPRECATED:
    // return constructModifierNode("deprecated");

    default:/*from w  ww.j  av a2 s  . c o m*/
        return null;
    }
}

From source file:org.sonar.java.resolve.FlagsTest.java

License:Open Source License

/**
 * Flags can be easily loaded from class-files into symbols.
 *//*from  w  w w. j  a v a2  s.  c  o  m*/
@Test
public void flags_match_asm_opcodes() {
    assertThat(Flags.PUBLIC).isEqualTo(Opcodes.ACC_PUBLIC);
    assertThat(Flags.PRIVATE).isEqualTo(Opcodes.ACC_PRIVATE);
    assertThat(Flags.PROTECTED).isEqualTo(Opcodes.ACC_PROTECTED);
    assertThat(Flags.STATIC).isEqualTo(Opcodes.ACC_STATIC);
    assertThat(Flags.FINAL).isEqualTo(Opcodes.ACC_FINAL);
    assertThat(Flags.SYNCHRONIZED).isEqualTo(Opcodes.ACC_SYNCHRONIZED);
    assertThat(Flags.VOLATILE).isEqualTo(Opcodes.ACC_VOLATILE);
    assertThat(Flags.TRANSIENT).isEqualTo(Opcodes.ACC_TRANSIENT);
    assertThat(Flags.NATIVE).isEqualTo(Opcodes.ACC_NATIVE);
    assertThat(Flags.INTERFACE).isEqualTo(Opcodes.ACC_INTERFACE);
    assertThat(Flags.ABSTRACT).isEqualTo(Opcodes.ACC_ABSTRACT);
    assertThat(Flags.STRICTFP).isEqualTo(Opcodes.ACC_STRICT);
    assertThat(Flags.SYNTHETIC).isEqualTo(Opcodes.ACC_SYNTHETIC);
    assertThat(Flags.ANNOTATION).isEqualTo(Opcodes.ACC_ANNOTATION);
    assertThat(Flags.ENUM).isEqualTo(Opcodes.ACC_ENUM);
}

From source file:org.springframework.migrationanalyzer.contributions.bytecode.AsmUtils.java

License:Apache License

/**
 * Converts the given bitwise ORed <code>modifiers</code> into a {@link String}.
 * /*from w w w.  j  a v a2  s  . co m*/
 * <p/>
 * 
 * The returned String should reflect the ordering recommended in the JLS:
 * 
 * <ul>
 * <li>Classes: <code>public protected private abstract static final strictfp</code></li>
 * <li>Fields: <code>public protected private static final transient volatile</code></li>
 * <li>Constructors: <code>public protected private</code></li>
 * <li>Methods: <code>public protected private abstract static final synchronized native strictfp</code></li>
 * </ul>
 * 
 * @param modifiers the modifiers
 * 
 * @return The String representation of the modifiers
 * 
 * @see Opcodes
 */
// CHECKSTYLE:OFF
static final String modifiersToString(int modifiers) {
    StringBuilder accessBuilder = new StringBuilder();

    if ((modifiers & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) {
        accessBuilder.append("public ");
    }
    if ((modifiers & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) {
        accessBuilder.append("protected ");
    }
    if ((modifiers & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) {
        accessBuilder.append("private ");
    }
    if ((modifiers & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) {
        accessBuilder.append("abstract ");
    }
    if ((modifiers & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) {
        accessBuilder.append("static ");
    }
    if ((modifiers & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) {
        accessBuilder.append("final ");
    }
    if ((modifiers & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED) {
        accessBuilder.append("synchronized ");
    }
    if ((modifiers & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE) {
        accessBuilder.append("native ");
    }
    if ((modifiers & Opcodes.ACC_TRANSIENT) == Opcodes.ACC_TRANSIENT) {
        accessBuilder.append("transient ");
    }
    if ((modifiers & Opcodes.ACC_VOLATILE) == Opcodes.ACC_VOLATILE) {
        accessBuilder.append("volatile ");
    }
    if ((modifiers & Opcodes.ACC_STRICT) == Opcodes.ACC_STRICT) {
        accessBuilder.append("strictfp ");
    }

    return accessBuilder.toString().trim();
}

From source file:org.springframework.migrationanalyzer.contributions.bytecode.AsmUtilsTests.java

License:Apache License

@Test
public void methodAccessOrdering() {
    assertEquals("public protected private abstract static final synchronized native strictfp",
            AsmUtils.modifiersToString(Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE
                    | Opcodes.ACC_ABSTRACT | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNCHRONIZED
                    | Opcodes.ACC_NATIVE | Opcodes.ACC_STRICT));
}

From source file:org.springsource.loaded.test.infra.ClassPrinter.java

License:Apache License

private String toAccessForClass(int flags) {
    StringBuilder sb = new StringBuilder();
    if ((flags & Opcodes.ACC_PUBLIC) != 0) {
        sb.append("public ");
    }/*  w  ww  .  j  a v  a2s.  c o m*/
    if ((flags & Opcodes.ACC_PRIVATE) != 0) {
        sb.append("private ");
    }
    if ((flags & Opcodes.ACC_PROTECTED) != 0) {
        sb.append("protected ");
    }
    if ((flags & Opcodes.ACC_STATIC) != 0) {
        sb.append("static ");
    }
    if ((flags & Opcodes.ACC_FINAL) != 0) {
        sb.append("final ");
    }
    if ((flags & Opcodes.ACC_SYNCHRONIZED) != 0) {
        sb.append("synchronized ");
    }
    if ((flags & Opcodes.ACC_BRIDGE) != 0) {
        sb.append("bridge ");
    }
    if ((flags & Opcodes.ACC_VARARGS) != 0) {
        sb.append("varargs ");
    }
    if ((flags & Opcodes.ACC_NATIVE) != 0) {
        sb.append("native ");
    }
    if ((flags & Opcodes.ACC_ABSTRACT) != 0) {
        sb.append("abstract ");
    }
    if ((flags & Opcodes.ACC_SYNTHETIC) != 0) {
        sb.append("synthetic ");
    }
    if ((flags & Opcodes.ACC_DEPRECATED) != 0) {
        sb.append("deprecated ");
    }
    if ((flags & Opcodes.ACC_INTERFACE) != 0) {
        sb.append("interface ");
    }
    return sb.toString().trim();
}