use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument 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.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class GrArgumentListImpl method addAfter.
@Override
public PsiElement addAfter(@NotNull PsiElement element, @Nullable PsiElement anchor) throws IncorrectOperationException {
if (element instanceof GrExpression || element instanceof GrNamedArgument) {
final boolean insertComma = getAllArguments().length != 0;
if (anchor == null)
anchor = getLeftParen();
PsiElement result;
result = super.addAfter(element, anchor);
if (insertComma) {
final ASTNode astNode = getNode();
if (anchor == getLeftParen()) {
astNode.addLeaf(GroovyTokenTypes.mCOMMA, ",", result.getNextSibling().getNode());
} else {
astNode.addLeaf(GroovyTokenTypes.mCOMMA, ",", result.getNode());
}
CodeStyleManager.getInstance(getManager().getProject()).reformat(this);
}
return result;
}
return super.addAfter(element, anchor);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class PsiUtil method getNamedArgumentValue.
@Nullable
public static PsiElement getNamedArgumentValue(GrNamedArgument otherNamedArgument, String argumentName) {
PsiElement parent = otherNamedArgument.getParent();
if (!(parent instanceof GrNamedArgumentsOwner))
return null;
GrNamedArgument namedArgument = ((GrNamedArgumentsOwner) parent).findNamedArgument(argumentName);
if (namedArgument == null)
return null;
return namedArgument.getExpression();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project android by JetBrains.
the class GradleDslParser method getMethodCall.
@NotNull
static GradleDslMethodCall getMethodCall(@NotNull GradleDslElement parentElement, @NotNull GrMethodCallExpression psiElement, @NotNull String propertyName, @NotNull GrArgumentList argumentList) {
GradleDslMethodCall methodCall = new GradleDslMethodCall(parentElement, psiElement, propertyName);
for (GrExpression expression : argumentList.getExpressionArguments()) {
if (expression instanceof GrListOrMap) {
GrListOrMap listOrMap = (GrListOrMap) expression;
if (listOrMap.isMap()) {
methodCall.addParsedExpressionMap(getExpressionMap(methodCall, expression, propertyName, listOrMap.getNamedArguments()));
} else {
for (GrExpression grExpression : listOrMap.getInitializers()) {
GradleDslExpression dslExpression = getExpressionElement(methodCall, expression, propertyName, grExpression);
if (dslExpression != null) {
methodCall.addParsedExpression(dslExpression);
}
}
}
} else if (expression instanceof GrClosableBlock) {
methodCall.setParsedClosureElement(getClosureElement(methodCall, (GrClosableBlock) expression, propertyName));
} else {
GradleDslExpression dslExpression = getExpressionElement(methodCall, expression, propertyName, expression);
if (dslExpression != null) {
methodCall.addParsedExpression(dslExpression);
}
}
}
GrNamedArgument[] namedArguments = argumentList.getNamedArguments();
if (namedArguments.length > 0) {
methodCall.addParsedExpressionMap(getExpressionMap(methodCall, argumentList, propertyName, namedArguments));
}
return methodCall;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project android by JetBrains.
the class GradleDslParser method getExpressionMap.
@NotNull
private static GradleDslExpressionMap getExpressionMap(@NotNull GradleDslElement parentElement, // GrArgumentList or GrListOrMap
@NotNull GroovyPsiElement mapPsiElement, @NotNull String propertyName, @NotNull GrNamedArgument... namedArguments) {
GradleDslExpressionMap expressionMap = new GradleDslExpressionMap(parentElement, mapPsiElement, propertyName);
for (GrNamedArgument namedArgument : namedArguments) {
String argName = namedArgument.getLabelName();
if (isEmpty(argName)) {
continue;
}
GrExpression valueExpression = namedArgument.getExpression();
if (valueExpression == null) {
continue;
}
GradleDslElement valueElement = getExpressionElement(expressionMap, mapPsiElement, argName, valueExpression);
if (valueElement == null && valueExpression instanceof GrListOrMap) {
GrListOrMap listOrMap = (GrListOrMap) valueExpression;
if (listOrMap.isMap()) {
valueElement = getExpressionMap(expressionMap, listOrMap, argName, listOrMap.getNamedArguments());
} else {
// ex: flatDir name: "libs", dirs: ["libs1", "libs2"]
valueElement = getExpressionList(expressionMap, listOrMap, argName, listOrMap.getInitializers());
}
}
if (valueElement != null) {
expressionMap.setParsedElement(argName, valueElement);
}
}
return expressionMap;
}
Aggregations