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.LoopStatement;
|
||||||
import com._1c.g5.v8.dt.bsl.model.Method;
|
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.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.StaticFeatureAccess;
|
||||||
import com._1c.g5.v8.dt.bsl.model.WhileStatement;
|
import com._1c.g5.v8.dt.bsl.model.WhileStatement;
|
||||||
import com._1c.g5.v8.dt.bsl.model.util.BslUtil;
|
import com._1c.g5.v8.dt.bsl.model.util.BslUtil;
|
||||||
@ -387,6 +388,28 @@ public class QueryInLoopCheck
|
|||||||
return predicate instanceof BooleanLiteral;
|
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,
|
private Collection<FeatureAccess> getQueryInLoopCallers(Module module, Map<String, String> methodsWithQuery,
|
||||||
Set<String> queryExecutionMethods, boolean checkQueryInInfiniteLoop, IProgressMonitor monitor)
|
Set<String> queryExecutionMethods, boolean checkQueryInInfiniteLoop, IProgressMonitor monitor)
|
||||||
{
|
{
|
||||||
@ -404,16 +427,7 @@ public class QueryInLoopCheck
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FeatureAccess featureAccess : EcoreUtil2.eAllOfType(loopStatement, FeatureAccess.class))
|
result.addAll(getQueryInLoopFeatures(loopStatement, methodsWithQuery, queryExecutionMethods));
|
||||||
{
|
|
||||||
if (featureAccess instanceof StaticFeatureAccess
|
|
||||||
&& isMethodWithQueryCalled((StaticFeatureAccess)featureAccess, methodsWithQuery)
|
|
||||||
|| featureAccess instanceof DynamicFeatureAccess
|
|
||||||
&& isQueryExecution((DynamicFeatureAccess)featureAccess, queryExecutionMethods))
|
|
||||||
{
|
|
||||||
result.add(featureAccess);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// @strict-types
|
||||||
|
|
||||||
Procedure QueryCorrect(SomeParameter) Export
|
Procedure QueryCorrect(SomeParameter) Export
|
||||||
|
|
||||||
SimpleQuery = New Query;
|
SimpleQuery = New Query;
|
||||||
@ -26,6 +28,8 @@ Procedure MethodCallsQueryCorrect(SomeParameter) Export
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// SomeArray - Array
|
||||||
Procedure ForEachStatementIncorrect(SomeArray) Export
|
Procedure ForEachStatementIncorrect(SomeArray) Export
|
||||||
|
|
||||||
ForEachQuery = New Query;
|
ForEachQuery = New Query;
|
||||||
@ -42,6 +46,8 @@ Procedure ForEachStatementIncorrect(SomeArray) Export
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// SomeArray - Array
|
||||||
Procedure ForToStatementIncorrect(SomeArray) Export
|
Procedure ForToStatementIncorrect(SomeArray) Export
|
||||||
|
|
||||||
ForToQuery = New Query;
|
ForToQuery = New Query;
|
||||||
@ -58,6 +64,8 @@ Procedure ForToStatementIncorrect(SomeArray) Export
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// SomeArray - Array
|
||||||
Procedure WhileStatementIncorrect(SomeArray) Export
|
Procedure WhileStatementIncorrect(SomeArray) Export
|
||||||
|
|
||||||
WhileQuery = New Query;
|
WhileQuery = New Query;
|
||||||
@ -72,12 +80,16 @@ Procedure WhileStatementIncorrect(SomeArray) Export
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// SomeArray - Array
|
||||||
Procedure MethodCallsIncorrectMethodCorrect(SomeArray) Export
|
Procedure MethodCallsIncorrectMethodCorrect(SomeArray) Export
|
||||||
|
|
||||||
ForEachStatementIncorrect(SomeArray);
|
ForEachStatementIncorrect(SomeArray);
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// SomeParameter - Number
|
||||||
Procedure LoopCallsMethodIncorrect(SomeParameter) Export
|
Procedure LoopCallsMethodIncorrect(SomeParameter) Export
|
||||||
|
|
||||||
LoopCallQuery = New Query;
|
LoopCallQuery = New Query;
|
||||||
@ -93,6 +105,8 @@ Procedure LoopCallsMethodIncorrect(SomeParameter) Export
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// SomeParameter - Number
|
||||||
Procedure LoopCallsMethodWithOtherMethodIncorrect(SomeParameter) Export
|
Procedure LoopCallsMethodWithOtherMethodIncorrect(SomeParameter) Export
|
||||||
|
|
||||||
MethodCallQuery = New Query;
|
MethodCallQuery = New Query;
|
||||||
@ -107,6 +121,8 @@ Procedure LoopCallsMethodWithOtherMethodIncorrect(SomeParameter) Export
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// SomeArray - Array
|
||||||
Procedure LoopWithConditionsIncorrect(SomeArray) Export
|
Procedure LoopWithConditionsIncorrect(SomeArray) Export
|
||||||
|
|
||||||
While SomeArray.Count() = 0 Do
|
While SomeArray.Count() = 0 Do
|
||||||
@ -124,6 +140,11 @@ Procedure LoopWithConditionsIncorrect(SomeArray) Export
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// ArrayElement - String
|
||||||
|
//
|
||||||
|
// Returns:
|
||||||
|
// Query
|
||||||
Function GetNewQuery(ArrayElement)
|
Function GetNewQuery(ArrayElement)
|
||||||
|
|
||||||
FunctionQuery = New Query;
|
FunctionQuery = New Query;
|
||||||
@ -138,6 +159,8 @@ Function GetNewQuery(ArrayElement)
|
|||||||
|
|
||||||
EndFunction
|
EndFunction
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// SomeArray - Array
|
||||||
Procedure QueryTypeFromFunctionIncorrect(SomeArray) Export
|
Procedure QueryTypeFromFunctionIncorrect(SomeArray) Export
|
||||||
|
|
||||||
For Each ArrayElement In SomeArray Do
|
For Each ArrayElement In SomeArray Do
|
||||||
@ -146,3 +169,25 @@ Procedure QueryTypeFromFunctionIncorrect(SomeArray) Export
|
|||||||
EndDo;
|
EndDo;
|
||||||
|
|
||||||
EndProcedure
|
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 "MethodCallsQueryCorrect":
|
||||||
case "MethodCallsIncorrectMethodCorrect":
|
case "MethodCallsIncorrectMethodCorrect":
|
||||||
case "GetNewQuery":
|
case "GetNewQuery":
|
||||||
|
case "QueryResultColumn":
|
||||||
|
case "ForEachParamQueryMethodCorrect":
|
||||||
{
|
{
|
||||||
// Those methods doesn't have errors
|
// Those methods doesn't have errors
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user