use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class MavenGroovyPomUtil method getGroovyMethodCalls.
@NotNull
public static List<String> getGroovyMethodCalls(PsiElement psiElement) {
LinkedList<String> methodCallInfo = ContainerUtilRt.newLinkedList();
for (GrMethodCall current = PsiTreeUtil.getParentOfType(psiElement, GrMethodCall.class); current != null; current = PsiTreeUtil.getParentOfType(current, GrMethodCall.class)) {
GrExpression expression = current.getInvokedExpression();
String text = expression.getText();
if (text != null) {
methodCallInfo.addFirst(text);
}
}
return methodCallInfo;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GrVariableJoinLinesHandler method tryJoinStatements.
@Override
public int tryJoinStatements(@NotNull GrStatement first, @NotNull GrStatement second) {
if (first instanceof GrVariableDeclaration && !((GrVariableDeclaration) first).isTuple() && second instanceof GrAssignmentExpression) {
final GrExpression lvalue = ((GrAssignmentExpression) second).getLValue();
final GrExpression rValue = ((GrAssignmentExpression) second).getRValue();
if (lvalue instanceof GrReferenceExpression && rValue != null) {
final PsiElement resolved = ((GrReferenceExpression) lvalue).resolve();
if (ArrayUtil.contains(resolved, ((GrVariableDeclaration) first).getVariables())) {
assert resolved instanceof GrVariable;
if (((GrVariable) resolved).getInitializerGroovy() == null) {
((GrVariable) resolved).setInitializerGroovy(rValue);
second.delete();
GrExpression newInitializer = ((GrVariable) resolved).getInitializerGroovy();
assert newInitializer != null;
return newInitializer.getTextRange().getEndOffset();
}
}
}
}
return CANNOT_JOIN;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class IntroduceVariableValidatorTest method processFile.
private String processFile(String fileText) throws IncorrectOperationException, InvalidDataException, IOException {
String result = "";
int startOffset = fileText.indexOf(TestUtils.BEGIN_MARKER);
if (startOffset < 0) {
startOffset = fileText.indexOf(ALL_MARKER);
replaceAllOccurences = true;
fileText = IntroduceVariableTest.removeAllMarker(fileText);
} else {
replaceAllOccurences = false;
fileText = TestUtils.removeBeginMarker(fileText);
}
int endOffset = fileText.indexOf(TestUtils.END_MARKER);
fileText = TestUtils.removeEndMarker(fileText);
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, fileText);
Editor myEditor = myFixture.getEditor();
myEditor.getSelectionModel().setSelection(startOffset, endOffset);
GrExpression selectedExpr = PsiImplUtil.findElementInRange(myFixture.getFile(), startOffset, endOffset, GrExpression.class);
Assert.assertNotNull("Selected expression reference points to null", selectedExpr);
final PsiElement tempContainer = GrIntroduceHandlerBase.getEnclosingContainer(selectedExpr);
Assert.assertTrue(tempContainer instanceof GroovyPsiElement);
PsiElement[] occurences = GroovyRefactoringUtil.getExpressionOccurrences(PsiUtil.skipParentheses(selectedExpr, false), tempContainer);
String varName = "preved";
GroovyVariableValidator validator = new GroovyVariableValidator(new GrIntroduceContextImpl(getProject(), myEditor, selectedExpr, null, null, occurences, tempContainer));
result = validator.isOKTest(varName, replaceAllOccurences);
return result;
}
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));
}
}
}
Aggregations