GrExpression (GrExpression expr) { final Project project = expr.getProject(); final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); boolean copied = false; if (expr instanceof GrApplicationStatement) { expr = convertAppInternal(factory, (GrApplicationStatement)expr); copied = true; } if (expr instanceof GrReferenceExpression && ((GrReferenceExpression)expr).getDotToken() == null && ((GrReferenceExpression)expr).getQualifier() != null) { expr = convertRefInternal(factory, ((GrReferenceExpression)expr)); copied = true; } if (!shouldManage(expr)) return expr; if (!copied) expr = (GrExpression)expr.copy(); for (PsiElement child = expr.getFirstChild(); child != null; child = child.getFirstChild()) { if (child instanceof GrApplicationStatement) { child = child.replace(convertAppInternal(factory, (GrApplicationStatement)child)); } else if (child instanceof GrReferenceExpression && ((GrReferenceExpression)child).getDotToken() == null && ((GrReferenceExpression)child).getQualifier() != null) { child = child.replace(convertRefInternal(factory, ((GrReferenceExpression)child))); } } return expr; }