use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class JavaI18nUtil method isValidPropertyReference.
static boolean isValidPropertyReference(@NotNull Project project, @NotNull PsiExpression expression, @NotNull String key, @NotNull Ref<String> outResourceBundle) {
final HashMap<String, Object> annotationAttributeValues = new HashMap<>();
annotationAttributeValues.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null);
if (mustBePropertyKey(expression, annotationAttributeValues)) {
final Object resourceBundleName = annotationAttributeValues.get(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER);
if (!(resourceBundleName instanceof PsiExpression)) {
return false;
}
PsiExpression expr = (PsiExpression) resourceBundleName;
final PsiConstantEvaluationHelper constantEvaluationHelper = JavaPsiFacade.getInstance(project).getConstantEvaluationHelper();
Object value = constantEvaluationHelper.computeConstantExpression(expr);
if (value == null) {
if (expr instanceof PsiReferenceExpression) {
final PsiElement resolve = ((PsiReferenceExpression) expr).resolve();
if (resolve instanceof PsiField && ((PsiField) resolve).hasModifierProperty(PsiModifier.FINAL)) {
value = constantEvaluationHelper.computeConstantExpression(((PsiField) resolve).getInitializer());
if (value == null) {
return false;
}
}
}
if (value == null) {
final ResourceBundle resourceBundle = resolveResourceBundleByKey(key, project);
if (resourceBundle == null) {
return false;
}
final PropertiesFile defaultPropertiesFile = resourceBundle.getDefaultPropertiesFile();
final String bundleName = BundleNameEvaluator.DEFAULT.evaluateBundleName(defaultPropertiesFile.getContainingFile());
if (bundleName == null) {
return false;
}
value = bundleName;
}
}
String bundleName = value.toString();
outResourceBundle.set(bundleName);
return isPropertyRef(expression, key, bundleName);
}
return true;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class PropertiesComponent method init.
public void init() {
setLayout(new BorderLayout());
myTable = new JBTable();
myTextArea = new JTextArea(0, 0);
myTextArea.setEditable(false);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
mySplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, scrollPane, ScrollPaneFactory.createScrollPane(myTextArea));
add(mySplitPane, BorderLayout.CENTER);
add(createToolbar(), BorderLayout.WEST);
final DefaultTableModel model = new DefaultTableModel(createTableModel(new HashMap<>()), new Object[] { "Name", "Value" }) {
public boolean isCellEditable(final int row, final int column) {
return false;
}
};
myTable.setModel(model);
myTable.setShowVerticalLines(true);
myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
myTable.getSelectionModel().addListSelectionListener(e -> {
int index = myTable.getSelectedRow();
if (index >= 0) {
Object value = myTable.getValueAt(index, 1);
if (value instanceof String) {
myTextArea.setText(((String) value));
} else {
myTextArea.setText("");
}
} else {
myTextArea.setText("");
}
});
myPopupActionGroup = createPopup();
PopupHandler.installPopupHandler(myTable, myPopupActionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance());
PopupHandler.installPopupHandler(scrollPane, myPopupActionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance());
final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_CLOSE_ACTIVE_TAB);
myCloseAction.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), this);
myRefreshAction.registerCustomShortcutSet(CommonShortcuts.getRerun(), this);
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class LocalTerminalDirectRunner method createProcess.
@Override
protected PtyProcess createProcess(@Nullable String directory) throws ExecutionException {
Map<String, String> envs = new HashMap<>(System.getenv());
if (!SystemInfo.isWindows) {
envs.put("TERM", "xterm-256color");
}
EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(envs, myDefaultCharset);
String[] command = getCommand(envs);
for (LocalTerminalCustomizer customizer : LocalTerminalCustomizer.EP_NAME.getExtensions()) {
try {
command = customizer.customizeCommandAndEnvironment(myProject, command, envs);
if (directory == null) {
directory = customizer.getDefaultFolder(myProject);
}
} catch (Exception e) {
LOG.error("Exception during customization of the terminal session", e);
}
}
try {
return PtyProcess.exec(command, envs, directory != null ? directory : TerminalProjectOptionsProvider.Companion.getInstance(myProject).getStartingDirectory());
} catch (IOException e) {
throw new ExecutionException(e);
}
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class EclipseImportBuilder method commit.
@Override
public List<Module> commit(final Project project, ModifiableModuleModel model, ModulesProvider modulesProvider, ModifiableArtifactModel artifactModel) {
final Collection<String> unknownLibraries = new TreeSet<>();
final Collection<String> unknownJdks = new TreeSet<>();
final Set<String> refsToModules = new HashSet<>();
final List<Module> result = new ArrayList<>();
final Map<Module, Set<String>> module2NatureNames = new HashMap<>();
try {
final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
final ModifiableRootModel[] rootModels = new ModifiableRootModel[getParameters().projectsToConvert.size()];
final Set<File> files = new HashSet<>();
final Set<String> moduleNames = new THashSet<>(getParameters().projectsToConvert.size());
for (String path : getParameters().projectsToConvert) {
String modulesDirectory = getParameters().converterOptions.commonModulesDirectory;
if (modulesDirectory == null) {
modulesDirectory = path;
}
final String moduleName = EclipseProjectFinder.findProjectName(path);
moduleNames.add(moduleName);
final File imlFile = new File(modulesDirectory + File.separator + moduleName + ModuleManagerImpl.IML_EXTENSION);
if (imlFile.isFile()) {
files.add(imlFile);
}
final File emlFile = new File(modulesDirectory + File.separator + moduleName + EclipseXml.IDEA_SETTINGS_POSTFIX);
if (emlFile.isFile()) {
files.add(emlFile);
}
}
if (!files.isEmpty()) {
final int resultCode = Messages.showYesNoCancelDialog(ApplicationNamesInfo.getInstance().getFullProductName() + " module files found:\n" + StringUtil.join(files, file -> file.getPath(), "\n") + ".\n Would you like to reuse them?", "Module Files Found", Messages.getQuestionIcon());
if (resultCode != Messages.YES) {
if (resultCode == Messages.NO) {
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
for (File file : files) {
final VirtualFile virtualFile = localFileSystem.findFileByIoFile(file);
if (virtualFile != null) {
ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<Void, IOException>() {
@Override
public Void compute() throws IOException {
virtualFile.delete(this);
return null;
}
});
} else {
FileUtil.delete(file);
}
}
} else {
return result;
}
}
}
int idx = 0;
for (String path : getParameters().projectsToConvert) {
String modulesDirectory = getParameters().converterOptions.commonModulesDirectory;
if (modulesDirectory == null) {
modulesDirectory = path;
}
final Module module = moduleModel.newModule(modulesDirectory + "/" + EclipseProjectFinder.findProjectName(path) + ModuleManagerImpl.IML_EXTENSION, StdModuleTypes.JAVA.getId());
result.add(module);
final Set<String> natures = collectNatures(path);
if (natures.size() > 0) {
module2NatureNames.put(module, natures);
}
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
rootModels[idx++] = rootModel;
final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
final EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, getParameters().projectsToConvert, moduleNames);
classpathReader.init(rootModel);
if (classpathFile.exists()) {
Element classpathElement = JDOMUtil.load(classpathFile);
classpathReader.readClasspath(rootModel, unknownLibraries, unknownJdks, refsToModules, getParameters().converterOptions.testPattern, classpathElement);
} else {
EclipseClasspathReader.setOutputUrl(rootModel, path + "/bin");
}
ClasspathStorage.setStorageType(rootModel, getParameters().linkConverted ? JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID : ClassPathStorageUtil.DEFAULT_STORAGE);
if (model != null) {
ApplicationManager.getApplication().runWriteAction(() -> rootModel.commit());
}
}
if (model == null) {
ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(rootModels, moduleModel));
}
} catch (Exception e) {
LOG.error(e);
}
scheduleNaturesImporting(project, module2NatureNames);
createEclipseLibrary(project, unknownLibraries, IdeaXml.ECLIPSE_LIBRARY);
StringBuilder message = new StringBuilder();
refsToModules.removeAll(getParameters().existingModuleNames);
for (String path : getParameters().projectsToConvert) {
final String projectName = EclipseProjectFinder.findProjectName(path);
if (projectName != null) {
refsToModules.remove(projectName);
getParameters().existingModuleNames.add(projectName);
}
}
if (!refsToModules.isEmpty()) {
message.append("Unknown modules detected");
for (String module : refsToModules) {
message.append("\n").append(module);
}
}
if (!unknownJdks.isEmpty()) {
if (message.length() > 0) {
message.append("\nand jdks");
} else {
message.append("Imported project refers to unknown jdks");
}
for (String unknownJdk : unknownJdks) {
message.append("\n").append(unknownJdk);
}
}
if (!unknownLibraries.isEmpty()) {
final StringBuilder buf = new StringBuilder();
buf.append("<html><body>");
buf.append(EclipseBundle.message("eclipse.import.warning.undefinded.libraries"));
for (String name : unknownLibraries) {
buf.append("<br>").append(name);
}
if (model == null) {
buf.append("<br><b>Please export Eclipse user libraries and import them now from resulted .userlibraries file</b>");
buf.append("</body></html>");
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {
@Override
public boolean isFileSelectable(VirtualFile file) {
return super.isFileSelectable(file) && Comparing.strEqual(file.getExtension(), "userlibraries");
}
};
descriptor.setDescription(buf.toString());
descriptor.setTitle(getTitle());
final VirtualFile selectedFile = FileChooser.chooseFile(descriptor, project, project.getBaseDir());
if (selectedFile != null) {
try {
EclipseUserLibrariesHelper.readProjectLibrariesContent(selectedFile, project, unknownLibraries);
} catch (Exception e) {
LOG.error(e);
}
}
}
}
if (message.length() > 0) {
Messages.showErrorDialog(project, message.toString(), getTitle());
}
return result;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class JavaFxImportsOptimizer method processFile.
@NotNull
@Override
public Runnable processFile(final PsiFile file) {
VirtualFile vFile = file.getVirtualFile();
if (vFile instanceof VirtualFileWindow)
vFile = ((VirtualFileWindow) vFile).getDelegate();
final Project project = file.getProject();
if (vFile == null || !ProjectRootManager.getInstance(project).getFileIndex().isInSourceContent(vFile)) {
return EmptyRunnable.INSTANCE;
}
final List<Pair<String, Boolean>> names = new ArrayList<>();
final Set<String> demandedForNested = new HashSet<>();
collectNamesToImport(names, demandedForNested, (XmlFile) file);
Collections.sort(names, (o1, o2) -> StringUtil.compare(o1.first, o2.first, true));
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
final List<Pair<String, Boolean>> sortedNames = ImportHelper.sortItemsAccordingToSettings(names, settings);
final Map<String, Boolean> onDemand = new HashMap<>();
ImportHelper.collectOnDemandImports(sortedNames, settings, onDemand);
for (String s : demandedForNested) {
onDemand.put(s, false);
}
final Set<String> imported = new HashSet<>();
final List<String> imports = new ArrayList<>();
for (Pair<String, Boolean> pair : sortedNames) {
final String qName = pair.first;
final String packageName = StringUtil.getPackageName(qName);
if (imported.contains(packageName) || imported.contains(qName)) {
continue;
}
if (onDemand.containsKey(packageName)) {
imported.add(packageName);
imports.add("<?import " + packageName + ".*?>");
} else {
imported.add(qName);
imports.add("<?import " + qName + "?>");
}
}
final PsiFileFactory factory = PsiFileFactory.getInstance(file.getProject());
final XmlFile dummyFile = (XmlFile) factory.createFileFromText("_Dummy_.fxml", StdFileTypes.XML, StringUtil.join(imports, "\n"));
final XmlDocument document = dummyFile.getDocument();
final XmlProlog newImportList = document != null ? document.getProlog() : null;
if (newImportList == null)
return EmptyRunnable.getInstance();
return () -> {
final XmlDocument xmlDocument = ((XmlFile) file).getDocument();
final XmlProlog prolog = xmlDocument != null ? xmlDocument.getProlog() : null;
if (prolog != null) {
final Collection<XmlProcessingInstruction> instructions = PsiTreeUtil.findChildrenOfType(prolog, XmlProcessingInstruction.class);
for (final XmlProcessingInstruction instruction : instructions) {
final ASTNode node = instruction.getNode();
final ASTNode nameNode = node.findChildByType(XmlTokenType.XML_NAME);
if (nameNode != null && nameNode.getText().equals("import")) {
instruction.delete();
}
}
prolog.add(newImportList);
} else {
document.addBefore(newImportList, document.getRootTag());
}
};
}
Aggregations