Example usage for org.objectweb.asm Opcodes ACC_STATIC

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

Introduction

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

Prototype

int ACC_STATIC

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

Click Source Link

Usage

From source file:com.google.template.soy.jbcsrc.FieldRef.java

License:Apache License

final boolean isStatic() {
    return (accessFlags() & Opcodes.ACC_STATIC) != 0;
}

From source file:com.google.template.soy.jbcsrc.restricted.FieldRef.java

License:Apache License

public static FieldRef staticFieldReference(java.lang.reflect.Field field) {
    if (!Modifier.isStatic(field.getModifiers())) {
        throw new IllegalStateException("Field: " + field + " is not static");
    }/*from  w  w  w  .  ja v a 2s .co  m*/
    return new AutoValue_FieldRef(TypeInfo.create(field.getDeclaringClass()), field.getName(),
            Type.getType(field.getType()), Opcodes.ACC_STATIC, /* isNullable= */ false);
}

From source file:com.google.template.soy.jbcsrc.restricted.FieldRef.java

License:Apache License

public static FieldRef createPublicStaticField(TypeInfo owner, String name, Type type) {
    return new AutoValue_FieldRef(owner, name, type,
            Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, !BytecodeUtils.isPrimitive(type));
}

From source file:com.google.template.soy.jbcsrc.restricted.FieldRef.java

License:Apache License

public final boolean isStatic() {
    return (accessFlags() & Opcodes.ACC_STATIC) != 0;
}

From source file:com.google.template.soy.jbcsrc.TemplateFactoryCompiler.java

License:Apache License

/**
 * Generates a static initializer that references the CompiledTemplate class to force eager
 * classloading (and thus verification errors). For example, <pre>{@code
 *   static {// w  w  w  .ja v  a 2  s  .c  om
 *     Class<?> clz = GeneratedTemplateClass.class;
 *   }}</pre>
 */
private void generateStaticInitializer(ClassVisitor cv) {
    if (Flags.DEBUG) {
        new Statement() {
            @Override
            void doGen(CodeBuilder adapter) {
                adapter.pushType(template.typeInfo().type());
                adapter.visitVarInsn(Opcodes.ASTORE, 0);
                adapter.returnValue();
            }
        }.writeMethod(Opcodes.ACC_STATIC, BytecodeUtils.CLASS_INIT, cv);
    }
}

From source file:com.google.template.soy.jbcsrc.TemplateVariableManager.java

License:Apache License

/**
 * Adds a private static final field and returns a reference to it.
 *
 * @param proposedName  The proposed name,  the actual name will be this plus an optional suffix
 *     to ensure uniqueness//from   w w  w.  j  a  va  2 s . c  om
 * @param initializer An expression to initialize the field.
 */
FieldRef addStaticField(String proposedName, Expression initializer) {
    String name = fieldNames.generateName(proposedName);
    FieldRef ref = new AutoValue_FieldRef(owner, name, initializer.resultType(),
            Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE, !initializer.isNonNullable());
    staticFields.add(new AutoValue_TemplateVariableManager_StaticFieldVariable(ref, initializer));
    return ref;
}

From source file:com.google.template.soy.jbcsrc.TemplateVariableManager.java

License:Apache License

/**
 * Adds definitions for all the static fields managed by this variable set and adds a
 * {@code <clinit>} method to the given class.
 *
 * @param writer The class to add the fields and static initializer to.
 *//*from  w  w  w  .  j a  va  2s.  c o  m*/
void defineStaticFields(ClassVisitor writer) {
    if (staticFields.isEmpty()) {
        return;
    }
    List<Statement> statements = new ArrayList<>();
    for (StaticFieldVariable staticField : staticFields) {
        staticField.field().defineField(writer);
        statements.add(staticField.field().putStaticField(staticField.initializer()));
    }
    statements.add(Statement.RETURN);
    Statement.concat(statements).writeMethod(Opcodes.ACC_STATIC, BytecodeUtils.CLASS_INIT, writer);
}

From source file:com.google.template.soy.jbcsrc.VariableSet.java

License:Apache License

/**
 * Adds a private static final field and returns a reference to it.
 *
 * @param proposedName  The proposed name,  the actual name will be this plus an optional suffix
 *     to ensure uniqueness/*from ww w  .j  a v  a  2s  .  co  m*/
 * @param initializer An expression to initialize the field.
 */
FieldRef addStaticField(String proposedName, Expression initializer) {
    String name = fieldNames.generateName(proposedName);
    FieldRef ref = new AutoValue_FieldRef(owner, name, initializer.resultType(),
            Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE, !initializer.isNonNullable());
    staticFields.add(new AutoValue_VariableSet_StaticFieldVariable(ref, initializer));
    return ref;
}

From source file:com.google.test.metric.asm.ClassInfoBuilderVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    boolean isStatic = (access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC;
    boolean isFinal = (access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL;
    return new MethodVisitorBuilder(repository, classInfo, name, desc, signature, exceptions, isStatic, isFinal,
            JavaVisibility.valueFromJavaBytecode(access));
}

From source file:com.google.test.metric.asm.FieldVisitorBuilder.java

License:Apache License

public FieldVisitorBuilder(ClassInfo classInfo, int access, String name, String desc, String signature,
        Object value) {/*from  www .  j ava 2  s.c o  m*/
    boolean isStatic = (access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC;
    boolean isPrivate = JavaVisibility.valueFromJavaBytecode(access) == Visibility.PRIVATE;
    boolean isFinal = (access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL;
    Type type = JavaType.fromDesc(desc);
    classInfo.addField(new FieldInfo(classInfo, name, type, isFinal, isStatic, isPrivate));
}