You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by go...@apache.org on 2013/04/24 22:29:09 UTC
git commit: [flex-falcon] - Added methods to IMXMLInstructionData for
getting the PI's target and content.
Updated Branches:
refs/heads/develop 6a164f397 -> d6fcec464
Added methods to IMXMLInstructionData for getting the PI's target and content.
getTarget()
getContent()
Added unit tests for these.
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/d6fcec46
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/d6fcec46
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/d6fcec46
Branch: refs/heads/develop
Commit: d6fcec46489f1daf788352d468bdcfd8568ffc91
Parents: 6a164f3
Author: Gordon Smith <go...@adobe.com>
Authored: Wed Apr 24 13:24:43 2013 -0700
Committer: Gordon Smith <go...@adobe.com>
Committed: Wed Apr 24 13:24:43 2013 -0700
----------------------------------------------------------------------
.../internal/mxml/MXMLInstructionDataTests.java | 40 +++++++++++++--
.../internal/mxml/MXMLInstructionData.java | 32 ++++++++++++
.../flex/compiler/mxml/IMXMLInstructionData.java | 19 ++++++-
3 files changed, 84 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d6fcec46/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
----------------------------------------------------------------------
diff --git a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
index 34ee37c..f1fe4ae 100644
--- a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
+++ b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/mxml/MXMLInstructionDataTests.java
@@ -50,29 +50,59 @@ public class MXMLInstructionDataTests extends MXMLUnitDataTests
};
IMXMLInstructionData instructionData = getMXMLInstructionData(code);
assertThat("getInstructionText", instructionData.getInstructionText(), is(code[0]));
+ assertThat("getTarget", instructionData.getTarget(), is(""));
+ assertThat("getContent", instructionData.getContent(), is(""));
}
@Test
- public void MXMLInstructionData_minimal()
+ public void MXMLInstructionData_minimal1()
{
String[] code = new String[]
{
- "<?xml?>"
+ "<?foo?>"
};
IMXMLInstructionData instructionData = getMXMLInstructionData(code);
assertThat("getInstructionText", instructionData.getInstructionText(), is(code[0]));
+ assertThat("getTarget", instructionData.getTarget(), is("foo"));
+ assertThat("getContent", instructionData.getContent(), is(""));
}
@Test
- public void MXMLInstructionData_typical()
+ public void MXMLInstructionData_minimal2()
{
String[] code = new String[]
{
- "<?xml version='1.0' encoding='utf-8'?>"
+ "<?foo ?>"
};
IMXMLInstructionData instructionData = getMXMLInstructionData(code);
assertThat("getInstructionText", instructionData.getInstructionText(), is(code[0]));
+ assertThat("getTarget", instructionData.getTarget(), is("foo"));
+ assertThat("getContent", instructionData.getContent(), is(""));
}
-
+ @Test
+ public void MXMLInstructionData_minimal3()
+ {
+ String[] code = new String[]
+ {
+ "<? foo?>"
+ };
+ IMXMLInstructionData instructionData = getMXMLInstructionData(code);
+ assertThat("getInstructionText", instructionData.getInstructionText(), is(code[0]));
+ assertThat("getTarget", instructionData.getTarget(), is(""));
+ assertThat("getContent", instructionData.getContent(), is("foo"));
+ }
+
+ @Test
+ public void MXMLInstructionData_typical()
+ {
+ String[] code = new String[]
+ {
+ "<?foo \t\r\nbar \t\r\nbaz \t\r\n?>"
+ };
+ IMXMLInstructionData instructionData = getMXMLInstructionData(code);
+ assertThat("getInstructionText", instructionData.getInstructionText(), is(code[0]));
+ assertThat("getTarget", instructionData.getTarget(), is("foo"));
+ assertThat("getContent", instructionData.getContent(), is("bar \t\r\nbaz \t\r\n"));
+ }
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d6fcec46/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLInstructionData.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLInstructionData.java b/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLInstructionData.java
index da2fec4..9290e5f 100644
--- a/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLInstructionData.java
+++ b/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLInstructionData.java
@@ -19,18 +19,36 @@
package org.apache.flex.compiler.internal.mxml;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.flex.compiler.mxml.IMXMLInstructionData;
import org.apache.flex.compiler.parsing.IMXMLToken;
public class MXMLInstructionData extends MXMLUnitData implements
IMXMLInstructionData
{
+ private static Pattern WHITESPACE = Pattern.compile("[ \t\r\n]+");
+
/**
* Constructor.
*/
MXMLInstructionData(IMXMLToken token)
{
instructionText = token.getText();
+
+ Matcher m = WHITESPACE.matcher(instructionText);
+ if (m.find())
+ {
+ targetEndIndex = m.start();
+ contentStartIndex = m.end();
+ }
+ else
+ {
+ targetEndIndex = instructionText.length() - 2;
+ contentStartIndex = instructionText.length() - 2;
+ }
+
setOffsets(token.getStart(), token.getEnd());
setColumn(token.getColumn());
@@ -38,6 +56,10 @@ public class MXMLInstructionData extends MXMLUnitData implements
}
private String instructionText;
+
+ private int targetEndIndex;
+
+ private int contentStartIndex;
//
// Object overrides
@@ -94,4 +116,14 @@ public class MXMLInstructionData extends MXMLUnitData implements
{
return instructionText;
}
+
+ public String getTarget()
+ {
+ return instructionText.substring(2, targetEndIndex);
+ }
+
+ public String getContent()
+ {
+ return instructionText.substring(contentStartIndex, instructionText.length() - 2);
+ }
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d6fcec46/compiler/src/org/apache/flex/compiler/mxml/IMXMLInstructionData.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/mxml/IMXMLInstructionData.java b/compiler/src/org/apache/flex/compiler/mxml/IMXMLInstructionData.java
index 786abd1..33eab77 100644
--- a/compiler/src/org/apache/flex/compiler/mxml/IMXMLInstructionData.java
+++ b/compiler/src/org/apache/flex/compiler/mxml/IMXMLInstructionData.java
@@ -25,8 +25,23 @@ package org.apache.flex.compiler.mxml;
public interface IMXMLInstructionData extends IMXMLUnitData
{
/**
- * Returns the raw processing instruction. It is up to clients to parse
- * this.
+ * Returns the raw processing instruction, starting with the {@code <?} and ending with the {@code ?>}.
*/
String getInstructionText();
+
+ /**
+ * Returns the target of the processing instruction.
+ * <p>
+ * The target is the identifier that follows the {@code <?}.
+ * For example, for {@code <?foo bar baz?>} the target is {@code "foo"}.
+ */
+ String getTarget();
+
+ /**
+ * Returns the content of the processing instruction.
+ * <p>
+ * The content is everything that follows the whitespace after the target, up to the {@code ?>}.
+ * For example, for {@code <?foo bar baz?>} the content is {@code "bar baz"}.
+ */
+ String getContent();
}