Package com.strobel.assembler.metadata

Examples of com.strobel.assembler.metadata.MethodDefinition


    public Void visitMethodDeclaration(final MethodDeclaration node, final Void ignored) {
        startNode(node);
        formatter.resetLineNumberOffsets(OffsetToLineNumberConverter.NOOP_CONVERTER);
        writeAnnotations(node.getAnnotations(), true);

        final MethodDefinition definition = node.getUserData(Keys.METHOD_DEFINITION);

        if (definition != null && definition.isDefault()) {
            writeKeyword(Roles.DEFAULT_KEYWORD);
        }

        writeModifiers(node.getModifiers());

        if (definition != null && (definition.isSynthetic() || definition.isBridgeMethod())) {
            space(lastWritten != LastWritten.Whitespace);
            formatter.writeComment(
                CommentType.MultiLine,
                definition.isBridgeMethod() ? " bridge " : " synthetic "
            );
            space();
        }

        if (definition == null || !definition.isTypeInitializer()) {
            final LineNumberTableAttribute lineNumberTable = SourceAttribute.find(
                AttributeNames.LineNumberTable,
                definition != null ? definition.getSourceAttributes()
                                   : Collections.<SourceAttribute>emptyList()
            );

            if (lineNumberTable != null) {
                formatter.resetLineNumberOffsets(new LineNumberTableConverter(lineNumberTable));
View Full Code Here


            if (parameter.getPosition() == parameter.getMethod().getParameters().size() - 1 &&
                parameter.getParameterType().isArray() &&
                parameter.getMethod() instanceof MethodReference) {

                final MethodReference method = (MethodReference) parameter.getMethod();
                final MethodDefinition resolvedMethod = method.resolve();

                if (resolvedMethod != null && Flags.testAny(resolvedMethod.getFlags(), Flags.ACC_VARARGS | Flags.VARARGS)) {
                    isVarArgs = true;
                }
            }
        }
View Full Code Here

        return null;
    }

    private boolean isCurrentMemberVisible() {
        final MethodDefinition currentMethod = context.getCurrentMethod();

        if (currentMethod != null && AstBuilder.isMemberHidden(currentMethod, context)) {
            return false;
        }
View Full Code Here

        if (foundOverride) {
            return;
        }

        final MethodDefinition method = node.getUserData(Keys.METHOD_DEFINITION);

        if (method.isStatic() || method.isConstructor() || method.isTypeInitializer()) {
            return;
        }

        final TypeDefinition declaringType = method.getDeclaringType();

        if (declaringType.getCompilerMajorVersion() < CompilerTarget.JDK1_6.majorVersion) {
            return;
        }

        final TypeReference annotationType = new MetadataParser(declaringType).parseTypeDescriptor(OVERRIDE_ANNOTATION_NAME);

        final List<MethodReference> candidates = MetadataHelper.findMethods(
            declaringType,
            new Predicate<MethodReference>() {
                @Override
                public boolean test(final MethodReference reference) {
                    return StringUtilities.equals(reference.getName(), method.getName());
                }
            },
            false,
            true
        );
View Full Code Here

        }
    }

    @Override
    public Void visitAnonymousObjectCreationExpression(final AnonymousObjectCreationExpression node, final Void data) {
        final MethodDefinition oldInitializer = _currentInitializerMethod;
        final MethodDefinition oldConstructor = _currentConstructor;

        _currentInitializerMethod = null;
        _currentConstructor = null;

        try {
View Full Code Here

        }
    }

    @Override
    public Void visitMethodDeclaration(final MethodDeclaration node, final Void _) {
        final MethodDefinition oldInitializer = _currentInitializerMethod;
        final MethodDefinition oldConstructor = _currentConstructor;

        final MethodDefinition method = node.getUserData(Keys.METHOD_DEFINITION);

        if (method != null &&
            method.isTypeInitializer() &&
            method.getDeclaringType().isInterface()) {

            _currentConstructor = null;
            _currentInitializerMethod = method;
        }
        else {
            _currentConstructor = method != null && method.isConstructor() ? method : null;
            _currentInitializerMethod = null;
        }

        try {
            return super.visitMethodDeclaration(node, _);
View Full Code Here

    @Override
    public Void visitSuperReferenceExpression(final SuperReferenceExpression node, final Void _) {
        super.visitSuperReferenceExpression(node, _);

        final MethodDefinition method = context.getCurrentMethod();

        if (method != null &&
            method.isConstructor() &&
            (method.isSynthetic() || method.getDeclaringType().isAnonymous()) &&
            node.getParent() instanceof InvocationExpression &&
            node.getRole() == Roles.TARGET_EXPRESSION) {

            //
            // For anonymous classes, take all statements after the base constructor call and move them
View Full Code Here

        return super.visitFieldDeclaration(node, data);
    }

    @Override
    public Void visitMethodDeclaration(final MethodDeclaration node, final Void _) {
        final MethodDefinition method = node.getUserData(Keys.METHOD_DEFINITION);

        if (method != null) {
            if (AstBuilder.isMemberHidden(method, context)) {
                node.remove();
                return null;
            }

            if (method.isTypeInitializer()) {
                if (node.getBody().getStatements().isEmpty()) {
                    node.remove();
                    return null;
                }
            }
View Full Code Here

        );
    }

    @Override
    public Void visitConstructorDeclaration(final ConstructorDeclaration node, final Void _) {
        final MethodDefinition method = node.getUserData(Keys.METHOD_DEFINITION);

        if (method != null) {
            if (AstBuilder.isMemberHidden(method, context)) {
                if (method.getDeclaringType().isEnum() &&
                    method.getDeclaringType().isAnonymous() &&
                    !node.getBody().getStatements().isEmpty()) {

                    //
                    // Keep initializer blocks in anonymous enum value bodies.
                    //
                    return super.visitConstructorDeclaration(node, _);
                }

                node.remove();
                return null;
            }

            if (!context.getSettings().getShowSyntheticMembers() &&
                node.getParameters().isEmpty() &&
                DEFAULT_CONSTRUCTOR_BODY.matches(node.getBody())) {

                //
                // Remove redundant default constructors.
                //

                final TypeDefinition declaringType = method.getDeclaringType();

                if (declaringType != null) {
                    final boolean hasOtherConstructors = any(
                        declaringType.getDeclaredMethods(),
                        new Predicate<MethodDefinition>() {
                            @Override
                            public boolean test(final MethodDefinition m) {
                                return m.isConstructor() &&
                                       !m.isSynthetic() &&
                                       !StringUtilities.equals(m.getErasedSignature(), method.getErasedSignature());
                            }
                        }
                    );

                    if (!hasOtherConstructors) {
View Full Code Here

        }

        @Override
        public Void visitAssignmentExpression(final AssignmentExpression node, final Void data) {
            final TypeDefinition currentType = context.getCurrentType();
            final MethodDefinition currentMethod = context.getCurrentMethod();

            if (_isSwitchMapWrapper &&
                currentType != null &&
                currentMethod != null &&
                currentMethod.isTypeInitializer()) {

                final Expression left = node.getLeft();
                final Expression right = node.getRight();

                if (left instanceof IndexerExpression &&
View Full Code Here

TOP

Related Classes of com.strobel.assembler.metadata.MethodDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.