Example usage for org.objectweb.asm Opcodes ACC_PROTECTED

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

Introduction

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

Prototype

int ACC_PROTECTED

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

Click Source Link

Usage

From source file:com.devexperts.usages.PublicApiAnalyzer.java

License:Open Source License

private static boolean isPublicApi(int access) {
    return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0;
}

From source file:com.facebook.buck.java.abi.MirrorTest.java

License:Apache License

@Test
public void shouldPreserveAField() throws IOException {
    Path jar = compileToJar(EMPTY_CLASSPATH, "A.java", Joiner.on("\n").join(ImmutableList
            .of("package com.example.buck;", "public class A {", "  protected String protectedField;", "}")));

    new StubJar(jar).writeTo(filesystem, stubJar);

    AbiClass stubbed = readClass(stubJar, "com/example/buck/A.class");
    FieldNode field = stubbed.findField("protectedField");
    assertEquals("protectedField", field.name);
    assertTrue((field.access & Opcodes.ACC_PROTECTED) > 0);
}

From source file:com.facebook.buck.jvm.java.abi.AbiFilteringClassVisitorTest.java

License:Apache License

@Test
public void testIncludesProtectedFields() {
    testIncludesFieldWithAccess(Opcodes.ACC_PROTECTED);
}

From source file:com.facebook.buck.jvm.java.abi.AccessFlags.java

License:Apache License

/**
 * Gets the class access flags (see JVMS8 4.1) for the given type element as they should appear in
 * the ClassNode of a class file. Inner-class specific flags are not allowed in that node,
 * presumably for compatibility reasons.
 *//*  ww w.  j a v  a  2s.c  o m*/
public int getAccessFlagsForClassNode(TypeElement e) {
    // Static never makes it into the file for classes
    int accessFlags = getAccessFlags(e) & ~Opcodes.ACC_STATIC;
    if (e.getNestingKind() != NestingKind.TOP_LEVEL) {
        if (e.getModifiers().contains(Modifier.PROTECTED)) {
            // It looks like inner classes with protected visibility get marked as public, and then
            // their InnerClasses attributes override that more specifically
            accessFlags = (accessFlags & ~Opcodes.ACC_PROTECTED) | Opcodes.ACC_PUBLIC;
        } else if (e.getModifiers().contains(Modifier.PRIVATE)) {
            // It looks like inner classes with private visibility get marked as package, and then
            // their InnerClasses attributes override that more specifically
            accessFlags = (accessFlags & ~Opcodes.ACC_PRIVATE);
        }
    }

    return accessFlags;
}

From source file:com.facebook.buck.jvm.java.abi.AccessFlags.java

License:Apache License

/** Gets the access flag (see JVMS8 4.1, 4.5, 4.6) corresponding to the given modifier. */
private static int modifierToAccessFlag(Modifier modifier) {
    switch (modifier) {
    case PUBLIC:/*from   w w  w  . ja v a2  s . c om*/
        return Opcodes.ACC_PUBLIC;
    case PROTECTED:
        return Opcodes.ACC_PROTECTED;
    case PRIVATE:
        return Opcodes.ACC_PRIVATE;
    case ABSTRACT:
        return Opcodes.ACC_ABSTRACT;
    case DEFAULT:
        return 0;
    case STATIC:
        return Opcodes.ACC_STATIC;
    case FINAL:
        return Opcodes.ACC_FINAL;
    case TRANSIENT:
        return Opcodes.ACC_TRANSIENT;
    case VOLATILE:
        return Opcodes.ACC_VOLATILE;
    case SYNCHRONIZED:
        return Opcodes.ACC_SYNCHRONIZED;
    case NATIVE:
        return Opcodes.ACC_NATIVE;
    case STRICTFP:
        return Opcodes.ACC_STRICT;
    default:
        throw new IllegalArgumentException(String.format("Unexpected modifier: %s", modifier));
    }
}

From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java

License:Apache License

@Test
public void testProtectedFlagOnField() throws IOException {
    testFieldFlags("protected", Opcodes.ACC_PROTECTED);
}

From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java

License:Apache License

@Test
public void testProtectedFlagOnMethod() throws IOException {
    testMethodFlags("protected", Opcodes.ACC_PROTECTED);
}

From source file:com.gargoylesoftware.js.nashorn.internal.ir.debug.NashornTextifier.java

License:Open Source License

