@@ -856,6 +856,42 @@ public void transform(CompilationUnitRewrite rewrite) {
856
856
}
857
857
858
858
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
+ }
860
896
}
861
897
}
0 commit comments