use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class EncapsulateFieldsProcessor method processUsagesPerFile.
private void processUsagesPerFile(UsageInfo[] usages) {
Map<PsiFile, List<EncapsulateFieldUsageInfo>> usagesInFiles = new HashMap<>();
for (UsageInfo usage : usages) {
PsiElement element = usage.getElement();
if (element == null)
continue;
final PsiFile file = element.getContainingFile();
List<EncapsulateFieldUsageInfo> usagesInFile = usagesInFiles.get(file);
if (usagesInFile == null) {
usagesInFile = new ArrayList<>();
usagesInFiles.put(file, usagesInFile);
}
usagesInFile.add(((EncapsulateFieldUsageInfo) usage));
}
for (List<EncapsulateFieldUsageInfo> usageInfos : usagesInFiles.values()) {
//this is to avoid elements to become invalid as a result of processUsage
final EncapsulateFieldUsageInfo[] infos = usageInfos.toArray(new EncapsulateFieldUsageInfo[usageInfos.size()]);
CommonRefactoringUtil.sortDepthFirstRightLeftOrder(infos);
for (EncapsulateFieldUsageInfo info : infos) {
final PsiElement element = info.getElement();
if (element == null)
continue;
EncapsulateFieldHelper helper = EncapsulateFieldHelper.getHelper(element.getLanguage());
helper.processUsage(info, myDescriptor, myNameToSetter.get(info.getFieldDescriptor().getSetterName()), myNameToGetter.get(info.getFieldDescriptor().getGetterName()));
}
}
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class JavaDirectInheritorsSearcher method calculateDirectSubClasses.
@NotNull
private static PsiClass[] calculateDirectSubClasses(@NotNull Project project, @NotNull PsiClass baseClass, @NotNull String baseClassName, @NotNull SearchScope useScope) {
DumbService dumbService = DumbService.getInstance(project);
GlobalSearchScope globalUseScope = dumbService.runReadActionInSmartMode(() -> StubHierarchyInheritorSearcher.restrictScope(GlobalSearchScopeUtil.toGlobalSearchScope(useScope, project)));
Collection<PsiReferenceList> candidates = dumbService.runReadActionInSmartMode(() -> JavaSuperClassNameOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
// memory/speed optimisation: it really is a map(string -> PsiClass or List<PsiClass>)
final Map<String, Object> classesWithFqn = new HashMap<>();
processConcurrentlyIfTooMany(candidates, referenceList -> {
ProgressManager.checkCanceled();
ApplicationManager.getApplication().runReadAction(() -> {
final PsiClass candidate = (PsiClass) referenceList.getParent();
boolean isInheritor = candidate.isInheritor(baseClass, false);
if (isInheritor) {
String fqn = candidate.getQualifiedName();
synchronized (classesWithFqn) {
Object value = classesWithFqn.get(fqn);
if (value == null) {
classesWithFqn.put(fqn, candidate);
} else if (value instanceof PsiClass) {
List<PsiClass> list = new ArrayList<>();
list.add((PsiClass) value);
list.add(candidate);
classesWithFqn.put(fqn, list);
} else {
@SuppressWarnings("unchecked") List<PsiClass> list = (List<PsiClass>) value;
list.add(candidate);
}
}
}
});
return true;
});
final List<PsiClass> result = new ArrayList<>();
for (Object value : classesWithFqn.values()) {
if (value instanceof PsiClass) {
result.add((PsiClass) value);
} else {
@SuppressWarnings("unchecked") List<PsiClass> list = (List<PsiClass>) value;
result.addAll(list);
}
}
Collection<PsiAnonymousClass> anonymousCandidates = dumbService.runReadActionInSmartMode(() -> JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
processConcurrentlyIfTooMany(anonymousCandidates, candidate -> {
boolean isInheritor = dumbService.runReadActionInSmartMode(() -> candidate.isInheritor(baseClass, false));
if (isInheritor) {
synchronized (result) {
result.add(candidate);
}
}
return true;
});
boolean isEnum = ReadAction.compute(baseClass::isEnum);
if (isEnum) {
// abstract enum can be subclassed in the body
PsiField[] fields = ReadAction.compute(baseClass::getFields);
for (final PsiField field : fields) {
ProgressManager.checkCanceled();
if (field instanceof PsiEnumConstant) {
PsiEnumConstantInitializer initializingClass = ReadAction.compute(((PsiEnumConstant) field)::getInitializingClass);
if (initializingClass != null) {
// it surely is an inheritor
result.add(initializingClass);
}
}
}
}
return result.isEmpty() ? PsiClass.EMPTY_ARRAY : result.toArray(new PsiClass[result.size()]);
}
use of com.intellij.util.containers.HashMap in project kotlin by JetBrains.
the class AndroidLintGlobalInspectionContext method performPreRunActivities.
@Override
public void performPreRunActivities(@NotNull List<Tools> globalTools, @NotNull List<Tools> localTools, @NotNull final GlobalInspectionContext context) {
final Project project = context.getProject();
if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID)) {
return;
}
final List<Issue> issues = AndroidLintExternalAnnotator.getIssuesFromInspections(project, null);
if (issues.size() == 0) {
return;
}
final Map<Issue, Map<File, List<ProblemData>>> problemMap = new HashMap<Issue, Map<File, List<ProblemData>>>();
final AnalysisScope scope = context.getRefManager().getScope();
if (scope == null) {
return;
}
final IntellijLintClient client = IntellijLintClient.forBatch(project, problemMap, scope, issues);
final LintDriver lint = new LintDriver(new IntellijLintIssueRegistry(), client);
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
ProgressWrapper.unwrap(indicator).setText("Running Android Lint");
}
EnumSet<Scope> lintScope;
//noinspection ConstantConditions
if (!IntellijLintProject.SUPPORT_CLASS_FILES) {
lintScope = EnumSet.copyOf(Scope.ALL);
// Can't run class file based checks
lintScope.remove(Scope.CLASS_FILE);
lintScope.remove(Scope.ALL_CLASS_FILES);
lintScope.remove(Scope.JAVA_LIBRARIES);
} else {
lintScope = Scope.ALL;
}
List<VirtualFile> files = null;
final List<Module> modules = Lists.newArrayList();
int scopeType = scope.getScopeType();
switch(scopeType) {
case AnalysisScope.MODULE:
{
SearchScope searchScope = scope.toSearchScope();
if (searchScope instanceof ModuleWithDependenciesScope) {
ModuleWithDependenciesScope s = (ModuleWithDependenciesScope) searchScope;
if (!s.isSearchInLibraries()) {
modules.add(s.getModule());
}
}
break;
}
case AnalysisScope.FILE:
case AnalysisScope.VIRTUAL_FILES:
case AnalysisScope.UNCOMMITTED_FILES:
{
files = Lists.newArrayList();
SearchScope searchScope = scope.toSearchScope();
if (searchScope instanceof LocalSearchScope) {
final LocalSearchScope localSearchScope = (LocalSearchScope) searchScope;
final PsiElement[] elements = localSearchScope.getScope();
final List<VirtualFile> finalFiles = files;
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
for (PsiElement element : elements) {
if (element instanceof PsiFile) {
// should be the case since scope type is FILE
Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (module != null && !modules.contains(module)) {
modules.add(module);
}
VirtualFile virtualFile = ((PsiFile) element).getVirtualFile();
if (virtualFile != null) {
finalFiles.add(virtualFile);
}
}
}
}
});
} else {
final List<VirtualFile> finalList = files;
scope.accept(new PsiElementVisitor() {
@Override
public void visitFile(PsiFile file) {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
finalList.add(virtualFile);
}
}
});
}
if (files.isEmpty()) {
files = null;
} else {
// Lint will compute it lazily based on actual files in the request
lintScope = null;
}
break;
}
case AnalysisScope.PROJECT:
{
modules.addAll(Arrays.asList(ModuleManager.getInstance(project).getModules()));
break;
}
case AnalysisScope.CUSTOM:
case AnalysisScope.MODULES:
case AnalysisScope.DIRECTORY:
{
// Handled by the getNarrowedComplementaryScope case below
break;
}
case AnalysisScope.INVALID:
break;
default:
Logger.getInstance(this.getClass()).warn("Unexpected inspection scope " + scope + ", " + scopeType);
}
if (modules.isEmpty()) {
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (scope.containsModule(module)) {
modules.add(module);
}
}
if (modules.isEmpty() && files != null) {
for (VirtualFile file : files) {
Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module != null && !modules.contains(module)) {
modules.add(module);
}
}
}
if (modules.isEmpty()) {
AnalysisScope narrowed = scope.getNarrowedComplementaryScope(project);
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (narrowed.containsModule(module)) {
modules.add(module);
}
}
}
}
LintRequest request = new IntellijLintRequest(client, project, files, modules, false);
request.setScope(lintScope);
lint.analyze(request);
myResults = problemMap;
}
use of com.intellij.util.containers.HashMap in project intellij-plugins by JetBrains.
the class FlexXmlBackedClassesIndex method getIndexer.
@Override
@NotNull
public DataIndexer<String, Void, FileContent> getIndexer() {
return new DataIndexer<String, Void, FileContent>() {
@Override
@NotNull
public Map<String, Void> map(@NotNull FileContent inputData) {
final XmlFile file = (XmlFile) inputData.getPsiFile();
final Map<String, Void> result = new HashMap<>();
for (JSClass clazz : XmlBackedJSClassImpl.getClasses(file)) {
JSReferenceList supers = getSupers(clazz);
if (supers != null) {
final JSExpression[] expressions = supers.getExpressions();
for (JSExpression expr : expressions) {
String s = expr instanceof JSReferenceExpression ? ((JSReferenceExpression) expr).getReferenceName() : null;
if (s != null)
result.put(s, null);
}
}
}
return result;
}
};
}
use of com.intellij.util.containers.HashMap in project intellij-plugins by JetBrains.
the class FlexXmlBackedMembersIndex method getIndexer.
@Override
@NotNull
public DataIndexer<String, Void, FileContent> getIndexer() {
return new DataIndexer<String, Void, FileContent>() {
@Override
@NotNull
public Map<String, Void> map(@NotNull FileContent inputData) {
final XmlFile file = (XmlFile) inputData.getPsiFile();
final Map<String, Void> result = new HashMap<>();
process(file, element -> {
String name = getName(element);
if (name != null) {
result.put(name, null);
}
}, false);
return result;
}
};
}
Aggregations