From efa7e985f9d26f696a53f5aedbdc17ad36d090c1 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 2 Apr 2007 19:30:49 +0400 Subject: [PATCH] IDEADEV-15674: honor '$' escapes in ant script --- .../codeInsight/daemon/AntHighlightingTest.java | 5 +++++ .../intellij/lang/ant/psi/impl/AntProjectImpl.java | 13 ++++++++----- .../lang/ant/psi/impl/AntStructuredElementImpl.java | 12 +++++++++++- .../providers/AntPropertyReferenceProvider.java | 5 +++++ .../daemonCodeAnalyzer/ant/EscapedProperties.xml | 5 +++++ 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 testData/codeInsight/daemonCodeAnalyzer/ant/EscapedProperties.xml diff --git a/codeInsight/tests/com/intellij/codeInsight/daemon/AntHighlightingTest.java b/codeInsight/tests/com/intellij/codeInsight/daemon/AntHighlightingTest.java index 9f15bff6bd96..555c88a1959f 100644 --- a/codeInsight/tests/com/intellij/codeInsight/daemon/AntHighlightingTest.java +++ b/codeInsight/tests/com/intellij/codeInsight/daemon/AntHighlightingTest.java @@ -64,6 +64,11 @@ public class AntHighlightingTest extends DaemonAnalyzerTestCase { doDoTest(true, false); } + public void testEscapedProperties() throws Exception { + configureByFiles(null, new VirtualFile[]{getVirtualFile(BASE_PATH + "/" + getTestName(false) + ".xml")}); + doDoTest(true, false); + } + public void testPropertiesFromFile() throws Exception { doTest(); } diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntProjectImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntProjectImpl.java index daca05c5c9c4..1eb47833d2c0 100644 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntProjectImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntProjectImpl.java @@ -238,12 +238,15 @@ public class AntProjectImpl extends AntStructuredElementImpl implements AntProje private void registerImportsDependentProperties(final String fileName) { int startProp = 0; while ((startProp = fileName.indexOf("${", startProp)) >= 0) { - final int endProp = fileName.indexOf('}', startProp + 2); - if (endProp > startProp + 2) { - if (myImportsDependentProperties == null) { - myImportsDependentProperties = new HashSet(); + if (startProp == 0 || fileName.charAt(startProp - 1) != '$') { + // if the '$' is not escaped + final int endProp = fileName.indexOf('}', startProp + 2); + if (endProp > startProp + 2) { + if (myImportsDependentProperties == null) { + myImportsDependentProperties = new HashSet(); + } + myImportsDependentProperties.add(fileName.substring(startProp + 2, endProp)); } - myImportsDependentProperties.add(fileName.substring(startProp + 2, endProp)); } startProp += 2; } diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntStructuredElementImpl.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntStructuredElementImpl.java index 23efe29542bf..d6eb7f685935 100644 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntStructuredElementImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/psi/impl/AntStructuredElementImpl.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.regex.Pattern; public class AntStructuredElementImpl extends AntElementImpl implements AntStructuredElement { @@ -45,6 +46,7 @@ public class AntStructuredElementImpl extends AntElementImpl implements AntStruc protected volatile boolean myInGettingChildren; @NonNls private static final String ANTLIB_NS_PREFIX = "antlib:"; @NonNls private static final String ANTLIB_XML = "antlib.xml"; + private static final Pattern $$_PATTERN = Pattern.compile("\\$\\$"); public AntStructuredElementImpl(final AntElement parent, final XmlTag sourceElement, @NonNls final String nameElementAttribute) { super(parent, sourceElement); @@ -261,7 +263,7 @@ public class AntStructuredElementImpl extends AntElementImpl implements AntStruc } } else if (value.indexOf('$') < 0){ - return value; + return value; // heuristics } } return null; @@ -409,6 +411,11 @@ public class AntStructuredElementImpl extends AntElementImpl implements AntStruc elementStack.add(this); int startProp = 0; while ((startProp = value.indexOf("${", startProp)) >= 0) { + if (startProp > 0 && value.charAt(startProp - 1) == '$') { + // the '$' is escaped + startProp += 2; + continue; + } final int endProp = value.indexOf('}', startProp + 2); if (endProp <= startProp + 2) { startProp += 2; @@ -448,6 +455,9 @@ public class AntStructuredElementImpl extends AntElementImpl implements AntStruc } } } + if (value.indexOf("$$") >= 0) { + return $$_PATTERN.matcher(value).replaceAll("\\$"); + } return value; } diff --git a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntPropertyReferenceProvider.java b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntPropertyReferenceProvider.java index 6d3fc958ff23..b8447b3bfe6a 100644 --- a/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntPropertyReferenceProvider.java +++ b/plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/providers/AntPropertyReferenceProvider.java @@ -73,6 +73,11 @@ public class AntPropertyReferenceProvider extends GenericReferenceProvider { int startIndex; int endIndex = -1; while ((startIndex = value.indexOf("${", endIndex + 1)) > endIndex) { + if (startIndex > 0 && value.charAt(startIndex - 1) == '$') { + // the '$' is escaped + endIndex = startIndex + 1; + continue; + } startIndex += 2; endIndex = startIndex; int nestedBrackets = 0; diff --git a/testData/codeInsight/daemonCodeAnalyzer/ant/EscapedProperties.xml b/testData/codeInsight/daemonCodeAnalyzer/ant/EscapedProperties.xml new file mode 100644 index 000000000000..5ca95c2e7d75 --- /dev/null +++ b/testData/codeInsight/daemonCodeAnalyzer/ant/EscapedProperties.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file