use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GroovyShellCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile file = parameters.getOriginalFile();
if (!(file instanceof GroovyShellCodeFragment))
return;
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
if (!(parent instanceof GrReferenceExpression && !((GrReferenceExpression) parent).isQualified()))
return;
if (PsiUtil.isExpressionStatement(parent)) {
addAllCommands(result);
} else if (parent.getParent() instanceof GrCommandArgumentList) {
PsiElement ppparent = parent.getParent().getParent();
if (ppparent instanceof GrMethodCall && isFirstArg((GrMethodCall) ppparent, parent)) {
GrExpression invokedExpression = ((GrMethodCall) ppparent).getInvokedExpression();
if (invokedExpression instanceof GrReferenceExpression && !((GrReferenceExpression) invokedExpression).isQualified()) {
String name = ((GrReferenceExpression) invokedExpression).getReferenceName();
if ("help".equals(name)) {
addAllCommands(result);
} else if ("show".equals(name)) {
add(result, "classes");
add(result, "imports");
add(result, "preferences");
add(result, "all");
} else if ("purge".equals(name)) {
add(result, "variables");
add(result, "classes");
add(result, "imports");
add(result, "preferences");
add(result, "all");
} else if ("record".equals(name)) {
add(result, "start");
add(result, "stop");
add(result, "status");
} else if ("history".equals(name)) {
add(result, "show");
add(result, "recall");
add(result, "flush");
add(result, "clear");
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GrIntroduceParameterDialog method doOKAction.
@Override
public void doOKAction() {
saveSettings();
super.doOKAction();
final GrParametersOwner toReplaceIn = myInfo.getToReplaceIn();
final GrExpression expr = GroovyIntroduceParameterUtil.findExpr(myInfo);
final GrVariable var = GroovyIntroduceParameterUtil.findVar(myInfo);
final StringPartInfo stringPart = findStringPart();
if (myTypeComboBox.isClosureSelected() || expr == null && var == null && stringPart == null) {
GrIntroduceParameterSettings settings = new ExtractClosureHelperImpl(myInfo, getEnteredName(), myDeclareFinalCheckBox.isSelected(), getParametersToRemove(), myDelegateViaOverloadingMethodCheckBox.isSelected(), getReplaceFieldsWithGetter(), myForceReturnCheckBox.isSelected(), false, myTypeComboBox.getSelectedType() == null);
if (toReplaceIn instanceof GrMethod) {
invokeRefactoring(new ExtractClosureFromMethodProcessor(settings));
} else {
invokeRefactoring(new ExtractClosureFromClosureProcessor(settings));
}
} else {
GrIntroduceParameterSettings settings = new GrIntroduceExpressionSettingsImpl(myInfo, getEnteredName(), myDeclareFinalCheckBox.isSelected(), getParametersToRemove(), myDelegateViaOverloadingMethodCheckBox.isSelected(), getReplaceFieldsWithGetter(), expr, var, myTypeComboBox.getSelectedType(), var != null, true, myForceReturnCheckBox.isSelected());
if (toReplaceIn instanceof GrMethod) {
invokeRefactoring(new GrIntroduceParameterProcessor(settings));
} else {
invokeRefactoring(new GrIntroduceClosureParameterProcessor(settings));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GrIntroduceParameterHandler method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable final DataContext dataContext) {
if (editor == null || file == null)
return;
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
final int offset = editor.getCaretModel().getOffset();
final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, offset, false);
if (expressions.isEmpty()) {
GrIntroduceHandlerBase.updateSelectionForVariable(editor, file, selectionModel, offset);
} else if (expressions.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) {
final TextRange textRange = expressions.get(0).getTextRange();
selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
} else {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<GrExpression>() {
@Override
public void pass(final GrExpression selectedValue) {
invoke(project, editor, file, selectedValue.getTextRange().getStartOffset(), selectedValue.getTextRange().getEndOffset());
}
}, grExpression -> grExpression.getText());
return;
}
}
invoke(project, editor, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GrIntroduceParameterHandler method createContext.
private static GrIntroduceContext createContext(@NotNull IntroduceParameterInfo info, @NotNull Editor editor) {
GrExpression expr = GroovyIntroduceParameterUtil.findExpr(info);
GrVariable var = GroovyIntroduceParameterUtil.findVar(info);
StringPartInfo stringPart = info.getStringPartInfo();
return new GrIntroduceVariableHandler().getContext(info.getProject(), editor, expr, var, stringPart, info.getToReplaceIn());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GrIntroduceParameterProcessor method createExpressionWrapper.
private static GrExpressionWrapper createExpressionWrapper(GrIntroduceParameterSettings settings) {
LOG.assertTrue(settings.getToReplaceIn() instanceof GrMethod);
LOG.assertTrue(settings.getToSearchFor() instanceof PsiMethod);
final StringPartInfo stringPartInfo = settings.getStringPartInfo();
GrVariable var = settings.getVar();
final GrExpression expression = stringPartInfo != null ? stringPartInfo.createLiteralFromSelected() : var != null ? var.getInitializerGroovy() : settings.getExpression();
return new GrExpressionWrapper(expression);
}
Aggregations