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:org.codehaus.groovy.control.ResolveVisitor.java

License:Apache License

protected boolean resolveFromModule(final ClassNode type, final boolean testModuleImports) {
    if (type instanceof ConstructedNestedClass)
        return false;

    // we decided if we have a vanilla name starting with a lower case
    // letter that we will not try to resolve this name against .*
    // imports. Instead a full import is needed for these.
    // resolveAliasFromModule will do this check for us. This method
    // does also check the module contains a class in the same package
    // of this name. This check is not done for vanilla names starting
    // with a lower case letter anymore
    if (type instanceof LowerCaseClass) {
        return resolveAliasFromModule(type);
    }//from   www  . j  a  va  2  s . co  m

    String name = type.getName();
    ModuleNode module = currentClass.getModule();
    if (module == null)
        return false;

    boolean newNameUsed = false;
    // we add a package if there is none yet and the module has one. But we
    // do not add that if the type is a ConstructedClassWithPackage. The code in ConstructedClassWithPackage
    // hasPackageName() will return true if ConstructedClassWithPackage#className has no dots.
    // but since the prefix may have them and the code there does ignore that
    // fact. We check here for ConstructedClassWithPackage.
    if (!type.hasPackageName() && module.hasPackageName() && !(type instanceof ConstructedClassWithPackage)) {
        type.setName(module.getPackageName() + name);
        newNameUsed = true;
    }
    // look into the module node if there is a class with that name
    List<ClassNode> moduleClasses = module.getClasses();
    for (ClassNode mClass : moduleClasses) {
        if (mClass.getName().equals(type.getName())) {
            if (mClass != type)
                type.setRedirect(mClass);
            return true;
        }
    }
    if (newNameUsed)
        type.setName(name);

    if (testModuleImports) {
        if (resolveAliasFromModule(type))
            return true;

        if (module.hasPackageName()) {
            // check package this class is defined in. The usage of ConstructedClassWithPackage here
            // means, that the module package will not be involved when the
            // compiler tries to find an inner class.
            ConstructedClassWithPackage tmp = new ConstructedClassWithPackage(module.getPackageName(), name);
            if (resolve(tmp, false, false, false)) {
                ambiguousClass(type, tmp, name);
                type.setRedirect(tmp.redirect());
                return true;
            }
        }

        // check module static imports (for static inner classes)
        for (ImportNode importNode : module.getStaticImports().values()) {
            if (importNode.getFieldName().equals(name)) {
                ClassNode tmp = new ConstructedNestedClass(importNode.getType(), name);
                if (resolve(tmp, false, false, true)) {
                    if ((tmp.getModifiers() & Opcodes.ACC_STATIC) != 0) {
                        type.setRedirect(tmp.redirect());
                        return true;
                    }
                }
            }
        }

        // check module node import packages
        for (ImportNode importNode : module.getStarImports()) {
            String packagePrefix = importNode.getPackageName();
            // We limit the inner class lookups here by using ConstructedClassWithPackage.
            // This way only the name will change, the packagePrefix will
            // not be included in the lookup. The case where the
            // packagePrefix is really a class is handled elsewhere.
            ConstructedClassWithPackage tmp = new ConstructedClassWithPackage(packagePrefix, name);
            if (resolve(tmp, false, false, true)) {
                ambiguousClass(type, tmp, name);
                type.setRedirect(tmp.redirect());
                return true;
            }
        }

        // check for star imports (import static pkg.Outer.*) matching static inner classes
        for (ImportNode importNode : module.getStaticStarImports().values()) {
            ClassNode tmp = new ConstructedNestedClass(importNode.getType(), name);
            if (resolve(tmp, false, false, true)) {
                if ((tmp.getModifiers() & Opcodes.ACC_STATIC) != 0) {
                    ambiguousClass(type, tmp, name);
                    type.setRedirect(tmp.redirect());
                    return true;
                }
            }

        }
    }
    return false;
}

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

License:Apache License

