mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2024-12-01 10:41:05 +02:00
parent
2d70f270c8
commit
bfff769435
@ -43,6 +43,7 @@ import com._1c.g5.v8.dt.bsl.model.Invocation;
|
||||
import com._1c.g5.v8.dt.bsl.model.LoopStatement;
|
||||
import com._1c.g5.v8.dt.bsl.model.Method;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com._1c.g5.v8.dt.bsl.model.Statement;
|
||||
import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess;
|
||||
import com._1c.g5.v8.dt.bsl.model.WhileStatement;
|
||||
import com._1c.g5.v8.dt.bsl.model.util.BslUtil;
|
||||
@ -387,6 +388,28 @@ public class QueryInLoopCheck
|
||||
return predicate instanceof BooleanLiteral;
|
||||
}
|
||||
|
||||
private Collection<FeatureAccess> getQueryInLoopFeatures(LoopStatement loopStatement,
|
||||
Map<String, String> methodsWithQuery, Set<String> queryExecutionMethods)
|
||||
{
|
||||
Collection<FeatureAccess> result = new ArrayList<>();
|
||||
|
||||
for (Statement statement : loopStatement.getStatements())
|
||||
{
|
||||
for (FeatureAccess featureAccess : EcoreUtil2.eAllOfType(statement, FeatureAccess.class))
|
||||
{
|
||||
if (featureAccess instanceof StaticFeatureAccess
|
||||
&& isMethodWithQueryCalled((StaticFeatureAccess)featureAccess, methodsWithQuery)
|
||||
|| featureAccess instanceof DynamicFeatureAccess
|
||||
&& isQueryExecution((DynamicFeatureAccess)featureAccess, queryExecutionMethods))
|
||||
{
|
||||
result.add(featureAccess);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Collection<FeatureAccess> getQueryInLoopCallers(Module module, Map<String, String> methodsWithQuery,
|
||||
Set<String> queryExecutionMethods, boolean checkQueryInInfiniteLoop, IProgressMonitor monitor)
|
||||
{
|
||||
@ -404,16 +427,7 @@ public class QueryInLoopCheck
|
||||
continue;
|
||||
}
|
||||
|
||||
for (FeatureAccess featureAccess : EcoreUtil2.eAllOfType(loopStatement, FeatureAccess.class))
|
||||
{
|
||||
if (featureAccess instanceof StaticFeatureAccess
|
||||
&& isMethodWithQueryCalled((StaticFeatureAccess)featureAccess, methodsWithQuery)
|
||||
|| featureAccess instanceof DynamicFeatureAccess
|
||||
&& isQueryExecution((DynamicFeatureAccess)featureAccess, queryExecutionMethods))
|
||||
{
|
||||
result.add(featureAccess);
|
||||
}
|
||||
}
|
||||
result.addAll(getQueryInLoopFeatures(loopStatement, methodsWithQuery, queryExecutionMethods));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -1,3 +1,5 @@
|
||||
// @strict-types
|
||||
|
||||
Procedure QueryCorrect(SomeParameter) Export
|
||||
|
||||
SimpleQuery = New Query;
|
||||
@ -26,6 +28,8 @@ Procedure MethodCallsQueryCorrect(SomeParameter) Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
// Parameters:
|
||||
// SomeArray - Array
|
||||
Procedure ForEachStatementIncorrect(SomeArray) Export
|
||||
|
||||
ForEachQuery = New Query;
|
||||
@ -42,6 +46,8 @@ Procedure ForEachStatementIncorrect(SomeArray) Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
// Parameters:
|
||||
// SomeArray - Array
|
||||
Procedure ForToStatementIncorrect(SomeArray) Export
|
||||
|
||||
ForToQuery = New Query;
|
||||
@ -58,6 +64,8 @@ Procedure ForToStatementIncorrect(SomeArray) Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
// Parameters:
|
||||
// SomeArray - Array
|
||||
Procedure WhileStatementIncorrect(SomeArray) Export
|
||||
|
||||
WhileQuery = New Query;
|
||||
@ -72,12 +80,16 @@ Procedure WhileStatementIncorrect(SomeArray) Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
// Parameters:
|
||||
// SomeArray - Array
|
||||
Procedure MethodCallsIncorrectMethodCorrect(SomeArray) Export
|
||||
|
||||
ForEachStatementIncorrect(SomeArray);
|
||||
|
||||
EndProcedure
|
||||
|
||||
// Parameters:
|
||||
// SomeParameter - Number
|
||||
Procedure LoopCallsMethodIncorrect(SomeParameter) Export
|
||||
|
||||
LoopCallQuery = New Query;
|
||||
@ -93,6 +105,8 @@ Procedure LoopCallsMethodIncorrect(SomeParameter) Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
// Parameters:
|
||||
// SomeParameter - Number
|
||||
Procedure LoopCallsMethodWithOtherMethodIncorrect(SomeParameter) Export
|
||||
|
||||
MethodCallQuery = New Query;
|
||||
@ -107,6 +121,8 @@ Procedure LoopCallsMethodWithOtherMethodIncorrect(SomeParameter) Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
// Parameters:
|
||||
// SomeArray - Array
|
||||
Procedure LoopWithConditionsIncorrect(SomeArray) Export
|
||||
|
||||
While SomeArray.Count() = 0 Do
|
||||
@ -124,6 +140,11 @@ Procedure LoopWithConditionsIncorrect(SomeArray) Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
// Parameters:
|
||||
// ArrayElement - String
|
||||
//
|
||||
// Returns:
|
||||
// Query
|
||||
Function GetNewQuery(ArrayElement)
|
||||
|
||||
FunctionQuery = New Query;
|
||||
@ -138,6 +159,8 @@ Function GetNewQuery(ArrayElement)
|
||||
|
||||
EndFunction
|
||||
|
||||
// Parameters:
|
||||
// SomeArray - Array
|
||||
Procedure QueryTypeFromFunctionIncorrect(SomeArray) Export
|
||||
|
||||
For Each ArrayElement In SomeArray Do
|
||||
@ -146,3 +169,25 @@ Procedure QueryTypeFromFunctionIncorrect(SomeArray) Export
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
||||
|
||||
Function QueryResultColumn() Export
|
||||
|
||||
FunctionQuery = New Query;
|
||||
|
||||
FunctionQuery.Text =
|
||||
"SELECT
|
||||
| 1";
|
||||
|
||||
Return FunctionQuery.Execute().Unload().UnloadColumn(0);
|
||||
|
||||
EndFunction
|
||||
|
||||
Procedure ForEachParamQueryMethodCorrect() Export
|
||||
|
||||
Result = 0;
|
||||
|
||||
For Each Num In QueryResultColumn() Do
|
||||
Result = Result + Num;
|
||||
EndDo;
|
||||
|
||||
EndProcedure
|
@ -80,6 +80,8 @@ public class QueryInLoopCheckTest
|
||||
case "MethodCallsQueryCorrect":
|
||||
case "MethodCallsIncorrectMethodCorrect":
|
||||
case "GetNewQuery":
|
||||
case "QueryResultColumn":
|
||||
case "ForEachParamQueryMethodCorrect":
|
||||
{
|
||||
// Those methods doesn't have errors
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user