use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GrCastFix method doCast.
static void doCast(@NotNull Project project, @NotNull PsiType type, @NotNull GrExpression expr) {
if (!type.isValid())
return;
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
final GrSafeCastExpression cast = (GrSafeCastExpression) factory.createExpressionFromText("foo as String");
final GrTypeElement typeElement = factory.createTypeElement(type);
cast.getOperand().replaceWithExpression(expr, true);
cast.getCastTypeElement().replace(typeElement);
final GrExpression replaced = expr.replaceWithExpression(cast, true);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(replaced);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GrCastFix method doFix.
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
final GrExpression cast = findExpressionToCast(descriptor);
if (cast == null)
return;
doCast(project, myExpectedType, cast);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class ChangeToMethodInspection method getFix.
@Nullable
protected GroovyFix getFix(@NotNull Transformation<?> transformation) {
return new GroovyFix() {
@Nls
@NotNull
@Override
public String getFamilyName() {
return message("replace.with.method.fix", transformation.getMethod());
}
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
PsiElement call = descriptor.getPsiElement().getParent();
if (!(call instanceof GrExpression))
return;
if (!transformation.couldApplyRow((GrExpression) call))
return;
transformation.applyRow((GrExpression) call);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class IsCaseTransformation method apply.
@Override
public void apply(@NotNull GrBinaryExpression expression) {
GrExpression rhsParenthesized = addParenthesesIfNeeded(getRhs(expression));
replaceExpression(expression, format("%s.isCase(%s)", rhsParenthesized.getText(), unparenthesize(getLhs(expression)).getText()));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class NotEqualTransformation method apply.
@Override
public void apply(@NotNull GrBinaryExpression expression) {
GrExpression lhsParenthesized = addParenthesesIfNeeded(getLhs(expression));
replaceExpression(expression, format("!%s.equals(%s)", lhsParenthesized.getText(), getRhs(expression).getText()));
}
Aggregations