use of com.perl5.lang.perl.psi.PsiPerlParenthesisedExpr in project Perl5-IDEA by Camelcade.
the class PerlFormattingStatementModifierUnwrap method apply.
@Override
public int apply() {
int delta = 0;
if (getMyModifier().isValid()) {
PsiPerlExpr expression = PsiTreeUtil.getChildOfType(getMyModifier(), PsiPerlExpr.class);
if (expression != null && expression instanceof PsiPerlParenthesisedExpr) {
PsiPerlExpr nestedExpression = ((PsiPerlParenthesisedExpr) expression).getExpr();
if (nestedExpression != null) {
delta = nestedExpression.getNode().getTextLength() - expression.getNode().getTextLength();
expression.replace(nestedExpression.copy());
}
}
}
return delta;
}
use of com.perl5.lang.perl.psi.PsiPerlParenthesisedExpr in project Perl5-IDEA by Camelcade.
the class PerlFormattingStatementModifierWrap method apply.
@Override
public int apply() {
int delta = 0;
if (getMyModifier().isValid()) {
PsiPerlExpr expression = PsiTreeUtil.getChildOfType(getMyModifier(), PsiPerlExpr.class);
if (expression != null && !(expression instanceof PsiPerlParenthesisedExpr)) {
PsiPerlParenthesisedExpr parenthesisedExpression = PerlElementFactory.createParenthesisedExpression(getMyModifier().getProject());
parenthesisedExpression.addAfter(expression.copy(), parenthesisedExpression.getFirstChild());
delta = expression.getNode().getTextLength() - parenthesisedExpression.getNode().getTextLength();
expression.replace(parenthesisedExpression);
}
}
return delta;
}
use of com.perl5.lang.perl.psi.PsiPerlParenthesisedExpr in project Perl5-IDEA by Camelcade.
the class PerlElementFactory method createParenthesisedExpression.
public static PsiPerlParenthesisedExpr createParenthesisedExpression(Project project) {
PerlFileImpl file = createFile(project, "();");
PsiPerlParenthesisedExpr result = PsiTreeUtil.findChildOfType(file, PsiPerlParenthesisedExpr.class);
assert result != null : "While creating PsiPerlParenthesisedExpr";
return result;
}
use of com.perl5.lang.perl.psi.PsiPerlParenthesisedExpr in project Perl5-IDEA by Camelcade.
the class StatementToCompoundIntention method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
PsiPerlStatementImpl statement = getStatement(element);
if (statement == null) {
return;
}
PsiPerlStatementModifier modifier = statement.getModifier();
if (modifier == null) {
return;
}
PsiElement keyword = modifier.getFirstChild();
if (keyword == null) {
return;
}
PsiPerlExpr modifierExpression = PsiTreeUtil.getChildOfType(modifier, PsiPerlExpr.class);
PsiPerlExpr valueExpression = modifierExpression instanceof PsiPerlParenthesisedExpr ? ((PsiPerlParenthesisedExpr) modifierExpression).getExpr() : modifierExpression;
String conditionText = valueExpression == null ? "" : valueExpression.getText();
TextRange modifierRangeInStatement = TextRange.from(modifier.getStartOffsetInParent(), modifier.getTextLength());
String statementText = modifierRangeInStatement.replace(statement.getText(), "");
StringBuilder newCode = new StringBuilder();
newCode.append(keyword.getText()).append("(").append(conditionText).append("){\n").append(statementText).append("\n}");
PerlFileImpl fakeFile = PerlElementFactory.createFile(project, newCode.toString());
PsiElement[] children = fakeFile.getChildren();
assert children.length == 1;
statement.replace(children[0]);
}
Aggregations