diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/MavenDomBuild.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/MavenDomBuild.java index db1282c8b0a5..964ae827236e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/MavenDomBuild.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/model/MavenDomBuild.java @@ -25,6 +25,7 @@ import com.intellij.util.xml.GenericDomValue; import com.intellij.util.xml.Required; import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.maven.dom.references.MavenDirectoryPathReferenceConverter; +import org.jetbrains.idea.maven.dom.references.MavenSourceDirectoryConverter; /** * http://maven.apache.org/POM/4.0.0:Build interface. @@ -46,7 +47,7 @@ public interface MavenDomBuild extends MavenDomBuildBase { */ @NotNull @Required(value = false, nonEmpty = true) - @Convert(value = MavenDirectoryPathReferenceConverter.class, soft = false) + @Convert(value = MavenSourceDirectoryConverter.class, soft = false) GenericDomValue getSourceDirectory(); /** @@ -60,7 +61,7 @@ public interface MavenDomBuild extends MavenDomBuildBase { */ @NotNull @Required(value = false, nonEmpty = true) - @Convert(value = MavenDirectoryPathReferenceConverter.class, soft = false) + @Convert(value = MavenSourceDirectoryConverter.class, soft = false) GenericDomValue getScriptSourceDirectory(); /** @@ -74,7 +75,7 @@ public interface MavenDomBuild extends MavenDomBuildBase { */ @NotNull @Required(value = false, nonEmpty = true) - @Convert(value = MavenDirectoryPathReferenceConverter.class, soft = false) + @Convert(value = MavenSourceDirectoryConverter.class, soft = false) GenericDomValue getTestSourceDirectory(); /** diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/references/MavenSourceDirectoryConverter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/references/MavenSourceDirectoryConverter.java new file mode 100644 index 000000000000..07a78f5166c2 --- /dev/null +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/references/MavenSourceDirectoryConverter.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2013 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.references; + +import com.intellij.util.xml.DomElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.idea.maven.dom.converters.MavenDomSoftAwareConverter; +import org.jetbrains.idea.maven.dom.model.MavenDomBuild; +import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel; + +/** + * @author Sergey Evdokimov + */ +public class MavenSourceDirectoryConverter extends MavenDirectoryPathReferenceConverter implements MavenDomSoftAwareConverter { + @Override + public boolean isSoft(@NotNull DomElement element) { + DomElement buildElement = element.getParent(); + if (!(buildElement instanceof MavenDomBuild)) { + return false; + } + + DomElement mavenProject = buildElement.getParent(); + if (!(mavenProject instanceof MavenDomProjectModel)) { + return false; + } + + return "pom".equals(((MavenDomProjectModel)mavenProject).getPackaging().getStringValue()); + } +} diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomSoftReferencesInParentTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomSoftReferencesInParentTest.java new file mode 100644 index 000000000000..2ce4d7e638d9 --- /dev/null +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomSoftReferencesInParentTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2000-2013 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 + */ +public class MavenDomSoftReferencesInParentTest extends MavenDomTestCase { + + public void testDoNotHighlightSourceDirectoryInParentPom() throws Throwable { + importProject("test\n" + + "project\n" + + "1\n" + + + "pom\n" + + "\n" + + "dsfsfd/sdfsdf\n" + + "qwqwq/weqweqw\n" + + "dfsdf/fsdf\n" + + "\n" + + ""); + + checkHighlighting(); + } + + public void testHighlightSourceDirectory() throws Throwable { + importProject("test\n" + + "project\n" + + "1\n" + + + "jar\n" + + + "\n" + + "foo1\n" + + "foo2\n" + + "foo3\n" + + "\n" + + ""); + + createProjectPom("test\n" + + "project\n" + + "1\n" + + + "jar\n" + + + "\n" + + //"foo1\n" + + //"foo2\n" + + //"foo3\n" + + + "foo1\n" + + "foo2\n" + + "foo3\n" + + "\n" + + ""); + + checkHighlighting(); + } + + +}