update copyright
[fedora-idea.git] / plugins / maven / src / main / java / org / jetbrains / idea / maven / dom / references / MavenFilteredPropertyPsiReference.java
blob01e421213a27cfc224c15df5f8e8f84b2965f306
1 /*
2 * Copyright 2000-2009 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 org.jetbrains.idea.maven.dom.references;
18 import com.intellij.lang.properties.psi.Property;
19 import com.intellij.openapi.util.TextRange;
20 import com.intellij.openapi.vfs.LocalFileSystem;
21 import com.intellij.openapi.vfs.VirtualFile;
22 import com.intellij.psi.PsiElement;
23 import com.intellij.psi.PsiFile;
24 import com.intellij.psi.PsiFileFactory;
25 import com.intellij.util.IncorrectOperationException;
26 import org.jetbrains.idea.maven.dom.MavenDomUtil;
27 import org.jetbrains.idea.maven.project.MavenProject;
29 import java.util.List;
31 public class MavenFilteredPropertyPsiReference extends MavenPropertyPsiReference {
32 public MavenFilteredPropertyPsiReference(MavenProject mavenProject, PsiElement element, String text, TextRange range, boolean isSoft) {
33 super(mavenProject, element, text, range, isSoft);
36 @Override
37 protected PsiElement doResolve() {
38 PsiElement result = super.doResolve();
39 if (result != null) return result;
41 for (String each : myMavenProject.getFilters()) {
42 VirtualFile file = LocalFileSystem.getInstance().findFileByPath(each);
43 if (file == null) continue;
44 Property property = MavenDomUtil.findProperty(myProject, file, myText);
45 if (property != null) return property;
48 return null;
51 @Override
52 protected void collectVariants(List<Object> result) {
53 super.collectVariants(result);
55 for (String each : myMavenProject.getFilters()) {
56 VirtualFile file = LocalFileSystem.getInstance().findFileByPath(each);
57 if (file == null) continue;
58 collectPropertiesFileVariants(MavenDomUtil.getPropertiesFile(myProject, file), "", result);
62 @Override
63 public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
64 String newText = myRange.replace(myElement.getText(), newElementName);
65 PsiFile psiFile = myElement.getContainingFile();
66 String newFileText = myElement.getTextRange().replace(psiFile.getText(), newText);
67 PsiFile f = PsiFileFactory.getInstance(myProject).createFileFromText("__" + psiFile.getName(), psiFile.getLanguage(), newFileText);
68 PsiElement el = f.findElementAt(myElement.getTextOffset());
69 return myElement.replace(el);