use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class GroovyMethodReturnNamedArgumentProvider method getNamedArguments.
@Override
public void getNamedArguments(@NotNull GrCall call, @NotNull GroovyResolveResult resolveResult, @Nullable String argumentName, boolean forCompletion, @NotNull Map<String, NamedArgumentDescriptor> result) {
PsiElement resolve = resolveResult.getElement();
if (!forCompletion || !(resolve instanceof PsiMethod))
return;
PsiType returnType = ((PsiMethod) resolve).getReturnType();
if (!(returnType instanceof PsiClassType))
return;
Map<String, NamedArgumentDescriptor> map = new HashMap<>();
GroovyConstructorNamedArgumentProvider.processClass(call, (PsiClassType) returnType, argumentName, map);
for (String name : map.keySet()) {
result.put(name, NamedArgumentDescriptor.SIMPLE_UNLIKELY);
}
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class MethodLateBoundReferencesSearcher method processQuery.
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiMethod method = queryParameters.getMethod();
SearchScope searchScope = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope()).intersectWith(getUseScope(method));
orderSearching(searchScope, method.getName(), method, queryParameters.getOptimizer(), method.getParameterList().getParametersCount());
final String propName = PropertyUtil.getPropertyName(method);
if (propName != null) {
orderSearching(searchScope, propName, method, queryParameters.getOptimizer(), -1);
}
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class PluginXmlClosureMemberContributor method processMembers.
@Override
public boolean processMembers(GrClosableBlock closure, PsiScopeProcessor processor, GrReferenceExpression refExpr, ResolveState state) {
PsiElement parent = closure.getParent();
if (parent instanceof GrArgumentList)
parent = parent.getParent();
if (!(parent instanceof GrMethodCall))
return true;
PsiMethod psiMethod = ((GrMethodCall) parent).resolveMethod();
if (psiMethod == null)
return true;
List<GroovyMethodInfo> infos = GroovyMethodInfo.getInfos(psiMethod);
if (infos.isEmpty())
return true;
int index = PsiUtil.getArgumentIndex((GrMethodCall) parent, closure);
if (index == -1)
return true;
for (GroovyMethodInfo info : infos) {
GroovyMethodDescriptor.ClosureArgument[] closureArguments = info.getDescriptor().myClosureArguments;
if (closureArguments != null) {
for (GroovyMethodDescriptor.ClosureArgument argument : closureArguments) {
if (argument.index == index && argument.methodContributor != null) {
ClosureMissingMethodContributor instance = SingletonInstancesCache.getInstance(argument.methodContributor, info.getPluginClassLoader());
if (!instance.processMembers(closure, processor, refExpr, state))
return false;
}
}
}
}
return true;
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class AnnotateOverriddenMethodParameterFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
PsiParameter parameter = PsiTreeUtil.getParentOfType(psiElement, PsiParameter.class, false);
if (parameter == null)
return;
PsiMethod method = PsiTreeUtil.getParentOfType(parameter, PsiMethod.class);
if (method == null)
return;
PsiParameter[] parameters = method.getParameterList().getParameters();
int index = ArrayUtilRt.find(parameters, parameter);
List<PsiParameter> toAnnotate = new ArrayList<>();
PsiMethod[] methods = OverridingMethodsSearch.search(method).toArray(PsiMethod.EMPTY_ARRAY);
for (PsiMethod psiMethod : methods) {
PsiParameter[] psiParameters = psiMethod.getParameterList().getParameters();
if (index >= psiParameters.length)
continue;
PsiParameter psiParameter = psiParameters[index];
if (!AnnotationUtil.isAnnotated(psiParameter, myAnnotation, false, false) && psiMethod.getManager().isInProject(psiMethod)) {
toAnnotate.add(psiParameter);
}
}
FileModificationService.getInstance().preparePsiElementsForWrite(toAnnotate);
for (PsiParameter psiParam : toAnnotate) {
assert psiParam != null : toAnnotate;
if (AnnotationUtil.isAnnotatingApplicable(psiParam, myAnnotation)) {
AddAnnotationPsiFix fix = new AddAnnotationPsiFix(myAnnotation, psiParam, PsiNameValuePair.EMPTY_ARRAY, myAnnosToRemove);
fix.invoke(project, psiParam.getContainingFile(), psiParam, psiParam);
}
}
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class JavaDocExternalFilter method getExternalDocInfoForElement.
@Override
@Nullable
public String getExternalDocInfoForElement(@NotNull String docURL, final PsiElement element) throws Exception {
String externalDoc = null;
myElement = element;
String projectPath = "/" + myProject.getName() + "/";
String builtInServer = "http://localhost:" + BuiltInServerOptions.getInstance().getEffectiveBuiltInServerPort() + projectPath;
if (docURL.startsWith(builtInServer)) {
Url url = Urls.parseFromIdea(docURL);
VirtualFile file = url == null ? null : WebServerPathToFileManager.getInstance(myProject).findVirtualFile(url.getPath().substring(projectPath.length()));
if (file != null) {
InputStreamReader reader = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8);
StringBuilder result = new StringBuilder();
try {
doBuildFromStream(docURL, reader, result);
} finally {
reader.close();
}
externalDoc = correctDocText(docURL, result);
}
}
if (externalDoc == null) {
externalDoc = super.getExternalDocInfoForElement(docURL, element);
}
if (externalDoc == null) {
return null;
}
if (element instanceof PsiMethod) {
final String className = ApplicationManager.getApplication().runReadAction(new NullableComputable<String>() {
@Override
@Nullable
public String compute() {
PsiClass aClass = ((PsiMethod) element).getContainingClass();
return aClass == null ? null : aClass.getQualifiedName();
}
});
Matcher matcher = ourMethodHeading.matcher(externalDoc);
StringBuilder buffer = new StringBuilder("<h3>");
DocumentationManager.createHyperlink(buffer, className, className, false);
return matcher.replaceFirst(buffer.append("</h3>").toString());
}
return externalDoc;
}
Aggregations