Skip to content

Commit

Permalink
Merge pull request #1454 from 1C-Company/G5V8DT-24841
Browse files Browse the repository at this point in the history
G5V8DT-24841 Не видит Экспортный метод из базовой формы #1324
  • Loading branch information
MaksimDzyuba authored Jul 25, 2024
2 parents 9b9aad6 + a38a535 commit 8024525
Show file tree
Hide file tree
Showing 44 changed files with 1,106 additions and 154 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ jobs:
# docker rmi $(docker image ls -aq) || true
df -h
- name: Cache maven repo
uses: actions/cache@v2
if: github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-latest-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('targets/default/default.target') }}
restore-keys: |
${{ runner.os }}-maven-latest-
- name: Build with Maven
working-directory: ./
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,38 @@

import java.util.Collection;
import java.util.List;
import java.util.stream.StreamSupport;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.IScopeProvider;

import com._1c.g5.v8.bm.core.IBmTransaction;
import com._1c.g5.v8.bm.integration.IBmModel;
import com._1c.g5.v8.dt.bsl.model.BslIndexPackage;
import com._1c.g5.v8.dt.bsl.model.BslFactory;
import com._1c.g5.v8.dt.bsl.model.BslPackage;
import com._1c.g5.v8.dt.bsl.model.DynamicFeatureAccess;
import com._1c.g5.v8.dt.bsl.model.Expression;
import com._1c.g5.v8.dt.bsl.model.FeatureAccess;
import com._1c.g5.v8.dt.bsl.model.FeatureEntry;
import com._1c.g5.v8.dt.bsl.model.Method;
import com._1c.g5.v8.dt.bsl.model.MethodsScopeSpec;
import com._1c.g5.v8.dt.bsl.model.Module;
import com._1c.g5.v8.dt.bsl.model.ModuleContextDefIndex;
import com._1c.g5.v8.dt.bsl.model.OperatorStyleCreator;
import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess;
import com._1c.g5.v8.dt.bsl.model.StringLiteral;
import com._1c.g5.v8.dt.bsl.resource.DynamicFeatureAccessComputer;
import com._1c.g5.v8.dt.bsl.resource.ExportMethodProvider;
import com._1c.g5.v8.dt.common.StringUtils;
import com._1c.g5.v8.dt.core.platform.IBmModelManager;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
import com._1c.g5.v8.dt.mcore.ContextDef;
import com._1c.g5.v8.dt.mcore.DerivedProperty;
import com._1c.g5.v8.dt.mcore.Environmental;
import com._1c.g5.v8.dt.mcore.Method;
import com._1c.g5.v8.dt.mcore.Property;
import com._1c.g5.v8.dt.mcore.Type;
import com._1c.g5.v8.dt.mcore.TypeItem;
import com._1c.g5.v8.dt.mcore.util.Environments;
import com._1c.g5.v8.dt.mcore.util.McoreUtil;
import com._1c.g5.v8.dt.metadata.mdclass.CommonModule;
import com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage;
import com.e1c.g5.dt.core.api.naming.INamingService;
import com.e1c.g5.v8.dt.check.CheckComplexity;
import com.e1c.g5.v8.dt.check.ICheckParameters;
import com.e1c.g5.v8.dt.check.components.BasicCheck;
Expand All @@ -70,8 +69,6 @@ public class NotifyDescriptionToServerProcedureCheck
{
private static final String CHECK_ID = "notify-description-to-server-procedure"; //$NON-NLS-1$

private static final String BSL = "bsl"; //$NON-NLS-1$

private static final String THIS_OBJECT = "ThisObject"; //$NON-NLS-1$

private static final String THIS_OBJECT_RU = "ЭтотОбъект"; //$NON-NLS-1$
Expand All @@ -81,32 +78,21 @@ public class NotifyDescriptionToServerProcedureCheck

private final DynamicFeatureAccessComputer dynamicFeatureAccessComputer;

private final ExportMethodProvider exportMethodProvider;

private final IResourceLookup resourceLookup;

private final INamingService namingService;

private final IBmModelManager bmModelManager;

private final IScopeProvider scopeProvider;

/**
* Instantiates a new notify description to server procedure check.
*
* @param dynamicFeatureAccessComputer the dynamic feature access computer service, cannot be {@code null}
* @param exportMethodProvider the export method provider service, cannot be {@code null}
* @param scopeProvider provides actual local methods, cannot be {@code null}
*/
@Inject
public NotifyDescriptionToServerProcedureCheck(DynamicFeatureAccessComputer dynamicFeatureAccessComputer,
ExportMethodProvider exportMethodProvider, IResourceLookup resourceLookup, INamingService namingService,
IBmModelManager bmModelManager)
IScopeProvider scopeProvider)
{
super();
this.dynamicFeatureAccessComputer = dynamicFeatureAccessComputer;
this.exportMethodProvider = exportMethodProvider;
this.resourceLookup = resourceLookup;
this.namingService = namingService;
this.bmModelManager = bmModelManager;
this.scopeProvider = scopeProvider;
}

