Search in sources :

Example 11 with NamedArgumentDescriptor

use of org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor in project intellij-community by JetBrains.

the class NonCodeMembersHolder method createMethod.

private static GrLightMethodBuilder createMethod(Map prop, PsiElement place, PsiManager manager) {
    String name = String.valueOf(prop.get("name"));
    final GrLightMethodBuilder method = new GrLightMethodBuilder(manager, name).addModifier(PsiModifier.PUBLIC);
    if (Boolean.TRUE.equals(prop.get("constructor"))) {
        method.setConstructor(true);
    } else {
        method.setReturnType(convertToPsiType(String.valueOf(prop.get("type")), place));
    }
    final Object params = prop.get("params");
    if (params instanceof Map) {
        boolean first = true;
        for (Object paramName : ((Map) params).keySet()) {
            Object value = ((Map) params).get(paramName);
            boolean isNamed = first && value instanceof List;
            first = false;
            String typeName = isNamed ? CommonClassNames.JAVA_UTIL_MAP : String.valueOf(value);
            method.addParameter(String.valueOf(paramName), convertToPsiType(typeName, place), false);
            if (isNamed) {
                Map<String, NamedArgumentDescriptor> namedParams = ContainerUtil.newHashMap();
                for (Object o : (List) value) {
                    if (o instanceof CustomMembersGenerator.ParameterDescriptor) {
                        namedParams.put(((CustomMembersGenerator.ParameterDescriptor) o).name, ((CustomMembersGenerator.ParameterDescriptor) o).descriptor);
                    }
                }
                method.setNamedParameters(namedParams);
            }
        }
    }
    if (Boolean.TRUE.equals(prop.get("isStatic"))) {
        method.addModifier(PsiModifier.STATIC);
    }
    final Object bindsTo = prop.get("bindsTo");
    if (bindsTo instanceof PsiElement) {
        method.setNavigationElement((PsiElement) bindsTo);
    }
    final Object toThrow = prop.get(CustomMembersGenerator.THROWS);
    if (toThrow instanceof List) {
        for (Object o : ((List) toThrow)) {
            final PsiType psiType = convertToPsiType(String.valueOf(o), place);
            if (psiType instanceof PsiClassType) {
                method.addException((PsiClassType) psiType);
            }
        }
    }
    Object doc = prop.get("doc");
    if (doc instanceof String) {
        method.putUserData(DOCUMENTATION, (String) doc);
    }
    Object docUrl = prop.get("docUrl");
    if (docUrl instanceof String) {
        method.putUserData(DOCUMENTATION_URL, (String) docUrl);
    }
    Object qName = prop.get("containingClass");
    if (qName instanceof String) {
        PsiClass foundClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(((String) qName), place.getResolveScope());
        if (foundClass != null) {
            method.setContainingClass(foundClass);
        }
    }
    return method;
}
Also used : NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) CustomMembersGenerator(org.jetbrains.plugins.groovy.dsl.CustomMembersGenerator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 12 with NamedArgumentDescriptor

use of org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor in project intellij-community by JetBrains.

the class GrFieldImpl method getNamedParameters.

@Override
@NotNull
public Map<String, NamedArgumentDescriptor> getNamedParameters() {
    final GrFieldStub 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;
    }
    return GrNamedArgumentSearchVisitor.find(this);
}
Also used : GrFieldStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrFieldStub) NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NamedArgumentDescriptor (org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor)12 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 PsiElement (com.intellij.psi.PsiElement)3 HashMap (java.util.HashMap)3 NotNull (org.jetbrains.annotations.NotNull)3 Map (java.util.Map)2 Nullable (org.jetbrains.annotations.Nullable)2 GrString (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 PsiTypeLookupItem (com.intellij.codeInsight.lookup.PsiTypeLookupItem)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiRecursiveElementWalkingVisitor (com.intellij.psi.PsiRecursiveElementWalkingVisitor)1 PsiType (com.intellij.psi.PsiType)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 IElementType (com.intellij.psi.tree.IElementType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CustomMembersGenerator (org.jetbrains.plugins.groovy.dsl.CustomMembersGenerator)1