TypeConversionDescriptor (PsiElement context, PsiType to, PsiType from, AtomicConversionType type, TypeMigrationLabeler labeler) { final PsiElement parent = context.getParent(); if (parent instanceof PsiAssignmentExpression) { final IElementType operationSign = ((PsiAssignmentExpression)parent).getOperationTokenType(); if (operationSign == JavaTokenType.EQ) { boolean rightInfected = ((PsiAssignmentExpression)parent).getLExpression() == context; String replacement = rightInfected ? "$qualifier$ = $val$.get()" : "$qualifier$.set($val$)"; return new TypeConversionDescriptor("$qualifier$ = $val$", replacement, (PsiAssignmentExpression)parent); } } if (context instanceof PsiReferenceExpression refExpr) { final PsiExpression qualifierExpression = refExpr.getQualifierExpression(); final PsiExpression expression = context.getParent() instanceof PsiMethodCallExpression && qualifierExpression != null ? qualifierExpression : refExpr; if (expression instanceof PsiReferenceExpression && to.equals(labeler.getTypeEvaluator().getType(expression))) { return new TypeConversionDescriptor("$qualifier$", "$qualifier$.get()", expression); } } else if (context instanceof PsiAssignmentExpression assignment) { final PsiJavaToken signToken = assignment.getOperationSign(); final IElementType operationSign = signToken.getTokenType(); final String sign = signToken.getText(); boolean voidContext = ExpressionUtils.isVoidContext(assignment); if (operationSign == JavaTokenType.EQ) { if (!voidContext) return null; final PsiExpression lExpression = assignment.getLExpression(); if (lExpression instanceof PsiReferenceExpression) { final PsiElement element = ((PsiReferenceExpression)lExpression).resolve(); if (element instanceof PsiVariable && ((PsiVariable)element).hasModifierProperty(PsiModifier.FINAL)) { return wrapWithNewExpression(to, from, assignment.getRExpression(), element, type); } } return new TypeConversionDescriptor("$qualifier$ = $val$", "$qualifier$.set($val$)"); } if (PsiUtil.isLanguageLevel8OrHigher(context) && !PsiTypes.booleanType().equals(from)) { final String name = JavaCodeStyleManager.getInstance(context.getProject()).suggestUniqueVariableName("v", context, false); return new TypeConversionDescriptor("$qualifier$" + sign + "$val$", "$qualifier$.updateAndGet(" + name + " -> " + getBoxedWrapper(from, to, name + " " + sign.charAt(0) + " $val$)")); } if (voidContext) { return new TypeConversionDescriptor("$qualifier$" + sign + "$val$", "$qualifier$.set(" + getBoxedWrapper(from, to, "$qualifier$.get() " + sign.charAt(0) + " $val$") + ")"); } } else if (context instanceof PsiPostfixExpression) { final String sign = ((PsiPostfixExpression)context).getOperationSign().getText(); return new TypeConversionDescriptor("$qualifier$" + sign, "$qualifier$.getAndSet(" + getBoxedWrapper(from, to, "$qualifier$.get() " + sign.charAt(0) + " 1") + ")"); } else if (context instanceof PsiPrefixExpression) { final PsiJavaToken operationSign = ((PsiPrefixExpression)context).getOperationSign(); if (operationSign.getTokenType() == JavaTokenType.EXCL) { return new TypeConversionDescriptor("!$qualifier$", "!$qualifier$.get()"); } final String sign = operationSign.getText(); return new TypeConversionDescriptor(sign + "$qualifier$", "$qualifier$.set(" + //todo reject? getBoxedWrapper(from, to, "$qualifier$.get() " + sign.charAt(0) + " 1") + ")"); } if (parent instanceof PsiVariable) { return wrapWithNewExpression(to, from, null, parent, type); } return null; }