void (List<RangeMarker> occurrenceMarkers, PsiFile file, Project project, @Nullable PsiVariable psiVariable) { if (occurrenceMarkers != null) { for (RangeMarker occurrenceMarker : occurrenceMarkers) { final PsiElement refVariableElement = file.findElementAt(occurrenceMarker.getStartOffset()); final PsiReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(refVariableElement, PsiReferenceExpression.class); if (referenceExpression != null) { final PsiElement parent = referenceExpression.getParent(); if (parent instanceof PsiVariable) { createCastInVariableDeclaration(project, (PsiVariable)parent); } else if (parent instanceof PsiReferenceExpression && psiVariable != null) { final PsiExpression initializer = psiVariable.getInitializer(); LOG.assertTrue(initializer != null); final PsiType type = initializer.getType(); if (((PsiReferenceExpression)parent).resolve() == null && type != null && !type.equals(psiVariable.getType()) && !LambdaUtil.notInferredType(type) && !PsiTypes.nullType().equals(type)) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); final PsiExpression castedExpr = elementFactory.createExpressionFromText("((" + type.getCanonicalText() + ")" + referenceExpression.getText() + ")", parent); JavaCodeStyleManager.getInstance(project).shortenClassReferences(referenceExpression.replace(castedExpr)); } } } } } if (psiVariable != null && psiVariable.isValid()) { createCastInVariableDeclaration(project, psiVariable); } }