use of com.perl5.lang.perl.psi.PsiPerlStatement in project Perl5-IDEA by Camelcade.
the class PerlUseVarsQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
Collection<PerlVariableDeclarationElement> declarations = myVariablesProvider.getValue();
if (declarations.isEmpty()) {
startElement.delete();
return;
}
StringBuilder newCode = new StringBuilder("our");
if (declarations.size() > 1) {
newCode.append("(");
}
newCode.append(StringUtil.join(ContainerUtil.map(declarations, PsiElement::getText), ","));
if (declarations.size() > 1) {
newCode.append(")");
}
newCode.append(";");
PerlFileImpl fakeFile = PerlElementFactory.createFile(myStartElement.getProject(), newCode.toString());
PsiPerlStatement newElement = PsiTreeUtil.findChildOfType(fakeFile, PsiPerlStatement.class);
if (newElement != null) {
startElement.replace(newElement);
}
}
use of com.perl5.lang.perl.psi.PsiPerlStatement in project Perl5-IDEA by Camelcade.
the class PerlFormattingScalarDerefCollapse method apply.
@Override
public int apply() {
int delta = 0;
if (myScalarElement.isValid() && myIndexElement.isValid()) {
String newCode = "$" + myScalarElement.getNode().getText() + myIndexElement.getNode().getText() + ";";
PerlFileImpl newFile = PerlElementFactory.createFile(myScalarElement.getProject(), newCode);
PsiPerlStatement statement = PsiTreeUtil.findChildOfType(newFile, PsiPerlStatement.class);
if (statement != null) {
delta = new PerlFormattingReplace(myScalarElement, myIndexElement, statement.getFirstChild(), statement.getFirstChild()).apply();
}
}
return delta;
}
Aggregations