private static void appendAccess(final StringBuilder sb, final int access) {
    if ((access & Opcodes.ACC_PUBLIC) != 0) {
        sb.append("public ");
    }//from ww  w.j a  v  a2  s  .c o m
    if ((access & Opcodes.ACC_PRIVATE) != 0) {
        sb.append("private ");
    }
    if ((access & Opcodes.ACC_PROTECTED) != 0) {
        sb.append("protected ");
    }
    if ((access & Opcodes.ACC_FINAL) != 0) {
        sb.append("final ");
    }
    if ((access & Opcodes.ACC_STATIC) != 0) {
        sb.append("static ");
    }
    if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
        sb.append("synchronized ");
    }
    if ((access & Opcodes.ACC_VOLATILE) != 0) {
        sb.append("volatile ");
    }
    if ((access & Opcodes.ACC_TRANSIENT) != 0) {
        sb.append("transient ");
    }
    if ((access & Opcodes.ACC_ABSTRACT) != 0) {
        sb.append("abstract ");
    }
    if ((access & Opcodes.ACC_STRICT) != 0) {
        sb.append("strictfp ");
    }
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        sb.append("synthetic ");
    }
    if ((access & Opcodes.ACC_MANDATED) != 0) {
        sb.append("mandated ");
    }
    if ((access & Opcodes.ACC_ENUM) != 0) {
        sb.append("enum ");
    }
}

From source file:com.github.veithen.phos.enforcer.ClassProcessor.java

License:Apache License

private static boolean isPublic(int access) {
    return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0;
}

From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java

License:Apache License

public void testTwo() {
    CollectClassData cd = collect(Two.class);
    // Don't check for super bit, as it will depend on the JDK used to compile.
    assertEquals(Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC, cd.getAccess() & ~Opcodes.ACC_SUPER);
    assertEquals(ClassType.Nested, cd.getClassType());
    List<CollectFieldData> fields = cd.getFields();
    assertEquals(2, fields.size());//from   w w w. j av a  2s  .c om
    CollectFieldData field = fields.get(0);
    assertEquals("field", field.getName());
    assertEquals("Ljava/lang/String;", field.getDesc());
    List<CollectAnnotationData> annotations = field.getAnnotations();
    assertEquals(0, annotations.size());
    field = fields.get(1);
    assertEquals("annotatedField", field.getName());
    assertEquals("Ljava/lang/String;", field.getDesc());
    annotations = field.getAnnotations();
    assertEquals(1, annotations.size());
    AnnotationData annotation = annotations.get(0).getAnnotation();
    assertEquals("Lcom/google/gwt/dev/javac/typemodel/test/TestAnnotation;", annotation.getDesc());
    assertEquals("field", annotation.getValues().get("value"));
    assertEquals(0, cd.getInterfaceInternalNames().length);
    annotations = cd.getAnnotations();
    assertEquals(1, annotations.size());
    annotation = annotations.get(0).getAnnotation();
    assertEquals("Lcom/google/gwt/dev/javac/typemodel/test/PrimitiveValuesAnnotation;", annotation.getDesc());
    assertEquals(Byte.valueOf((byte) 42), annotation.getValues().get("b"));
    assertEquals(42, annotation.getValues().get("i"));
    assertEquals("java/lang/Object", cd.getSuperInternalName());
    assertEquals("CollectClassDataTest.Two", cd.getNestedSourceName());

    List<CollectMethodData> methods = cd.getMethods();
    assertEquals(3, methods.size());
    // TODO(jat): Is it safe to assume the order?
    CollectMethodData method = methods.get(0);
    Type[] argTypes = method.getArgTypes();
    String[] argNames = method.getArgNames();
    assertEquals("<init>", method.getName());
    assertEquals(1, argTypes.length);
    assertEquals(1, argNames.length);
    assertEquals(1, method.getArgAnnotations().length);
    assertEquals(0, method.getAnnotations().size());
    assertEquals(0, method.getExceptions().length);

    method = methods.get(1);
    argTypes = method.getArgTypes();
    argNames = method.getArgNames();
    assertEquals("foo", method.getName());
    assertEquals(1, argTypes.length);
    assertEquals("int", argTypes[0].getClassName());
    assertEquals(1, argNames.length);
    assertEquals("a", argNames[0]);
    assertEquals(1, method.getArgAnnotations().length);
    assertEquals(0, method.getArgAnnotations()[0].size());
    assertEquals(1, method.getAnnotations().size());
    assertEquals(1, method.getExceptions().length);

    method = methods.get(2);
    argTypes = method.getArgTypes();
    argNames = method.getArgNames();
    assertEquals("<init>", method.getName());
    assertEquals(2, argTypes.length);
    assertEquals("int", argTypes[0].getClassName());
    assertEquals("java.lang.String", argTypes[1].getClassName());
    assertEquals(2, argNames.length);
    assertEquals("a", argNames[0]);
    assertEquals("b", argNames[1]);
    assertEquals(2, method.getArgAnnotations().length);
    assertEquals(0, method.getArgAnnotations()[0].size());
    assertEquals(0, method.getArgAnnotations()[1].size());
    assertEquals(0, method.getAnnotations().size());
    assertEquals(0, method.getExceptions().length);
}