@Override
Expand Down Expand Up @@ -142,33 +128,13 @@ protected void check(Object object, ResultAcceptor resultAceptor, ICheckParamete
}

StringLiteral param = (StringLiteral)osc.getParams().get(0);
final String methodName = getCalledProcedureName(param);
String methodName = getCalledProcedureName(param);
if (monitor.isCanceled() || StringUtils.isBlank(methodName))
{
return;
}

String contextDefUriAsString = getBslModuleUri(osc);

if (monitor.isCanceled() || contextDefUriAsString == null)
{
return;
}

URI contextDefUri = URI.createURI(contextDefUriAsString, true);

IDtProject project = resourceLookup.getDtProject(contextDefUri);
String contextDefIndexFqn = namingService.getDependentObjectFqnAsString(contextDefUri,
BslIndexPackage.Literals.MODULE_CONTEXT_DEF_INDEX);
IBmModel model = bmModelManager.getModel(project);
IBmTransaction bmTransaction = model.getEngine().getCurrentTransaction();
ModuleContextDefIndex index = (ModuleContextDefIndex)bmTransaction.getTopObjectByFqn(contextDefIndexFqn);
if (index == null)
{
return;
}

Collection<Method> methods = exportMethodProvider.getMockMethods(index.getContextDef(), methodName, osc);
Collection<Environmental> methods = getMethods(methodName, osc, monitor);
if (methods.isEmpty())
{
resultAceptor.addIssue(
Expand All @@ -177,7 +143,7 @@ protected void check(Object object, ResultAcceptor resultAceptor, ICheckParamete
}
else
{
for (Method method : methods)
for (Environmental method : methods)
{
Environments calleeEnv = method.environments();
if (calleeEnv.containsAny(Environments.MNG_CLIENTS))
Expand All @@ -193,116 +159,85 @@ protected void check(Object object, ResultAcceptor resultAceptor, ICheckParamete

}

private String getCalledProcedureName(Expression param)
{
if (param instanceof StringLiteral)
{
StringLiteral literal = (StringLiteral)param;
if (literal.getLines().size() == 1)
{
return literal.lines(true).get(0);
}
}
return null;
}

private String getBslModuleUri(OperatorStyleCreator osc)
private Collection<Environmental> getMethods(String methodName, OperatorStyleCreator osc, IProgressMonitor monitor)
{
List<Expression> params = osc.getParams();

if (params.size() > 1)
{
Expression moduleParam = params.get(1);
if (moduleParam instanceof StaticFeatureAccess)
{
return getBslModuleUri((StaticFeatureAccess)moduleParam);
}
else if (moduleParam instanceof DynamicFeatureAccess)
{
return getBslModuleUri((DynamicFeatureAccess)moduleParam);
}
}

return null;
}

private String getBslModuleUri(StaticFeatureAccess object)
{
URI uri = null;
if (object.getName().equals(THIS_OBJECT) || object.getName().equals(THIS_OBJECT_RU))
{
uri = EcoreUtil.getURI(object);
}
else
{
uri = getCommonModuleUri(object);
}
return constructBslUri(uri);
}

private String getBslModuleUri(DynamicFeatureAccess object)
{
URI uri = getCommonModuleUri(object);

return constructBslUri(uri);
}

private String constructBslUri(URI uri)
{
if (uri == null)
{
return null;
}
return uri.trimFragment().trimFileExtension().appendFileExtension(BSL).toString();
}

private URI getCommonModuleUri(DynamicFeatureAccess object)
{
Environmental environmental = EcoreUtil2.getContainerOfType(object, Environmental.class);

List<FeatureEntry> features = dynamicFeatureAccessComputer.getLastObject(object, environmental.environments());
for (FeatureEntry featureEntry : features)
{
EObject feature = featureEntry.getFeature();
if (feature instanceof Property && ((Property)feature).getName().equals(THIS_OBJECT))
if (moduleParam instanceof FeatureAccess featureAccess)
{
Expression staticFeatureAccess = object.getSource();
if (staticFeatureAccess instanceof StaticFeatureAccess)
if (featureAccess instanceof StaticFeatureAccess
&& (THIS_OBJECT_RU.equals(featureAccess.getName()) || THIS_OBJECT.equals(featureAccess.getName())))
{
return getCommonModuleUri((StaticFeatureAccess)staticFeatureAccess);
Module module = EcoreUtil2.getContainerOfType(featureAccess, Module.class);
MethodsScopeSpec spec = BslFactory.eINSTANCE.createMethodsScopeSpec();
spec.setModule(module);
spec.setOnlyModuleItems(true);
spec.setEnvironments(Environments.ALL_CLIENTS);
IScope methodScope =
scopeProvider.getScope(spec, BslPackage.Literals.METHODS_SCOPE_SPEC__METHOD_REF);
return StreamSupport
.stream(methodScope.getElements(QualifiedName.create(methodName)).spliterator(), false)
.map(IEObjectDescription::getEObjectOrProxy)
.filter(Method.class::isInstance)
.map(Method.class::cast)
.filter(Method::isExport)
.map(Environmental.class::cast)
.toList();
}
}
else if (feature instanceof Module)
{
return EcoreUtil.getURI(feature);
}
else if (feature instanceof CommonModule)
{
EObject module = (EObject)feature.eGet(MdClassPackage.Literals.COMMON_MODULE__MODULE, false);
if (module != null)
else
{
return EcoreUtil.getURI(module);
Environmental environmental = EcoreUtil2.getContainerOfType(featureAccess, Environmental.class);
List<FeatureEntry> entries = featureAccess instanceof StaticFeatureAccess
? ((StaticFeatureAccess)featureAccess).getFeatureEntries() : dynamicFeatureAccessComputer
.getLastObject((DynamicFeatureAccess)featureAccess, environmental.environments());
for (FeatureEntry entry : entries)
{
if (entry.getFeature() instanceof DerivedProperty derivedProperty
&& derivedProperty.getSource() instanceof CommonModule)
{
List<TypeItem> types = derivedProperty.getTypes();
if (types != null && types.size() == 1 && types.get(0) instanceof Type)
{
return ((Type)types.get(0)).getContextDef()
.allMethods()
.stream()
.filter(Environmental.class::isInstance)
.filter(item -> methodName.equalsIgnoreCase(item.getName()))
.map(Environmental.class::cast)
.toList();
}
}
else if (entry.getFeature() instanceof Property property
&& THIS_OBJECT.equals(property.getName())
&& property.eContainer() instanceof ContextDef contextDef)
{
return contextDef.allMethods()
.stream()
.filter(Environmental.class::isInstance)
.filter(item -> methodName.equalsIgnoreCase(item.getName()))
.map(Environmental.class::cast)
.toList();
}
}
}
}
}
return null;

return List.of();
}

private URI getCommonModuleUri(StaticFeatureAccess object)
private String getCalledProcedureName(Expression param)
{
for (FeatureEntry entry : object.getFeatureEntries())
if (param instanceof StringLiteral)
{
EObject f = entry.getFeature();
if (f instanceof DerivedProperty)
StringLiteral literal = (StringLiteral)param;
if (literal.getLines().size() == 1)
{
EObject source = ((DerivedProperty)f).getSource();
if (source instanceof CommonModule)
{
return EcoreUtil.getURI((EObject)source.eGet(MdClassPackage.Literals.COMMON_MODULE__MODULE, false));
}
return literal.lines(true).get(0);
}
}
return null;
}

}
1 change: 1 addition & 0 deletions targets/default/default.target
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="slicer" includeSource="true" type="InstallableUnit">
<repository id="dt_repository" location="https://edt.1c.ru/downloads/releases/ruby/2024.1/"/>
<unit id="com._1c.g5.v8.dt.platform.support_v8.3.19.feature.feature.group" version="0.0.0"/>
<unit id="com._1c.g5.v8.dt.platform.support_v8.3.23.feature.feature.group" version="0.0.0"/>
</location>

<!-- EDT -->
Expand Down
Loading

0 comments on commit 8024525

Please sign in to comment.