mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-53817 (Environment variable is red (not set) despite the fact it is used in profile <activation>.)
This commit is contained in:
+31
-3
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.xml.XmlDocument;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
@@ -62,12 +63,12 @@ public class MavenPropertyPsiReference extends MavenPsiReference {
|
||||
|
||||
protected final MavenDomProjectModel myProjectDom;
|
||||
protected final MavenProject myMavenProject;
|
||||
private final boolean mySoft;
|
||||
private Boolean mySoft;
|
||||
|
||||
public MavenPropertyPsiReference(MavenProject mavenProject, PsiElement element, String text, TextRange range, boolean isSoft) {
|
||||
super(element, text, range);
|
||||
myMavenProject = mavenProject;
|
||||
mySoft = isSoft;
|
||||
mySoft = isSoft ? true : null;
|
||||
myProjectDom = MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
|
||||
}
|
||||
|
||||
@@ -430,7 +431,34 @@ public class MavenPropertyPsiReference extends MavenPsiReference {
|
||||
|
||||
@Override
|
||||
public boolean isSoft() {
|
||||
return mySoft;
|
||||
Boolean res = mySoft;
|
||||
if (res == null) {
|
||||
XmlTag xmlTag = PsiTreeUtil.getParentOfType(getElement(), XmlTag.class);
|
||||
while (xmlTag != null) {
|
||||
if (xmlTag.getName().equals("profile")) {
|
||||
XmlTag activation = xmlTag.findFirstSubTag("activation");
|
||||
if (activation != null) {
|
||||
for (XmlTag propertyTag : activation.findSubTags("property")) {
|
||||
XmlTag nameTag = propertyTag.findFirstSubTag("name");
|
||||
if (nameTag != null) {
|
||||
if (nameTag.getValue().getTrimmedText().equals(myText)) {
|
||||
res = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
xmlTag = xmlTag.getParentTag();
|
||||
}
|
||||
|
||||
if (res == null) res = false;
|
||||
mySoft = res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private interface SchemaProcessor<T> {
|
||||
|
||||
@@ -194,11 +194,25 @@ public abstract class MavenDomTestCase extends MavenImportingTestCase {
|
||||
String text = VfsUtilCore.loadText(file);
|
||||
int index = text.indexOf(referenceText);
|
||||
assert index >= 0;
|
||||
|
||||
|
||||
assert text.indexOf(referenceText, index + referenceText.length()) == -1 : "Reference text '" + referenceText + "' occurs more than one times";
|
||||
|
||||
|
||||
return getReferenceAt(file, index);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected PsiReference getReference(VirtualFile file, @NotNull String referenceText, int index) throws IOException {
|
||||
String text = VfsUtilCore.loadText(file);
|
||||
int k = -1;
|
||||
|
||||
do {
|
||||
k = text.indexOf(referenceText, k + 1);
|
||||
assert k >= 0 : index;
|
||||
}
|
||||
while (--index >= 0);
|
||||
|
||||
return getReferenceAt(file, k);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected PsiElement resolveReference(VirtualFile file, @NotNull String referenceText) throws IOException {
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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 org.jetbrains.idea.maven.dom
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
class MavenPropertyInActivationSectionTest extends MavenDomTestCase {
|
||||
|
||||
public void testResolvePropertyFromActivationSection() throws IOException {
|
||||
importProject("""
|
||||
<groupId>example</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<name>example</name>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>glassfish-env-path</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env.GLASSFISH_HOME_123</name>
|
||||
</property>
|
||||
</activation>
|
||||
|
||||
<properties>
|
||||
<glassfish.home.path>\${env.GLASSFISH_HOME_123}</glassfish.home.path>
|
||||
</properties>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<aaa>\${env.GLASSFISH_HOME_123}</aaa>
|
||||
</properties>
|
||||
""");
|
||||
|
||||
assert getReference(myProjectPom, "env.GLASSFISH_HOME_123", 1).isSoft()
|
||||
assert !getReference(myProjectPom, "env.GLASSFISH_HOME_123", 2).isSoft()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user