use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GrStringUtil method checkGStringInjectionForUnnecessaryBraces.
public static boolean checkGStringInjectionForUnnecessaryBraces(GrStringInjection injection) {
final GrClosableBlock block = injection.getClosableBlock();
if (block == null)
return false;
final GrStatement[] statements = block.getStatements();
if (statements.length != 1)
return false;
if (!(statements[0] instanceof GrReferenceExpression))
return false;
return checkBraceIsUnnecessary(statements[0], injection.getNextSibling());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class PsiUtil method getArgumentIndex.
public static int getArgumentIndex(@NotNull GrCall call, @NotNull PsiElement argument) {
GrArgumentList argumentList = call.getArgumentList();
if (argumentList == null)
return -1;
GrExpression[] expressionArguments = argumentList.getExpressionArguments();
for (int i = 0; i < expressionArguments.length; i++) {
if (argument.equals(expressionArguments[i])) {
int res = i;
if (argumentList.getNamedArguments().length > 0) {
// first argument is map defined by named arguments
res++;
}
return res;
}
}
if (argument instanceof GrClosableBlock) {
GrClosableBlock[] closureArgs = call.getClosureArguments();
for (int i = 0; i < closureArgs.length; i++) {
if (argument.equals(closureArgs[i])) {
int res = i + expressionArguments.length;
if (argumentList.getNamedArguments().length > 0) {
// first argument is map defined by named arguments
res++;
}
return res;
}
}
}
return -1;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class ResolveUtil method treeWalkUp.
public static boolean treeWalkUp(@NotNull final PsiElement place, @NotNull final PsiElement originalPlace, @NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state) {
final GrClosableBlock maxScope = ResolveUtilKt.processNonCodeMembers(state) ? PsiTreeUtil.getParentOfType(place, GrClosableBlock.class, true, PsiFile.class) : null;
return PsiTreeUtil.treeWalkUp(place, maxScope, (scope, lastParent) -> {
ProgressManager.checkCanceled();
if (!doProcessDeclarations(originalPlace, lastParent, scope, substituteProcessor(processor, scope), state)) {
return false;
}
issueLevelChangeEvents(processor, scope);
return true;
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class ResolveUtil method findDuplicate.
public static PsiNamedElement findDuplicate(@NotNull GrVariable variable) {
if (isScriptField(variable)) {
final String name = variable.getName();
final GroovyScriptClass script = (GroovyScriptClass) ((GroovyFile) variable.getContainingFile()).getScriptClass();
assert script != null;
List<GrField> duplicates = ContainerUtil.filter(script.getFields(), (GrField f) -> {
if (!(f instanceof GrScriptField))
return false;
if (!name.equals(f.getName()))
return false;
if (((GrScriptField) f).getOriginalVariable() == variable)
return false;
return true;
});
return duplicates.size() > 0 ? duplicates.get(0) : null;
} else {
PsiNamedElement duplicate = resolveExistingElement(variable, new DuplicateVariablesProcessor(variable), GrVariable.class);
final PsiElement context1 = variable.getContext();
if (duplicate == null && variable instanceof GrParameter && context1 != null) {
final PsiElement context = context1.getContext();
if (context instanceof GrClosableBlock || context instanceof GrMethod && !(context.getParent() instanceof GroovyFile) || context instanceof GrTryCatchStatement) {
duplicate = resolveExistingElement(context.getParent(), new DuplicateVariablesProcessor(variable), GrVariable.class);
}
}
if (duplicate instanceof GrLightParameter && "args".equals(duplicate.getName())) {
return null;
} else {
return duplicate;
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock 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;
}
Aggregations