protected Element compressGroupOfOneGroup(ElementGroup elg) { // remove group of one group. if ( elg.size() == 1 ) { Element e1 = elg.get(0) ; if ( e1 instanceof ElementGroup ) return e1 ; } return elg ; }
@Override public void visit(ElementGroup el) { // BIND scope rules // (and service warning) for ( int i = 0 ; i < el.size() ; i++ ) { Element e = el.get(i) ; // Tests. if ( e instanceof ElementBind ) { Collection<Var> accScope = calcScopeAll(el.getElements(), i) ; check(accScope, (ElementBind)e) ; } if ( e instanceof ElementService ) { Collection<Var> accScope = calcScopeAll(el.getElements(), i) ; check(accScope, (ElementService)e) ; } } }
private static Element getElementOfGroupOfOne(Element e) { if ( groupOfOne(e) ) { ElementGroup eg = (ElementGroup)e ; return eg.get(0) ; } return null ; }
private Element asElement(Op op) { ElementGroup g = asElementGroup(op) ; if ( g.size() == 1 ) return g.get(0) ; return g ; }
private ElementGroup unwrap(ElementGroup eltGroup) { if ( eltGroup.size() != 1 ) return eltGroup ; Element el = eltGroup.get(0) ; if ( ! ( el instanceof ElementGroup ) ) return eltGroup ; ElementGroup eltGroup2 = (ElementGroup)el ; return unwrap(eltGroup2) ; }
@Override public void visit(OpJoin opJoin) { Element eLeft = asElement(opJoin.getLeft()) ; ElementGroup eRightGroup = asElementGroup(opJoin.getRight()) ; Element eRight = eRightGroup ; // Very special case. If the RHS is not something that risks // reparsing into a combined element of a group, strip the group-of-one. // See also ElementTransformCleanGroupsOfOne if ( eRightGroup.size() == 1 ) { // This always was a {} around it but it's unnecessary in a group of one. if ( eRightGroup.get(0) instanceof ElementSubQuery ) eRight = eRightGroup.get(0) ; } ElementGroup g = currentGroup() ; insertIntoGroup(g, eLeft) ; insertIntoGroup(g, eRight) ; return ; }
@Test public void bNodeSPARQL_Query_1() { String qs = "SELECT * { ?s ?p <_:ABC>}"; Query query = QueryFactory.create(qs); Element el = ((ElementGroup)query.getQueryPattern()).get(0); ElementPathBlock epb = (ElementPathBlock)el; TriplePath tp = epb.getPattern().get(0); Triple t = tp.asTriple(); assertEquals("ABC", t.getObject().getBlankNodeLabel()); }
Element inner = eGroup.get(0) ; if ( ! ( inner instanceof ElementGroup ) ) return super.transform(eltOptional, transformedElt) ;