Skip to content

Commit dfdd920

Browse files
committed
Enhancement.
1 parent d69d3bf commit dfdd920

File tree

1 file changed

+37
-1
lines changed
  • edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis

1 file changed

+37
-1
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Stream.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,42 @@ public void transform(CompilationUnitRewrite rewrite) {
856856
}
857857

858858
protected void unorder(CompilationUnitRewrite rewrite) {
859-
// TODO Auto-generated method stub
859+
MethodInvocation creation = this.getCreation();
860+
ASTRewrite astRewrite = rewrite.getASTRewrite();
861+
MethodInvocation termOp = findTerminalOperation(creation);
862+
Expression expression = termOp.getExpression();
863+
864+
boolean done = false;
865+
boolean hasDistinct = false;
866+
867+
while (expression != null && !done)
868+
if (expression.getNodeType() == ASTNode.METHOD_INVOCATION) {
869+
MethodInvocation inv = (MethodInvocation) expression;
870+
AST ast = creation.getAST();
871+
872+
String identifier = inv.getName().getIdentifier();
873+
874+
if (identifier.equals("distinct")) {
875+
MethodInvocation newMethodInvocation = ast.newMethodInvocation();
876+
newMethodInvocation.setName(ast.newSimpleName("unordered"));
877+
MethodInvocation exprCopy = (MethodInvocation) ASTNode.copySubtree(ast, inv.getExpression());
878+
newMethodInvocation.setExpression(exprCopy);
879+
astRewrite.replace(inv.getExpression(), newMethodInvocation, null);
880+
hasDistinct = true;
881+
}
882+
883+
expression = inv.getExpression();
884+
} else
885+
done = true;
886+
887+
if (!hasDistinct) {
888+
AST ast = creation.getAST();
889+
890+
MethodInvocation newMethodInvocation = ast.newMethodInvocation();
891+
newMethodInvocation.setName(ast.newSimpleName("unordered"));
892+
MethodInvocation exprCopy = (MethodInvocation) ASTNode.copySubtree(ast, termOp.getExpression());
893+
newMethodInvocation.setExpression(exprCopy);
894+
astRewrite.replace(termOp.getExpression(), newMethodInvocation, null);
895+
}
860896
}
861897
}

0 commit comments

Comments
 (0)