Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/rxm.git

Restored sequential attribute detection.

Author Dave Jarvis <email>
Date 2015-03-25 00:01:09 GMT-0700
Commit 3d5e4a04d0ae579d287f870eeb350372d3c32021
Parent c61c0a3
Delta 31 lines added, 38 lines removed, 7-line decrease
source/java/com/whitemagicsoftware/rxm/Tree.java
/**
- * Answers whether the given payload has any siblings before it.
- *
- * @param payload The payload to find in the branches (sub-trees).
- *
- * @return true At least one antecedent payload exists in the branches.
- */
- public boolean hasPrecedingPayload( T payload ) {
- return indexOf( payload ) > 0;
- }
-
- /**
- * Answers whether the given payload has any siblings after it.
- *
- * @param payload The payload to find in the branches (sub-trees).
- *
- * @return true At least one subsequent payload exists in the branches.
- */
- public boolean hasFollowingPayload( T payload ) {
- int index = indexOf( payload );
-
- return index > -1 && index < getBranches().size();
- }
-
- /**
* Returns the first branch from this tree's list of branches.
*
source/java/com/whitemagicsoftware/rxm/xml/AttributeMapContext.java
}
+ public void hasPrecedingPayload( boolean hasPrecedingPayload ) {
+ this.hasPrecedingPayload = hasPrecedingPayload;
+ }
+
+ public void hasFollowingPayload( boolean hasFollowingPayload ) {
+ this.hasFollowingPayload = hasFollowingPayload;
+ }
+
/**
* Opens the XMLATTRIBUTES expression.
source/java/com/whitemagicsoftware/rxm/xml/SelectClause.java
}
+ public String toString() {
+ return "SELECT" + getNewlineIndent() + super.toString();
+ }
+
/**
* Adds the root context node to the top-most part of the tree. This
/**
- * Creates a new tree with the given parser rule context. This is required
- * so that the *Context classes are aware of their relative position in the
- * hierarchy. As a consequence of that knowledge, the objects have access
- * to the nearest table name, whether siblings exist, etc.
+ * Creates a new tree with the given parser rule context.
*
* @param ctx The context to wrap in a payload that is added to a tree.
- *
* @return A new tree with a single data element and no branches.
*/
source/java/com/whitemagicsoftware/rxm/xml/SelectTree.java
}
- /*
+ /**
* This converts all payload instances in the tree to their transformed
* equivalent using a depth-first traversal.
for( Tree<ParserRuleContext> branch : tree.getBranches() ) {
+ ParserRuleContext context = branch.getPayload();
+
// Recurse for all the branches at this level of the tree.
+ if( context instanceof AttributeMapContext ) {
+ AttributeMapContext ctx = (AttributeMapContext)context;
+ Tree<ParserRuleContext> parent = branch.getParent();
+
+ ctx.hasPrecedingPayload( hasPrecedingPayload( parent, ctx ) );
+ ctx.hasFollowingPayload( hasFollowingPayload( parent, ctx ) );
+ }
+
sb.append( newline ).append( toString( branch, depth + getIndentBy() ) );
}
* the given payload.
*/
- private List<ParserRuleContext> getConsecutiveRules( ParserRuleContext p ) {
+ private List<ParserRuleContext> getConsecutiveRules(
+ Tree<ParserRuleContext> tree, ParserRuleContext p ) {
List<ParserRuleContext> result = new ArrayList<ParserRuleContext>();
- for( Tree<ParserRuleContext> branch : getBranches() ) {
+ for( Tree<ParserRuleContext> branch : tree.getBranches() ) {
if( branch.isPayloadClass( p.getClass() ) ) {
result.add( branch.getPayload() );
* that is before the given payload.
*/
- @Override
- public boolean hasPrecedingPayload( ParserRuleContext payload ) {
- return getConsecutiveRules( payload ).indexOf( payload ) > 0;
+ public boolean hasPrecedingPayload( Tree<ParserRuleContext> tree, ParserRuleContext payload ) {
+ return getConsecutiveRules( tree, payload ).indexOf( payload ) > 0;
}
* that is after the given payload.
*/
- @Override
- public boolean hasFollowingPayload( ParserRuleContext payload ) {
- List<ParserRuleContext> siblings = getConsecutiveRules( payload );
+ public boolean hasFollowingPayload( Tree<ParserRuleContext> tree, ParserRuleContext payload ) {
+ List<ParserRuleContext> siblings = getConsecutiveRules( tree, payload );
int index = siblings.indexOf( payload );