Example usage for org.objectweb.asm Opcodes ACC_PRIVATE

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

Introduction

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

Prototype

int ACC_PRIVATE

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

Click Source Link

Usage

From source file:org.boretti.drools.integration.drools5.DroolsClassVisitor.java

License:Open Source License

@Override
public void visitEnd() {
    FieldVisitor fv = null;//from w  w  w .  j a  va 2  s .c  om
    if (isNeedChangeForBoth()) {
        fv = super.visitField(Opcodes.ACC_PRIVATE, DROOLS_FIELD_NAME, Type.BOOLEAN_TYPE.getDescriptor(), null,
                null);
        if (fv != null) {
            AnnotationVisitor av = fv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true);
            AnnotationVisitor value = av.visitArray("value");
            value.visit("", "Generated by Drools5IntegrationHelper Maven plugin");
            value.visitEnd();
            av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current));
            av.visitEnd();
            fv.visitEnd();
        }
    }
    if (isNeedChangeForField()) {
        fv = super.visitField(Opcodes.ACC_PRIVATE, DROOLS_FIELD_RULE,
                Type.getType(RuleBase.class).getDescriptor(), null, null);
        if (fv != null) {
            AnnotationVisitor av = fv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true);
            AnnotationVisitor value = av.visitArray("value");
            value.visit("", "Generated by Drools5IntegrationHelper Maven plugin");
            value.visitEnd();
            av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current));
            av.visitEnd();
            fv.visitEnd();
        }
        MethodVisitor mv = super.visitMethod(Opcodes.ACC_PRIVATE, DROOLS_METHOD_RUN, "()V", null, null);
        AnnotationVisitor av = mv.visitAnnotation(Type.getType(Generated.class).getDescriptor(), true);
        AnnotationVisitor value = av.visitArray("value");
        value.visit("", "Generated by Drools5IntegrationHelper Maven plugin");
        value.visitEnd();
        av.visit("date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(current));
        av.visitEnd();
        mv.visitCode();
        Label start = new Label();
        mv.visitLabel(start);
        Label doIt = new Label();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_NAME,
                Type.BOOLEAN_TYPE.getDescriptor());
        mv.visitJumpInsn(Opcodes.IFEQ, doIt);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitLabel(doIt);
        mv.visitFrame(Opcodes.F_SAME, 1, new Object[] { Type.getObjectType(me).getInternalName() }, 0,
                new Object[] {});
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_RULE,
                Type.getType(RuleBase.class).getDescriptor());
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(RuleBase.class).getInternalName(),
                "newStatelessSession", "()Lorg/drools/StatelessSession;");
        mv.visitInsn(Opcodes.DUP);
        mv.visitLdcInsn(FIELD_NAME_LOGGER);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getType(Object.class).getInternalName(), "getClass",
                "()Ljava/lang/Class;");
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getType(org.apache.log4j.Logger.class).getInternalName(),
                "getLogger", "(Ljava/lang/Class;)Lorg/apache/log4j/Logger;");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(StatelessSession.class).getInternalName(),
                "setGlobal", "(Ljava/lang/String;Ljava/lang/Object;)V");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(StatelessSession.class).getInternalName(),
                "execute", "(Ljava/lang/Object;)V");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitFieldInsn(Opcodes.PUTFIELD, Type.getObjectType(me).getInternalName(), DROOLS_FIELD_NAME,
                Type.BOOLEAN_TYPE.getDescriptor());
        mv.visitInsn(Opcodes.RETURN);
        Label end = new Label();
        mv.visitLabel(end);
        mv.visitLocalVariable("this", Type.getObjectType(me).getDescriptor(), null, start, end, 0);
        mv.visitMaxs(4, 1);
        mv.visitEnd();
    }
    super.visitEnd();
}

From source file:org.cacheonix.impl.transformer.CacheonixClassAdapter.java

License:LGPL

public void visitEnd() {

    final String signature = null;

    // Add CacheonixConfig Field Now
    if (!bCacheonixConfigPresent) {
        final FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL,
                CACHEONIX_CONFIG_FILE_FIELD, Type.getType(String.class).getDescriptor(), signature,
                cacheonixConfigFileFieldValue);
        if (fv != null) {
            fv.visitEnd();// w ww .  j  a va 2 s  . com
        }
    }

    // Add CacheonixCacheName Field Now
    if (!bCacheonixCacheName) {
        final FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL,
                CACHE_NAME_FIELD, Type.getType(String.class).getDescriptor(), signature,
                cacheonixCacheFieldValue);
        if (fv != null) {
            fv.visitEnd();
        }
    }

    cv.visitEnd();
}

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();/*from www.  j  ava2s. c o  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 a va2 s .c o m*/
            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.antlr.AntlrParserPlugin.java

License:Apache License

/**
 * Returns true if the modifiers flags contain a visibility modifier
 *///from ww w  .  ja va2 s.  c o m
protected boolean hasVisibility(int modifiers) {
    return (modifiers & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) != 0;
}

From source file:org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.java

License:Apache License

