use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class AccessorReferencesSearcher method processQuery.
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
final PsiElement element = queryParameters.getElementToSearch();
if (element instanceof PsiMethod) {
final String propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod) element);
if (propertyName == null)
return;
SearchScope scope = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope());
queryParameters.getOptimizer().searchWord(propertyName, scope, UsageSearchContext.IN_CODE, true, element);
} else if (element instanceof GrField) {
for (GrAccessorMethod method : ((GrField) element).getGetters()) {
MethodReferencesSearch.search(method, queryParameters.getEffectiveSearchScope(), true).forEach(consumer);
}
final GrAccessorMethod setter = ((GrField) element).getSetter();
if (setter != null) {
MethodReferencesSearch.search(setter, queryParameters.getEffectiveSearchScope(), true).forEach(consumer);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class AnnotatedMembersSearcher method execute.
@Override
public boolean execute(@NotNull final AnnotatedElementsSearch.Parameters p, @NotNull final Processor<PsiModifierListOwner> consumer) {
final PsiClass annClass = p.getAnnotationClass();
assert annClass.isAnnotationType() : "Annotation type should be passed to annotated members search";
final String annotationFQN = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return annClass.getQualifiedName();
}
});
assert annotationFQN != null;
final SearchScope scope = p.getScope();
final List<PsiModifierListOwner> candidates;
if (scope instanceof GlobalSearchScope) {
candidates = getAnnotatedMemberCandidates(annClass, ((GlobalSearchScope) scope));
} else {
candidates = new ArrayList<>();
for (final PsiElement element : ((LocalSearchScope) scope).getScope()) {
ApplicationManager.getApplication().runReadAction(() -> {
if (element instanceof GroovyPsiElement) {
((GroovyPsiElement) element).accept(new GroovyRecursiveElementVisitor() {
@Override
public void visitMethod(@NotNull GrMethod method) {
candidates.add(method);
}
@Override
public void visitField(@NotNull GrField field) {
candidates.add(field);
}
});
}
});
}
}
for (final PsiModifierListOwner candidate : candidates) {
boolean accepted = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
if (AnnotatedElementsSearcher.isInstanceof(candidate, p.getTypes())) {
PsiModifierList list = candidate.getModifierList();
if (list != null) {
for (PsiAnnotation annotation : list.getAnnotations()) {
if ((p.isApproximate() || annotationFQN.equals(annotation.getQualifiedName())) && !consumer.process(candidate)) {
return false;
}
}
}
}
return true;
}
});
if (!accepted)
return false;
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitor method checkIndexProperty.
private void checkIndexProperty(@NotNull CallInfo<? extends GrIndexProperty> info) {
if (hasErrorElements(info.getArgumentList()))
return;
if (!checkCannotInferArgumentTypes(info))
return;
final PsiType type = info.getQualifierInstanceType();
if (ResolveUtil.getClassReferenceFromExpression(info.getCall()) != null) {
return;
}
final PsiType[] types = info.getArgumentTypes();
if (checkSimpleArrayAccess(info, type, types))
return;
final GroovyResolveResult[] results = info.multiResolve();
final GroovyResolveResult resolveResult = info.advancedResolve();
if (resolveResult.getElement() != null) {
PsiElement resolved = resolveResult.getElement();
if (resolved instanceof PsiMethod && !resolveResult.isInvokedOnProperty()) {
checkMethodApplicability(resolveResult, true, info);
} else if (resolved instanceof GrField) {
checkCallApplicability(((GrField) resolved).getTypeGroovy(), true, info);
} else if (resolved instanceof PsiField) {
checkCallApplicability(((PsiField) resolved).getType(), true, info);
}
} else if (results.length > 0) {
for (GroovyResolveResult result : results) {
PsiElement resolved = result.getElement();
if (resolved instanceof PsiMethod && !result.isInvokedOnProperty()) {
if (!checkMethodApplicability(result, false, info))
return;
} else if (resolved instanceof GrField) {
if (!checkCallApplicability(((GrField) resolved).getTypeGroovy(), false, info))
return;
} else if (resolved instanceof PsiField) {
if (!checkCallApplicability(((PsiField) resolved).getType(), false, info))
return;
}
}
registerError(info.getElementToHighlight(), ProblemHighlightType.GENERIC_ERROR, GroovyBundle.message("method.call.is.ambiguous"));
} else {
final String typesString = buildArgTypesList(types);
registerError(info.getElementToHighlight(), ProblemHighlightType.GENERIC_ERROR, GroovyBundle.message("cannot.find.operator.overload.method", typesString));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class GebPageMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
if (!ResolveUtil.shouldProcessProperties(processor.getHint(ElementClassHint.KEY)))
return;
PsiElement grCall = place.getParent();
if (grCall instanceof GrMethodCall) {
PsiElement grClosure = grCall.getParent();
if (grClosure instanceof GrClosableBlock) {
PsiElement contentField = grClosure.getParent();
if (contentField instanceof GrField) {
GrField f = (GrField) contentField;
if ("content".equals(f.getName()) && f.hasModifierProperty(PsiModifier.STATIC) && f.getContainingClass() == aClass) {
Map<String, PsiField> elements = GebUtil.getContentElements(aClass);
for (PsiField field : elements.values()) {
if (field.getNavigationElement() == place) {
// Don't resolve variable definition.
return;
}
}
}
}
}
}
processPageFields(processor, aClass, state);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField in project intellij-community by JetBrains.
the class ReachingDefinitionsCollector method addClosureUsages.
private static void addClosureUsages(final Map<String, VariableInfo> imap, final Map<String, VariableInfo> omap, final GrStatement first, final GrStatement last, GrControlFlowOwner flowOwner) {
flowOwner.accept(new GroovyRecursiveElementVisitor() {
@Override
public void visitClosure(@NotNull GrClosableBlock closure) {
addUsagesInClosure(imap, omap, closure, first, last);
super.visitClosure(closure);
}
private void addUsagesInClosure(final Map<String, VariableInfo> imap, final Map<String, VariableInfo> omap, final GrClosableBlock closure, final GrStatement first, final GrStatement last) {
closure.accept(new GroovyRecursiveElementVisitor() {
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression refExpr) {
if (refExpr.isQualified()) {
return;
}
PsiElement resolved = refExpr.resolve();
if (!(resolved instanceof GrVariable)) {
return;
}
GrVariable variable = (GrVariable) resolved;
if (PsiTreeUtil.isAncestor(closure, variable, true)) {
return;
}
if (variable instanceof ClosureSyntheticParameter && PsiTreeUtil.isAncestor(closure, ((ClosureSyntheticParameter) variable).getClosure(), false)) {
return;
}
String name = variable.getName();
if (!(variable instanceof GrField)) {
if (!isInFragment(first, last, resolved)) {
if (isInFragment(first, last, closure)) {
addVariable(name, imap, variable.getManager(), variable.getType());
}
} else {
if (!isInFragment(first, last, closure)) {
addVariable(name, omap, variable.getManager(), variable.getType());
}
}
}
}
});
}
});
}
Aggregations