use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class DirectoryStorageUtil method loadFrom.
@NotNull
public static Map<String, Element> loadFrom(@Nullable VirtualFile dir, @Nullable PathMacroSubstitutor pathMacroSubstitutor) {
if (dir == null || !dir.exists()) {
return Collections.emptyMap();
}
StringInterner interner = new StringInterner();
Map<String, Element> fileToState = new THashMap<>();
for (VirtualFile file : dir.getChildren()) {
// ignore system files like .DS_Store on Mac
if (!StringUtilRt.endsWithIgnoreCase(file.getNameSequence(), FileStorageCoreUtil.DEFAULT_EXT)) {
continue;
}
try {
if (file.getLength() == 0) {
LOG.warn("Ignore empty file " + file.getPath());
continue;
}
Element element = JDOMUtil.load(file.getInputStream());
String componentName = FileStorageCoreUtil.getComponentNameIfValid(element);
if (componentName == null) {
continue;
}
if (!element.getName().equals(FileStorageCoreUtil.COMPONENT)) {
LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPresentableUrl());
continue;
}
List<Element> elementChildren = element.getChildren();
if (elementChildren.isEmpty()) {
continue;
}
Element state = (Element) elementChildren.get(0).detach();
if (JDOMUtil.isEmpty(state)) {
continue;
}
JDOMUtil.internElement(state, interner);
if (pathMacroSubstitutor != null) {
pathMacroSubstitutor.expandPaths(state);
if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) {
((TrackingPathMacroSubstitutor) pathMacroSubstitutor).addUnknownMacros(componentName, PathMacrosCollector.getMacroNames(state));
}
}
fileToState.put(file.getName(), state);
} catch (Throwable e) {
LOG.warn("Unable to load state", e);
}
}
return fileToState;
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class ModuleManagerImpl method loadModules.
protected void loadModules(@NotNull ModuleModelImpl moduleModel) {
myFailedModulePaths.clear();
if (myModulePathsToLoad == null || myModulePathsToLoad.isEmpty()) {
return;
}
myFailedModulePaths.addAll(myModulePathsToLoad);
ProgressIndicator globalIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
ProgressIndicator progressIndicator = myProject.isDefault() || globalIndicator == null ? new EmptyProgressIndicator() : globalIndicator;
progressIndicator.setText("Loading modules...");
progressIndicator.setText2("");
List<Module> modulesWithUnknownTypes = new SmartList<>();
List<ModuleLoadingErrorDescription> errors = Collections.synchronizedList(new ArrayList<>());
ModuleGroupInterner groupInterner = new ModuleGroupInterner();
ExecutorService service = AppExecutorUtil.createBoundedApplicationPoolExecutor("modules loader", JobSchedulerImpl.CORES_COUNT);
List<Pair<Future<Module>, ModulePath>> tasks = new ArrayList<>();
Set<String> paths = new THashSet<>();
boolean parallel = Registry.is("parallel.modules.loading");
for (ModulePath modulePath : myModulePathsToLoad) {
if (progressIndicator.isCanceled()) {
break;
}
try {
String path = modulePath.getPath();
if (!paths.add(path))
continue;
if (!parallel) {
tasks.add(Pair.create(null, modulePath));
continue;
}
ThrowableComputable<Module, IOException> computable = moduleModel.loadModuleInternal(path);
Future<Module> future = service.submit(() -> {
progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
try {
return computable.compute();
} catch (IOException e) {
reportError(errors, modulePath, e);
} catch (Exception e) {
LOG.error(e);
}
return null;
});
tasks.add(Pair.create(future, modulePath));
} catch (IOException e) {
reportError(errors, modulePath, e);
}
}
for (Pair<Future<Module>, ModulePath> task : tasks) {
if (progressIndicator.isCanceled()) {
break;
}
try {
Module module;
if (parallel) {
module = task.first.get();
} else {
module = moduleModel.loadModuleInternal(task.second.getPath()).compute();
progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
}
if (module == null)
continue;
if (isUnknownModuleType(module)) {
modulesWithUnknownTypes.add(module);
}
ModulePath modulePath = task.second;
final String groupPathString = modulePath.getGroup();
if (groupPathString != null) {
// model should be updated too
groupInterner.setModuleGroupPath(moduleModel, module, groupPathString.split(MODULE_GROUP_SEPARATOR));
}
myFailedModulePaths.remove(modulePath);
} catch (IOException e) {
reportError(errors, task.second, e);
} catch (Exception e) {
LOG.error(e);
}
}
service.shutdown();
progressIndicator.checkCanceled();
Application app = ApplicationManager.getApplication();
if (app.isInternal() || app.isEAP() || ApplicationInfo.getInstance().getBuild().isSnapshot()) {
Map<String, Module> track = new THashMap<>();
for (Module module : moduleModel.getModules()) {
for (String url : ModuleRootManager.getInstance(module).getContentRootUrls()) {
Module oldModule = track.put(url, module);
if (oldModule != null) {
//Map<String, VirtualFilePointer> track1 = ContentEntryImpl.track;
//VirtualFilePointer pointer = track1.get(url);
LOG.error("duplicated content url: " + url);
}
}
}
}
onModuleLoadErrors(moduleModel, errors);
showUnknownModuleTypeNotification(modulesWithUnknownTypes);
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class MethodParameterPanel method resetImpl.
protected void resetImpl() {
setPsiClass(myOrigInjection.getClassName());
rebuildTreeModel();
final THashMap<String, MethodParameterInjection.MethodInfo> map = new THashMap<>();
for (PsiMethod method : myData.keySet()) {
final MethodParameterInjection.MethodInfo methodInfo = myData.get(method);
map.put(methodInfo.getMethodSignature(), methodInfo);
}
for (MethodParameterInjection.MethodInfo info : myOrigInjection.getMethodInfos()) {
final MethodParameterInjection.MethodInfo curInfo = map.get(info.getMethodSignature());
if (curInfo != null) {
System.arraycopy(info.getParamFlags(), 0, curInfo.getParamFlags(), 0, Math.min(info.getParamFlags().length, curInfo.getParamFlags().length));
curInfo.setReturnFlag(info.isReturnFlag());
} else {
final PsiMethod missingMethod = MethodParameterInjection.makeMethod(myProject, info.getMethodSignature());
myData.put(missingMethod, info.copy());
}
}
refreshTreeStructure();
final Enumeration enumeration = myRootNode.children();
while (enumeration.hasMoreElements()) {
PsiMethod method = (PsiMethod) ((DefaultMutableTreeNode) enumeration.nextElement()).getUserObject();
assert myData.containsKey(method);
}
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class ShuffleNamesAction method shuffleIds.
private static boolean shuffleIds(PsiFile file, Editor editor) {
final Map<String, String> map = new THashMap<>();
final StringBuilder sb = new StringBuilder();
final StringBuilder quote = new StringBuilder();
final ArrayList<String> split = new ArrayList<>(100);
file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof LeafPsiElement) {
String type = ((LeafPsiElement) element).getElementType().toString();
String text = element.getText();
if (text.isEmpty())
return;
for (int i = 0, len = text.length(); i < len / 2; i++) {
char c = text.charAt(i);
if (c == text.charAt(len - i - 1) && !Character.isLetter(c)) {
quote.append(c);
} else
break;
}
boolean isQuoted = quote.length() > 0;
boolean isNumber = false;
if (isQuoted || type.equals("ID") || type.contains("IDENT") && !"ts".equals(text) || (isNumber = text.matches("[0-9]+"))) {
String replacement = map.get(text);
if (replacement == null) {
split.addAll(Arrays.asList((isQuoted ? text.substring(quote.length(), text.length() - quote.length()).replace("''", "") : text).split("")));
if (!isNumber) {
for (ListIterator<String> it = split.listIterator(); it.hasNext(); ) {
String s = it.next();
if (s.isEmpty()) {
it.remove();
continue;
}
int c = s.charAt(0);
int cap = c & 32;
c &= ~cap;
c = (char) ((c >= 'A') && (c <= 'Z') ? ((c - 'A' + 7) % 26 + 'A') : c) | cap;
it.set(String.valueOf((char) c));
}
}
Collections.shuffle(split);
if (isNumber && "0".equals(split.get(0))) {
split.set(0, "1");
}
replacement = StringUtil.join(split, "");
if (isQuoted) {
replacement = quote + replacement + quote.reverse();
}
map.put(text, replacement);
}
text = replacement;
}
sb.append(text);
quote.setLength(0);
split.clear();
}
super.visitElement(element);
}
});
editor.getDocument().setText(sb.toString());
return true;
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class EclipseImportBuilder method validate.
@Override
public boolean validate(final Project currentProject, final Project dstProject) {
final Ref<Exception> refEx = new Ref<>();
final Set<String> variables = new THashSet<>();
final Map<String, String> naturesNames = new THashMap<>();
final List<String> projectsToConvert = getParameters().projectsToConvert;
final boolean oneProjectToConvert = projectsToConvert.size() == 1;
final String separator = oneProjectToConvert ? "<br>" : ", ";
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
try {
for (String path : projectsToConvert) {
File classPathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
if (classPathFile.exists()) {
EclipseClasspathReader.collectVariables(variables, JDOMUtil.load(classPathFile), path);
}
collectUnknownNatures(path, naturesNames, separator);
}
} catch (IOException | JDOMException e) {
refEx.set(e);
}
}, EclipseBundle.message("eclipse.import.converting"), false, currentProject);
if (!refEx.isNull()) {
Messages.showErrorDialog(dstProject, refEx.get().getMessage(), getTitle());
return false;
}
if (!ProjectMacrosUtil.checkNonIgnoredMacros(dstProject, variables)) {
return false;
}
if (!naturesNames.isEmpty()) {
final String title = "Unknown Natures Detected";
final String naturesByProject;
if (oneProjectToConvert) {
naturesByProject = naturesNames.values().iterator().next();
} else {
naturesByProject = StringUtil.join(naturesNames.keySet(), projectPath -> projectPath + "(" + naturesNames.get(projectPath) + ")", "<br>");
}
Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:<br>" + naturesByProject + "<br>" + "Some settings may be lost after import.", NotificationType.WARNING));
}
return true;
}
Aggregations