use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GroovyArgListSelectioner method select.
@Override
public List<TextRange> select(PsiElement element, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = super.select(element, editorText, cursorOffset, editor);
if (element instanceof GrArgumentList) {
GrArgumentList args = ((GrArgumentList) element);
TextRange range = args.getTextRange();
if (range.contains(cursorOffset)) {
PsiElement leftParen = args.getLeftParen();
PsiElement rightParen = args.getRightParen();
if (leftParen != null) {
int leftOffset = leftParen.getTextOffset();
if (rightParen != null) {
if (leftOffset + 1 < rightParen.getTextOffset()) {
int rightOffset = rightParen.getTextRange().getEndOffset();
range = new TextRange(leftParen.getTextRange().getStartOffset() + 1, rightOffset - 1);
result.add(range);
}
} else {
range = new TextRange(leftParen.getTextRange().getStartOffset() + 1, element.getTextRange().getEndOffset());
result.add(range);
}
}
}
}
final PsiElement parent = element.getParent();
if (parent instanceof GrReferenceExpression) {
final GrArgumentList argumentList = ((GrCall) parent.getParent()).getArgumentList();
final PsiElement refName = ((GrReferenceExpression) parent).getReferenceNameElement();
if (argumentList != null && refName == element) {
result.add(new TextRange(refName.getTextRange().getStartOffset(), argumentList.getTextRange().getEndOffset()));
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression 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.GrReferenceExpression in project intellij-community by JetBrains.
the class DynamicTest method testMethod.
public void testMethod() throws Throwable {
final GrReferenceExpression referenceExpression = doDynamicFix();
final PsiType[] psiTypes = PsiUtil.getArgumentTypes(referenceExpression, false);
final String[] methodArgumentsNames = GroovyNamesUtil.getMethodArgumentsNames(getProject(), psiTypes);
final List<ParamInfo> pairs = QuickfixUtil.swapArgumentsAndTypes(methodArgumentsNames, psiTypes);
assertNotNull(getDClassElement().getMethod(referenceExpression.getReferenceName(), QuickfixUtil.getArgumentsTypes(pairs)));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GroovyIntroduceParameterObjectDelegate method collectInternalUsages.
@Override
public <M1 extends PsiNamedElement, P1 extends ParameterInfo> ReadWriteAccessDetector.Access collectInternalUsages(Collection<FixableUsageInfo> usages, GrMethod overridingMethod, IntroduceParameterObjectClassDescriptor<M1, P1> classDescriptor, P1 parameterInfo, String mergedParamName) {
final int oldIndex = parameterInfo.getOldIndex();
final GrParameter parameter = overridingMethod.getParameterList().getParameters()[oldIndex];
final ReadWriteAccessDetector.Access[] accessors = new ReadWriteAccessDetector.Access[1];
final String setter = classDescriptor.getSetterName(parameterInfo, overridingMethod);
final String getter = classDescriptor.getGetterName(parameterInfo, overridingMethod);
ReferencesSearch.search(parameter, new LocalSearchScope(overridingMethod)).forEach(reference -> {
final PsiElement element = reference.getElement();
if (element instanceof GrReferenceExpression) {
accessors[0] = ReadWriteAccessDetector.Access.Read;
usages.add(new GrReplaceParameterReferenceWithCall(element, getter, mergedParamName));
}
return true;
});
return accessors[0];
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GrAliasImportIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
GrImportStatement context;
final PsiMember resolved;
if (element instanceof GrReferenceExpression) {
GrReferenceExpression ref = (GrReferenceExpression) element;
GroovyResolveResult result = ref.advancedResolve();
context = (GrImportStatement) result.getCurrentFileResolveContext();
assert context != null;
resolved = (PsiMember) result.getElement();
} else if (element instanceof GrImportStatement) {
context = (GrImportStatement) element;
resolved = (PsiMember) context.getImportReference().resolve();
} else {
return;
}
assert resolved != null;
doRefactoring(project, context, resolved);
}
Aggregations