use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class VcsLogJoiner method getRedCommitsAndSavedRedIndex.
@NotNull
private Pair<Integer, Set<CommitId>> getRedCommitsAndSavedRedIndex(@NotNull List<? extends Commit> savedLog, @NotNull Collection<CommitId> previousRefs, @NotNull List<? extends Commit> firstBlock, @NotNull Collection<CommitId> newRefs) {
Set<CommitId> startRedCommits = new THashSet<>(previousRefs);
startRedCommits.removeAll(newRefs);
Set<CommitId> startGreenNodes = new THashSet<>(newRefs);
for (Commit commit : firstBlock) {
startGreenNodes.add(commit.getId());
startGreenNodes.addAll(commit.getParents());
}
RedGreenSorter<CommitId, Commit> sorter = new RedGreenSorter<>(startRedCommits, startGreenNodes, savedLog);
int saveRegIndex = sorter.getFirstSaveIndex();
return new Pair<>(saveRegIndex, sorter.getAllRedCommit());
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class GenerateVisitorByHierarchyAction method generateVisitorClass.
private static void generateVisitorClass(final String visitorName, final PsiClass baseClass, final PsiDirectory directory, final GlobalSearchScope scope) {
final THashMap<PsiClass, Set<PsiClass>> classes = new THashMap<>();
for (PsiClass aClass : ClassInheritorsSearch.search(baseClass, scope, true).findAll()) {
if (aClass.hasModifierProperty(PsiModifier.ABSTRACT) == baseClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
final List<PsiClass> implementors = ContainerUtil.findAll(ClassInheritorsSearch.search(aClass).findAll(), psiClass -> !psiClass.hasModifierProperty(PsiModifier.ABSTRACT));
classes.put(aClass, new THashSet<>(implementors));
}
}
final THashMap<PsiClass, Set<PsiClass>> pathMap = new THashMap<>();
for (PsiClass aClass : classes.keySet()) {
final Set<PsiClass> superClasses = new LinkedHashSet<>();
for (PsiClass superClass : aClass.getSupers()) {
if (superClass.isInheritor(baseClass, true)) {
superClasses.add(superClass);
final Set<PsiClass> superImplementors = classes.get(superClass);
if (superImplementors != null) {
superImplementors.removeAll(classes.get(aClass));
}
}
}
if (superClasses.isEmpty()) {
superClasses.add(baseClass);
}
pathMap.put(aClass, superClasses);
}
pathMap.put(baseClass, Collections.<PsiClass>emptySet());
final ArrayList<PsiFile> psiFiles = new ArrayList<>();
for (Set<PsiClass> implementors : classes.values()) {
for (PsiClass psiClass : implementors) {
psiFiles.add(psiClass.getContainingFile());
}
}
final Project project = baseClass.getProject();
final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorName, GlobalSearchScope.projectScope(project));
if (visitorClass != null) {
psiFiles.add(visitorClass.getContainingFile());
}
final int finalDetectedPrefix = detectClassPrefix(classes.keySet()).length();
new WriteCommandAction(project, PsiUtilCore.toPsiFileArray(psiFiles)) {
protected void run(@NotNull final Result result) throws Throwable {
if (visitorClass == null) {
final String shortClassName = PsiNameHelper.getShortClassName(visitorName);
if (directory != null) {
final PsiClass visitorClass = JavaDirectoryService.getInstance().createClass(directory, shortClassName);
generateVisitorClass(visitorClass, classes, pathMap, finalDetectedPrefix);
}
} else {
generateVisitorClass(visitorClass, classes, pathMap, finalDetectedPrefix);
}
}
@Override
protected boolean isGlobalUndoAction() {
return true;
}
}.execute();
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class DefaultSymbolNavigationContributor method processElementsWithName.
@Override
public void processElementsWithName(@NotNull String name, @NotNull final Processor<NavigationItem> processor, @NotNull final FindSymbolParameters parameters) {
GlobalSearchScope scope = parameters.getSearchScope();
IdFilter filter = parameters.getIdFilter();
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(scope.getProject());
String completePattern = parameters.getCompletePattern();
final Condition<PsiMember> qualifiedMatcher = getQualifiedNameMatcher(completePattern);
//noinspection UnusedDeclaration
final Set<PsiMethod> collectedMethods = new THashSet<>();
boolean success = cache.processFieldsWithName(name, field -> {
if (isOpenable(field) && qualifiedMatcher.value(field))
return processor.process(field);
return true;
}, scope, filter) && cache.processClassesWithName(name, aClass -> {
if (isOpenable(aClass) && qualifiedMatcher.value(aClass))
return processor.process(aClass);
return true;
}, scope, filter) && cache.processMethodsWithName(name, method -> {
if (!method.isConstructor() && isOpenable(method) && qualifiedMatcher.value(method)) {
collectedMethods.add(method);
}
return true;
}, scope, filter);
if (success) {
// hashSuperMethod accesses index and can not be invoked without risk of the deadlock in processMethodsWithName
Iterator<PsiMethod> iterator = collectedMethods.iterator();
while (iterator.hasNext()) {
PsiMethod method = iterator.next();
if (!hasSuperMethod(method, scope, qualifiedMatcher) && !processor.process(method))
return;
ProgressManager.checkCanceled();
iterator.remove();
}
}
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class PsiClassImplUtil method processDeclarationsInClassNotCached.
private static boolean processDeclarationsInClassNotCached(@NotNull PsiClass aClass, @NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, @Nullable Set<PsiClass> visited, final PsiElement last, @NotNull final PsiElement place, final boolean isRaw, @NotNull final LanguageLevel languageLevel, @NotNull final GlobalSearchScope resolveScope) {
if (visited == null)
visited = new THashSet<>();
if (!visited.add(aClass))
return true;
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, aClass);
final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
final NameHint nameHint = processor.getHint(NameHint.KEY);
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.FIELD)) {
if (nameHint != null) {
final PsiField fieldByName = aClass.findFieldByName(nameHint.getName(state), false);
if (fieldByName != null && !processor.execute(fieldByName, state))
return false;
} else {
final PsiField[] fields = aClass.getFields();
for (final PsiField field : fields) {
if (!processor.execute(field, state))
return false;
}
}
}
PsiElementFactory factory = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory();
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.METHOD)) {
PsiSubstitutor baseSubstitutor = state.get(PsiSubstitutor.KEY);
final PsiMethod[] methods = nameHint != null ? aClass.findMethodsByName(nameHint.getName(state), false) : aClass.getMethods();
for (final PsiMethod method : methods) {
PsiSubstitutor finalSubstitutor = checkRaw(isRaw, factory, method, baseSubstitutor);
ResolveState methodState = finalSubstitutor == baseSubstitutor ? state : state.put(PsiSubstitutor.KEY, finalSubstitutor);
if (!processor.execute(method, methodState))
return false;
}
}
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
if (last != null && last.getContext() == aClass) {
// Parameters
final PsiTypeParameterList list = aClass.getTypeParameterList();
if (list != null && !list.processDeclarations(processor, ResolveState.initial(), last, place))
return false;
}
if (!(last instanceof PsiReferenceList) && !(last instanceof PsiModifierList)) {
// Inners
if (nameHint != null) {
final PsiClass inner = aClass.findInnerClassByName(nameHint.getName(state), false);
if (inner != null) {
if (!processor.execute(inner, state))
return false;
}
} else {
final PsiClass[] inners = aClass.getInnerClasses();
for (final PsiClass inner : inners) {
if (!processor.execute(inner, state))
return false;
}
}
}
}
if (last instanceof PsiReferenceList)
return true;
final Set<PsiClass> visited1 = visited;
return processSuperTypes(aClass, state.get(PsiSubstitutor.KEY), factory, languageLevel, resolveScope, (superClass, finalSubstitutor) -> processDeclarationsInClass(superClass, processor, state.put(PsiSubstitutor.KEY, finalSubstitutor), visited1, last, place, languageLevel, isRaw, resolveScope));
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class JavaLanguageInjectionSupport method createFrom.
private static MethodParameterInjection createFrom(final Project project, final BaseInjection injection, final PsiMethod contextMethod, final boolean includeAllPlaces) {
final PsiClass[] classes;
final String className;
if (contextMethod != null) {
final PsiClass psiClass = contextMethod.getContainingClass();
className = psiClass == null ? "" : StringUtil.notNullize(psiClass.getQualifiedName());
classes = psiClass == null ? PsiClass.EMPTY_ARRAY : new PsiClass[] { psiClass };
} else {
String found = null;
final Pattern pattern = Pattern.compile(".*definedInClass\\(\"([^\"]*)\"\\)+");
for (InjectionPlace place : injection.getInjectionPlaces()) {
final Matcher matcher = pattern.matcher(place.getText());
if (matcher.matches()) {
found = matcher.group(1);
}
}
if (found == null) {
// hack to guess at least the class name
final Matcher matcher = ourPresentationPattern.matcher(injection.getDisplayName());
if (matcher.matches()) {
final String pkg = matcher.group(2);
found = pkg.substring(1, pkg.length() - 1) + "." + matcher.group(1);
}
}
classes = found != null && project.isInitialized() ? JavaPsiFacade.getInstance(project).findClasses(found, GlobalSearchScope.allScope(project)) : PsiClass.EMPTY_ARRAY;
className = StringUtil.notNullize(classes.length == 0 ? found : classes[0].getQualifiedName());
}
final MethodParameterInjection result = new MethodParameterInjection();
result.copyFrom(injection);
result.setInjectionPlaces(InjectionPlace.EMPTY_ARRAY);
result.setClassName(className);
final ArrayList<MethodInfo> infos = new ArrayList<>();
if (classes.length > 0) {
final THashSet<String> visitedSignatures = new THashSet<>();
final PatternCompiler<PsiElement> compiler = injection.getCompiler();
for (PsiClass psiClass : classes) {
for (PsiMethod method : psiClass.getMethods()) {
final PsiModifierList modifiers = method.getModifierList();
if (modifiers.hasModifierProperty(PsiModifier.PRIVATE) || modifiers.hasModifierProperty(PsiModifier.PACKAGE_LOCAL))
continue;
boolean add = false;
final MethodInfo methodInfo = createMethodInfo(method);
if (!visitedSignatures.add(methodInfo.getMethodSignature()))
continue;
if (isInjectable(method.getReturnType(), method.getProject())) {
final int parameterIndex = -1;
int index = ArrayUtilRt.find(injection.getInjectionPlaces(), new InjectionPlace(compiler.compileElementPattern(getPatternStringForJavaPlace(method, parameterIndex)), true));
final InjectionPlace place = index > -1 ? injection.getInjectionPlaces()[index] : null;
methodInfo.setReturnFlag(place != null && place.isEnabled() || includeAllPlaces);
add = true;
}
final PsiParameter[] parameters = method.getParameterList().getParameters();
for (int i = 0; i < parameters.length; i++) {
final PsiParameter p = parameters[i];
if (isInjectable(p.getType(), p.getProject())) {
int index = ArrayUtilRt.find(injection.getInjectionPlaces(), new InjectionPlace(compiler.compileElementPattern(getPatternStringForJavaPlace(method, i)), true));
final InjectionPlace place = index > -1 ? injection.getInjectionPlaces()[index] : null;
methodInfo.getParamFlags()[i] = place != null && place.isEnabled() || includeAllPlaces;
add = true;
}
}
if (add) {
infos.add(methodInfo);
}
}
}
}
// else {
// todo tbd
//for (InjectionPlace place : injection.getInjectionPlaces()) {
// final Matcher matcher = pattern.matcher(place.getText());
// if (matcher.matches()) {
//
// }
//}
// }
result.setMethodInfos(infos);
result.generatePlaces();
return result;
}
Aggregations