Package com.strobel.decompiler.patterns

Examples of com.strobel.decompiler.patterns.Match


        CONTINUE_OUTER_PATTERN = continueOuter;
    }

    public final WhileStatement transformContinueOuter(final WhileStatement loop) {
        final Match m = CONTINUE_OUTER_PATTERN.match(loop);

        if (!m.success()) {
            return null;
        }

        final LabelStatement label = (LabelStatement) m.get("label").iterator().next();

        label.remove();
        loop.getParent().insertChildBefore(loop, label, BlockStatement.STATEMENT_ROLE);

        return loop;
View Full Code Here


                        EntityDeclaration.addModifier(d, Modifier.FINAL);
                    }
                }

                final BlockStatement body = transformBlock(lambda.getBody());
                final Match m = LAMBDA_BODY_PATTERN.match(body);

                if (m.success()) {
                    final AstNode bodyNode = first(m.<AstNode>get("body"));
                    bodyNode.remove();
                    lambdaExpression.setBody(bodyNode);

                    if (EMPTY_LAMBDA_BODY_PATTERN.matches(bodyNode)) {
                        bodyNode.getChildrenByRole(BlockStatement.STATEMENT_ROLE).clear();
View Full Code Here

        return (position == null || position instanceof AstNode) && matches(position, match);
    }

    @Override
    public final Match match(final INode other) {
        final Match match = Match.createNew();
        return matches(other, match) ? match : Match.failure();
    }
View Full Code Here

                )
            );

            for (final EntityDeclaration d : declaration.getMembers()) {
                if (d instanceof MethodDeclaration) {
                    final Match match = pattern.match(d);

                    if (match.success()) {
                        final MemberReferenceExpression reference = firstOrDefault(match.<MemberReferenceExpression>get("valuesField"));
                        return reference.getUserData(Keys.MEMBER_REFERENCE);
                    }
                }
            }
View Full Code Here

        if (_currentInitializerMethod == null && _currentConstructor == null || context.getCurrentType() == null) {
            return null;
        }

        final Match match = FIELD_ASSIGNMENT.match(node);

        if (match.success()) {
            final Expression target = (Expression) firstOrDefault(match.get("target"));
            final FieldReference reference = (FieldReference) target.getUserData(Keys.MEMBER_REFERENCE);
            final FieldDefinition definition = reference.resolve();

            //
            // Final fields with constant values area already initialized inline, so any additional assignments
View Full Code Here

            for (Statement current = parentStatement.getNextStatement();
                 current instanceof ExpressionStatement; ) {

                final Statement next = current.getNextStatement();
                final Expression expression = ((ExpressionStatement) current).getExpression();
                final Match match = FIELD_ASSIGNMENT.match(expression);

                if (match.success()) {
                    final Expression target = (Expression) firstOrDefault(match.get("target"));
                    final MemberReference reference = target.getUserData(Keys.MEMBER_REFERENCE);

                    if (StringUtilities.equals(context.getCurrentType().getInternalName(), reference.getDeclaringType().getInternalName())) {
                        _initializers.put(
                            reference.getFullName(),
View Full Code Here

        if (input == null || input.isNull()) {
            return null;
        }

        final Match m2 = HASH_CODE_PATTERN.match(input);

        if (!m2.success()) {
            return null;
        }

        final InvocationExpression hashCodeCall = first(m2.<InvocationExpression>get("hashCodeCall"));
        final MemberReference hashCodeMethod = hashCodeCall.getUserData(Keys.MEMBER_REFERENCE);

        if (!(hashCodeMethod instanceof MethodReference &&
              "java/lang/String".equals(hashCodeMethod.getDeclaringType().getInternalName()))) {

            return null;
        }

        final List<Match> matches = new ArrayList<>();

        final AstNodeCollection<SwitchSection> sections = node.getSwitchSections();

        for (final SwitchSection section : sections) {
            final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels();

            if (caseLabels.isEmpty() ||
                caseLabels.hasSingleElement() && caseLabels.firstOrNullObject().isNull()) {

                //
                // Eclipse does not emit default sections.
                //
                return null;
            }

            final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject());

            if (m3.success()) {
                matches.add(m3);
            }
            else {
                return null;
            }
        }

        int matchIndex = 0;
        BreakStatement defaultBreak = null;

        for (final SwitchSection section : sections) {
            final Match m = matches.get(matchIndex++);
            final IfElseStatement test = first(m.<IfElseStatement>get("test"));
            final List<PrimitiveExpression> stringValues = toList(m.<PrimitiveExpression>get("stringValue"));
            final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels();

            if (defaultBreak == null) {
                defaultBreak = firstOrDefault(m.<BreakStatement>get("defaultBreak"));
            }

            caseLabels.clear();
            test.remove();
View Full Code Here

                arrayCreation.getDimensions().add(new IdentifierExpressionBackReference("size").toExpression());
                arrayCreation.setType(new NamedNode("type", new AnyNode()).toType());

                pattern.setBody(arrayCreation);

                final Match match = pattern.match(node);

                if (match.success()) {
                    final AstType type = first(match.<AstType>get("type"));

                    if (signature.getReturnType().getElementType().isEquivalentTo(type.toTypeReference())) {
                        final MethodGroupExpression replacement = new MethodGroupExpression(
                            Expression.MYSTERY_OFFSET,
                            new TypeReferenceExpression(Expression.MYSTERY_OFFSET, type.clone().makeArrayType()),
View Full Code Here

            arguments.hasSingleElement()) {

            final Expression firstArgument;

            if (arguments.hasSingleElement()) {
                final Match m = _stringBuilderArgumentPattern.match(arguments.firstOrNullObject());

                if (!m.success()) {
                    return super.visitObjectCreationExpression(node, data);
                }

                firstArgument = firstOrDefault(m.<Expression>get("firstArgument"));
            }
            else {
                firstArgument = null;
            }
View Full Code Here

        if (!(next instanceof SwitchStatement)) {
            return null;
        }

        final Match m1 = TABLE_SWITCH_INPUT.match(previous);

        if (!m1.success()) {
            return null;
        }

        final Expression input = node.getExpression();

        if (input == null || input.isNull()) {
            return null;
        }

        final Match m2 = HASH_CODE_PATTERN.match(input);

        if (!m2.success()) {
            return null;
        }

        final InvocationExpression hashCodeCall = first(m2.<InvocationExpression>get("hashCodeCall"));
        final MemberReference hashCodeMethod = hashCodeCall.getUserData(Keys.MEMBER_REFERENCE);

        if (!(hashCodeMethod instanceof MethodReference &&
              "java/lang/String".equals(hashCodeMethod.getDeclaringType().getInternalName()))) {

            return null;
        }

        final Map<Integer, List<String>> tableInputMap = new LinkedHashMap<>();

        IdentifierExpression tableSwitchInput = null;

        for (final SwitchSection section : node.getSwitchSections()) {
            final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject());

            if (!m3.success()) {
                return null;
            }

            if (tableSwitchInput == null) {
                tableSwitchInput = first(m3.<IdentifierExpression>get("tableSwitchInput"));
                assert tableSwitchInput != null;
            }

            final List<PrimitiveExpression> stringValues = toList(m3.<PrimitiveExpression>get("stringValue"));
            final List<PrimitiveExpression> tableSwitchCaseValues = toList(m3.<PrimitiveExpression>get("tableSwitchCaseValue"));

            if (stringValues.isEmpty() || stringValues.size() != tableSwitchCaseValues.size()) {
                return null;
            }
View Full Code Here

TOP

Related Classes of com.strobel.decompiler.patterns.Match

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.