Example usage for org.objectweb.asm Opcodes ACC_TRANSIENT

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

Introduction

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

Prototype

int ACC_TRANSIENT

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

Click Source Link

Usage

From source file:org.apache.tika.parser.asm.XHTMLClassVisitor.java

License:Apache License

private void writeAccess(int access) throws SAXException {
    writeAccess(access, Opcodes.ACC_PRIVATE, "private");
    writeAccess(access, Opcodes.ACC_PROTECTED, "protected");
    writeAccess(access, Opcodes.ACC_PUBLIC, "public");
    writeAccess(access, Opcodes.ACC_STATIC, "static");
    writeAccess(access, Opcodes.ACC_FINAL, "final");
    writeAccess(access, Opcodes.ACC_ABSTRACT, "abstract");
    writeAccess(access, Opcodes.ACC_SYNCHRONIZED, "synchronized");
    writeAccess(access, Opcodes.ACC_TRANSIENT, "transient");
    writeAccess(access, Opcodes.ACC_VOLATILE, "volatile");
    writeAccess(access, Opcodes.ACC_NATIVE, "native");
}

From source file:org.batoo.jpa.core.impl.instance.Enhancer.java

License:Open Source License

/**
 * Returns the enhanced class bytecode.//  w  ww . j a  v a2 s.c o  m
 * 
 * @param clazz
 *            the class to enhance
 * @return the enhanced class
 * @throws Exception
 *             thrown in case of an error
 * 
 * @since 2.0.0
 */
