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() + "'");
}
}
}
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);
}
}
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;
}
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();
}
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);
}
Aggregations