Search in sources :

Example 1 with GrNamedArgumentSearchVisitor

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrNamedArgumentSearchVisitor in project intellij-community by JetBrains.

the class GrMethodBaseImpl method getNamedParameters.

@Override
@NotNull
public Map<String, NamedArgumentDescriptor> getNamedParameters() {
    final GrMethodStub stub = getStub();
    if (stub != null) {
        String[] namedParameters = stub.getNamedParameters();
        if (namedParameters.length == 0)
            return Collections.emptyMap();
        Map<String, NamedArgumentDescriptor> result = ContainerUtil.newHashMap();
        for (String parameter : namedParameters) {
            result.put(parameter, GrNamedArgumentSearchVisitor.CODE_NAMED_ARGUMENTS_DESCR);
        }
        return result;
    }
    GrOpenBlock body = getBlock();
    if (body == null)
        return Collections.emptyMap();
    GrParameter[] parameters = getParameters();
    if (parameters.length == 0)
        return Collections.emptyMap();
    GrParameter firstParameter = parameters[0];
    PsiType type = firstParameter.getTypeGroovy();
    GrTypeElement typeElement = firstParameter.getTypeElementGroovy();
    if (type != null && typeElement != null && type.getPresentableText() != null && !type.getPresentableText().endsWith("Map")) {
        return Collections.emptyMap();
    }
    GrNamedArgumentSearchVisitor visitor = new GrNamedArgumentSearchVisitor(firstParameter.getNameIdentifierGroovy().getText());
    body.accept(visitor);
    return visitor.getResult();
}
Also used : NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) GrNamedArgumentSearchVisitor(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrNamedArgumentSearchVisitor) GrOpenBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock) GrMethodStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 NamedArgumentDescriptor (org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor)1 GrNamedArgumentSearchVisitor (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrNamedArgumentSearchVisitor)1 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)1 GrMethodStub (org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub)1