//@formatter:off
public static byte[] create(Class<?> clazz) throws Exception {

    final String enhancingClassName = Type.getInternalName(clazz);
    final String enhancedClassName = enhancingClassName + Enhancer.SUFFIX_ENHANCED;
    final String descEnhancer = Enhancer.makeClassDesc(enhancedClassName);

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, enhancedClassName, null, enhancingClassName,
            new String[] { Type.getInternalName(EnhancedInstance.class) });

    // Field: serialVersionUID
    cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
            Enhancer.FIELD_SERIAL_VERSION_UID, Type.getDescriptor(Long.TYPE), null, Long.valueOf(1L))
            .visitEnd();

    // Container fields
    cw.visitField(Opcodes.ACC_PRIVATE, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN, null,
            null).visitEnd();
    cw.visitField(Opcodes.ACC_PRIVATE, Enhancer.FIELD_ENHANCED_INTERNAL, Enhancer.DESCRIPTOR_BOOLEAN, null,
            null).visitEnd();
    cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_TRANSIENT, Enhancer.FIELD_ENHANCED_ID,
            Enhancer.DESCRIPTOR_OBJECT, null, null).visitEnd();
    cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_TRANSIENT, Enhancer.FIELD_ENHANCED_TYPE,
            Enhancer.DESCRIPTOR_CLASS, null, null).visitEnd();
    cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_TRANSIENT,
            Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION, null, null).visitEnd();
    cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_TRANSIENT, Enhancer.FIELD_ENHANCED_MANAGED_INSTANCE,
            Enhancer.DESCRIPTOR_MANAGED_INSTANCE, null, null).visitEnd();

    // Constructors
    Enhancer.createNoArgConstructor(enhancingClassName, enhancedClassName, descEnhancer, cw);
    Enhancer.createContainerConstructor(enhancingClassName, enhancedClassName, descEnhancer, cw);
    Enhancer.createMethodIsInitialized(enhancedClassName, descEnhancer, cw);
    Enhancer.createMethodSetInitialized(enhancedClassName, descEnhancer, cw);
    Enhancer.createMethodCheck(enhancedClassName, descEnhancer, cw);
    Enhancer.createMethodGetManagedInstance(enhancedClassName, descEnhancer, cw);
    Enhancer.createMethodSetManagedInstance(enhancedClassName, descEnhancer, cw);
    Enhancer.createMethodSetInternal(enhancedClassName, descEnhancer, cw);

    final Map<String, Method> methods = Maps.newHashMap();

    Class<?> currentClass = clazz;
    while (currentClass != Object.class) { // we are not interested in Object.class
        for (final Method method : currentClass.getDeclaredMethods()) {
            int modifiers = method.getModifiers();

            if (Modifier.isAbstract(modifiers) || Modifier.isStatic(modifiers) || Modifier.isPrivate(modifiers)
                    || method.isSynthetic() || method.isBridge()) {
                continue;
            }

            // Filter out the details that we are not interested
            modifiers &= Modifier.ABSTRACT;
            modifiers &= Modifier.FINAL;
            modifiers &= Modifier.NATIVE;
            modifiers &= Modifier.PRIVATE;
            modifiers &= Modifier.PROTECTED;
            modifiers &= Modifier.STATIC;
            modifiers &= Modifier.STRICT;

            if ((modifiers == Modifier.PUBLIC) || (modifiers == 0)) {
                // we are not interested in the return type to omit the overridden methods
                final String desc = method.getName()
                        + Enhancer.makeDescription(Void.TYPE, method.getParameterTypes());

                if (methods.get(desc) == null) {
                    methods.put(desc, method);
                }
            }
        }

        currentClass = currentClass.getSuperclass();
    }

    for (final Method method : methods.values()) {
        if (!Enhancer.IGNORED_METHODS.contains(method.getName())) {
            Enhancer.createOverrriddenMethod(enhancingClassName, enhancedClassName, descEnhancer, cw, method);
        }
    }

    cw.visitEnd();

    return cw.toByteArray();
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void fieldDef(AST fieldDef) {
    List<AnnotationNode> annotations = new ArrayList<>();
    AST node = fieldDef.getFirstChild();

    int modifiers = 0;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        node = node.getNextSibling();//  ww w.j  a  va 2  s .co  m
    }

    if (classNode.isInterface()) {
        modifiers |= Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
        if ((modifiers & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) == 0) {
            modifiers |= Opcodes.ACC_PUBLIC;
        }
    }

    ClassNode type = null;
    if (isType(TYPE, node)) {
        type = makeTypeWithArguments(node);
        node = node.getNextSibling();
    }

    String name = identifier(node);
    node = node.getNextSibling();

    Expression initialValue = null;
    if (node != null) {
        assertNodeType(ASSIGN, node);
        initialValue = expression(node.getFirstChild());
    }

    if (classNode.isInterface() && initialValue == null && type != null) {
        initialValue = getDefaultValueForPrimitive(type);
    }

    FieldNode fieldNode = new FieldNode(name, modifiers, type, classNode, initialValue);
    fieldNode.addAnnotations(annotations);
    configureAST(fieldNode, fieldDef);

    if (!hasVisibility(modifiers)) {
        // let's set the modifiers on the field
        int fieldModifiers = 0;
        int flags = Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT | Opcodes.ACC_VOLATILE | Opcodes.ACC_FINAL;

        if (!hasVisibility(modifiers)) {
            modifiers |= Opcodes.ACC_PUBLIC;
            fieldModifiers |= Opcodes.ACC_PRIVATE;
        }

        // let's pass along any other modifiers we need
        fieldModifiers |= (modifiers & flags);
        fieldNode.setModifiers(fieldModifiers);
        fieldNode.setSynthetic(true);

        // in the case that there is already a field, we would
        // like to use that field, instead of the default field
        // for the property
        FieldNode storedNode = classNode.getDeclaredField(fieldNode.getName());
        if (storedNode != null && !classNode.hasProperty(name)) {
            fieldNode = storedNode;
            // we remove it here, because addProperty will add it
            // again and we want to avoid it showing up multiple
            // times in the fields list.
            classNode.getFields().remove(storedNode);
        }

        PropertyNode propertyNode = new PropertyNode(fieldNode, modifiers, null, null);
        configureAST(propertyNode, fieldDef);
        classNode.addProperty(propertyNode);
    } else {
        fieldNode.setModifiers(modifiers);
        // if there is a property of that name, then a field of that
        // name already exists, which means this new field here should
        // be used instead of the field the property originally has.
        PropertyNode pn = classNode.getProperty(name);
        if (pn != null && pn.getField().isSynthetic()) {
            classNode.getFields().remove(pn.getField());
            pn.setField(fieldNode);
        }
        classNode.addField(fieldNode);
    }
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected int modifiers(AST modifierNode, List<AnnotationNode> annotations, int defaultModifiers) {
    assertNodeType(MODIFIERS, modifierNode);

    boolean access = false;
    int answer = 0;

    for (AST node = modifierNode.getFirstChild(); node != null; node = node.getNextSibling()) {
        int type = node.getType();
        switch (type) {
        case STATIC_IMPORT:
            // ignore
            break;

        // annotations
        case ANNOTATION:
            annotations.add(annotation(node));
            break;

        // core access scope modifiers
        case LITERAL_private:
            answer = setModifierBit(node, answer, Opcodes.ACC_PRIVATE);
            access = setAccessTrue(node, access);
            break;

        case LITERAL_protected:
            answer = setModifierBit(node, answer, Opcodes.ACC_PROTECTED);
            access = setAccessTrue(node, access);
            break;

        case LITERAL_public:
            answer = setModifierBit(node, answer, Opcodes.ACC_PUBLIC);
            access = setAccessTrue(node, access);
            break;

        // other modifiers
        case ABSTRACT:
            answer = setModifierBit(node, answer, Opcodes.ACC_ABSTRACT);
            break;

        case FINAL:
            answer = setModifierBit(node, answer, Opcodes.ACC_FINAL);
            break;

        case LITERAL_native:
            answer = setModifierBit(node, answer, Opcodes.ACC_NATIVE);
            break;

        case LITERAL_static:
            answer = setModifierBit(node, answer, Opcodes.ACC_STATIC);
            break;

        case STRICTFP:
            answer = setModifierBit(node, answer, Opcodes.ACC_STRICT);
            break;

        case LITERAL_synchronized:
            answer = setModifierBit(node, answer, Opcodes.ACC_SYNCHRONIZED);
            break;

        case LITERAL_transient:
            answer = setModifierBit(node, answer, Opcodes.ACC_TRANSIENT);
            break;

        case LITERAL_volatile:
            answer = setModifierBit(node, answer, Opcodes.ACC_VOLATILE);
            break;

        default:/*from   w w  w .  j av  a  2  s .  com*/
            unknownAST(node);
        }
    }
    if (!access) {
        answer |= defaultModifiers;
        // ACC_SYNTHETIC isn't used here, use it as a special flag
        if (defaultModifiers == Opcodes.ACC_PUBLIC)
            answer |= Opcodes.ACC_SYNTHETIC;
    }
    return answer;
}

