2 * Copyright 2000-2010 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.lang
.properties
.uml
;
18 import com
.intellij
.lang
.properties
.psi
.PropertiesFile
;
19 import com
.intellij
.lang
.properties
.psi
.Property
;
20 import com
.intellij
.openapi
.project
.Project
;
21 import com
.intellij
.openapi
.vcs
.FileStatus
;
22 import com
.intellij
.openapi
.vfs
.LocalFileSystem
;
23 import com
.intellij
.openapi
.vfs
.VirtualFile
;
24 import com
.intellij
.psi
.PsiElement
;
25 import com
.intellij
.psi
.PsiFile
;
26 import com
.intellij
.psi
.PsiManager
;
27 import com
.intellij
.psi
.PsiNamedElement
;
28 import com
.intellij
.psi
.util
.PsiFilter
;
29 import com
.intellij
.uml
.UmlChangeTracker
;
30 import org
.jetbrains
.annotations
.Nullable
;
33 import java
.util
.HashMap
;
37 * @author Konstantin Bulenkov
39 public class PropertyChangeTracker
extends UmlChangeTracker
<PropertiesFile
, Property
, PsiElement
> {
40 private static final PsiFilter
<Property
> PROPERTY_FILTER
=
41 new PsiFilter
<Property
>(Property
.class) {
43 public boolean areEquivalent(Property e1
, Property e2
) {
44 final String key1
= e1
.getKey();
45 return key1
!= null && key1
.equals(e2
.getKey());
48 private HashMap
<PropertiesFile
, FileStatus
> map
;
50 public PropertyChangeTracker(Project project
, @Nullable PsiFile before
, @Nullable PsiFile after
) {
51 super(project
, before
, after
);
55 public PsiFilter
<PropertiesFile
>[] getNodeFilters() {
56 return new PsiFilter
[] {new PsiFilter(PropertiesFile
.class)};
60 public PsiFilter
<Property
>[] getNodeContentFilters() {
61 return new PsiFilter
[] {PROPERTY_FILTER
};
65 public Map
<PropertiesFile
, FileStatus
> getNodeElements() {
67 map
= new HashMap
<PropertiesFile
, FileStatus
>();
68 final PropertiesFile after
= (PropertiesFile
)getAfter();
69 final PropertiesFile before
= (PropertiesFile
)getBefore();
71 map
.put(before
, FileStatus
.DELETED
);
72 } else if (before
== null) {
73 map
.put(after
, FileStatus
.ADDED
);
75 map
.put(after
, FileStatus
.MODIFIED
);
82 public RelationshipInfo
[] getRelationships() {
83 return RelationshipInfo
.EMPTY
;
87 public PsiNamedElement
findElementByFQN(Project project
, String fqn
) {
88 final File file
= new File(fqn
);
90 final VirtualFile vf
= LocalFileSystem
.getInstance().findFileByIoFile(file
);
92 final PsiFile psiFile
= PsiManager
.getInstance(project
).findFile(vf
);
93 if (psiFile
instanceof PropertiesFile
) {
102 public String
getPresentableName(PsiNamedElement e
) {
103 return e
instanceof Property ?
((Property
)e
).getKey() : super.getPresentableName(e
);