private void checkThisAndSuperAsPropertyAccess(final PropertyExpression expression) {
    if (expression.isImplicitThis())
        return;//ww w .j a  v  a  2  s  .  co m
    String prop = expression.getPropertyAsString();
    if (prop == null)
        return;
    if (!prop.equals("this") && !prop.equals("super"))
        return;

    ClassNode type = expression.getObjectExpression().getType();
    if (expression.getObjectExpression() instanceof ClassExpression) {
        if (!(currentClass instanceof InnerClassNode) && !Traits.isTrait(type)) {
            addError("The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.",
                    expression);
            return;
        }
        if (currentScope != null && !currentScope.isInStaticContext() && Traits.isTrait(type)
                && "super".equals(prop) && directlyImplementsTrait(type)) {
            return;
        }
        ClassNode iterType = currentClass;
        while (iterType != null) {
            if (iterType.equals(type))
                break;
            iterType = iterType.getOuterClass();
        }
        if (iterType == null) {
            addError("The class '" + type.getName() + "' needs to be an outer class of '"
                    + currentClass.getName() + "' when using '.this' or '.super'.", expression);
        }
        if ((currentClass.getModifiers() & Opcodes.ACC_STATIC) == 0)
            return;
        if (currentScope != null && !currentScope.isInStaticContext())
            return;
        addError("The usage of 'Class.this' and 'Class.super' within static nested class '"
                + currentClass.getName() + "' is not allowed in a static context.", expression);
    }
}

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

License:Apache License

private static GroovyFieldProposal createClassProposal() {
    FieldNode field = new FieldNode("class", Opcodes.ACC_PUBLIC & Opcodes.ACC_STATIC & Opcodes.ACC_FINAL,
            VariableScope.CLASS_CLASS_NODE, VariableScope.OBJECT_CLASS_NODE, null);
    field.setDeclaringClass(VariableScope.OBJECT_CLASS_NODE);
    return new GroovyFieldProposal(field);
}

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

License:Apache License

@Override
protected int getModifiers() {
    return method.getModifiers() & ~Opcodes.ACC_STATIC; // category methods are defined as static, but should not appear as such when a proposal
}

From source file:org.codehaus.groovy.eclipse.dsl.contributions.MethodContributionElement.java

License:Open Source License

protected int opcode() {
    int modifiers = isStatic ? Opcodes.ACC_STATIC : Opcodes.ACC_PUBLIC;
    modifiers |= isDeprecated ? Opcodes.ACC_DEPRECATED : 0;
    return modifiers;
}

From source file:org.codehaus.groovy.eclipse.refactoring.core.extract.ExtractGroovyMethodRefactoring.java

License:Apache License

private void checkStaticModifier() {
    if (methodCodeFinder.isStatic()) {
        newMethod.setModifiers(newMethodModifier | Opcodes.ACC_STATIC);
    } else {//from   w w w  . ja v a2  s.c  o  m
        newMethod.setModifiers(newMethodModifier);
    }
}

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

License:Apache License

