Skip to content

Package: SoqlQueryListener

SoqlQueryListener

nameinstructionbranchcomplexitylinemethod
SoqlQueryListener(MetamodelImpl)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
buildGrouping()
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
buildOrdering()
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
buildSparqlQueryString()
M: 1 C: 105
99%
M: 1 C: 13
93%
M: 1 C: 7
88%
M: 1 C: 22
96%
M: 0 C: 1
100%
createSyntheticAttributeForEntityId()
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
currentPointerIsNotAttributeReference()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterArithmeticFactor(SoqlParser.ArithmeticFactorContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterArithmeticPrimary(SoqlParser.ArithmeticPrimaryContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterArithmeticTerm(SoqlParser.ArithmeticTermContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterAttribute(SoqlParser.AttributeContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterComparisonExpression(SoqlParser.ComparisonExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterConditionalExpression(SoqlParser.ConditionalExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterConditionalFactor(SoqlParser.ConditionalFactorContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterConditionalTerm(SoqlParser.ConditionalTermContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterCount(SoqlParser.CountContext)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
enterDistinct(SoqlParser.DistinctContext)
M: 0 C: 11
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
enterDistinctParam(SoqlParser.DistinctParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterEveryRule(ParserRuleContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterFunctionsReturningNumerics(SoqlParser.FunctionsReturningNumericsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterFunctionsReturningStrings(SoqlParser.FunctionsReturningStringsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterGroupByClause(SoqlParser.GroupByClauseContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterGroupByParam(SoqlParser.GroupByParamContext)
M: 0 C: 64
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
enterGroupByParamComma(SoqlParser.GroupByParamCommaContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterInExpression(SoqlParser.InExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterInItem(SoqlParser.InItemContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterInputParameter(SoqlParser.InputParameterContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterJoinedParams(SoqlParser.JoinedParamsContext)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
enterLikeExpression(SoqlParser.LikeExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterLiteral(SoqlParser.LiteralContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
enterMemberOfExpression(SoqlParser.MemberOfExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterObjWithAttr(SoqlParser.ObjWithAttrContext)
M: 0 C: 63
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 15
100%
M: 0 C: 1
100%
enterObjWithOutAttr(SoqlParser.ObjWithOutAttrContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterObject(SoqlParser.ObjectContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterOrderByClause(SoqlParser.OrderByClauseContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterOrderByFullForm(SoqlParser.OrderByFullFormContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterOrderByFullFormComma(SoqlParser.OrderByFullFormCommaContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterOrderByParam(SoqlParser.OrderByParamContext)
M: 0 C: 70
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
enterParam(SoqlParser.ParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterParamComma(SoqlParser.ParamCommaContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
enterParams(SoqlParser.ParamsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterQuerySentence(SoqlParser.QuerySentenceContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterSelectStatement(SoqlParser.SelectStatementContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterSelectedParam(SoqlParser.SelectedParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterSimpleArithmeticExpression(SoqlParser.SimpleArithmeticExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterSimpleConditionalExpression(SoqlParser.SimpleConditionalExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterStringExpression(SoqlParser.StringExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterTable(SoqlParser.TableContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterTableName(SoqlParser.TableNameContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterTableWithName(SoqlParser.TableWithNameContext)
M: 0 C: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
enterTables(SoqlParser.TablesContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterTypeDef(SoqlParser.TypeDefContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
enterWhereClauseParam(SoqlParser.WhereClauseParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterWhereClauseValue(SoqlParser.WhereClauseValueContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterWhereClauseWrapper(SoqlParser.WhereClauseWrapperContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitArithmeticFactor(SoqlParser.ArithmeticFactorContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitArithmeticPrimary(SoqlParser.ArithmeticPrimaryContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitArithmeticTerm(SoqlParser.ArithmeticTermContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitAttribute(SoqlParser.AttributeContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitComparisonExpression(SoqlParser.ComparisonExpressionContext)
M: 5 C: 73
94%
M: 2 C: 10
83%
M: 2 C: 5
71%
M: 0 C: 17
100%
M: 0 C: 1
100%
exitConditionalExpression(SoqlParser.ConditionalExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitConditionalFactor(SoqlParser.ConditionalFactorContext)
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
exitConditionalTerm(SoqlParser.ConditionalTermContext)
M: 0 C: 20
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
exitCount(SoqlParser.CountContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
exitDistinct(SoqlParser.DistinctContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitDistinctParam(SoqlParser.DistinctParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitEveryRule(ParserRuleContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitFunctionsReturningNumerics(SoqlParser.FunctionsReturningNumericsContext)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
exitFunctionsReturningStrings(SoqlParser.FunctionsReturningStringsContext)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
exitGroupByClause(SoqlParser.GroupByClauseContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitGroupByParam(SoqlParser.GroupByParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitGroupByParamComma(SoqlParser.GroupByParamCommaContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitInExpression(SoqlParser.InExpressionContext)
M: 4 C: 41
91%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 10
100%
M: 0 C: 1
100%
exitInItem(SoqlParser.InItemContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitInputParameter(SoqlParser.InputParameterContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitJoinedParams(SoqlParser.JoinedParamsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitLikeExpression(SoqlParser.LikeExpressionContext)
M: 0 C: 42
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 10
100%
M: 0 C: 1
100%
exitLiteral(SoqlParser.LiteralContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
exitMemberOfExpression(SoqlParser.MemberOfExpressionContext)
M: 0 C: 32
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 7
100%
M: 0 C: 1
100%
exitObjWithAttr(SoqlParser.ObjWithAttrContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitObjWithOutAttr(SoqlParser.ObjWithOutAttrContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitObject(SoqlParser.ObjectContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitOrderByClause(SoqlParser.OrderByClauseContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitOrderByFullForm(SoqlParser.OrderByFullFormContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitOrderByFullFormComma(SoqlParser.OrderByFullFormCommaContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitOrderByParam(SoqlParser.OrderByParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitParam(SoqlParser.ParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitParamComma(SoqlParser.ParamCommaContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
exitParams(SoqlParser.ParamsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitQuerySentence(SoqlParser.QuerySentenceContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
exitSelectStatement(SoqlParser.SelectStatementContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitSelectedParam(SoqlParser.SelectedParamContext)
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
exitSimpleArithmeticExpression(SoqlParser.SimpleArithmeticExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitSimpleConditionalExpression(SoqlParser.SimpleConditionalExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitStringExpression(SoqlParser.StringExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTable(SoqlParser.TableContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTableName(SoqlParser.TableNameContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTableWithName(SoqlParser.TableWithNameContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTables(SoqlParser.TablesContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTypeDef(SoqlParser.TypeDefContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitWhereClauseParam(SoqlParser.WhereClauseParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitWhereClauseValue(SoqlParser.WhereClauseValueContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitWhereClauseWrapper(SoqlParser.WhereClauseWrapperContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getAttributeFromParam(ParserRuleContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getCountPart()
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getEntityType(String)
M: 2 C: 23
92%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 5
83%
M: 0 C: 1
100%
getOrderingBy(ParserRuleContext)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getOwnerFromParam(ParserRuleContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSparqlQuery()
M: 4 C: 7
64%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
isIdentifier(SoqlNode, SoqlNode)
M: 4 C: 26
87%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 5
71%
M: 0 C: 1
100%
isRootIdentifier(SoqlAttribute)
M: 0 C: 17
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 2
100%
M: 0 C: 1
100%
linkContextNodes(ParserRuleContext)
M: 0 C: 47
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
popAttribute()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
processAllFilters(ArrayList, ArrayList)
M: 0 C: 24
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
processAttribute(SoqlAttribute)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
processAttributes()
M: 0 C: 89
100%
M: 0 C: 10
100%
M: 0 C: 6
100%
M: 0 C: 21
100%
M: 0 C: 1
100%
processFilter(ArrayList)
M: 0 C: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
processInvFilter(ArrayList)
M: 2 C: 50
96%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 11
92%
M: 0 C: 1
100%
processSupremeAttributes()
M: 0 C: 35
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
pushNewAttribute(SoqlAttribute)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
resolveBindableType(Attribute)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
resolveInExpressionValue(SoqlParser.InExpressionContext)
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setAllNodesIris(EntityType, SoqlNode)
M: 1 C: 62
98%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 1 C: 16
94%
M: 0 C: 1
100%
setIris(SoqlNode)
M: 2 C: 28
93%
M: 3 C: 3
50%
M: 3 C: 1
25%
M: 2 C: 7
78%
M: 0 C: 1
100%
setObjectIri(SoqlNode)
M: 6 C: 16
73%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 5
71%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
visitErrorNode(ErrorNode)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
visitTerminal(TerminalNode)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.query.soql;
19:
20: import cz.cvut.kbss.jopa.exception.SoqlException;
21: import cz.cvut.kbss.jopa.model.MetamodelImpl;
22: import cz.cvut.kbss.jopa.model.metamodel.Attribute;
23: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
24: import cz.cvut.kbss.jopa.model.metamodel.IdentifiableEntityType;
25: import cz.cvut.kbss.jopa.model.metamodel.PluralAttribute;
26: import cz.cvut.kbss.jopa.model.metamodel.SingularAttribute;
27: import cz.cvut.kbss.jopa.model.metamodel.Type;
28: import cz.cvut.kbss.jopa.query.sparql.SparqlConstants;
29: import org.antlr.v4.runtime.ParserRuleContext;
30: import org.antlr.v4.runtime.tree.ErrorNode;
31: import org.antlr.v4.runtime.tree.ParseTree;
32: import org.antlr.v4.runtime.tree.TerminalNode;
33: import org.slf4j.Logger;
34: import org.slf4j.LoggerFactory;
35:
36: import java.util.ArrayList;
37: import java.util.Collection;
38: import java.util.HashMap;
39: import java.util.HashSet;
40: import java.util.Iterator;
41: import java.util.List;
42: import java.util.Map;
43: import java.util.Objects;
44: import java.util.Set;
45: import java.util.stream.Collectors;
46:
47: public class SoqlQueryListener implements SoqlListener {
48:
49: private static final Logger LOG = LoggerFactory.getLogger(SoqlQueryListener.class);
50:
51: private final MetamodelImpl metamodel;
52:
53: private String soql;
54: private String sparql;
55:
56: private String typeDef = SoqlConstants.SELECT;
57:
58: // keeps pointer at created object of SoqlAttribute while processing other necessary rules
59: private SoqlAttribute attrPointer;
60:
61: private final List<SoqlAttribute> attributes;
62:
63: // keeps index of first object of SoqlAttribute after OR operator
64: private final Set<SoqlAttribute> objectOfNextOr;
65:
66: private final List<SoqlOrderParameter> orderAttributes;
67:
68: private final List<SoqlGroupParameter> groupAttributes;
69:
70: private final Map<String, String> objectTypes;
71:
72: private boolean isSelectedParamDistinct = false;
73:
74: private boolean isSelectedParamCount = false;
75:
76: private boolean isInObjectIdentifierExpression = false;
77:
78: private String projectedVariable;
79:
80: private String rootVariable = "?x";
81:
82:
83: public SoqlQueryListener(MetamodelImpl metamodel) {
84: this.metamodel = Objects.requireNonNull(metamodel);
85: this.attributes = new ArrayList<>();
86: this.objectOfNextOr = new HashSet<>();
87: this.orderAttributes = new ArrayList<>();
88: this.groupAttributes = new ArrayList<>();
89: this.objectTypes = new HashMap<>();
90: }
91:
92: @Override
93: public void enterQuerySentence(SoqlParser.QuerySentenceContext ctx) {
94: }
95:
96: @Override
97: public void exitQuerySentence(SoqlParser.QuerySentenceContext ctx) {
98: this.soql = ctx.getText();
99: buildSparqlQueryString();
100: }
101:
102: @Override
103: public void enterSelectStatement(SoqlParser.SelectStatementContext ctx) {
104: }
105:
106: @Override
107: public void exitSelectStatement(SoqlParser.SelectStatementContext ctx) {
108: }
109:
110: @Override
111: public void enterParams(SoqlParser.ParamsContext ctx) {
112: }
113:
114: @Override
115: public void exitParams(SoqlParser.ParamsContext ctx) {
116: }
117:
118: @Override
119: public void enterParam(SoqlParser.ParamContext ctx) {
120: }
121:
122: @Override
123: public void exitParam(SoqlParser.ParamContext ctx) {
124: }
125:
126: @Override
127: public void enterJoinedParams(SoqlParser.JoinedParamsContext ctx) {
128: SoqlNode firstNode = linkContextNodes(ctx);
129: SoqlAttribute myAttr = new SoqlAttribute(firstNode);
130: pushNewAttribute(myAttr);
131: }
132:
133: private void pushNewAttribute(SoqlAttribute myAttr) {
134: attributes.add(myAttr);
135: this.attrPointer = myAttr;
136: }
137:
138: private void popAttribute() {
139: this.attrPointer = attributes.remove(attributes.size() - 1);
140: }
141:
142: @Override
143: public void exitJoinedParams(SoqlParser.JoinedParamsContext ctx) {
144: }
145:
146: @Override
147: public void enterParamComma(SoqlParser.ParamCommaContext ctx) {
148: }
149:
150: @Override
151: public void exitParamComma(SoqlParser.ParamCommaContext ctx) {
152: }
153:
154: @Override
155: public void enterDistinctParam(SoqlParser.DistinctParamContext ctx) {
156: }
157:
158: @Override
159: public void exitDistinctParam(SoqlParser.DistinctParamContext ctx) {
160: }
161:
162: @Override
163: public void enterSelectedParam(SoqlParser.SelectedParamContext ctx) {
164: }
165:
166: @Override
167: public void exitSelectedParam(SoqlParser.SelectedParamContext ctx) {
168:• if (!isSelectedParamCount) {
169: this.projectedVariable = ctx.getText();
170: }
171: }
172:
173: @Override
174: public void enterCount(SoqlParser.CountContext ctx) {
175: isSelectedParamCount = true;
176: }
177:
178: @Override
179: public void exitCount(SoqlParser.CountContext ctx) {
180: this.projectedVariable = ctx.getChild(2).getText();
181: }
182:
183: @Override
184: public void enterObject(SoqlParser.ObjectContext ctx) {
185: }
186:
187: @Override
188: public void exitObject(SoqlParser.ObjectContext ctx) {
189: }
190:
191: @Override
192: public void enterObjWithAttr(SoqlParser.ObjWithAttrContext ctx) {
193: String owner = getOwnerFromParam(ctx);
194: String attribute = getAttributeFromParam(ctx);
195: // objectNode.attributeNode
196: SoqlNode objectNode = new AttributeNode(owner);
197: SoqlNode attributeNode = new AttributeNode(objectNode, attribute);
198: objectNode.setChild(attributeNode);
199: setIris(objectNode);
200: SoqlAttribute newAttr = new SoqlAttribute(objectNode);
201:• if (isIdentifier(objectNode, attributeNode)) {
202: this.isInObjectIdentifierExpression = true;
203:• if (projectedVariable.equals(objectNode.getValue()) && currentPointerIsNotAttributeReference()) {
204: attrPointer.setProjected(true);
205: } else {
206: newAttr.setProjected(true);
207: pushNewAttribute(newAttr);
208: }
209: } else {
210: pushNewAttribute(newAttr);
211: }
212: }
213:
214: private boolean isIdentifier(SoqlNode objectNode, SoqlNode attributeNode) {
215:• if (!objectTypes.containsKey(objectNode.getValue())) {
216: return false;
217: }
218: final String objectName = objectTypes.get(objectNode.getValue());
219: IdentifiableEntityType<?> entityType = getEntityType(objectName);
220:• if (entityType == null) {
221: return false;
222: }
223: return entityType.getIdentifier().getName().equals(attributeNode.getValue());
224: }
225:
226: private boolean currentPointerIsNotAttributeReference() {
227:• return !attrPointer.getFirstNode().hasChild();
228: }
229:
230: @Override
231: public void exitObjWithAttr(SoqlParser.ObjWithAttrContext ctx) {
232: }
233:
234: @Override
235: public void enterObjWithOutAttr(SoqlParser.ObjWithOutAttrContext ctx) {
236: }
237:
238: @Override
239: public void exitObjWithOutAttr(SoqlParser.ObjWithOutAttrContext ctx) {
240: }
241:
242: @Override
243: public void enterAttribute(SoqlParser.AttributeContext ctx) {
244: }
245:
246: @Override
247: public void exitAttribute(SoqlParser.AttributeContext ctx) {
248: }
249:
250: @Override
251: public void enterTypeDef(SoqlParser.TypeDefContext ctx) {
252: typeDef = ctx.getChild(0).getText();
253: }
254:
255: @Override
256: public void exitTypeDef(SoqlParser.TypeDefContext ctx) {
257: }
258:
259: @Override
260: public void enterDistinct(SoqlParser.DistinctContext ctx) {
261:• if (SoqlConstants.DISTINCT.equals(ctx.getChild(0).getText())) {
262: isSelectedParamDistinct = true;
263: }
264: }
265:
266: @Override
267: public void exitDistinct(SoqlParser.DistinctContext ctx) {
268: }
269:
270: @Override
271: public void enterWhereClauseWrapper(SoqlParser.WhereClauseWrapperContext ctx) {
272: }
273:
274: @Override
275: public void exitWhereClauseWrapper(SoqlParser.WhereClauseWrapperContext ctx) {
276: }
277:
278: @Override
279: public void enterConditionalExpression(SoqlParser.ConditionalExpressionContext ctx) {
280: }
281:
282: @Override
283: public void exitConditionalExpression(SoqlParser.ConditionalExpressionContext ctx) {
284: }
285:
286: @Override
287: public void enterConditionalTerm(SoqlParser.ConditionalTermContext ctx) {
288: }
289:
290: @Override
291: public void exitConditionalTerm(SoqlParser.ConditionalTermContext ctx) {
292: final ParserRuleContext parentCtx = ctx.getParent();
293:• if (parentCtx.getChildCount() > 1 && !parentCtx.getChild(0).equals(ctx)) {
294: objectOfNextOr.add(attrPointer);
295: }
296: }
297:
298: @Override
299: public void enterConditionalFactor(SoqlParser.ConditionalFactorContext ctx) {
300: }
301:
302: @Override
303: public void exitConditionalFactor(SoqlParser.ConditionalFactorContext ctx) {
304:• if (ctx.getChildCount() > 1) {
305: attrPointer.setNot(true);
306: }
307: }
308:
309: @Override
310: public void enterSimpleConditionalExpression(SoqlParser.SimpleConditionalExpressionContext ctx) {
311: }
312:
313: @Override
314: public void exitSimpleConditionalExpression(SoqlParser.SimpleConditionalExpressionContext ctx) {
315: }
316:
317: @Override
318: public void enterInExpression(SoqlParser.InExpressionContext ctx) {
319: }
320:
321: @Override
322: public void exitInExpression(SoqlParser.InExpressionContext ctx) {
323:• assert ctx.getChildCount() > 2;
324:• if (isInObjectIdentifierExpression) {
325: pushNewAttribute(createSyntheticAttributeForEntityId());
326: }
327: final ParseTree value = resolveInExpressionValue(ctx);
328:• if (ctx.getChild(1).getText().equals(SoqlConstants.NOT)) {
329: attrPointer.setOperator(InOperator.notIn());
330: } else {
331: attrPointer.setOperator(InOperator.in());
332: }
333: attrPointer.setValue(value.getText());
334: this.isInObjectIdentifierExpression = false;
335: }
336:
337: private SoqlAttribute createSyntheticAttributeForEntityId() {
338: return new SoqlAttribute(
339:• attrPointer.getFirstNode().hasChild() ? attrPointer.getFirstNode().getChild() :
340: new AttributeNode(rootVariable.substring(1)));
341: }
342:
343: private ParseTree resolveInExpressionValue(SoqlParser.InExpressionContext ctx) {
344: final ParseTree lastToken = ctx.getChild(ctx.getChildCount() - 1);
345:• if (")".equals(lastToken.getText())) {
346: return ctx.getChild(ctx.getChildCount() - 2);
347: }
348: return lastToken;
349: }
350:
351: @Override
352: public void enterInItem(SoqlParser.InItemContext ctx) {
353: }
354:
355: @Override
356: public void exitInItem(SoqlParser.InItemContext ctx) {
357: }
358:
359: @Override
360: public void enterLiteral(SoqlParser.LiteralContext ctx) {
361: }
362:
363: @Override
364: public void exitLiteral(SoqlParser.LiteralContext ctx) {
365: }
366:
367: @Override
368: public void enterLikeExpression(SoqlParser.LikeExpressionContext ctx) {
369: }
370:
371: @Override
372: public void exitLikeExpression(SoqlParser.LikeExpressionContext ctx) {
373:• if (ctx.getChildCount() > 2 && ctx.getChild(1).getText().equals(SoqlConstants.NOT)) {
374: attrPointer.setOperator(LikeOperator.notLike());
375: ParseTree whereClauseValue = ctx.getChild(3);
376: attrPointer.setValue(whereClauseValue.getText());
377: } else {
378: attrPointer.setOperator(LikeOperator.like());
379: ParseTree whereClauseValue = ctx.getChild(2);
380: attrPointer.setValue(whereClauseValue.getText());
381: }
382: this.isInObjectIdentifierExpression = false;
383: }
384:
385: @Override
386: public void enterMemberOfExpression(SoqlParser.MemberOfExpressionContext ctx) {
387:
388: }
389:
390: @Override
391: public void exitMemberOfExpression(SoqlParser.MemberOfExpressionContext ctx) {
392:• if (ctx.getChildCount() > 2 && ctx.getChild(1).getText().equals(SoqlConstants.NOT)) {
393: attrPointer.setNot(true);
394: }
395: attrPointer.setOperator(MemberOfOperator.memberOf());
396: ParseTree whereClauseValue = ctx.getChild(0);
397: attrPointer.setValue(whereClauseValue.getText());
398: this.isInObjectIdentifierExpression = false;
399: }
400:
401: @Override
402: public void enterComparisonExpression(SoqlParser.ComparisonExpressionContext ctx) {
403: }
404:
405: @Override
406: public void exitComparisonExpression(SoqlParser.ComparisonExpressionContext ctx) {
407: String operator = ctx.getChild(1).getText();
408:
409: ParseTree whereClauseValue = ctx.getChild(2);
410:
411:• if (isInObjectIdentifierExpression) {
412:• assert Objects.equals(operator, "=");
413:• if (attrPointer.isProjected()) {
414: this.rootVariable = SoqlUtils.soqlVariableToSparqlVariable(whereClauseValue.getText());
415: }
416:• if (attributes.size() > 1) {
417:• if (isRootIdentifier(attrPointer)) {
418: // If the current attribute is identifier (i.e., something like root.iri = :iri) and there are other attributes to work with,
419: // just pop it and not use it in the query anymore
420: popAttribute();
421: } else {
422: final String varName = whereClauseValue.getText();
423: attrPointer.getFirstNode().getChild().setValue(
424:• varName.charAt(0) == SoqlConstants.VARIABLE_PREFIX ? varName.substring(1) : varName);
425: }
426: }
427: } else {
428: attrPointer.setOperator(new ComparisonOperator(operator));
429: attrPointer.setValue(whereClauseValue.getText());
430: }
431: this.isInObjectIdentifierExpression = false;
432: }
433:
434: private boolean isRootIdentifier(SoqlAttribute attribute) {
435:• return isIdentifier(attribute.getFirstNode(), attribute.getFirstNode().getChild()) &&
436:• !attribute.getFirstNode().getChild().hasChild();
437: }
438:
439: @Override
440: public void enterTables(SoqlParser.TablesContext ctx) {
441: }
442:
443: @Override
444: public void exitTables(SoqlParser.TablesContext ctx) {
445: }
446:
447: @Override
448: public void enterTable(SoqlParser.TableContext ctx) {
449: }
450:
451: @Override
452: public void exitTable(SoqlParser.TableContext ctx) {
453: }
454:
455: @Override
456: public void enterTableName(SoqlParser.TableNameContext ctx) {
457: }
458:
459: @Override
460: public void exitTableName(SoqlParser.TableNameContext ctx) {
461: }
462:
463: @Override
464: public void enterTableWithName(SoqlParser.TableWithNameContext ctx) {
465: String table = ctx.getChild(0).getChild(0).getText();
466: String objectName = ctx.getChild(1).getChild(0).getText();
467: objectTypes.put(objectName, table);
468: SoqlNode node = new AttributeNode(table);
469: setObjectIri(node);
470: SoqlAttribute myAttr = new SoqlAttribute(node);
471: pushNewAttribute(myAttr);
472: }
473:
474: @Override
475: public void exitTableWithName(SoqlParser.TableWithNameContext ctx) {
476: }
477:
478: @Override
479: public void enterWhereClauseValue(SoqlParser.WhereClauseValueContext ctx) {
480: }
481:
482: @Override
483: public void exitWhereClauseValue(SoqlParser.WhereClauseValueContext ctx) {
484: }
485:
486: @Override
487: public void enterWhereClauseParam(SoqlParser.WhereClauseParamContext ctx) {
488: }
489:
490: @Override
491: public void exitWhereClauseParam(SoqlParser.WhereClauseParamContext ctx) {
492: }
493:
494: @Override
495: public void enterStringExpression(SoqlParser.StringExpressionContext ctx) {
496:
497: }
498:
499: @Override
500: public void exitStringExpression(SoqlParser.StringExpressionContext ctx) {
501:
502: }
503:
504: @Override
505: public void enterFunctionsReturningStrings(SoqlParser.FunctionsReturningStringsContext ctx) {
506:
507: }
508:
509: @Override
510: public void exitFunctionsReturningStrings(SoqlParser.FunctionsReturningStringsContext ctx) {
511: final String functionName = ctx.getChild(0).getText();
512: final FunctionNode node = new FunctionNode(attrPointer.getFirstNode(), functionName);
513: attrPointer.setFirstNode(node);
514: }
515:
516: @Override
517: public void enterSimpleArithmeticExpression(SoqlParser.SimpleArithmeticExpressionContext ctx) {
518:
519: }
520:
521: @Override
522: public void exitSimpleArithmeticExpression(SoqlParser.SimpleArithmeticExpressionContext ctx) {
523:
524: }
525:
526: @Override
527: public void enterArithmeticTerm(SoqlParser.ArithmeticTermContext ctx) {
528:
529: }
530:
531: @Override
532: public void exitArithmeticTerm(SoqlParser.ArithmeticTermContext ctx) {
533:
534: }
535:
536: @Override
537: public void enterArithmeticFactor(SoqlParser.ArithmeticFactorContext ctx) {
538:
539: }
540:
541: @Override
542: public void exitArithmeticFactor(SoqlParser.ArithmeticFactorContext ctx) {
543:
544: }
545:
546: @Override
547: public void enterArithmeticPrimary(SoqlParser.ArithmeticPrimaryContext ctx) {
548:
549: }
550:
551: @Override
552: public void exitArithmeticPrimary(SoqlParser.ArithmeticPrimaryContext ctx) {
553:
554: }
555:
556: @Override
557: public void enterFunctionsReturningNumerics(SoqlParser.FunctionsReturningNumericsContext ctx) {
558: }
559:
560: @Override
561: public void exitFunctionsReturningNumerics(SoqlParser.FunctionsReturningNumericsContext ctx) {
562: final String functionName = ctx.getChild(0).getText();
563: final FunctionNode node = new FunctionNode(attrPointer.getFirstNode(), functionName);
564: attrPointer.setFirstNode(node);
565: }
566:
567: @Override
568: public void enterOrderByClause(SoqlParser.OrderByClauseContext ctx) {
569: }
570:
571: @Override
572: public void exitOrderByClause(SoqlParser.OrderByClauseContext ctx) {
573: }
574:
575: @Override
576: public void enterOrderByFullFormComma(SoqlParser.OrderByFullFormCommaContext ctx) {
577: }
578:
579: @Override
580: public void exitOrderByFullFormComma(SoqlParser.OrderByFullFormCommaContext ctx) {
581: }
582:
583: @Override
584: public void enterOrderByFullForm(SoqlParser.OrderByFullFormContext ctx) {
585: }
586:
587: @Override
588: public void exitOrderByFullForm(SoqlParser.OrderByFullFormContext ctx) {
589: }
590:
591: @Override
592: public void enterOrderByParam(SoqlParser.OrderByParamContext ctx) {
593: SoqlNode firstNode = linkContextNodes(ctx);
594: String orderingBy = getOrderingBy(ctx.getParent());
595: SoqlOrderParameter orderParam = new SoqlOrderParameter(firstNode, orderingBy);
596: boolean attrSet = false;
597:• for (SoqlAttribute attr : attributes) {
598:• if (attr.getAsParam().equals(orderParam.getAsParam())) {
599: orderParam.setAttribute(attr);
600: attrSet = true;
601: }
602: }
603:• if (!attrSet) {
604: SoqlAttribute myAttr = new SoqlAttribute(firstNode);
605: myAttr.setValue(orderParam.getAsValue(rootVariable));
606: myAttr.setOrderBy(true);
607: attributes.add(1, myAttr);
608: orderParam.setAttribute(myAttr);
609: }
610: orderAttributes.add(orderParam);
611: }
612:
613: @Override
614: public void exitOrderByParam(SoqlParser.OrderByParamContext ctx) {
615: }
616:
617: @Override
618: public void enterGroupByClause(SoqlParser.GroupByClauseContext ctx) {
619: }
620:
621: @Override
622: public void exitGroupByClause(SoqlParser.GroupByClauseContext ctx) {
623: }
624:
625: @Override
626: public void enterGroupByParamComma(SoqlParser.GroupByParamCommaContext ctx) {
627: }
628:
629: @Override
630: public void exitGroupByParamComma(SoqlParser.GroupByParamCommaContext ctx) {
631: }
632:
633: @Override
634: public void enterGroupByParam(SoqlParser.GroupByParamContext ctx) {
635: SoqlNode firstNode = linkContextNodes(ctx);
636: SoqlGroupParameter groupParam = new SoqlGroupParameter(firstNode);
637: boolean attrSet = false;
638:• for (SoqlAttribute attr : attributes) {
639:• if (attr.getAsParam().equals(groupParam.getAsParam())) {
640: groupParam.setAttribute(attr);
641: attrSet = true;
642: }
643: }
644:• if (!attrSet) {
645: SoqlAttribute myAttr = new SoqlAttribute(firstNode);
646: myAttr.setValue(groupParam.getAsValue(rootVariable));
647: myAttr.setGroupBy(true);
648: attributes.add(1, myAttr);
649: groupParam.setAttribute(myAttr);
650: }
651: groupAttributes.add(groupParam);
652: }
653:
654: private SoqlNode linkContextNodes(ParserRuleContext ctx) {
655: SoqlNode firstNode = new AttributeNode(getOwnerFromParam(ctx));
656: SoqlNode currentNode = firstNode;
657:• for (int i = 2; i < ctx.getChildCount(); i += 2) {
658: SoqlNode prevNode = currentNode;
659: currentNode = new AttributeNode(prevNode, ctx.getChild(i).getText());
660: prevNode.setChild(currentNode);
661: }
662: setIris(firstNode);
663:• if (currentNode.getIri().isEmpty()) {
664: currentNode.getParent().setChild(null);
665: this.isInObjectIdentifierExpression = true;
666: }
667: return firstNode;
668: }
669:
670: @Override
671: public void exitGroupByParam(SoqlParser.GroupByParamContext ctx) {
672: }
673:
674: @Override
675: public void enterInputParameter(SoqlParser.InputParameterContext ctx) {
676:
677: }
678:
679: @Override
680: public void exitInputParameter(SoqlParser.InputParameterContext ctx) {
681:
682: }
683:
684: @Override
685: public void visitTerminal(TerminalNode terminalNode) {
686: }
687:
688: @Override
689: public void visitErrorNode(ErrorNode errorNode) {
690: }
691:
692: @Override
693: public void enterEveryRule(ParserRuleContext parserRuleContext) {
694: }
695:
696: @Override
697: public void exitEveryRule(ParserRuleContext parserRuleContext) {
698: }
699:
700: //Methods to help parse tree
701: private String getOwnerFromParam(ParserRuleContext ctx) {
702: return ctx.getChild(0).getChild(0).getText();
703: }
704:
705: private String getAttributeFromParam(ParserRuleContext ctx) {
706: return ctx.getChild(2).getChild(0).getText();
707: }
708:
709: private String getOrderingBy(ParserRuleContext ctx) {
710:• return ctx.getChildCount() > 1 ? ctx.getChild(1).getText() : "";
711: }
712:
713: private void setObjectIri(SoqlNode node) {
714: IdentifiableEntityType<?> entityType = getEntityType(node.getValue());
715:• if (entityType == null) {
716: return;
717: }
718: node.setIri(entityType.getIRI().toString());
719:• if (node.hasChild()) {
720: setAllNodesIris(entityType, node.getChild());
721: }
722: }
723:
724: private IdentifiableEntityType<?> getEntityType(String name) {
725:• for (EntityType<?> type : metamodel.getEntities()) {
726: IdentifiableEntityType<?> entityType = (IdentifiableEntityType<?>) type;
727:• if (entityType.getName().equals(name)) {
728: return entityType;
729: }
730: }
731: return null;
732: }
733:
734: private void setAllNodesIris(EntityType<?> entityType, SoqlNode node) {
735: final String nodeName = node.getValue();
736:• if (entityType.getIdentifier().getName().equals(nodeName)) {
737: return;
738: }
739:• if (entityType.getTypes() != null && entityType.getTypes().getName().equals(node.getValue())) {
740: node.setIri(SparqlConstants.RDF_TYPE_SHORTCUT);
741: return;
742: }
743: final Attribute<?, ?> att;
744: try {
745: att = entityType.getAttribute(node.getValue());
746: } catch (IllegalArgumentException e) {
747: throw new SoqlException("No matching attribute with name '" + node.getValue() + "' found on entity type '" + entityType.getName() + "'.");
748: }
749: //not implemented case of 3 or more fragments (chained SoqlNodes)
750: node.setIri(att.getIRI().toString());
751:• if (node.hasChild()) {
752: final Type<?> type = resolveBindableType(att);
753:• if (type.getPersistenceType() != Type.PersistenceType.ENTITY) {
754: return;
755: }
756: setAllNodesIris((EntityType<?>) type, node.getChild());
757: }
758: }
759:
760: private static Type<?> resolveBindableType(Attribute<?, ?> att) {
761:• if (att.isCollection()) {
762: return ((PluralAttribute<?, ?, ?>) att).getElementType();
763: } else {
764: return ((SingularAttribute<?, ?>) att).getType();
765: }
766: }
767:
768: private void setIris(SoqlNode firstNode) {
769:• if (!objectTypes.containsKey(firstNode.getValue())) {
770: return;
771: }
772: String objectName = objectTypes.get(firstNode.getValue());
773: IdentifiableEntityType<?> entityType = getEntityType(objectName);
774:• if (entityType == null) {
775: return;
776: }
777:• if (firstNode.hasChild()) {
778: setAllNodesIris(entityType, firstNode.getChild());
779: }
780: }
781:
782: public String getSparqlQuery() {
783:• assert sparql != null;
784: return sparql;
785: }
786:
787: //Methods to build new Query
788: private void buildSparqlQueryString() {
789:• if (attributes.isEmpty()) {
790: return;
791: }
792: StringBuilder newQueryBuilder = new StringBuilder(typeDef);
793:• if (isSelectedParamCount) {
794: newQueryBuilder.append(getCountPart());
795: } else {
796:• if (isSelectedParamDistinct) {
797: newQueryBuilder.append(' ').append(SoqlConstants.DISTINCT);
798: }
799: newQueryBuilder.append(' ').append(rootVariable).append(' ');
800: }
801: newQueryBuilder.append("WHERE { ");
802: newQueryBuilder.append(processSupremeAttributes());
803:• if (!objectOfNextOr.isEmpty()) {
804: newQueryBuilder.append("{ ");
805: }
806: newQueryBuilder.append(processAttributes());
807:• if (!objectOfNextOr.isEmpty()) {
808: newQueryBuilder.append("} ");
809: }
810: newQueryBuilder.append('}');
811:• if (!groupAttributes.isEmpty()) {
812: newQueryBuilder.append(' ').append(buildGrouping());
813: }
814:• if (!orderAttributes.isEmpty()) {
815: newQueryBuilder.append(' ').append(buildOrdering());
816: }
817: sparql = newQueryBuilder.toString();
818: LOG.trace("Translated SOQL query '{}' to SPARQL '{}'.", soql, sparql);
819: }
820:
821: private StringBuilder getCountPart() {
822: StringBuilder countPart = new StringBuilder(" (COUNT(");
823:• if (isSelectedParamDistinct) {
824: countPart.append(SoqlConstants.DISTINCT).append(' ');
825: }
826: countPart.append(rootVariable).append(") AS ?count) ");
827: return countPart;
828: }
829:
830: private StringBuilder processSupremeAttributes() {
831: StringBuilder attributesPart = new StringBuilder();
832: final Iterator<SoqlAttribute> it = attributes.iterator();
833:• while (it.hasNext()) {
834: final SoqlAttribute current = it.next();
835:• if (current.isInstanceOf() || current.isOrderBy() || current.isGroupBy()) {
836: attributesPart.append(processAttribute(current));
837: it.remove();
838: }
839: }
840: return attributesPart;
841: }
842:
843: private StringBuilder processAttributes() {
844: StringBuilder attributesPart = new StringBuilder();
845: ArrayList<SoqlAttribute> toFilter = new ArrayList<>();
846: ArrayList<SoqlAttribute> toInvFilter = new ArrayList<>();
847:• for (SoqlAttribute myAttr : attributes) {
848:• if (objectOfNextOr.contains(myAttr)) {
849: StringBuilder orPart = new StringBuilder();
850: orPart.append(processAllFilters(toFilter, toInvFilter));
851: toFilter.clear();
852: toInvFilter.clear();
853: orPart.append("} UNION { ");
854: attributesPart.append(orPart);
855: }
856:• if (myAttr.isNot()) {
857: toInvFilter.add(myAttr);
858: } else {
859:• if (myAttr.requiresFilter()) {
860: toFilter.add(myAttr);
861: }
862: final String bgp = processAttribute(myAttr);
863:• if (attributesPart.indexOf(bgp) == -1) {
864: attributesPart.append(bgp);
865: }
866: }
867: }
868: attributesPart.append(processAllFilters(toFilter, toInvFilter));
869: return attributesPart;
870: }
871:
872: private StringBuilder processAllFilters(ArrayList<SoqlAttribute> toFilter, ArrayList<SoqlAttribute> toInvFilter) {
873: StringBuilder part = new StringBuilder();
874:• if (!toFilter.isEmpty()) {
875: part.append(processFilter(toFilter));
876: }
877:• if (!toInvFilter.isEmpty()) {
878: part.append(processInvFilter(toInvFilter));
879: }
880: return part;
881: }
882:
883: private String processFilter(ArrayList<SoqlAttribute> toFilter) {
884: StringBuilder buildFilter = new StringBuilder();
885:• if (toFilter.isEmpty()) {
886: return "";
887: }
888: buildFilter.append("FILTER (");
889: buildFilter.append(toFilter.stream().map(SoqlAttribute::getFilterExpressions).flatMap(Collection::stream)
890: .collect(Collectors.joining(" && ")));
891: buildFilter.append(") ");
892: return buildFilter.toString();
893: }
894:
895: private String processInvFilter(ArrayList<SoqlAttribute> toInvFilter) {
896: StringBuilder buildInvFilter = new StringBuilder();
897: ArrayList<SoqlAttribute> toFilter = new ArrayList<>();
898:• if (toInvFilter.isEmpty()) {
899: return "";
900: }
901: buildInvFilter.append("FILTER NOT EXISTS { ");
902:• for (SoqlAttribute attr : toInvFilter) {
903: buildInvFilter.append(processAttribute(attr));
904:• if (attr.requiresFilter()) {
905: toFilter.add(attr);
906: }
907: }
908: buildInvFilter.append(processFilter(toFilter)).append("} ");
909: return buildInvFilter.toString();
910: }
911:
912: private String processAttribute(SoqlAttribute attr) {
913: return attr.getBasicGraphPattern(rootVariable);
914: }
915:
916: private String buildOrdering() {
917: StringBuilder sb = new StringBuilder(SoqlConstants.ORDER_BY);
918:• for (SoqlOrderParameter orderParam : orderAttributes) {
919: sb.append(' ').append(orderParam.getOrderByPart());
920: }
921: return sb.toString();
922: }
923:
924: private String buildGrouping() {
925: StringBuilder sb = new StringBuilder(SoqlConstants.GROUP_BY);
926:• for (SoqlGroupParameter groupParam : groupAttributes) {
927: sb.append(' ').append(groupParam.getGroupByPart());
928: }
929: return sb.toString();
930: }
931: }