use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class GroovyConstructorUsagesSearcher method processConstructorUsages.
static void processConstructorUsages(final PsiMethod constructor, final SearchScope searchScope, final Processor<PsiReference> consumer, final SearchRequestCollector collector, final boolean includeOverloads) {
if (!constructor.isConstructor())
return;
final PsiClass clazz = constructor.getContainingClass();
if (clazz == null)
return;
SearchScope onlyGroovy = GroovyScopeUtil.restrictScopeToGroovyFiles(searchScope, GroovyScopeUtil.getEffectiveScope(constructor));
Set<PsiClass> processed = collector.getSearchSession().getUserData(LITERALLY_CONSTRUCTED_CLASSES);
if (processed == null) {
collector.getSearchSession().putUserData(LITERALLY_CONSTRUCTED_CLASSES, processed = ContainerUtil.newConcurrentSet());
}
if (!processed.add(clazz))
return;
if (clazz.isEnum() && clazz instanceof GroovyPsiElement) {
for (PsiField field : clazz.getFields()) {
if (field instanceof GrEnumConstant) {
final PsiReference ref = field.getReference();
if (ref != null && ref.isReferenceTo(constructor)) {
if (!consumer.process(ref))
return;
}
}
}
}
final LiteralConstructorSearcher literalProcessor = new LiteralConstructorSearcher(constructor, consumer, includeOverloads);
final Processor<GrNewExpression> newExpressionProcessor = grNewExpression -> {
final PsiMethod resolvedConstructor = grNewExpression.resolveMethod();
if (includeOverloads || constructor.getManager().areElementsEquivalent(resolvedConstructor, constructor)) {
return consumer.process(grNewExpression.getReferenceElement());
}
return true;
};
processGroovyClassUsages(clazz, searchScope, collector, newExpressionProcessor, literalProcessor);
//this()
if (clazz instanceof GrTypeDefinition) {
if (!processConstructors(constructor, consumer, clazz, true)) {
return;
}
}
//super()
DirectClassInheritorsSearch.search(clazz, onlyGroovy).forEach(new ReadActionProcessor<PsiClass>() {
@Override
public boolean processInReadAction(PsiClass inheritor) {
if (inheritor instanceof GrTypeDefinition) {
if (!processConstructors(constructor, consumer, inheritor, false))
return false;
}
return true;
}
});
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class GroovyFileImpl method processCachedDeclarations.
private static boolean processCachedDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, MostlySingularMultiMap<String, ResultWithContext> cache) {
for (PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
String name = ResolveUtil.getNameHint(each);
Processor<ResultWithContext> cacheProcessor = res -> each.execute(res.getElement(), state.put(ClassHint.RESOLVE_CONTEXT, res.getFileContext()));
boolean result = name != null ? cache.processForKey(name, cacheProcessor) : cache.processAllValues(cacheProcessor);
if (!result)
return false;
}
return true;
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class GroovyLanguageInjectionSupport method doInject.
private static boolean doInject(@NotNull String languageId, @NotNull PsiElement psiElement, @NotNull PsiLanguageInjectionHost host) {
final PsiElement target = getTopLevelInjectionTarget(psiElement);
final PsiElement parent = target.getParent();
final Project project = psiElement.getProject();
if (parent instanceof GrReturnStatement) {
final GrControlFlowOwner owner = ControlFlowUtils.findControlFlowOwner(parent);
if (owner instanceof GrOpenBlock && owner.getParent() instanceof GrMethod) {
return JavaLanguageInjectionSupport.doInjectInJavaMethod(project, (PsiMethod) owner.getParent(), -1, host, languageId);
}
} else if (parent instanceof GrMethod) {
return JavaLanguageInjectionSupport.doInjectInJavaMethod(project, (GrMethod) parent, -1, host, languageId);
} else if (parent instanceof GrAnnotationNameValuePair) {
final PsiReference ref = parent.getReference();
if (ref != null) {
final PsiElement resolved = ref.resolve();
if (resolved instanceof PsiMethod) {
return JavaLanguageInjectionSupport.doInjectInJavaMethod(project, (PsiMethod) resolved, -1, host, languageId);
}
}
} else if (parent instanceof GrArgumentList && parent.getParent() instanceof GrMethodCall) {
final PsiMethod method = ((GrMethodCall) parent.getParent()).resolveMethod();
if (method != null) {
final int index = GrInjectionUtil.findParameterIndex(target, ((GrMethodCall) parent.getParent()));
if (index >= 0) {
return JavaLanguageInjectionSupport.doInjectInJavaMethod(project, method, index, host, languageId);
}
}
} else if (parent instanceof GrAssignmentExpression) {
final GrExpression expr = ((GrAssignmentExpression) parent).getLValue();
if (expr instanceof GrReferenceExpression) {
final PsiElement element = ((GrReferenceExpression) expr).resolve();
if (element != null) {
return doInject(languageId, element, host);
}
}
} else {
if (parent instanceof PsiVariable) {
Processor<PsiLanguageInjectionHost> fixer = getAnnotationFixer(project, languageId);
if (JavaLanguageInjectionSupport.doAddLanguageAnnotation(project, (PsiModifierListOwner) parent, host, languageId, fixer))
return true;
} else if (target instanceof PsiVariable && !(target instanceof LightElement)) {
Processor<PsiLanguageInjectionHost> fixer = getAnnotationFixer(project, languageId);
if (JavaLanguageInjectionSupport.doAddLanguageAnnotation(project, (PsiModifierListOwner) target, host, languageId, fixer))
return true;
}
}
return false;
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class PatternEditorContextMembersProvider method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, @NotNull final PsiScopeProcessor scopeProcessor, @NotNull final PsiElement place, @NotNull final ResolveState state) {
final PsiFile file = place.getContainingFile().getOriginalFile();
final BaseInjection injection = file.getUserData(BaseInjection.INJECTION_KEY);
Processor<PsiElement> processor = element -> element.processDeclarations(scopeProcessor, state, null, place);
if (injection == null) {
processDevContext(file, processor);
} else {
processPatternContext(injection, file, processor);
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method isCheapEnoughToSearch.
@NotNull
@Override
public SearchCostResult isCheapEnoughToSearch(@NotNull String name, @NotNull final GlobalSearchScope scope, @Nullable final PsiFile fileToIgnoreOccurrencesIn, @Nullable final ProgressIndicator progress) {
final AtomicInteger count = new AtomicInteger();
final ProgressIndicator indicator = progress == null ? new EmptyProgressIndicator() : progress;
final Processor<VirtualFile> processor = new Processor<VirtualFile>() {
private final VirtualFile virtualFileToIgnoreOccurrencesIn = fileToIgnoreOccurrencesIn == null ? null : fileToIgnoreOccurrencesIn.getVirtualFile();
@Override
public boolean process(VirtualFile file) {
indicator.checkCanceled();
if (Comparing.equal(file, virtualFileToIgnoreOccurrencesIn))
return true;
final int value = count.incrementAndGet();
return value < 10;
}
};
List<IdIndexEntry> keys = getWordEntries(name, true);
boolean cheap = keys.isEmpty() || processFilesContainingAllKeys(myManager.getProject(), scope, null, keys, processor);
if (!cheap) {
return SearchCostResult.TOO_MANY_OCCURRENCES;
}
return count.get() == 0 ? SearchCostResult.ZERO_OCCURRENCES : SearchCostResult.FEW_OCCURRENCES;
}
Aggregations