private ControlFlowNode findNode(final Instruction instruction) { if (instruction == null) { return null; } return firstOrDefault( _nodes, new Predicate<ControlFlowNode>() { @Override public boolean test(final ControlFlowNode node) { return node.getNodeType() == ControlFlowNodeType.Normal && instruction.getOffset() >= node.getStart().getOffset() && instruction.getOffset() < node.getEnd().getEndOffset(); } } ); }
private ControlFlowNode findNode(final Instruction instruction) { if (instruction == null) { return null; } return firstOrDefault( _nodes, new Predicate<ControlFlowNode>() { @Override public boolean test(final ControlFlowNode node) { return node.getNodeType() == ControlFlowNodeType.Normal && instruction.getOffset() >= node.getStart().getOffset() && instruction.getOffset() < node.getEnd().getEndOffset(); } } ); }
private ControlFlowNode findNode(final Instruction instruction) { if (instruction == null) { return null; } return firstOrDefault( _nodes, new Predicate<ControlFlowNode>() { @Override public boolean test(final ControlFlowNode node) { return node.getNodeType() == ControlFlowNodeType.Normal && instruction.getOffset() >= node.getStart().getOffset() && instruction.getOffset() < node.getEnd().getEndOffset(); } } ); }
protected boolean arrayAccessAtTheLeftSideOfAssignment(final AstNode node) { final AssignmentExpression assignment = firstOrDefault(node.getAncestors(AssignmentExpression.class)); if (assignment == null) { return false; } final Expression left = assignment.getLeft(); return left.isAncestorOf(node) && left instanceof IndexerExpression; }
protected boolean arrayAccessAtTheLeftSideOfAssignment(final AstNode node) { final AssignmentExpression assignment = firstOrDefault(node.getAncestors(AssignmentExpression.class)); if (assignment == null) { return false; } final Expression left = assignment.getLeft(); return left.isAncestorOf(node) && left instanceof IndexerExpression; }
protected boolean arrayAccessAtTheLeftSideOfAssignment(final AstNode node) { final AssignmentExpression assignment = firstOrDefault(node.getAncestors(AssignmentExpression.class)); if (assignment == null) { return false; } final Expression left = assignment.getLeft(); return left.isAncestorOf(node) && left instanceof IndexerExpression; }
@Override public AstType makeArrayType() { insertChildBefore(firstOrDefault(getArraySpecifiers()), new ArraySpecifier(), ARRAY_SPECIFIER_ROLE); final TypeReference typeReference = getUserData(Keys.TYPE_REFERENCE); if (typeReference != null) { putUserData(Keys.TYPE_REFERENCE, typeReference.makeArrayType()); } return this; }
@Override public AstType makeArrayType() { insertChildBefore(firstOrDefault(getArraySpecifiers()), new ArraySpecifier(), ARRAY_SPECIFIER_ROLE); final TypeReference typeReference = getUserData(Keys.TYPE_REFERENCE); if (typeReference != null) { putUserData(Keys.TYPE_REFERENCE, typeReference.makeArrayType()); } return this; }
@Override public AstType makeArrayType() { insertChildBefore(firstOrDefault(getArraySpecifiers()), new ArraySpecifier(), ARRAY_SPECIFIER_ROLE); final TypeReference typeReference = getUserData(Keys.TYPE_REFERENCE); if (typeReference != null) { putUserData(Keys.TYPE_REFERENCE, typeReference.makeArrayType()); } return this; }
@Override public Void visitReturnStatement(final ReturnStatement node, final Void data) { final MethodDeclaration methodDeclaration = firstOrDefault(node.getAncestors(MethodDeclaration.class)); if (methodDeclaration != null && !methodDeclaration.isNull()) { final TypeReference returnType = getType(methodDeclaration.getReturnType()); final Expression returnValue = node.getExpression(); if (returnType != null && !returnValue.isNull()) { processPossibleTypeCast(returnValue, returnType); } } return super.visitReturnStatement(node, data); }
@Override public Void visitReturnStatement(final ReturnStatement node, final Void data) { final MethodDeclaration methodDeclaration = firstOrDefault(node.getAncestors(MethodDeclaration.class)); if (methodDeclaration != null && !methodDeclaration.isNull()) { final TypeReference returnType = getType(methodDeclaration.getReturnType()); final Expression returnValue = node.getExpression(); if (returnType != null && returnValue != null && !returnValue.isNull()) { processPossibleTypeCast(returnValue, returnType); } } return super.visitReturnStatement(node, data); }
@Override public Void visitArrayInitializerExpression(final ArrayInitializerExpression node, final Void data) { super.visitArrayInitializerExpression(node, data); final ArrayCreationExpression creation = firstOrDefault(ofType(node.getAncestors(), ArrayCreationExpression.class)); if (creation == null || !creation.getAdditionalArraySpecifiers().hasSingleElement()) { return null; } for (final Expression element : node.getElements()) { addCastForAssignment(creation.getType(), element); } return null; }
@Override public Void visitReturnStatement(final ReturnStatement node, final Void data) { final MethodDeclaration methodDeclaration = firstOrDefault(node.getAncestors(MethodDeclaration.class)); if (methodDeclaration != null && !methodDeclaration.isNull()) { final TypeReference returnType = getType(methodDeclaration.getReturnType()); final Expression returnValue = node.getExpression(); if (returnType != null && returnValue != null && !returnValue.isNull()) { processPossibleTypeCast(returnValue, returnType); } } return super.visitReturnStatement(node, data); }
@Override public Void visitConditionalExpression(final ConditionalExpression node, final Void data) { super.visitConditionalExpression(node, data); final Match m = PATTERN.match(node); if (m.success()) { final InvocationExpression call = firstOrDefault(m.<InvocationExpression>get("methodCall")); final MemberReference method = call != null ? call.getUserData(Keys.MEMBER_REFERENCE) : null; if (method == null || !method.isEquivalentTo(_method)) { return null; } final PrimitiveExpression className = firstOrDefault(m.<PrimitiveExpression>get("class")); if (className != null && className.getValue() instanceof String) { final AstBuilder builder = context.getUserData(Keys.AST_BUILDER); final String dottedName = (String) className.getValue(); final TypeReference classType = _parser.parseTypeDescriptor(dottedName.replace('.', '/')); final ClassOfExpression replacement = new ClassOfExpression( call.getOffset(), builder.convertType(classType) ); node.replaceWith(replacement); } } return null; }
@Override public Void visitExpressionStatement(final ExpressionStatement node, final Void data) { super.visitExpressionStatement(node, data); // // Remove `super()`-style invocations within constructors, but only if they actually // bind to a constructor. Keep calls to potentially obfuscated methods named 'super'. // if (inConstructor() && !context.getSettings().getShowSyntheticMembers()) { final Match match = EMPTY_SUPER.match(node); if (match.success()) { final AstNode target = firstOrDefault(match.<AstNode>get("target")); final MemberReference member = target.getUserData(Keys.MEMBER_REFERENCE); if (member instanceof MethodReference && ((MethodReference) member).isConstructor()) { node.remove(); } } } return null; } }
@Override public Void visitExpressionStatement(final ExpressionStatement node, final Void data) { super.visitExpressionStatement(node, data); // // Remove `super()`-style invocations within constructors, but only if they actually // bind to a constructor. Keep calls to potentially obfuscated methods named 'super'. // if (inConstructor() && !context.getSettings().getShowSyntheticMembers()) { final Match match = EMPTY_SUPER.match(node); if (match.success()) { final AstNode target = firstOrDefault(match.<AstNode>get("target")); final MemberReference member = target.getUserData(Keys.MEMBER_REFERENCE); if (member instanceof MethodReference && ((MethodReference) member).isConstructor()) { node.remove(); } } } return null; } }
@Override public Void visitSwitchSection(final SwitchSection node, final Void ignored) { startNode(node); boolean first = true; for (final CaseLabel label : node.getCaseLabels()) { if (!first) { newLine(); } label.acceptVisitor(this, ignored); first = false; } final boolean isBlock = node.getStatements().size() == 1 && firstOrDefault(node.getStatements()) instanceof BlockStatement; if (policy.IndentCaseBody && !isBlock) { formatter.indent(); } if (!isBlock) { newLine(); } for (final Statement statement : node.getStatements()) { statement.acceptVisitor(this, ignored); } if (policy.IndentCaseBody && !isBlock) { formatter.unindent(); } endNode(node); return null; }
@Override public Void visitObjectCreationExpression(final ObjectCreationExpression node, final Void data) { final AstNodeCollection<Expression> arguments = node.getArguments(); if (arguments.isEmpty() || 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; } final TypeReference typeReference = node.getType().toTypeReference(); if (typeReference != null && isStringBuilder(typeReference)) { convertStringBuilderToConcatenation(node, firstArgument); } } return super.visitObjectCreationExpression(node, data); }
@Override public Void visitObjectCreationExpression(final ObjectCreationExpression node, final Void data) { final AstNodeCollection<Expression> arguments = node.getArguments(); if (arguments.isEmpty() || 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; } final TypeReference typeReference = node.getType().toTypeReference(); if (typeReference != null && isStringBuilder(typeReference)) { convertStringBuilderToConcatenation(node, firstArgument); } } return super.visitObjectCreationExpression(node, data); }
@Override public Void visitObjectCreationExpression(final ObjectCreationExpression node, final Void data) { final AstNodeCollection<Expression> arguments = node.getArguments(); if (arguments.isEmpty() || 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; } final TypeReference typeReference = node.getType().toTypeReference(); if (typeReference != null && isStringBuilder(typeReference)) { convertStringBuilderToConcatenation(node, firstArgument); } } return super.visitObjectCreationExpression(node, data); }