TypeConversionDescriptor (PsiElement context, PsiType to, PsiType from, AtomicConversionType type, TypeMigrationLabeler labeler) { final PsiClass toTypeClass = PsiUtil.resolveClassInType(to); LOG.assertTrue(toTypeClass != null); final String qualifiedName = toTypeClass.getQualifiedName(); if (context instanceof PsiParenthesizedExpression) { context = PsiUtil.skipParenthesizedExprDown((PsiExpression)context); } if (qualifiedName != null) { if (qualifiedName.equals(AtomicInteger.class.getName()) || qualifiedName.equals(AtomicLong.class.getName())) { if (context instanceof PsiPostfixExpression) { final IElementType operationSign = ((PsiPostfixExpression)context).getOperationTokenType(); if (operationSign == JavaTokenType.MINUSMINUS) { return new TypeConversionDescriptor("$qualifier$--", "$qualifier$.getAndDecrement()"); } if (operationSign == JavaTokenType.PLUSPLUS) { return new TypeConversionDescriptor("$qualifier$++", "$qualifier$.getAndIncrement()"); } } else if (context instanceof PsiPrefixExpression) { final IElementType operationSign = ((PsiPrefixExpression)context).getOperationTokenType(); if (operationSign == JavaTokenType.MINUSMINUS) { return new TypeConversionDescriptor("--$qualifier$", "$qualifier$.decrementAndGet()"); } if (operationSign == JavaTokenType.PLUSPLUS) { return new TypeConversionDescriptor("++$qualifier$", "$qualifier$.incrementAndGet()"); } if (operationSign == JavaTokenType.MINUS && !(context.getParent() instanceof PsiAssignmentExpression)) { return wrapWithNewExpression(to, from, (PsiExpression)context, context, type); } } else if (context instanceof PsiAssignmentExpression) { final PsiJavaToken signToken = ((PsiAssignmentExpression)context).getOperationSign(); final IElementType operationSign = signToken.getTokenType(); final String sign = signToken.getText(); if (operationSign == JavaTokenType.PLUSEQ || operationSign == JavaTokenType.MINUSEQ) { return new TypeConversionDescriptor("$qualifier$ " + sign + " $val$", "$qualifier$.addAndGet(" + (operationSign == JavaTokenType.MINUSEQ ? "-($val$))" : "$val$)")) { @Override public PsiExpression replace(PsiExpression expression, @NotNull TypeEvaluator evaluator) { final PsiMethodCallExpression result = (PsiMethodCallExpression)super.replace(expression, evaluator); final PsiExpression argument = result.getArgumentList().getExpressions()[0]; if (argument instanceof PsiPrefixExpression) { final PsiExpression operand = ((PsiPrefixExpression)argument).getOperand(); final PsiExpression striped = PsiUtil.skipParenthesizedExprDown(operand); if (striped != null && operand != striped) { operand.replace(striped); } } return result; } }; } } else if (context instanceof PsiLiteralExpression && !(context.getParent() instanceof PsiAssignmentExpression)) { return wrapWithNewExpression(to, from, (PsiExpression)context, context, type); } } else if (qualifiedName.equals(AtomicIntegerArray.class.getName()) || qualifiedName.equals(AtomicLongArray.class.getName())) { PsiElement parentExpression = context.getParent(); if (parentExpression instanceof PsiPostfixExpression) { final IElementType operationSign = ((PsiPostfixExpression)parentExpression).getOperationTokenType(); if (operationSign == JavaTokenType.MINUSMINUS) { return new TypeConversionDescriptor("$qualifier$[$idx$]--", "$qualifier$.getAndDecrement($idx$)", (PsiExpression)parentExpression); } if (operationSign == JavaTokenType.PLUSPLUS) { return new TypeConversionDescriptor("$qualifier$[$idx$]++", "$qualifier$.getAndIncrement($idx$)", (PsiExpression)parentExpression); } } else if (parentExpression instanceof PsiPrefixExpression) { final IElementType operationSign = ((PsiPrefixExpression)parentExpression).getOperationTokenType(); if (operationSign == JavaTokenType.MINUSMINUS) { return new TypeConversionDescriptor("--$qualifier$[$idx$]", "$qualifier$.decrementAndGet($idx$)", (PsiExpression)parentExpression); } if (operationSign == JavaTokenType.PLUSPLUS) { return new TypeConversionDescriptor("++$qualifier$[$idx$]", "$qualifier$.incrementAndGet($idx$)", (PsiExpression)parentExpression); } } else if (parentExpression instanceof PsiAssignmentExpression) { final PsiJavaToken signToken = ((PsiAssignmentExpression)parentExpression).getOperationSign(); final IElementType operationSign = signToken.getTokenType(); final String sign = signToken.getText(); if (operationSign == JavaTokenType.PLUSEQ || operationSign == JavaTokenType.MINUSEQ) { return new TypeConversionDescriptor("$qualifier$[$idx$] " + sign + " $val$", "$qualifier$.getAndAdd($idx$, " + (operationSign == JavaTokenType.MINUSEQ ? "-" : "") + "($val$))", (PsiExpression)parentExpression); } } } } return from instanceof PsiArrayType ? findDirectConversionForAtomicReferenceArray(context, to, from, type) : findDirectConversionForAtomicReference(context, to, from, type, labeler); }