@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { if (!(holder.getFile() instanceof PropertiesFileImpl)) { return PsiElementVisitor.EMPTY_VISITOR; } final PropertiesCodeStyleSettings codeStyleSettings = PropertiesCodeStyleSettings.getInstance(holder.getProject()); final char codeStyleKeyValueDelimiter = codeStyleSettings.KEY_VALUE_DELIMITER; return new PsiElementVisitor() { @Override public void visitElement(PsiElement element) { if (element instanceof PropertyImpl) { final Character delimiter = ((PropertyImpl)element).getKeyValueDelimiter(); if (delimiter != null && !delimiter.equals(codeStyleKeyValueDelimiter)) { holder.registerProblem(element, PropertiesBundle.message("wrong.property.key.value.delimiter.inspection.display.name"), new ReplaceKeyValueDelimiterQuickFix(element)); } } } }; }
public static void parseProperty(PsiBuilder builder) { if (builder.getTokenType() == PropertiesTokenTypes.KEY_CHARACTERS) { final PsiBuilder.Marker prop = builder.mark(); parseKey(builder); if (builder.getTokenType() == PropertiesTokenTypes.KEY_VALUE_SEPARATOR) { parseKeyValueSeparator(builder); parseValue(builder); } prop.done(PropertiesElementTypes.PROPERTY); } else { builder.advanceLexer(); builder.error(PropertiesBundle.message("property.key.expected.parsing.error.message")); } }
@Override public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) { ResourceBundleEditor bundleEditor = ResourceBundleUtil.getEditor(dataContext); if (bundleEditor == null) { return; } String propertyName = bundleEditor.getState(FileEditorStateLevel.NAVIGATION).getPropertyName(); if (propertyName == null) { return; } ResourceBundle bundle = ResourceBundleUtil.getResourceBundleFromDataContext(dataContext); if (bundle == null) { return; } Messages.showInputDialog(project, PropertiesBundle.message("rename.bundle.enter.new.resource.bundle.key.name.prompt.text"), PropertiesBundle.message("rename.resource.bundle.key.dialog.title"), Messages.getQuestionIcon(), propertyName, new ResourceBundleKeyRenameValidator(project, bundleEditor, bundle, propertyName)); }
public final void actionPerformed(AnActionEvent e) { String[] strings = ArrayUtil.toStringArray(myPredefinedSeparators); String current = getCurrentSeparator(); String separator = Messages.showEditableChooseDialog(PropertiesBundle.message("select.property.separator.dialog.text"), PropertiesBundle.message("select.property.separator.dialog.title"), Messages.getQuestionIcon(), strings, current, null); if (separator == null) { return; } myPredefinedSeparators.add(separator); refillActionGroup(); }
public static void renameResourceBundleKeySection(final List<PsiElement> psiElements, final String section, final int sectionPosition) { if (psiElements.isEmpty()) { return; } final Project project = psiElements.get(0).getProject(); Messages.showInputDialog(project, PropertiesBundle.message("rename.bundle.enter.new.resource.bundle.section.name.prompt.text"), PropertiesBundle.message("rename.resource.bundle.section.dialog.title"), Messages.getQuestionIcon(), section, new ResourceBundleKeySectionInputValidator(psiElements, section, sectionPosition, project)); }
@Override @NotNull public ActionPresentation getPresentation() { return new ActionPresentationData(PropertiesBundle.message("structure.view.group.by.prefixes.action.name"), PropertiesBundle.message("structure.view.group.by.prefixes.action.description"), AllIcons.Actions.GroupByPrefix); }
public final void actionPerformed(AnActionEvent e) { String[] strings = myPredefinedSeparators.keySet().toArray(new String[myPredefinedSeparators.size()]); String current = getCurrentSeparator(); String separator = Messages.showEditableChooseDialog(PropertiesBundle.message("select.property.separator.dialog.text"), PropertiesBundle.message("select.property.separator.dialog.title"), Messages.getQuestionIcon(), strings, current, null); if (separator == null) { return; } myPredefinedSeparators.put(separator, separator); refillActionGroup(); }
protected AddNewPropertyFileAction() { super(PropertiesBundle.message("add.property.files.to.resource.bundle.dialog.action.title"), null, AllIcons.FileTypes.Properties); }
protected CreateResourceBundleAction() { super(PropertiesBundle.message("create.resource.bundle.dialog.action.title"), null, AllIcons.FileTypes.Properties); }
@Override protected String getErrorTitle() { return PropertiesBundle.message("create.resource.bundle.dialog.error"); }
@Override protected String getCommandName() { return PropertiesBundle.message("create.resource.bundle.dialog.command"); }
@Override protected String getActionName(PsiDirectory directory, String newName) { return PropertiesBundle.message("create.resource.bundle.dialog.action.name", newName); }
@NotNull public String getDescription() { return PropertiesBundle.message("resourcebundle.fake.file.type.description"); }
public SelectSeparatorAction() { super(PropertiesBundle.message("select.separator.action.with.empty.separator.name")); }
public CombinePropertiesFilesAction() { super(PropertiesBundle.message("combine.properties.files.title"), null, AllIcons.FileTypes.Properties); }
@Override public String getDialogTitle() { return PropertiesBundle.message("resource.bundle.renamer"); }
@Override public String getDialogDescription() { return PropertiesBundle.message("resource.bundle.renamer.dialog.description"); }
@Override public String entityName() { return PropertiesBundle.message("resource.bundle.renamer.entity.name"); }
@Nullable @Override public String getOptionName() { return PropertiesBundle.message("resource.bundle.renamer.option"); }
public static void renameResourceBundleBaseName(final @NotNull ResourceBundle resourceBundle, final @NotNull Project project) { Messages.showInputDialog(project, PropertiesBundle.message("rename.bundle.enter.new.resource.bundle.base.name.prompt.text"), PropertiesBundle.message("rename.resource.bundle.dialog.title"), Messages.getQuestionIcon(), resourceBundle.getBaseName(), new ResourceBundleBaseNameInputValidator(project, resourceBundle)); }
@NotNull public String getDisplayName() { return PropertiesBundle.message("trail.spaces.property.inspection.display.name"); }
@Nullable @Override public JComponent createOptionsPanel() { return new SingleCheckboxOptionsPanel(PropertiesBundle.message("trailing.spaces.in.property.inspection.ignore.visible.spaces"), this, "myIgnoreVisibleSpaces"); }
private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextBase context, final RefManager refManager, final ProblemDescriptionsProcessor processor) { if (!(file instanceof PropertiesFile)) return; if (!context.isToCheckFile(file, this)) return; final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject()); final PropertiesFile propertiesFile = (PropertiesFile)file; final List<IProperty> properties = propertiesFile.getProperties(); Module module = ModuleUtilCore.findModuleForPsiElement(file); if (module == null) return; final GlobalSearchScope scope = CURRENT_FILE ? GlobalSearchScope.fileScope(file) : MODULE_WITH_DEPENDENCIES ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(file.getProject()); final Map<String, Set<PsiFile>> processedValueToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>()); final Map<String, Set<PsiFile>> processedKeyToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>()); final ProgressIndicator original = ProgressManager.getInstance().getProgressIndicator(); final ProgressIndicator progress = ProgressWrapper.wrap(original); ProgressManager.getInstance().runProcess(new Runnable() { @Override public void run() { if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(properties, progress, false, new Processor<IProperty>() { @Override public boolean process(final IProperty property) { if (original != null) { if (original.isCanceled()) return false; original.setText2(PropertiesBundle.message("searching.for.property.key.progress.text", property.getUnescapedKey())); } processTextUsages(processedValueToFiles, property.getValue(), processedKeyToFiles, searchHelper, scope); processTextUsages(processedKeyToFiles, property.getUnescapedKey(), processedValueToFiles, searchHelper, scope); return true; } })) throw new ProcessCanceledException(); List<ProblemDescriptor> problemDescriptors = new ArrayList<ProblemDescriptor>(); Map<String, Set<String>> keyToDifferentValues = new HashMap<String, Set<String>>(); if (CHECK_DUPLICATE_KEYS || CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) { prepareDuplicateKeysByFile(processedKeyToFiles, manager, keyToDifferentValues, problemDescriptors, file, original); } if (CHECK_DUPLICATE_VALUES) prepareDuplicateValuesByFile(processedValueToFiles, manager, problemDescriptors, file, original); if (CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) { processDuplicateKeysWithDifferentValues(keyToDifferentValues, processedKeyToFiles, problemDescriptors, manager, file, original); } if (!problemDescriptors.isEmpty()) { processor.addProblemElement(refManager.getReference(file), problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()])); } } }, progress); }
@NotNull public String getUnresolvedMessagePattern() { return PropertiesBundle.message("unresolved.property.key"); }
public void inlineElement(final Project project, Editor editor, PsiElement psiElement) { if (!(psiElement instanceof IProperty)) return; IProperty property = (IProperty)psiElement; final String propertyValue = property.getValue(); if (propertyValue == null) return; final List<PsiElement> occurrences = Collections.synchronizedList(ContainerUtil.<PsiElement>newArrayList()); final Collection<PsiFile> containingFiles = Collections.synchronizedSet(new HashSet<PsiFile>()); containingFiles.add(psiElement.getContainingFile()); boolean result = ReferencesSearch.search(psiElement).forEach( new Processor<PsiReference>() { public boolean process(final PsiReference psiReference) { PsiElement element = psiReference.getElement(); PsiElement parent = element.getParent(); if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiMethodCallExpression) { if (((PsiExpressionList)parent).getExpressions().length == 1) { occurrences.add(parent.getParent()); containingFiles.add(element.getContainingFile()); return true; } } return false; } } ); if (!result) { CommonRefactoringUtil.showErrorHint(project, editor, "Property has non-method usages", REFACTORING_NAME, null); } if (occurrences.isEmpty()) { CommonRefactoringUtil.showErrorHint(project, editor, "Property has no usages", REFACTORING_NAME, null); return; } if (!ApplicationManager.getApplication().isUnitTestMode()) { String occurrencesString = RefactoringBundle.message("occurrences.string", occurrences.size()); String question = PropertiesBundle.message("inline.property.confirmation", property.getName(), propertyValue) + " " + occurrencesString; RefactoringMessageDialog dialog = new RefactoringMessageDialog(REFACTORING_NAME, question, HelpID.INLINE_VARIABLE, "OptionPane.questionIcon", true, project); if (!dialog.showAndGet()) { return; } } final RefactoringEventData data = new RefactoringEventData(); data.addElement(psiElement.copy()); new WriteCommandAction.Simple(project, REFACTORING_NAME, containingFiles.toArray(new PsiFile[containingFiles.size()])) { @Override protected void run() throws Throwable { project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(REFACTORING_ID, data); PsiLiteral stringLiteral = (PsiLiteral)JavaPsiFacade.getInstance(getProject()).getElementFactory(). createExpressionFromText("\"" + StringUtil.escapeStringCharacters(propertyValue) + "\"", null); for (PsiElement occurrence : occurrences) { occurrence.replace(stringLiteral.copy()); } project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(REFACTORING_ID, null); } }.execute(); }
@Override @NotNull public String getDisplayName() { return PropertiesBundle.message("unused.property.inspection.display.name"); }
private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextImpl context, final RefManager refManager, final ProblemDescriptionsProcessor processor) { if (!(file instanceof PropertiesFile)) return; if (!context.isToCheckFile(file, this)) return; final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject()); final PropertiesFile propertiesFile = (PropertiesFile)file; final List<IProperty> properties = propertiesFile.getProperties(); Module module = ModuleUtil.findModuleForPsiElement(file); if (module == null) return; final GlobalSearchScope scope = CURRENT_FILE ? GlobalSearchScope.fileScope(file) : MODULE_WITH_DEPENDENCIES ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(file.getProject()); final Map<String, Set<PsiFile>> processedValueToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>()); final Map<String, Set<PsiFile>> processedKeyToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>()); final ProgressIndicator original = ProgressManager.getInstance().getProgressIndicator(); final ProgressIndicator progress = ProgressWrapper.wrap(original); ProgressManager.getInstance().runProcess(new Runnable() { @Override public void run() { if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(properties, progress, false, new Processor<IProperty>() { @Override public boolean process(final IProperty property) { if (original != null) { if (original.isCanceled()) return false; original.setText2(PropertiesBundle.message("searching.for.property.key.progress.text", property.getUnescapedKey())); } processTextUsages(processedValueToFiles, property.getValue(), processedKeyToFiles, searchHelper, scope); processTextUsages(processedKeyToFiles, property.getUnescapedKey(), processedValueToFiles, searchHelper, scope); return true; } })) throw new ProcessCanceledException(); List<ProblemDescriptor> problemDescriptors = new ArrayList<ProblemDescriptor>(); Map<String, Set<String>> keyToDifferentValues = new HashMap<String, Set<String>>(); if (CHECK_DUPLICATE_KEYS || CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) { prepareDuplicateKeysByFile(processedKeyToFiles, manager, keyToDifferentValues, problemDescriptors, file, original); } if (CHECK_DUPLICATE_VALUES) prepareDuplicateValuesByFile(processedValueToFiles, manager, problemDescriptors, file, original); if (CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) { processDuplicateKeysWithDifferentValues(keyToDifferentValues, processedKeyToFiles, problemDescriptors, manager, file, original); } if (!problemDescriptors.isEmpty()) { processor.addProblemElement(refManager.getReference(file), problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()])); } } }, progress); }
@NotNull public ActionPresentation getPresentation() { return new ActionPresentationData(PropertiesBundle.message("structure.view.group.by.prefixes.action.name"), PropertiesBundle.message("structure.view.group.by.prefixes.action.description"), AllIcons.Actions.GroupByPrefix); }
public void update(PresentationData presentation) { presentation.setIcon(AllIcons.Nodes.ResourceBundle); presentation.setPresentableText(PropertiesBundle.message("project.view.resource.bundle.tree.node.text", getValue().getBaseName())); }
@Override @NotNull public String getDescription() { return PropertiesBundle.message("properties.files.file.type.description"); }