ProblemDescriptor (PsiNewExpression expression) { PsiExpressionList argumentList = expression.getArgumentList(); if (argumentList == null) return null; final PsiJavaCodeReferenceElement anchor = expression.getClassOrAnonymousClassReference(); if (anchor == null) return null; if (argumentList.isEmpty()) { LocalQuickFix[] fixes = { new StringConstructorFix(true), LocalQuickFix.from(new UpdateInspectionOptionFix( myInspection, "ignoreStringConstructor", InspectionGadgetsBundle.message("inspection.redundant.string.option.do.not.report.string.constructors"), true))}; return myManager.createProblemDescriptor(anchor, (TextRange)null, InspectionGadgetsBundle.message("inspection.redundant.string.constructor.message"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly, fixes); } final PsiExpression[] args = argumentList.getExpressions(); if (isNewStringFromByteArrayParams(args)) { PsiMethodCallExpression methodCall = getMethodCallExpression(args[0]); if (BYTE_ARRAY_OUTPUT_STREAM_INTO_BYTE_ARRAY.test(methodCall)) { final PsiElement qualifier = methodCall.getMethodExpression().getQualifier(); if (qualifier == null) return null; String newExpressionText = qualifier.getText() + ".toString(" + (args.length == 2 ? args[1].getText() : "") + ")"; return myManager.createProblemDescriptor(anchor, (TextRange)null, InspectionGadgetsBundle.message("inspection.byte.array.output.stream.to.string.message"), ProblemHighlightType.WARNING, myIsOnTheFly, new ByteArrayOutputStreamToStringFix(newExpressionText)); } } if (argumentList.getExpressionCount() == 1) { final CharArrayCreationArgument charArrayCreationArgument = CharArrayCreationArgument.from(argumentList); if (charArrayCreationArgument != null) { LocalQuickFix[] fixes = { new ReplaceWithValueOfFix(), LocalQuickFix.from(new UpdateInspectionOptionFix( myInspection, "ignoreStringConstructor", InspectionGadgetsBundle.message("inspection.redundant.string.option.do.not.report.string.constructors"), true))}; return myManager.createProblemDescriptor(anchor, (TextRange)null, JavaAnalysisBundle.message("inspection.can.be.replaced.with.message", "String.valueOf()"), ProblemHighlightType.WARNING, myIsOnTheFly, fixes); } PsiExpression arg = argumentList.getExpressions()[0]; if (TypeUtils.isJavaLangString(arg.getType()) && (PsiUtil.isLanguageLevel7OrHigher(expression) || !STRING_SUBSTRING.matches(arg))) { LocalQuickFix[] fixes = { new StringConstructorFix(false), LocalQuickFix.from(new UpdateInspectionOptionFix( myInspection, "ignoreStringConstructor", InspectionGadgetsBundle.message("inspection.redundant.string.option.do.not.report.string.constructors"), true))}; return myManager.createProblemDescriptor(anchor, (TextRange)null, InspectionGadgetsBundle.message("inspection.redundant.string.constructor.message"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly, fixes); } } else if (isNewStringCreatedFromEntireArray(args)) { LocalQuickFix fix = new RemoveRedundantOffsetAndLengthArgumentsFix(args[1], args[2]); return myManager.createProblemDescriptor(args[1], args[2], InspectionGadgetsBundle.message("inspection.redundant.arguments.message"), ProblemHighlightType.LIKE_UNUSED_SYMBOL, myIsOnTheFly, fix); } return null; }