Search in sources :

Example 71 with PsiMethod

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);
    }
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) PsiMethod(com.intellij.psi.PsiMethod) HashMap(java.util.HashMap) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Example 72 with PsiMethod

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);
    }
}
Also used : PsiMethod(com.intellij.psi.PsiMethod)

Example 73 with PsiMethod

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;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) PsiMethod(com.intellij.psi.PsiMethod) GroovyMethodDescriptor(org.jetbrains.plugins.groovy.extensions.GroovyMethodDescriptor) PsiElement(com.intellij.psi.PsiElement) GroovyMethodInfo(org.jetbrains.plugins.groovy.extensions.GroovyMethodInfo)

Example 74 with PsiMethod

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);
        }
    }
}
Also used : AddAnnotationPsiFix(com.intellij.codeInsight.intention.AddAnnotationPsiFix) PsiParameter(com.intellij.psi.PsiParameter) PsiMethod(com.intellij.psi.PsiMethod) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement)

Example 75 with PsiMethod

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) InputStreamReader(java.io.InputStreamReader) PsiMethod(com.intellij.psi.PsiMethod) Matcher(java.util.regex.Matcher) PsiClass(com.intellij.psi.PsiClass) Url(com.intellij.util.Url) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)232 PsiClass (com.intellij.psi.PsiClass)97 PsiElement (com.intellij.psi.PsiElement)71 ArrayList (java.util.ArrayList)24 NotNull (org.jetbrains.annotations.NotNull)22 Nullable (org.jetbrains.annotations.Nullable)19 Project (com.intellij.openapi.project.Project)16 PsiField (com.intellij.psi.PsiField)13 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)12 Location (com.intellij.execution.Location)11 JavaEvaluator (com.android.tools.klint.client.api.JavaEvaluator)9 PsiReference (com.intellij.psi.PsiReference)9 PsiFile (com.intellij.psi.PsiFile)8 PsiAnnotation (com.intellij.psi.PsiAnnotation)7 List (java.util.List)7 Nullable (com.android.annotations.Nullable)6 Module (com.intellij.openapi.module.Module)6 PsiType (com.intellij.psi.PsiType)6 SearchScope (com.intellij.psi.search.SearchScope)6 PsiParameter (com.intellij.psi.PsiParameter)5