From 75842e14c9b0ff86ca4b030498e9b4758b2add00 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 12 Feb 2010 18:16:05 +0300 Subject: [PATCH] Properties support --- plugins/properties/properties.iml | 1 + plugins/properties/src/META-INF/plugin.xml | 1 + plugins/properties/src/META-INF/uml.xml | 6 ++ .../properties/uml/PropertyChangeProvider.java | 39 ++++++++ .../lang/properties/uml/PropertyChangeTracker.java | 100 +++++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 plugins/properties/src/META-INF/uml.xml create mode 100644 plugins/properties/src/com/intellij/lang/properties/uml/PropertyChangeProvider.java create mode 100644 plugins/properties/src/com/intellij/lang/properties/uml/PropertyChangeTracker.java diff --git a/plugins/properties/properties.iml b/plugins/properties/properties.iml index 60abeffd22..622bbd2918 100644 --- a/plugins/properties/properties.iml +++ b/plugins/properties/properties.iml @@ -17,6 +17,7 @@ + diff --git a/plugins/properties/src/META-INF/plugin.xml b/plugins/properties/src/META-INF/plugin.xml index 1e6f414ba1..7edea916f9 100644 --- a/plugins/properties/src/META-INF/plugin.xml +++ b/plugins/properties/src/META-INF/plugin.xml @@ -3,6 +3,7 @@ Properties Support com.intellij.modules.xml com.intellij.spellchecker + com.intellij.uml This plugin enables smart editing of properties files. diff --git a/plugins/properties/src/META-INF/uml.xml b/plugins/properties/src/META-INF/uml.xml new file mode 100644 index 0000000000..67f22df850 --- /dev/null +++ b/plugins/properties/src/META-INF/uml.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/plugins/properties/src/com/intellij/lang/properties/uml/PropertyChangeProvider.java b/plugins/properties/src/com/intellij/lang/properties/uml/PropertyChangeProvider.java new file mode 100644 index 0000000000..b8c2ea7964 --- /dev/null +++ b/plugins/properties/src/com/intellij/lang/properties/uml/PropertyChangeProvider.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.lang.properties.uml; + +import com.intellij.lang.properties.PropertiesFileType; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import com.intellij.uml.UmlChangeTracker; +import com.intellij.uml.UmlChangesProvider; +import org.jetbrains.annotations.Nullable; + +/** + * @author Konstantin Bulenkov + */ +public class PropertyChangeProvider extends UmlChangesProvider{ + @Override + public boolean accept(FileType type) { + return type == PropertiesFileType.FILE_TYPE; + } + + @Override + public UmlChangeTracker createTracker(Project project, @Nullable PsiFile before, @Nullable PsiFile after) { + return new PropertyChangeTracker(project, before, after); + } +} diff --git a/plugins/properties/src/com/intellij/lang/properties/uml/PropertyChangeTracker.java b/plugins/properties/src/com/intellij/lang/properties/uml/PropertyChangeTracker.java new file mode 100644 index 0000000000..aa74c15168 --- /dev/null +++ b/plugins/properties/src/com/intellij/lang/properties/uml/PropertyChangeTracker.java @@ -0,0 +1,100 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.lang.properties.uml; + +import com.intellij.lang.properties.psi.PropertiesFile; +import com.intellij.lang.properties.psi.Property; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.FileStatus; +import com.intellij.openapi.vcs.changes.PsiChangeTracker; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.PsiNamedElement; +import com.intellij.psi.util.PsiFilter; +import com.intellij.uml.UmlChangeTracker; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Konstantin Bulenkov + */ +public class PropertyChangeTracker extends UmlChangeTracker { + private static final PsiFilter PROPERTY_FILTER = + new PsiFilter(Property.class) { + @Override + public boolean areEquivalent(Property e1, Property e2) { + final String key1 = e1.getKey(); + return key1 != null && key1.equals(e2.getKey()); + } + }; + private HashMap map; + + public PropertyChangeTracker(Project project, @Nullable PsiFile before, @Nullable PsiFile after) { + super(project, before, after); + } + + @Override + public PsiFilter[] getNodeFilters() { + return new PsiFilter[] {new PsiFilter(PropertiesFile.class)}; + } + + @Override + public PsiFilter[] getNodeContentFilters() { + return new PsiFilter[] {PROPERTY_FILTER}; + } + + @Override + public Map getNodeElements() { + if (map == null) { + map = new HashMap(); + for (PsiFilter filter : getNodeFilters()) { + map.putAll(PsiChangeTracker.getElementsChanged(getAfter(), getBefore(), filter)); + } + } + return map; + } + + @Override + public RelationshipInfo[] getRelationships() { + return RelationshipInfo.EMPTY; + } + + @Override + public PsiNamedElement findElementByFQN(Project project, String fqn) { + final File file = new File(fqn); + if (file.exists()) { + final VirtualFile vf = LocalFileSystem.getInstance().findFileByIoFile(file); + if (vf != null) { + final PsiFile psiFile = PsiManager.getInstance(project).findFile(vf); + if (psiFile instanceof PropertiesFile) { + return psiFile; + } + } + } + return null; + } + + @Override + public String getPresentableName(PsiNamedElement e) { + return e instanceof Property ? ((Property)e).getKey() : super.getPresentableName(e); + } +} -- 2.11.4.GIT