Search in sources :

Example 6 with NamedArgumentDescriptor

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

the class GroovyTypeCheckVisitor method checkNamedArguments.

private void checkNamedArguments(GroovyPsiElement context, GrNamedArgument[] namedArguments, Map<String, NamedArgumentDescriptor> map) {
    for (GrNamedArgument namedArgument : namedArguments) {
        String labelName = namedArgument.getLabelName();
        NamedArgumentDescriptor descriptor = map.get(labelName);
        if (descriptor == null)
            continue;
        GrExpression namedArgumentExpression = namedArgument.getExpression();
        if (namedArgumentExpression == null)
            continue;
        if (getTupleInitializer(namedArgumentExpression) != null)
            continue;
        if (PsiUtil.isRawClassMemberAccess(namedArgumentExpression))
            continue;
        PsiType expressionType = TypesUtil.boxPrimitiveType(namedArgumentExpression.getType(), context.getManager(), context.getResolveScope());
        if (expressionType == null)
            continue;
        if (!descriptor.checkType(expressionType, context)) {
            registerError(namedArgumentExpression, ProblemHighlightType.GENERIC_ERROR, "Type of argument '" + labelName + "' can not be '" + expressionType.getPresentableText() + "'");
        }
    }
}
Also used : NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)

Example 7 with NamedArgumentDescriptor

use of org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor 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 8 with NamedArgumentDescriptor

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

the class GrArgumentLabelImpl method getReferenceFromNamedArgumentProviders.

@Nullable
private PsiPolyVariantReference getReferenceFromNamedArgumentProviders() {
    PsiElement namedArgument = getParent();
    if (!(namedArgument instanceof GrNamedArgument))
        return null;
    PsiElement nameElement = getNameElement();
    if (!(nameElement instanceof LeafPsiElement))
        return null;
    IElementType elementType = ((LeafPsiElement) nameElement).getElementType();
    if (elementType != GroovyTokenTypes.mIDENT && !CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) {
        return null;
    }
    GrCall call = PsiUtil.getCallByNamedParameter((GrNamedArgument) namedArgument);
    if (call == null)
        return NamedArgumentUtilKt.getReferenceFromDescriptor(this);
    String labelName = getName();
    Map<String, NamedArgumentDescriptor> providers = GroovyNamedArgumentProvider.getNamedArgumentsFromAllProviders(call, labelName, false);
    if (providers != null) {
        NamedArgumentDescriptor descr = providers.get(labelName);
        if (descr != null) {
            PsiPolyVariantReference res = descr.createReference(this);
            if (res != null) {
                return res;
            }
        }
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with NamedArgumentDescriptor

use of org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor 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)

Example 10 with NamedArgumentDescriptor

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

the class GroovyTypeCheckVisitor method checkNamedArgumentsType.

private void checkNamedArgumentsType(@NotNull CallInfo<?> info) {
    GroovyPsiElement rawCall = info.getCall();
    if (!(rawCall instanceof GrCall))
        return;
    GrCall call = (GrCall) rawCall;
    GrNamedArgument[] namedArguments = PsiUtil.getFirstMapNamedArguments(call);
    if (namedArguments.length == 0)
        return;
    Map<String, NamedArgumentDescriptor> map = GroovyNamedArgumentProvider.getNamedArgumentsFromAllProviders(call, null, false);
    if (map == null)
        return;
    checkNamedArguments(call, namedArguments, map);
}
Also used : NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)

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