aa74c15168977883d24892df7dba780c943030da
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
.vcs
.changes
.PsiChangeTracker
;
23 import com
.intellij
.openapi
.vfs
.LocalFileSystem
;
24 import com
.intellij
.openapi
.vfs
.VirtualFile
;
25 import com
.intellij
.psi
.PsiElement
;
26 import com
.intellij
.psi
.PsiFile
;
27 import com
.intellij
.psi
.PsiManager
;
28 import com
.intellij
.psi
.PsiNamedElement
;
29 import com
.intellij
.psi
.util
.PsiFilter
;
30 import com
.intellij
.uml
.UmlChangeTracker
;
31 import org
.jetbrains
.annotations
.Nullable
;
34 import java
.util
.HashMap
;
38 * @author Konstantin Bulenkov
40 public class PropertyChangeTracker
extends UmlChangeTracker
<PropertiesFile
, Property
, PsiElement
> {
41 private static final PsiFilter
<Property
> PROPERTY_FILTER
=
42 new PsiFilter
<Property
>(Property
.class) {
44 public boolean areEquivalent(Property e1
, Property e2
) {
45 final String key1
= e1
.getKey();
46 return key1
!= null && key1
.equals(e2
.getKey());
49 private HashMap
<PropertiesFile
, FileStatus
> map
;
51 public PropertyChangeTracker(Project project
, @Nullable PsiFile before
, @Nullable PsiFile after
) {
52 super(project
, before
, after
);
56 public PsiFilter
<PropertiesFile
>[] getNodeFilters() {
57 return new PsiFilter
[] {new PsiFilter(PropertiesFile
.class)};
61 public PsiFilter
<Property
>[] getNodeContentFilters() {
62 return new PsiFilter
[] {PROPERTY_FILTER
};
66 public Map
<PropertiesFile
, FileStatus
> getNodeElements() {
68 map
= new HashMap
<PropertiesFile
, FileStatus
>();
69 for (PsiFilter
<PropertiesFile
> filter
: getNodeFilters()) {
70 map
.putAll(PsiChangeTracker
.getElementsChanged(getAfter(), getBefore(), filter
));
77 public RelationshipInfo
[] getRelationships() {
78 return RelationshipInfo
.EMPTY
;
82 public PsiNamedElement
findElementByFQN(Project project
, String fqn
) {
83 final File file
= new File(fqn
);
85 final VirtualFile vf
= LocalFileSystem
.getInstance().findFileByIoFile(file
);
87 final PsiFile psiFile
= PsiManager
.getInstance(project
).findFile(vf
);
88 if (psiFile
instanceof PropertiesFile
) {
97 public String
getPresentableName(PsiNamedElement e
) {
98 return e
instanceof Property ?
((Property
)e
).getKey() : super.getPresentableName(e
);