@Override public void run() { try { final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(refExpression.getProject()).getElementFactory(); final PsiExpression copyExpression = elementFactory.createExpressionFromText(refExpression.getText(), refExpression); if (copyExpression instanceof PsiReferenceExpression) { final PsiReferenceExpression copy = (PsiReferenceExpression)copyExpression; final PsiExpression qualifier = copy.getQualifierExpression(); if (qualifier != null) { qualifier.replace(castOperand); result.set(Boolean.valueOf(copy.resolve() == resolved)); } } } catch (IncorrectOperationException ignore) { } } });
String text = binaryExpression.getText().substring(0, element.getStartOffsetInParent()); PsiExpression subExpression = JavaPsiFacade.getInstance(binaryExpression.getProject()).getElementFactory() .createExpressionFromText(text, binaryExpression); addFormatParameter(subExpression, formatString, formatParameters, printfFormat);
private static PsiExpression getBoxedArgument(PsiExpression arg) throws IncorrectOperationException { arg = PsiUtil.deparenthesizeExpression(arg); assert arg != null; if (PsiUtil.isLanguageLevel5OrHigher(arg)) { return arg; } final PsiType type = arg.getType(); if (!(type instanceof PsiPrimitiveType) || type.equals(PsiType.NULL)) { return arg; } final PsiPrimitiveType primitiveType = (PsiPrimitiveType)type; final String boxedQName = primitiveType.getBoxedTypeName(); if (boxedQName == null) { return arg; } final GlobalSearchScope resolveScope = arg.getResolveScope(); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(arg.getProject()); final PsiJavaCodeReferenceElement ref = factory.createReferenceElementByFQClassName(boxedQName, resolveScope); final PsiNewExpression newExpr = (PsiNewExpression)factory.createExpressionFromText("new A(b)", null); final PsiElement classRef = newExpr.getClassReference(); assert classRef != null; classRef.replace(ref); final PsiExpressionList argumentList = newExpr.getArgumentList(); assert argumentList != null; argumentList.getExpressions()[0].replace(arg); return newExpr; }
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); final PsiExpression expressionFromText = factory.createExpressionFromText(methodCall.getText(), methodCall); if (!(expressionFromText instanceof PsiMethodCallExpression)) return; PsiMethodCallExpression newCall = (PsiMethodCallExpression)expressionFromText;