mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Properties support
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
<orderEntry type="module" module-name="annotations" />
|
||||
<orderEntry type="module" module-name="testFramework" />
|
||||
<orderEntry type="module" module-name="spellchecker" />
|
||||
<orderEntry type="module" module-name="uml-api" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<name>Properties Support</name>
|
||||
<depends>com.intellij.modules.xml</depends>
|
||||
<depends optional="true" config-file="spellchecker.xml">com.intellij.spellchecker</depends>
|
||||
<depends optional="true" config-file="uml.xml">com.intellij.uml</depends>
|
||||
<description>
|
||||
This plugin enables smart editing of properties files.
|
||||
</description>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<!DOCTYPE idea-plugin PUBLIC "Plugin/DTD" "http://plugins.intellij.net/plugin.dtd">
|
||||
<idea-plugin url="http://www.jetbrains.com/idea">
|
||||
<extensions xmlns="com.intellij">
|
||||
<uml.changesProvider implementation="com.intellij.lang.properties.uml.PropertyChangeProvider"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<PropertiesFile, Property, PsiElement> {
|
||||
private static final PsiFilter<Property> PROPERTY_FILTER =
|
||||
new PsiFilter<Property>(Property.class) {
|
||||
@Override
|
||||
public boolean areEquivalent(Property e1, Property e2) {
|
||||
final String key1 = e1.getKey();
|
||||
return key1 != null && key1.equals(e2.getKey());
|
||||
}
|
||||
};
|
||||
private HashMap<PropertiesFile, FileStatus> map;
|
||||
|
||||
public PropertyChangeTracker(Project project, @Nullable PsiFile before, @Nullable PsiFile after) {
|
||||
super(project, before, after);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiFilter<PropertiesFile>[] getNodeFilters() {
|
||||
return new PsiFilter[] {new PsiFilter(PropertiesFile.class)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiFilter<Property>[] getNodeContentFilters() {
|
||||
return new PsiFilter[] {PROPERTY_FILTER};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<PropertiesFile, FileStatus> getNodeElements() {
|
||||
if (map == null) {
|
||||
map = new HashMap<PropertiesFile, FileStatus>();
|
||||
for (PsiFilter<PropertiesFile> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user