From source file:org.codehaus.groovy.parser.antlr4.ASTBuilder.java

License:Apache License

/**
 * Traverse through modifiers, and combine them in one int value. Raise an error if there is multiple occurrences of same modifier.
 *
 * @param ctxList                   modifiers list.
 * @param defaultVisibilityModifier Default visibility modifier. Can be null. Applied if providen, and no visibility modifier exists in the ctxList.
 * @return tuple of int modifier and boolean flag, signalising visibility modifiers presence(true if there is visibility modifier in list, false otherwise).
 * @see #checkModifierDuplication(int, int, TerminalNode)
 *///from   w  ww  .ja va 2  s  . c  o  m
public List<Object> parseModifiers(List<? extends GroovyLangParser.MemberModifierContext> ctxList,
        Integer defaultVisibilityModifier) {
    int modifiers = 0;
    boolean hasVisibilityModifier = false;
    for (GroovyLangParser.MemberModifierContext it : ctxList) {
        TerminalNode child = (TerminalNode) it.getChild(0);
        switch (child.getSymbol().getType()) {
        case GroovyLangLexer.KW_STATIC:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_STATIC, child);
            break;
        case GroovyLangLexer.KW_ABSTRACT:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_ABSTRACT, child);
            break;
        case GroovyLangLexer.KW_FINAL:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_FINAL, child);
            break;
        case GroovyLangLexer.KW_NATIVE:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_NATIVE, child);
            break;
        case GroovyLangLexer.KW_SYNCHRONIZED:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_SYNCHRONIZED, child);
            break;
        case GroovyLangLexer.KW_TRANSIENT:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_TRANSIENT, child);
            break;
        case GroovyLangLexer.KW_VOLATILE:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_VOLATILE, child);
            break;
        case GroovyLangLexer.VISIBILITY_MODIFIER:
            modifiers |= parseVisibilityModifiers(child);
            hasVisibilityModifier = true;
            break;
        }
    }
    if (!hasVisibilityModifier && defaultVisibilityModifier != null)
        modifiers |= defaultVisibilityModifier;

    return new LinkedList<Object>(Arrays.asList(modifiers, hasVisibilityModifier));
}

