properties: @Override

This commit is contained in:
Dmitry Batkovich
2016-10-31 19:12:47 +03:00
parent 7df1f3e858
commit 5e966402a2
25 changed files with 82 additions and 0 deletions
@@ -31,6 +31,7 @@ import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
public class EnterInPropertiesFileHandler extends EnterHandlerDelegateAdapter {
@Override
public Result preprocessEnter(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final Ref<Integer> caretOffsetRef, @NotNull final Ref<Integer> caretAdvance,
@NotNull final DataContext dataContext, final EditorActionHandler originalHandler) {
if (file instanceof PropertiesFile) {
@@ -39,6 +39,7 @@ import java.util.List;
public class ResourcesFavoriteNodeProvider extends FavoriteNodeProvider {
@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
@@ -56,6 +57,7 @@ public class ResourcesFavoriteNodeProvider extends FavoriteNodeProvider {
return null;
}
@Override
public boolean elementContainsFile(final Object element, final VirtualFile vFile) {
if (element instanceof ResourceBundle) {
ResourceBundle bundle = (ResourceBundle)element;
@@ -71,14 +73,17 @@ public class ResourcesFavoriteNodeProvider extends FavoriteNodeProvider {
return false;
}
@Override
public int getElementWeight(final Object element, final boolean isSortByType) {
return -1;
}
@Override
public String getElementLocation(final Object element) {
return null;
}
@Override
public boolean isInvalidElement(final Object element) {
if (element instanceof ResourceBundle) {
ResourceBundle resourceBundle = (ResourceBundle)element;
@@ -91,11 +96,13 @@ public class ResourcesFavoriteNodeProvider extends FavoriteNodeProvider {
return false;
}
@Override
@NotNull
public String getFavoriteTypeId() {
return "resource_bundle";
}
@Override
public String getElementUrl(final Object element) {
if (element instanceof ResourceBundleImpl) {
return ((ResourceBundleImpl)element).getUrl();
@@ -103,10 +110,12 @@ public class ResourcesFavoriteNodeProvider extends FavoriteNodeProvider {
return null;
}
@Override
public String getElementModuleName(final Object element) {
return null;
}
@Override
public Object[] createPathFromUrl(final Project project, final String url, final String moduleName) {
return new Object[]{PropertiesImplUtil.createByUrl(url, project)};
}
@@ -28,6 +28,7 @@ import org.jetbrains.annotations.NotNull;
* @author yole
*/
public class PropertiesDescriptionProvider implements ElementDescriptionProvider {
@Override
public String getElementDescription(@NotNull final PsiElement element, @Nullable final ElementDescriptionLocation location) {
if (element instanceof IProperty) {
if (location instanceof DeleteTypeDescriptionLocation) {
@@ -34,6 +34,7 @@ import org.jetbrains.annotations.Nullable;
import java.awt.*;
public class PropertiesDocumentationProvider extends AbstractDocumentationProvider {
@Override
@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
if (element instanceof IProperty) {
@@ -56,6 +57,7 @@ public class PropertiesDocumentationProvider extends AbstractDocumentationProvid
return StringUtil.escapeXml(raw);
}
@Override
public String generateDoc(final PsiElement element, @Nullable final PsiElement originalElement) {
if (element instanceof IProperty) {
IProperty property = (IProperty)element;
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
* @author Maxim.Mossienko
*/
public class PropertiesFileTypeFactory extends FileTypeFactory {
@Override
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
consumer.consume(PropertiesFileType.INSTANCE, PropertiesFileType.DEFAULT_EXTENSION);
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Document;
import com.intellij.psi.PsiFile;
public class PropertiesJoinLinesHandler implements JoinLinesHandlerDelegate {
@Override
public int tryJoinLines(final Document doc, final PsiFile psiFile, int start, final int end) {
if (!(psiFile instanceof PropertiesFile)) return -1;
// strip continuation char
@@ -24,6 +24,7 @@ import com.intellij.lang.properties.parsing.PropertiesElementTypes;
import com.intellij.psi.tree.IElementType;
public class PropertiesWordCompletionFilter extends DefaultWordCompletionFilter {
@Override
public boolean isWordCompletionEnabledIn(final IElementType element) {
return super.isWordCompletionEnabledIn(element) || element == PropertiesElementTypes.PROPERTY;
}
@@ -58,12 +58,14 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement>
return ReflectionUtil.isAssignable(PsiFile.class, elementClass);
}
@Override
@Nullable
public PsiElement resolve() {
ResolveResult[] resolveResults = multiResolve(false);
return resolveResults.length == 1 ? resolveResults[0].getElement() : null;
}
@Override
@NotNull
public ResolveResult[] multiResolve(final boolean incompleteCode) {
PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(myElement.getProject());
@@ -71,11 +73,13 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement>
return PsiElementResolveResult.createResults(ContainerUtil.map(propertiesFiles, PROPERTIES_FILE_PSI_ELEMENT_FUNCTION));
}
@Override
@NotNull
public String getCanonicalText() {
return myBundleName;
}
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
if (newElementName.endsWith(PropertiesFileType.DOT_DEFAULT_EXTENSION)) {
newElementName = newElementName.substring(0, newElementName.lastIndexOf(PropertiesFileType.DOT_DEFAULT_EXTENSION));
@@ -95,6 +99,7 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement>
return StringUtil.indexOf(getValue(), '/') != -1 ? '/' : '.';
}
@Override
public PsiElement bindToElement(@NotNull final PsiElement element) throws IncorrectOperationException {
if (!(element instanceof PropertiesFile)) {
throw new IncorrectOperationException();
@@ -104,6 +109,7 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement>
}
@Override
public boolean isReferenceTo(PsiElement element) {
if (element instanceof PropertiesFile) {
final String name = ResourceBundleManager.getInstance(element.getProject()).getFullName((PropertiesFile)element);
@@ -114,6 +120,7 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement>
return false;
}
@Override
@NotNull
public Object[] getVariants() {
final ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(getElement().getProject());
@@ -139,6 +146,7 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement>
return variants.toArray(new LookupElement[variants.size()]);
}
@Override
public String evaluateBundleName(final PsiFile psiFile) {
return BundleNameEvaluator.DEFAULT.evaluateBundleName(psiFile);
}
@@ -36,6 +36,7 @@ public class ResourceBundleReferenceProvider extends PsiReferenceProvider {
mySoft = soft;
}
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
ResourceBundleReference reference = new ResourceBundleReference(element, mySoft);
@@ -86,6 +86,7 @@ public class PropertiesGroupingStructureViewComponent extends StructureViewCompo
refillActionGroup();
}
@Override
public final void update(AnActionEvent e) {
String separator = getCurrentSeparator();
Presentation presentation = e.getPresentation();
@@ -121,6 +122,7 @@ public class PropertiesGroupingStructureViewComponent extends StructureViewCompo
super(PropertiesBundle.message("select.separator.action.with.empty.separator.name"));
}
@Override
public final void actionPerformed(AnActionEvent e) {
String[] strings = ArrayUtil.toStringArray(myPredefinedSeparators);
String current = getCurrentSeparator();
@@ -24,16 +24,19 @@ import org.jetbrains.annotations.NotNull;
* @author cdr
*/
class ResourceBundleFileType extends FakeFileType {
@Override
@NotNull
public String getName() {
return "ResourceBundle";
}
@Override
@NotNull
public String getDescription() {
return PropertiesBundle.message("resourcebundle.fake.file.type.description");
}
@Override
public boolean isMyFileType(@NotNull VirtualFile file) {
return file instanceof ResourceBundleAsVirtualFile;
}
@@ -95,6 +95,7 @@ public class ResourceBundleStructureViewComponent extends PropertiesGroupingStru
return PsiFile.EMPTY_ARRAY;
}
@Override
public Object getData(final String dataId) {
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
return new ResourceBundleAsVirtualFile(myResourceBundle);
@@ -183,6 +184,7 @@ public class ResourceBundleStructureViewComponent extends PropertiesGroupingStru
return super.getData(dataId);
}
@Override
protected boolean showScrollToFromSourceActions() {
return false;
}
@@ -225,6 +227,7 @@ public class ResourceBundleStructureViewComponent extends PropertiesGroupingStru
}
}
@Override
@NonNls
public String getHelpID() {
return "editing.propertyFile.bundleEditor";
@@ -107,10 +107,12 @@ public class IncompletePropertyInspectionOptionsPanel {
}
private class MyListModel extends AbstractListModel {
@Override
public int getSize() {
return mySuffixes.size();
}
@Override
public Object getElementAt(int index) {
return ArrayUtil.toStringArray(mySuffixes)[index];
}
@@ -36,6 +36,7 @@ import java.util.Arrays;
public class ResourceBundleDeleteProvider implements DeleteProvider {
private static final Logger LOG = Logger.getInstance(ResourceBundleDeleteProvider.class);
@Override
public void deleteElement(@NotNull DataContext dataContext) {
final ResourceBundle[] resourceBundles = ResourceBundle.ARRAY_DATA_KEY.getData(dataContext);
if (resourceBundles != null && resourceBundles.length != 0) {
@@ -57,6 +58,7 @@ public class ResourceBundleDeleteProvider implements DeleteProvider {
}
}
@Override
public boolean canDeleteElement(@NotNull DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
return project != null;
@@ -42,6 +42,7 @@ public class ResourceBundleGrouper implements TreeStructureProvider, DumbAware {
myProject = project;
}
@Override
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (parent instanceof ResourceBundleNode) return children;
@@ -114,6 +115,7 @@ public class ResourceBundleGrouper implements TreeStructureProvider, DumbAware {
});
}
@Override
public Object getData(Collection<AbstractTreeNode> selected, String dataName) {
if (selected == null) return null;
if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataName)) {
@@ -40,6 +40,7 @@ public class ResourceBundleMoveProvider extends MoveHandlerDelegate {
return ResourceBundle.ARRAY_DATA_KEY.getData(dataContext) != null;
}
@Override
public boolean canMove(PsiElement[] elements, @Nullable final PsiElement targetContainer) {
return false;
}
@@ -57,6 +57,7 @@ public class ResourceBundleNode extends ProjectViewNode<ResourceBundle> implemen
super(project, resourceBundle, settings);
}
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
List<PropertiesFile> propertiesFiles = getValue().getPropertiesFiles();
@@ -68,6 +69,7 @@ public class ResourceBundleNode extends ProjectViewNode<ResourceBundle> implemen
return children;
}
@Override
public boolean contains(@NotNull VirtualFile file) {
if (!file.isValid()) return false;
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
@@ -75,6 +77,7 @@ public class ResourceBundleNode extends ProjectViewNode<ResourceBundle> implemen
return propertiesFile != null && getValue().getPropertiesFiles().contains(propertiesFile);
}
@Override
public VirtualFile getVirtualFile() {
final List<PropertiesFile> list = getValue().getPropertiesFiles();
if (!list.isEmpty()) {
@@ -83,28 +86,34 @@ public class ResourceBundleNode extends ProjectViewNode<ResourceBundle> implemen
return null;
}
@Override
public void update(PresentationData presentation) {
presentation.setIcon(AllIcons.Nodes.ResourceBundle);
presentation.setPresentableText(PropertiesBundle.message("project.view.resource.bundle.tree.node.text", getValue().getBaseName()));
}
@Override
public boolean canNavigateToSource() {
return true;
}
@Override
public boolean canNavigate() {
return true;
}
@Override
public void navigate(final boolean requestFocus) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(getProject(), new ResourceBundleAsVirtualFile(getValue()));
FileEditorManager.getInstance(getProject()).openTextEditor(descriptor, requestFocus);
}
@Override
public boolean isSortByFirstChild() {
return true;
}
@Override
public Comparable getTypeSortKey() {
return new PsiFileNode.ExtensionSortKey(StdFileTypes.PROPERTIES.getDefaultExtension());
}
@@ -36,10 +36,12 @@ import java.util.List;
* @author yole
*/
public class PropertiesFilesSafeDeleteProcessor implements SafeDeleteProcessorDelegate {
@Override
public boolean handlesElement(final PsiElement element) {
return element instanceof PropertiesFile;
}
@Override
public NonCodeUsageSearchInfo findUsages(@NotNull final PsiElement element, @NotNull final PsiElement[] allElementsToDelete, @NotNull final List<UsageInfo> result) {
PropertiesFile file = (PropertiesFile) element;
List<PsiElement> elements = new ArrayList<>();
@@ -53,23 +55,28 @@ public class PropertiesFilesSafeDeleteProcessor implements SafeDeleteProcessorDe
return new NonCodeUsageSearchInfo(SafeDeleteProcessor.getDefaultInsideDeletedCondition(allElementsToDelete), elements);
}
@Override
public Collection<PsiElement> getElementsToSearch(@NotNull final PsiElement element, @NotNull final Collection<PsiElement> allElementsToDelete) {
return Collections.singletonList(element);
}
@Override
public Collection<PsiElement> getAdditionalElementsToDelete(@NotNull final PsiElement element, @NotNull final Collection<PsiElement> allElementsToDelete,
final boolean askUser) {
return null;
}
@Override
public Collection<String> findConflicts(@NotNull final PsiElement element, @NotNull final PsiElement[] allElementsToDelete) {
return null;
}
@Override
public UsageInfo[] preprocessUsages(final Project project, final UsageInfo[] usages) {
return usages;
}
@Override
public void prepareForDeletion(final PsiElement element) throws IncorrectOperationException {
}
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
public class PropertiesRefactoringSupportProvider extends RefactoringSupportProvider {
@Override
public boolean isSafeDeleteAvailable(@NotNull PsiElement element) {
return true;
}
@@ -35,11 +35,13 @@ import java.util.List;
import java.util.Map;
public class RenamePropertyProcessor extends RenamePsiElementProcessor {
@Override
public boolean canProcessElement(@NotNull final PsiElement element) {
return element instanceof IProperty ||
(element instanceof PomTargetPsiElement && ((PomTargetPsiElement)element).getTarget() instanceof XmlProperty);
}
@Override
public void prepareRenaming(final PsiElement element, final String newName,
final Map<PsiElement, String> allRenames) {
ResourceBundle resourceBundle = PropertiesImplUtil.getProperty(element).getPropertiesFile().getResourceBundle();
@@ -115,10 +115,12 @@ public class ResourceBundleRenameUtil {
myResourceBundle = resourceBundle;
}
@Override
public boolean checkInput(String inputString) {
return inputString.indexOf(File.separatorChar) < 0 && inputString.indexOf('/') < 0;
}
@Override
public boolean canClose(final String inputString) {
final List<PropertiesFile> propertiesFiles = myResourceBundle.getPropertiesFiles();
for (PropertiesFile propertiesFile : propertiesFiles) {
@@ -57,16 +57,19 @@ public class CreatePropertyFix implements IntentionAction, LocalQuickFix {
myPropertiesFiles = propertiesFiles;
}
@Override
@NotNull
public String getName() {
return NAME;
}
@Override
@NotNull
public String getFamilyName() {
return getText();
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement psiElement = descriptor.getPsiElement();
if (isAvailable(project, null, null)) {
@@ -74,15 +77,18 @@ public class CreatePropertyFix implements IntentionAction, LocalQuickFix {
}
}
@Override
@NotNull
public String getText() {
return NAME;
}
@Override
public boolean isAvailable(@NotNull Project project, @Nullable Editor editor, @Nullable PsiFile file) {
return myElement != null && myElement.retrieve() != null;
}
@Override
public void invoke(@NotNull final Project project, @Nullable Editor editor, @NotNull PsiFile file) {
invokeAction(project, file, myElement.retrieve(), myKey, myPropertiesFiles);
}
@@ -97,18 +103,22 @@ public class CreatePropertyFix implements IntentionAction, LocalQuickFix {
if (ApplicationManager.getApplication().isUnitTestMode()) {
model = new I18nizeQuickFixModel() {
@Override
public String getValue() {
return "";
}
@Override
public String getKey() {
return dialogCustomization.getSuggestedName();
}
@Override
public boolean hasValidData() {
return true;
}
@Override
public Collection<PropertiesFile> getAllPropertiesFiles() {
return propertiesFiles;
}
@@ -160,6 +170,7 @@ public class CreatePropertyFix implements IntentionAction, LocalQuickFix {
}, CodeInsightBundle.message("quickfix.i18n.command.name"), project));
}
@Override
public boolean startInWriteAction() {
return false;
}
@@ -33,6 +33,7 @@ public class PropertiesFileStructureViewComponent extends PropertiesGroupingStru
myPropertiesFile = propertiesFile;
}
@Override
public Object getData(String dataId) {
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
return myPropertiesFile.getVirtualFile();
@@ -30,9 +30,11 @@ import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
public class PropertiesStructureViewBuilderFactory implements PsiStructureViewFactory {
@Override
@NotNull
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
return new StructureViewBuilder() {
@Override
@NotNull
public StructureView createStructureView(FileEditor fileEditor, @NotNull Project project) {
return new PropertiesFileStructureViewComponent(project, (PropertiesFileImpl)psiFile, fileEditor);
@@ -41,30 +41,36 @@ public class PropertiesColorsPage implements ColorSettingsPage {
}
}
@Override
@NotNull
public String getDisplayName() {
return OptionsBundle.message("properties.options.display.name");
}
@Override
public Icon getIcon() {
return AllIcons.FileTypes.Properties;
}
@Override
@NotNull
public AttributesDescriptor[] getAttributeDescriptors() {
return ATTRS;
}
@Override
@NotNull
public ColorDescriptor[] getColorDescriptors() {
return ColorDescriptor.EMPTY_ARRAY;
}
@Override
@NotNull
public SyntaxHighlighter getHighlighter() {
return new PropertiesHighlighter();
}
@Override
@NotNull
public String getDemoText() {
return "# Comment on keys and values\n" +
@@ -74,6 +80,7 @@ public class PropertiesColorsPage implements ColorSettingsPage {
;
}
@Override
public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
return null;
}