public AnnotatedNode parseMember(ClassNode classNode, GroovyLangParser.FieldDeclarationContext ctx) {
    //noinspection GroovyAssignabilityCheck
    final Iterator<Object> iterator = parseModifiers(ctx.memberModifier()).iterator();
    int modifiers = ((Integer) (iterator.hasNext() ? iterator.next() : null));
    boolean hasVisibilityModifier = ((Boolean) (iterator.hasNext() ? iterator.next() : null));

    modifiers |= classNode.isInterface() ? Opcodes.ACC_STATIC | Opcodes.ACC_FINAL : 0;

    AnnotatedNode node = null;//www. ja v a 2 s.  c om
    List<? extends GroovyLangParser.SingleDeclarationContext> variables = ctx.singleDeclaration();
    for (GroovyLangParser.SingleDeclarationContext variableCtx : variables) {
        GroovyLangParser.ExpressionContext initExprContext = variableCtx.expression();
        Expression initialierExpression = asBoolean(initExprContext) ? parseExpression(initExprContext) : null;
        ClassNode typeDeclaration = asBoolean(ctx.genericClassNameExpression())
                ? parseExpression(ctx.genericClassNameExpression())
                : ClassHelper.OBJECT_TYPE;

        Object defaultValue = findDefaultValueByType(typeDeclaration);
        Expression initialValue = classNode.isInterface() && (null == initialierExpression)
                ? (null == defaultValue ? null : new ConstantExpression(defaultValue))
                : initialierExpression;

        org.codehaus.groovy.syntax.Token token;
        if (asBoolean(variableCtx.ASSIGN())) {
            token = createGroovyToken(variableCtx.ASSIGN().getSymbol(), Types.ASSIGN);
        } else {
            int line = variableCtx.start.getLine();
            int col = -1; //ASSIGN TOKEN DOES NOT APPEAR, SO COL IS -1. IF NO ERROR OCCURS, THE ORIGINAL CODE CAN BE REMOVED IN THE FURTURE: variableCtx.getStart().getCharPositionInLine() + 1; // FIXME Why assignment token location is it's first occurrence.

            token = new org.codehaus.groovy.syntax.Token(Types.ASSIGN, "=", line, col);
        }

        if (classNode.isInterface() || hasVisibilityModifier) {
            modifiers |= classNode.isInterface() ? Opcodes.ACC_PUBLIC : 0;

            FieldNode field = classNode.addField(variableCtx.IDENTIFIER().getText(), modifiers, typeDeclaration,
                    initialValue, token);
            attachAnnotations(field, ctx.annotationClause());
            node = setupNodeLocation(field, variables.size() == 1 ? ctx : variableCtx);
        } else {// no visibility specified. Generate property node.
            Integer propertyModifier = modifiers | Opcodes.ACC_PUBLIC;
            PropertyNode propertyNode = classNode.addProperty(variableCtx.IDENTIFIER().getText(),
                    propertyModifier, typeDeclaration, initialValue, null, null, token);
            propertyNode.getField().setModifiers(modifiers | Opcodes.ACC_PRIVATE);
            propertyNode.getField().setSynthetic(!classNode.isInterface());
            node = setupNodeLocation(propertyNode.getField(), variables.size() == 1 ? ctx : variableCtx);
            attachAnnotations(propertyNode.getField(), ctx.annotationClause());
            setupNodeLocation(propertyNode, variables.size() == 1 ? ctx : variableCtx);
        }
    }
    return node;
}

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

License:Apache License

public MethodNode getOrCreateClinitMethod(ClassNode classNode) {
    MethodNode methodNode = DefaultGroovyMethods.find(classNode.getMethods(), new Closure<Boolean>(null, null) {
        public Boolean doCall(MethodNode it) {
            return it.getName().equals("<clinit>");
        }//from  ww  w .ja v  a 2 s  . co m
    });
    if (!asBoolean(methodNode)) {
        methodNode = new MethodNode("<clinit>", Opcodes.ACC_STATIC, ClassHelper.VOID_TYPE, new Parameter[0],
                new ClassNode[0], new BlockStatement());
        methodNode.setSynthetic(true);
        classNode.addMethod(methodNode);
    }

    return methodNode;
}

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

License:Apache License

public int parseClassModifiers(List<? extends GroovyLangParser.ClassModifierContext> ctxs) {
    List<TerminalNode> visibilityModifiers = new LinkedList<TerminalNode>();
    int modifiers = 0;
    for (int i = 0; i < ctxs.size(); i++) {
        for (Object ctx : ctxs.get(i).children) {
            ParseTree child = null;/*  w w  w.  j  a v  a  2  s.c  om*/
            if (ctx instanceof List) {
                List list = (List) ctx;
                assert list.size() == 1;
                child = (ParseTree) list.get(0);
            } else
                child = (ParseTree) ctx;

            assert child instanceof TerminalNode;
            switch (((TerminalNode) child).getSymbol().getType()) {
            case GroovyLangLexer.VISIBILITY_MODIFIER:
                visibilityModifiers.add((TerminalNode) child);
                break;
            case GroovyLangLexer.KW_STATIC:
                modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_STATIC, (TerminalNode) child);
                break;
            case GroovyLangLexer.KW_ABSTRACT:
                modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_ABSTRACT, (TerminalNode) child);
                break;
            case GroovyLangLexer.KW_FINAL:
                modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_FINAL, (TerminalNode) child);
                break;
            case GroovyLangLexer.KW_STRICTFP:
                modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_STRICT, (TerminalNode) child);
                break;
            }
        }
    }

    if (asBoolean(visibilityModifiers))
        modifiers |= parseVisibilityModifiers(visibilityModifiers, 0);
    else
        modifiers |= Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC;
    return modifiers;
}

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  .j  a v  a2 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));
}