From source file:org.codehaus.groovy.transform.LogASTTransformation.java

License:Apache License

private int lookupLogFieldModifiers(AnnotatedNode targetClass, AnnotationNode logAnnotation) {
    int modifiers = getVisibility(logAnnotation, targetClass, ClassNode.class, Opcodes.ACC_PRIVATE);
    return Opcodes.ACC_FINAL | Opcodes.ACC_TRANSIENT | Opcodes.ACC_STATIC | modifiers;
}

From source file:org.enerj.enhancer.MetaData.java

License:Open Source License

/**
 * Determines if a field is persistent. If the specified class is found 
 * in the source path, the metadata and/or Field definition is used
 * to determine persistability. If the class is not in the source path, the
 * database schema is used to determine persistability. 
 *<p>//from  w  w  w.ja  v  a  2 s  . com
 * EnerJ will attempt to persist all fields of a class that are not marked static, final,
 * transient, or are marked "transient=false" in the metadata. At runtime, 
 * if EnerJ tries to persist a field
 * and the field contains an object that is not an SCO nor a FCO, EnerJ throws 
 * org.odmg.ClassNotPersistenceCapableException.
 *
 * @param aClassName the fully qualified dotted class name that the field is contained in.
 * @param aFieldName the name of the field.
 * @param someModifiers The field's access modifiers as defined by ASM Opcodes.ACC_*.
 *
 * @return true if the field is persistent, else false.
 */
boolean isFieldPersistent(String aClassName, String aFieldName, int someModifiers) throws MetaDataException {
    // If the _containing_ class of the field is not persistable, neither is the field.
    if (!isClassAFCO(aClassName)) {
        return false;
    }

    // Static or final fields are never persistent
    if (isStaticOrFinal(someModifiers)) {
        return false;
    }

    FieldDef fieldDef = getFieldOverrides(aClassName, aFieldName);

    if (fieldDef != null) {
        // If "transient=" was specified, use it to determine the override.
        int persistentOverride = fieldDef.getPersistentOverride();
        if (persistentOverride != FieldDef.PERSISTENT_USE_FIELDDEF) {
            return persistentOverride == FieldDef.PERSISTENT_YES;
        }
    }

    // Transient fields are not persistent, by default (if not overridden in metadata).
    return (someModifiers & Opcodes.ACC_TRANSIENT) != Opcodes.ACC_TRANSIENT;
}

From source file:org.evosuite.symbolic.instrument.AccessFlags.java

License:Open Source License

static boolean isTransient(int access) {
    return is(access, Opcodes.ACC_TRANSIENT);
}

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

License:Apache License

@Override
public boolean isTransient() {
    return isAccessModifier(Opcodes.ACC_TRANSIENT);
}

From source file:org.jacoco.core.runtime.ModifiedSystemClassRuntime.java

License:Open Source License

private static void createDataField(final ClassVisitor visitor, final String dataField) {
    visitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_TRANSIENT,
            dataField, ACCESS_FIELD_TYPE, null, null);
}