use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrIntroduceHandlerBase method expressionIsIncorrect.
public static boolean expressionIsIncorrect(@Nullable GrExpression expression, boolean acceptVoidCalls) {
if (expression instanceof GrParenthesizedExpression)
return true;
if (PsiUtil.isSuperReference(expression))
return true;
if (expression instanceof GrAssignmentExpression)
return true;
if (expression instanceof GrReferenceExpression && expression.getParent() instanceof GrCall) {
final GroovyResolveResult resolveResult = ((GrReferenceExpression) expression).advancedResolve();
final PsiElement resolved = resolveResult.getElement();
return resolved instanceof PsiMethod && !resolveResult.isInvokedOnProperty() || resolved instanceof PsiClass;
}
if (expression instanceof GrReferenceExpression && expression.getParent() instanceof GrReferenceExpression) {
return !PsiUtil.isThisReference(expression) && ((GrReferenceExpression) expression).resolve() instanceof PsiClass;
}
if (expression instanceof GrClosableBlock && expression.getParent() instanceof GrStringInjection)
return true;
if (!acceptVoidCalls && expression instanceof GrMethodCall && PsiType.VOID.equals(expression.getType()))
return true;
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyInlineMethodUtil method replaceParametersWithArguments.
/**
* Inline method call's arguments as its parameters
*
* @param call method call
* @param method given method
*/
public static void replaceParametersWithArguments(GrCallExpression call, GrMethod method) throws IncorrectOperationException {
GrParameter[] parameters = method.getParameters();
if (parameters.length == 0)
return;
GrArgumentList argumentList = call.getArgumentList();
if (argumentList == null) {
setDefaultValuesToParameters(method, null, call);
return;
}
Project project = call.getProject();
final GroovyResolveResult resolveResult = call.advancedResolve();
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, resolveResult.getSubstitutor());
if (signature == null) {
return;
}
GrClosureSignatureUtil.ArgInfo<PsiElement>[] infos = GrClosureSignatureUtil.mapParametersToArguments(signature, call.getNamedArguments(), call.getExpressionArguments(), call.getClosureArguments(), call, true, false);
if (infos == null)
return;
for (int i = 0; i < infos.length; i++) {
GrClosureSignatureUtil.ArgInfo<PsiElement> argInfo = infos[i];
GrParameter parameter = parameters[i];
final GrExpression arg = inferArg(signature, parameters, parameter, argInfo, project);
if (arg != null) {
replaceAllOccurrencesWithExpression(method, call, arg, parameter);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class StubGenerator method resolveChainingConstructor.
@Nullable
private static GroovyResolveResult resolveChainingConstructor(GrMethod constructor) {
LOG.assertTrue(constructor.isConstructor());
final GrConstructorInvocation constructorInvocation = PsiImplUtil.getChainingConstructorInvocation(constructor);
if (constructorInvocation == null) {
return null;
}
GroovyResolveResult resolveResult = constructorInvocation.advancedResolve();
if (resolveResult.getElement() != null) {
return resolveResult;
}
final GroovyResolveResult[] results = constructorInvocation.multiResolve(false);
if (results.length > 0) {
int i = 0;
while (results.length > i + 1) {
final PsiMethod candidate = (PsiMethod) results[i].getElement();
final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(constructor.getProject()).getResolveHelper();
if (candidate != null && candidate != constructor && resolveHelper.isAccessible(candidate, constructorInvocation, null)) {
break;
}
i++;
}
return results[i];
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyDocumentationProvider method getMethodCandidateInfo.
private static String getMethodCandidateInfo(GrReferenceExpression expr) {
final GroovyResolveResult[] candidates = expr.multiResolve(false);
final String text = expr.getText();
if (candidates.length > 0) {
@NonNls final StringBuilder sb = new StringBuilder();
for (final GroovyResolveResult candidate : candidates) {
final PsiElement element = candidate.getElement();
if (!(element instanceof PsiMethod)) {
continue;
}
final String str = PsiFormatUtil.formatMethod((PsiMethod) element, candidate.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
createElementLink(sb, element, str);
}
return CodeInsightBundle.message("javadoc.candidates", text, sb);
}
return CodeInsightBundle.message("javadoc.candidates.not.found", text);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyRefactoringSupportProvider method isMemberInplaceRenameAvailable.
@Override
public boolean isMemberInplaceRenameAvailable(@NotNull PsiElement element, @Nullable PsiElement context) {
if (context == null || context.getContainingFile() instanceof GroovyFile)
return false;
PsiElement parent = context.getParent();
//don't try to inplace rename aliased imported references
if (parent instanceof GrReferenceElement) {
GroovyResolveResult result = ((GrReferenceElement) parent).advancedResolve();
PsiElement fileResolveContext = result.getCurrentFileResolveContext();
if (fileResolveContext instanceof GrImportStatement && ((GrImportStatement) fileResolveContext).isAliasedImport()) {
return false;
}
}
return element instanceof GrMember;
}
Aggregations