use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class CompleteReferencesWithSameQualifier method addVariantsWithSameQualifier.
private void addVariantsWithSameQualifier(@NotNull PsiElement element, @NotNull Set<String> result) {
if (element instanceof GrReferenceExpression && element != myRefExpr && !PsiUtil.isLValue((GroovyPsiElement) element)) {
final GrReferenceExpression refExpr = (GrReferenceExpression) element;
final String refName = refExpr.getReferenceName();
if (refName != null && !result.contains(refName) && myMatcher.prefixMatches(refName)) {
final GrExpression hisQualifier = refExpr.getQualifierExpression();
if (hisQualifier != null && myQualifier != null) {
if (PsiEquivalenceUtil.areElementsEquivalent(hisQualifier, myQualifier)) {
if (refExpr.resolve() == null) {
result.add(refName);
}
}
} else if (hisQualifier == null && myQualifier == null) {
if (refExpr.resolve() == null) {
result.add(refName);
}
}
}
}
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
addVariantsWithSameQualifier(child, result);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class ReachingDefinitionsCollector method filterNonlocals.
private static VariableInfo[] filterNonlocals(Map<String, VariableInfo> infos, GrStatement place) {
List<VariableInfo> result = new ArrayList<>();
for (Iterator<VariableInfo> iterator = infos.values().iterator(); iterator.hasNext(); ) {
VariableInfo info = iterator.next();
String name = info.getName();
GroovyPsiElement property = ResolveUtil.resolveProperty(place, name);
if (property instanceof GrVariable) {
iterator.remove();
} else if (property instanceof GrReferenceExpression) {
GrMember member = PsiTreeUtil.getParentOfType(property, GrMember.class);
if (member == null) {
continue;
} else if (!member.hasModifierProperty(PsiModifier.STATIC)) {
if (member.getContainingClass() instanceof GroovyScriptClass) {
//binding variable
continue;
}
}
}
if (ResolveUtil.resolveClass(place, name) == null) {
result.add(info);
}
}
return result.toArray(new VariableInfo[result.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class ApplicationStatementUtil method convertAppInternal.
private static GrMethodCallExpression convertAppInternal(GroovyPsiElementFactory factory, GrApplicationStatement app) {
final GrCommandArgumentList list = app.getArgumentList();
final GrMethodCallExpression prototype = (GrMethodCallExpression) factory.createExpressionFromText("foo()");
prototype.getInvokedExpression().replace(app.getInvokedExpression());
final GrArgumentList pList = prototype.getArgumentList();
final PsiElement anchor = pList.getRightParen();
for (GroovyPsiElement arg : list.getAllArguments()) {
pList.addBefore(arg, anchor);
}
return prototype;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class ControlFlowBuilder method collectCorrespondingPendingEdges.
@NotNull
private List<Pair<InstructionImpl, GroovyPsiElement>> collectCorrespondingPendingEdges(@Nullable PsiElement currentScope) {
if (currentScope == null) {
List<Pair<InstructionImpl, GroovyPsiElement>> result = myPending;
myPending = ContainerUtil.newArrayList();
return result;
} else {
ArrayList<Pair<InstructionImpl, GroovyPsiElement>> targets = ContainerUtil.newArrayList();
for (int i = myPending.size() - 1; i >= 0; i--) {
final Pair<InstructionImpl, GroovyPsiElement> pair = myPending.get(i);
final PsiElement scopeWhenToAdd = pair.getSecond();
if (scopeWhenToAdd == null)
continue;
if (!PsiTreeUtil.isAncestor(scopeWhenToAdd, currentScope, false)) {
targets.add(pair);
myPending.remove(i);
} else {
break;
}
}
return targets;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class ControlFlowBuilder method collectAndRemoveAllPendingNegations.
private List<GotoInstruction> collectAndRemoveAllPendingNegations(GroovyPsiElement currentScope) {
List<GotoInstruction> negations = new ArrayList<>();
for (Iterator<Pair<InstructionImpl, GroovyPsiElement>> iterator = myPending.iterator(); iterator.hasNext(); ) {
Pair<InstructionImpl, GroovyPsiElement> pair = iterator.next();
InstructionImpl instruction = pair.first;
GroovyPsiElement scope = pair.second;
if (!PsiTreeUtil.isAncestor(scope, currentScope, true) && instruction instanceof GotoInstruction) {
negations.add((GotoInstruction) instruction);
iterator.remove();
}
}
return negations;
}
Aggregations