use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class ConvertParameterToMapEntryIntention method collectOwnerOccurrences.
private static boolean collectOwnerOccurrences(final Project project, final GrParametersOwner owner, final Collection<PsiElement> occurrences) {
final PsiElement namedElem = getReferencedElement(owner);
if (namedElem == null)
return true;
final Ref<Boolean> result = new Ref<>(true);
final Task task = new Task.Modal(project, GroovyIntentionsBundle.message("find.method.ro.closure.usages.0", owner instanceof GrClosableBlock ? CLOSURE_CAPTION : METHOD_CAPTION), true) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
final Collection<PsiReference> references = Collections.synchronizedSet(new HashSet<PsiReference>());
final Processor<PsiReference> consumer = psiReference -> {
references.add(psiReference);
return true;
};
ReferencesSearch.search(namedElem).forEach(consumer);
boolean isProperty = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return namedElem instanceof GrField && ((GrField) namedElem).isProperty();
}
});
if (isProperty) {
final GrAccessorMethod[] getters = ApplicationManager.getApplication().runReadAction(new Computable<GrAccessorMethod[]>() {
@Override
public GrAccessorMethod[] compute() {
return ((GrField) namedElem).getGetters();
}
});
for (GrAccessorMethod getter : getters) {
MethodReferencesSearch.search(getter).forEach(consumer);
}
}
for (final PsiReference reference : references) {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiElement element = reference.getElement();
if (element != null) {
occurrences.add(element);
}
});
}
}
@Override
public void onCancel() {
result.set(false);
}
@Override
public void onThrowable(@NotNull Throwable error) {
super.onThrowable(error);
result.set(false);
}
@Override
public void onSuccess() {
result.set(true);
}
};
ProgressManager.getInstance().run(task);
return result.get().booleanValue();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GrAliasImportIntention method doRefactoring.
private static void doRefactoring(@NotNull Project project, @NotNull GrImportStatement importStatement, @NotNull PsiMember member) {
if (member instanceof GrAccessorMethod && !importStatement.isOnDemand() && !importStatement.getImportedName().equals(member.getName())) {
member = ((GrAccessorMethod) member).getProperty();
}
final GroovyFileBase file = (GroovyFileBase) importStatement.getContainingFile();
final List<UsageInfo> usages = findUsages(member, file);
GrImportStatement templateImport = createTemplateImport(project, importStatement, member, file);
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (!importStatement.isOnDemand()) {
importStatement.delete();
}
updateRefs(usages, member.getName(), templateImport);
} else {
runTemplate(project, importStatement, member, file, usages, templateImport);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GrClassImplUtil method doGetGetters.
@NotNull
private static GrAccessorMethod[] doGetGetters(GrField field) {
PsiClass containingClass = field.getContainingClass();
if (containingClass == null)
return GrAccessorMethod.EMPTY_ARRAY;
GrAccessorMethod getter = null;
GrAccessorMethod booleanGetter = null;
PsiMethod[] getters = containingClass.findMethodsByName(GroovyPropertyUtils.getGetterNameNonBoolean(field.getName()), false);
for (PsiMethod method : getters) {
if (method instanceof GrAccessorMethod) {
getter = (GrAccessorMethod) method;
break;
}
}
PsiMethod[] booleanGetters = containingClass.findMethodsByName(GroovyPropertyUtils.getGetterNameBoolean(field.getName()), false);
for (PsiMethod method : booleanGetters) {
if (method instanceof GrAccessorMethod) {
booleanGetter = (GrAccessorMethod) method;
break;
}
}
if (getter != null && booleanGetter != null) {
return new GrAccessorMethod[] { getter, booleanGetter };
} else if (getter != null) {
return new GrAccessorMethod[] { getter };
} else {
return GrAccessorMethod.EMPTY_ARRAY;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GroovyPropertyUtils method getFieldAccessors.
public static List<GrAccessorMethod> getFieldAccessors(GrField field) {
List<GrAccessorMethod> accessors = new ArrayList<>();
final GrAccessorMethod[] getters = field.getGetters();
Collections.addAll(accessors, getters);
final GrAccessorMethod setter = field.getSetter();
if (setter != null)
accessors.add(setter);
return accessors;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GrMainCompletionProvider method completeStaticMembers.
static StaticMemberProcessor completeStaticMembers(CompletionParameters parameters) {
final PsiElement position = parameters.getPosition();
final PsiElement originalPosition = parameters.getOriginalPosition();
final StaticMemberProcessor processor = new StaticMemberProcessor(position) {
@NotNull
@Override
protected LookupElement createLookupElement(@NotNull PsiMember member, @NotNull PsiClass containingClass, boolean shouldImport) {
shouldImport |= originalPosition != null && PsiTreeUtil.isAncestor(containingClass, originalPosition, false);
return createGlobalMemberElement(member, containingClass, shouldImport);
}
@Override
protected LookupElement createLookupElement(@NotNull List<PsiMethod> overloads, @NotNull PsiClass containingClass, boolean shouldImport) {
shouldImport |= originalPosition != null && PsiTreeUtil.isAncestor(containingClass, originalPosition, false);
return new JavaGlobalMemberLookupElement(overloads, containingClass, QualifiedMethodInsertHandler.INSTANCE, StaticImportInsertHandler.INSTANCE, shouldImport);
}
@Override
protected boolean isAccessible(PsiMember member) {
boolean result = super.isAccessible(member);
if (!result && member instanceof GrField) {
GrAccessorMethod[] getters = ((GrField) member).getGetters();
return getters.length > 0 && super.isAccessible(getters[0]);
}
return result;
}
};
final PsiFile file = position.getContainingFile();
if (file instanceof GroovyFile) {
for (GrImportStatement statement : ((GroovyFile) file).getImportStatements()) {
if (statement.isStatic()) {
GrCodeReferenceElement importReference = statement.getImportReference();
if (importReference != null) {
if (!statement.isOnDemand()) {
importReference = importReference.getQualifier();
}
if (importReference != null) {
final PsiElement target = importReference.resolve();
if (target instanceof PsiClass) {
processor.importMembersOf((PsiClass) target);
}
}
}
}
}
}
return processor;
}
Aggregations