Reference inside <relativePath>../pom.xml</relativePath> refers to <xs:element name...
authorSergey Evdokimov <sergey.evdokimov@jetbrains.com>
Tue, 3 Sep 2013 09:25:32 +0000 (13:25 +0400)
committerSergey Evdokimov <sergey.evdokimov@jetbrains.com>
Tue, 3 Sep 2013 09:26:05 +0000 (13:26 +0400)
+review CR-IC @Dmitriy.Avdeev

platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/PsiDelegateReference.java [new file with mode: 0644]
platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/PsiSoftReferenceDecorator.java [new file with mode: 0644]
plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenModelValidationTest.java
xml/impl/src/com/intellij/xml/util/XmlEnumeratedValueReferenceProvider.java

diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/PsiDelegateReference.java b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/PsiDelegateReference.java
new file mode 100644 (file)
index 0000000..9d2d8f1
--- /dev/null
@@ -0,0 +1,68 @@
+package com.intellij.psi.impl.source.resolve.reference.impl;
+
+import com.intellij.openapi.util.TextRange;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiReference;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Sergey Evdokimov
+ */
+public class PsiDelegateReference implements PsiReference {
+
+  private final PsiReference myDelegate;
+
+  public PsiDelegateReference(@NotNull PsiReference delegate) {
+    myDelegate = delegate;
+  }
+
+  @Override
+  public PsiElement getElement() {
+    return myDelegate.getElement();
+  }
+
+  @Override
+  public TextRange getRangeInElement() {
+    return myDelegate.getRangeInElement();
+  }
+
+  @Nullable
+  @Override
+  public PsiElement resolve() {
+    return myDelegate.resolve();
+  }
+
+  @NotNull
+  @Override
+  public String getCanonicalText() {
+    return myDelegate.getCanonicalText();
+  }
+
+  @Override
+  public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
+    return myDelegate.handleElementRename(newElementName);
+  }
+
+  @Override
+  public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
+    return myDelegate.bindToElement(element);
+  }
+
+  @Override
+  public boolean isReferenceTo(PsiElement element) {
+    return myDelegate.isReferenceTo(element);
+  }
+
+  @NotNull
+  @Override
+  public Object[] getVariants() {
+    return myDelegate.getVariants();
+  }
+
+  @Override
+  public boolean isSoft() {
+    return myDelegate.isSoft();
+  }
+}
diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/PsiSoftReferenceDecorator.java b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/PsiSoftReferenceDecorator.java
new file mode 100644 (file)
index 0000000..b89c13e
--- /dev/null
@@ -0,0 +1,32 @@
+package com.intellij.psi.impl.source.resolve.reference.impl;
+
+import com.intellij.psi.PsiReference;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Sergey Evdokimov
+ */
+public class PsiSoftReferenceDecorator extends PsiDelegateReference {
+
+  private final boolean mySoft;
+
+  public PsiSoftReferenceDecorator(@NotNull PsiReference delegate, boolean soft) {
+    super(delegate);
+    mySoft = soft;
+  }
+
+  @Override
+  public boolean isSoft() {
+    return mySoft;
+  }
+
+  public static PsiReference[] create(PsiReference[] refs, boolean soft) {
+    PsiReference[] res = new PsiReference[refs.length];
+
+    for (int i = 0; i < refs.length; i++) {
+      res[i] = new PsiSoftReferenceDecorator(refs[i], soft);
+    }
+
+    return res;
+  }
+}
index 84262aaa7fbe22a741782437c8f54830a347bffa..c7e271838fbd21c3659733d88e0a8e2a647b1301 100644 (file)
@@ -17,8 +17,8 @@ package org.jetbrains.idea.maven.dom;
 
 import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
-
-import java.io.IOException;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
 
 public class MavenModelValidationTest extends MavenDomWithIndicesTestCase {
   @Override
@@ -44,6 +44,26 @@ public class MavenModelValidationTest extends MavenDomWithIndicesTestCase {
     assertCompletionVariants(modulePom, "src", "module1", "pom.xml");
   }
 
+  public void testRelativePathDefaultValue() throws Exception {
+    createProjectPom("<groupId>test</groupId>" +
+                     "<artifactId>project</artifactId>" +
+                     "<version>1</version>");
+
+    VirtualFile modulePom = createModulePom("module1",
+                                            "<groupId>test</groupId>" +
+                                            "<artifactId>module1</artifactId>" +
+                                            "<version>1</version>" +
+                                            "<parent>" +
+                                            "<relativePath>../pom.<caret>xml</relativePath>" +
+                                            "</parent>");
+
+    configTest(modulePom);
+    PsiElement elementAtCaret = myFixture.getElementAtCaret();
+
+    assertInstanceOf(elementAtCaret, PsiFile.class);
+    assertEquals(((PsiFile)elementAtCaret).getVirtualFile(), myProjectPom);
+  }
+
   public void testUnderstandingProjectSchemaWithoutNamespace() throws Exception {
     VfsUtil.saveText(myProjectPom,
                      "<project>" +
index c1309a54f1d2f84431394ef6deb7e4929273ba95..3c05af67b483049235ab49f683d16ed58565e654 100644 (file)
@@ -18,8 +18,12 @@ package com.intellij.xml.util;
 import com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor;
 import com.intellij.openapi.util.Key;
 import com.intellij.psi.*;
+import com.intellij.psi.impl.source.resolve.reference.impl.PsiSoftReferenceDecorator;
 import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
-import com.intellij.psi.xml.*;
+import com.intellij.psi.xml.XmlAttribute;
+import com.intellij.psi.xml.XmlElement;
+import com.intellij.psi.xml.XmlTag;
+import com.intellij.psi.xml.XmlText;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.ProcessingContext;
 import com.intellij.xml.impl.XmlEnumerationDescriptor;
@@ -56,7 +60,8 @@ public class XmlEnumeratedValueReferenceProvider<T extends PsiElement> extends P
           enumerationDescriptor.isEnumerated((XmlElement)element) ||
           unquotedValue.equals(enumerationDescriptor.getDefaultValue())) { // todo case insensitive
         //noinspection unchecked
-        return enumerationDescriptor.getValueReferences((XmlElement)element, unquotedValue);
+        //return enumerationDescriptor.getValueReferences((XmlElement)element, unquotedValue);
+        return PsiSoftReferenceDecorator.create(enumerationDescriptor.getValueReferences((XmlElement)element, unquotedValue), true);
       }
     }
     return PsiReference.EMPTY_ARRAY;