private MethodNode addSyntheticMethodForDGSM(MethodNode mn) {
    Parameter[] parameters = removeFirstParameter(mn.getParameters());
    ArgumentListExpression args = args(parameters);
    args.getExpressions().add(0, ConstantExpression.NULL);

    MethodNode syntheticMethodNode = controller.getClassNode().addSyntheticMethod(
            "dgsm$$" + mn.getParameters()[0].getType().getName().replace(".", "$") + "$$" + mn.getName(),
            Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC,
            mn.getReturnType(), parameters, ClassNode.EMPTY_ARRAY,
            block(returnS(callX(new ClassExpression(mn.getDeclaringClass()), mn.getName(), args))));

    syntheticMethodNode.addAnnotation(new AnnotationNode(ClassHelper.make(Generated.class)));
    syntheticMethodNode//w  w  w .  ja v  a  2s .  c  o  m
            .addAnnotation(new AnnotationNode(ClassHelper.make(groovy.transform.CompileStatic.class)));

    return syntheticMethodNode;
}

From source file:org.codehaus.groovy.classgen.asm.sc.StaticTypesMethodReferenceExpressionWriter.java

License:Apache License

private MethodNode addSyntheticMethodForConstructorReference(String syntheticMethodName, ClassNode returnType,
        Parameter[] parametersWithExactType) {
    ArgumentListExpression ctorArgs = args(parametersWithExactType);

    MethodNode syntheticMethodNode = controller.getClassNode()
            .addSyntheticMethod(syntheticMethodName,
                    Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC,
                    returnType, parametersWithExactType, ClassNode.EMPTY_ARRAY,
                    block(returnS(/*from  w  w  w.j  av  a 2s  .  c  om*/
                            returnType.isArray()
                                    ? new ArrayExpression(
                                            ClassHelper.make(
                                                    ArrayTypeUtils.elementType(returnType.getTypeClass())),
                                            null, ctorArgs.getExpressions())
                                    : ctorX(returnType, ctorArgs))));

    syntheticMethodNode.addAnnotation(new AnnotationNode(ClassHelper.make(Generated.class)));
    syntheticMethodNode
            .addAnnotation(new AnnotationNode(ClassHelper.make(groovy.transform.CompileStatic.class)));

    return syntheticMethodNode;
}

From source file:org.codehaus.groovy.control.OptimizerVisitor.java

License:Apache License

private void setConstField(ConstantExpression constantExpression) {
    final Object n = constantExpression.getValue();
    if (!(n instanceof Number))
        return;/*from ww  w.j  a  v a2 s.c o m*/
    if (n instanceof Integer || n instanceof Double)
        return;
    if (n instanceof Long && (0L == (Long) n || 1L == (Long) n))
        return; // LCONST_0, LCONST_1

    boolean isPrimitive = isPrimitiveType(constantExpression.getType());
    FieldNode field = isPrimitive ? const2Prims.get(n) : const2Objects.get(n);
    if (field != null) {
        constantExpression.setConstantName(field.getName());
        return;
    }
    String name;
    do {
        name = "$const$" + index++;
    } while (currentClass.getDeclaredField(name) != null);
    // TODO consider moving initcode to <clinit> and remaking field final
    field = new FieldNode(name, Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC,
            constantExpression.getType(), currentClass, constantExpression);
    field.setSynthetic(true);
    missingFields.add(field);
    constantExpression.setConstantName(field.getName());
    if (isPrimitive) {
        const2Prims.put(n, field);
    } else {
        const2Objects.put(n, field);
    }
}

From source file:org.codehaus.groovy.eclipse.codeassist.creators.FieldProposalCreator.java

License:Apache License

/**
 * find the most accessible element//w  w w  .  j  av  a 2s.co m
 */
private boolean leftIsMoreAccessible(FieldNode field, FieldNode existing) {
    int leftAcc;
    switch (field.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) {
    case Opcodes.ACC_PUBLIC:
        leftAcc = 0;
        break;
    case Opcodes.ACC_PROTECTED:
        leftAcc = 1;
        break;
    case Opcodes.ACC_PRIVATE:
        leftAcc = 3;
        break;
    default: // package default
        leftAcc = 2;
        break;
    }

    int rightAcc;
    switch (existing.getModifiers() & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) {
    case Opcodes.ACC_PUBLIC:
        rightAcc = 0;
        break;
    case Opcodes.ACC_PROTECTED:
        rightAcc = 1;
        break;
    case Opcodes.ACC_PRIVATE:
        rightAcc = 3;
        break;
    default: // package default
        rightAcc = 2;
        break;
    }
    return leftAcc < rightAcc;
}

From source file:org.codehaus.groovy.eclipse.codeassist.proposals.AbstractGroovyProposal.java

License:Apache License

/**
 * Use {@link ProposalUtils#getImage(CompletionProposal)} instead
 *
 * @param node//  ww w .  j av  a  2 s .  co  m
 * @return
 */
@Deprecated
protected Image getImageFor(ASTNode node) {
    if (node instanceof FieldNode) {
        int mods = ((FieldNode) node).getModifiers();
        if (test(mods, Opcodes.ACC_PUBLIC)) {
            return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC);
        } else if (test(mods, Opcodes.ACC_PROTECTED)) {
            return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PROTECTED);
        } else if (test(mods, Opcodes.ACC_PRIVATE)) {
            return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE);
        }
        return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_DEFAULT);
    } else if (node instanceof PropertyNode) {
        // property nodes are not really used any more.
        int mods = ((PropertyNode) node).getModifiers();
        if (test(mods, Opcodes.ACC_PUBLIC)) {
            return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC);
        } else if (test(mods, Opcodes.ACC_PROTECTED)) {
            return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PROTECTED);
        } else if (test(mods, Opcodes.ACC_PRIVATE)) {
            return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE);
        }
        return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_DEFAULT);
    }
    return null;
}