use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method detectAccessibilityConflicts.
public static void detectAccessibilityConflicts(@Nullable GroovyPsiElement elementToProcess, final UsageInfo[] usages, MultiMap<PsiElement, String> conflicts, boolean replaceFieldsWithGetters, Project project) {
if (elementToProcess == null)
return;
final ReferencedElementsCollector collector = new ReferencedElementsCollector();
elementToProcess.accept(collector);
final List<PsiElement> result = collector.getResult();
if (result.isEmpty())
return;
for (final UsageInfo usageInfo : usages) {
if (!(usageInfo instanceof ExternalUsageInfo) || !IntroduceParameterUtil.isMethodUsage(usageInfo))
continue;
final PsiElement place = usageInfo.getElement();
for (PsiElement element : result) {
if (element instanceof PsiField && replaceFieldsWithGetters) {
//check getter access instead
final PsiClass psiClass = ((PsiField) element).getContainingClass();
LOG.assertTrue(psiClass != null);
final PsiMethod method = GroovyPropertyUtils.findGetterForField((PsiField) element);
if (method != null) {
element = method;
}
}
if (element instanceof PsiMember && !JavaPsiFacade.getInstance(project).getResolveHelper().isAccessible((PsiMember) element, place, null)) {
String message = RefactoringBundle.message("0.is.not.accessible.from.1.value.for.introduced.parameter.in.that.method.call.will.be.incorrect", RefactoringUIUtil.getDescription(element, true), RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(place), true));
conflicts.putValue(element, message);
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class GrUnresolvableLocalCollisionDetector method visitUpstreamCollisions.
private static void visitUpstreamCollisions(PsiElement element, String newName, GroovyPsiElement place, CollidingVariableVisitor visitor) {
final GrReferenceExpression refExpr = GroovyPsiElementFactory.getInstance(place.getProject()).createReferenceExpressionFromText(newName, place);
final GroovyResolveResult[] results = refExpr.multiResolve(false);
for (GroovyResolveResult result : results) {
final PsiElement resolved = result.getElement();
if (resolved instanceof GrParameter || (resolved instanceof GrVariable && !(resolved instanceof GrField))) {
final PsiElement parent = PsiTreeUtil.findCommonParent(resolved, element);
if (parent != null) {
PsiElement current = element;
while (current != null && current != parent) {
if (current instanceof PsiMethod || current instanceof PsiClass || current instanceof GrClosableBlock) {
return;
}
current = current.getParent();
}
}
if (!place.getManager().areElementsEquivalent(element, resolved)) {
visitor.visitCollidingVariable((PsiVariable) resolved);
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class ArgumentListGenerator method generateMultiArg.
private boolean generateMultiArg(GrClosureSignatureUtil.ArgInfo<PsiElement> arg, GrClosureParameter param, PsiSubstitutor substitutor, Project project, GroovyPsiElement context) {
final PsiType type = param.getType();
if (type instanceof PsiEllipsisType) {
for (PsiElement element : arg.args) {
LOG.assertTrue(element instanceof GrExpression);
((GrExpression) element).accept(myExpressionGenerator);
myBuilder.append(", ");
}
if (!arg.args.isEmpty()) {
myBuilder.delete(myBuilder.length() - 2, myBuilder.length());
return true;
} else {
return false;
}
} else if (type instanceof PsiArrayType) {
myBuilder.append("new ");
if (arg.args.isEmpty()) {
TypeWriter.writeType(myBuilder, ((PsiArrayType) type).getComponentType(), context);
myBuilder.append("[0]");
} else {
TypeWriter.writeTypeForNew(myBuilder, type, context);
myBuilder.append("{");
for (PsiElement element : arg.args) {
LOG.assertTrue(element instanceof GrExpression);
((GrExpression) element).accept(myExpressionGenerator);
myBuilder.append(", ");
}
if (!arg.args.isEmpty())
myBuilder.delete(myBuilder.length() - 2, myBuilder.length());
//if (arg.args.size() > 0) myBuilder.removeFromTheEnd(2);
myBuilder.append('}');
}
} else {
final GrExpression listOrMap = GroovyRefactoringUtil.generateArgFromMultiArg(substitutor, arg.args, type, project);
LOG.assertTrue(listOrMap instanceof GrListOrMap);
listOrMap.accept(myExpressionGenerator);
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.
the class GroovyVariableCanBeFinalInspection method checkVariableAssignedInsideClosureOrAnonymous.
private static boolean checkVariableAssignedInsideClosureOrAnonymous(@NotNull GrControlFlowOwner owner, @NotNull GrVariable variable) {
final Collection<PsiReference> references = ReferencesSearch.search(variable, variable.getUseScope()).findAll();
for (final PsiReference reference : references) {
final PsiElement element = reference.getElement();
if (!(element instanceof GroovyPsiElement))
continue;
final GroovyPsiElement groovyElement = (GroovyPsiElement) element;
final GroovyPsiElement closure = PsiTreeUtil.getParentOfType(groovyElement, GrClosableBlock.class, GrAnonymousClassDefinition.class);
if (closure == null || !PsiTreeUtil.isAncestor(owner, closure, false))
continue;
if (PsiUtil.isLValue(groovyElement))
return true;
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement 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