1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2025-02-21 16:05:10 +02:00

Merge branch 'edt-2024-1' into G5V8DT-22792

This commit is contained in:
Maxim Dzyuba 2024-06-19 00:08:55 +03:00
commit e6eb68c176
7 changed files with 162 additions and 59 deletions

View File

@ -20,7 +20,7 @@ Bundle-Localization: plugin
Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.0.0)",
com._1c.g5.v8.bm.core;version="[8.0.0,9.0.0)",
com._1c.g5.v8.dt.bsl.comment;version="[3.0.0,4.0.0)",
com._1c.g5.v8.dt.bsl.common;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.bsl.common;version="[7.0.0,8.0.0)",
com._1c.g5.v8.dt.bsl.documentation.comment;version="[5.0.0,6.0.0)",
com._1c.g5.v8.dt.bsl.formatting;version="[3.0.0,4.0.0)",
com._1c.g5.v8.dt.bsl.model;version="[5.0.0,6.0.0)",
@ -28,10 +28,10 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.0
com._1c.g5.v8.dt.bsl.resource.owner;version="[2.0.0,3.0.0)",
com._1c.g5.v8.dt.bsl.services;version="[7.0.0,8.0.0)",
com._1c.g5.v8.dt.bsl.ui;version="[9.0.0,10.0.0)",
com._1c.g5.v8.dt.bsl.ui.contentassist;version="[8.0.0,9.0.0)",
com._1c.g5.v8.dt.bsl.ui.contentassist;version="[9.0.0,10.0.0)",
com._1c.g5.v8.dt.bsl.ui.editor;version="[10.0.0,11.0.0)",
com._1c.g5.v8.dt.bsl.ui.event;version="[5.0.0,6.0.0)",
com._1c.g5.v8.dt.bsl.ui.menu;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.bsl.ui.event;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.bsl.ui.menu;version="[7.0.0,8.0.0)",
com._1c.g5.v8.dt.bsl.ui.quickfix;version="[4.1.0,5.0.0)",
com._1c.g5.v8.dt.bsl.util;version="[8.0.0,9.0.0)",
com._1c.g5.v8.dt.common;version="[6.0.0,7.0.0)",

View File

@ -165,7 +165,7 @@ public class FormatDocCommentModuleEditorHandler
int methodOffset = lines.get(0).getOffset();
int length = lines.get(lines.size() - 1).getEndOffset() - methodOffset;
String lineFormatter = proposalProvider.getLineFormatter(module, methodOffset, viewer.getDocument());
String lineFormatter = proposalProvider.getLineFormatter(module, viewer.getDocument(), methodOffset);
IV8Project project = v8projectManager.getProject(module);
boolean oldFormat = (project != null && project.getProject() != null)
? this.bslPreferences.getDocumentCommentProperties(project.getProject()).oldCommentFormat() : true;

View File

@ -22,7 +22,7 @@ import org.eclipse.xtext.nodemodel.INode;
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
/**
* Provides offset and suffixes information of module region
* Provides offsets and suffixes information of module region
*
* @author Kuznetsov Nikita
*/
@ -32,6 +32,8 @@ public final class BslModuleOffsets
private int endOffset;
private int insertOffset;
private boolean needReplace;
private Map<String, BslModuleOffsets> suffixes;
/**
@ -89,6 +91,24 @@ public final class BslModuleOffsets
return insertOffset;
}
/**
* Is need to replace existing module region
*
* @return <code>true</code> if need to replace existing region, <code>false</code> otherwise
*/
public boolean needReplace()
{
return needReplace;
}
/**
* Sets necessity of replacing existing module region
*/
public void setNeedReplace()
{
needReplace = true;
}
/**
* Add suffix of the name of this module region
*

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2023, 1C-Soft LLC and others.
* Copyright (C) 2023-2024, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@ -12,8 +12,9 @@
*******************************************************************************/
package com.e1c.v8codestyle.internal.bsl.ui.services;
import org.eclipse.emf.common.util.URI;
import com._1c.g5.v8.dt.bsl.common.IBslModuleTextInsertInfo;
import com._1c.g5.v8.dt.bsl.model.Module;
/**
* Built-in language module region information with {@link String} region wrap data
@ -23,34 +24,47 @@ import com._1c.g5.v8.dt.bsl.model.Module;
public class BslModuleRegionsInfo
implements IBslModuleTextInsertInfo
{
private final URI resourceURI;
private final int insertPosition;
private final Module module;
private final int clearPosition;
private final int clearLength;
private final String regionName;
/**
* {@link BslModuleRegionsInfo} constructor
*
* @param resourceURI current module or document resource {@link URI}, cannot be <code>null</code>
* @param insertPosition <code>int</code> insertion offset, cannot be negative
* @param module current {@link Module}, cannot be <code>null</code>
* @param clearPosition text clear <code>int</code> position, can be negative if no clear needed
* @param clearLength text clear <code>int</code> length, can be negative if no clear needed
* @param regionName {@link String} region name, can be <code>null</code>
*/
public BslModuleRegionsInfo(int insertPosition, Module module, String regionName)
public BslModuleRegionsInfo(URI resourceURI, int insertPosition, int clearPosition, int clearLength,
String regionName)
{
this.resourceURI = resourceURI;
this.insertPosition = insertPosition;
this.module = module;
this.clearPosition = clearPosition;
this.clearLength = clearLength;
this.regionName = regionName;
}
@Override
public int getInsertPosition()
public URI getResourceURI()
{
return insertPosition;
return resourceURI;
}
@Override
public Module getModule()
public int getPosition()
{
return module;
return clearLength > 0 ? clearPosition : insertPosition;
}
@Override
public int getClearLength()
{
return clearLength;
}
/**

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2023, 1C-Soft LLC and others.
* Copyright (C) 2023-2024, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@ -22,7 +22,9 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import com._1c.g5.v8.dt.bsl.common.EventItemType;
import com._1c.g5.v8.dt.bsl.common.IBslModuleEventData;
@ -33,6 +35,7 @@ import com._1c.g5.v8.dt.bsl.model.RegionPreprocessor;
import com._1c.g5.v8.dt.bsl.model.util.BslUtil;
import com._1c.g5.v8.dt.bsl.resource.owner.BslOwnerComputerService;
import com._1c.g5.v8.dt.bsl.ui.BslGeneratorMultiLangProposals;
import com._1c.g5.v8.dt.bsl.ui.editor.BslXtextDocument;
import com._1c.g5.v8.dt.bsl.ui.event.BslModuleEventData;
import com._1c.g5.v8.dt.common.PreferenceUtils;
import com._1c.g5.v8.dt.common.StringUtils;
@ -53,69 +56,90 @@ import com.google.inject.Inject;
public class BslModuleRegionsInfoService
implements IBslModuleTextInsertInfoService
{
@Inject
private IModuleStructureProvider moduleStructureProvider;
@Override
public IBslModuleTextInsertInfo getEventHandlerTextInsertInfo(IXtextDocument document, Module module,
int defaultPosition, IBslModuleEventData data)
public IBslModuleTextInsertInfo getEventHandlerTextInsertInfo(IXtextDocument document, int defaultPosition,
IBslModuleEventData data)
{
if (!(data instanceof BslModuleEventData))
{
return () -> defaultPosition;
return IBslModuleTextInsertInfo.getDefaultModuleTextInsertInfo(document, defaultPosition);
}
URI moduleResourceUri = module.eResource().getURI();
BslModuleEventData bslModuleEventData = (BslModuleEventData)data;
URI resourceURI = document.getResourceURI();
IResourceServiceProvider rsp =
IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(moduleResourceUri);
IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(resourceURI);
IV8ProjectManager projectManager = rsp.get(IV8ProjectManager.class);
BslOwnerComputerService bslOwnerComputerService = rsp.get(BslOwnerComputerService.class);
IV8Project project = projectManager.getProject(moduleResourceUri);
EClass moduleOwner = bslOwnerComputerService.computeOwnerEClass(module);
IV8Project project = projectManager.getProject(resourceURI);
ModuleInfoUnitOfWork moduleInfoUnitOfWork = new ModuleInfoUnitOfWork(rsp.get(BslOwnerComputerService.class));
ModuleInfo moduleInfo = document instanceof BslXtextDocument bslXTextDocument
? bslXTextDocument.readOnlyDataModelWithoutSync(moduleInfoUnitOfWork)
: document.readOnly(moduleInfoUnitOfWork);
EObject eventOwner = data.getEventOwner();
BslModuleEventData regionData = (BslModuleEventData)data;
EventItemType itemType = regionData.getEventItemType();
String suffix = getSuffix(eventOwner, itemType);
List<RegionPreprocessor> regionPreprocessors = BslUtil.getAllRegionPreprocessors(module);
String suffix = getSuffix(eventOwner, itemType, bslModuleEventData.isInternal());
ScriptVariant scriptVariant = project.getScriptVariant();
String declaredRegionName = getDeclaredRegionName(moduleOwner, itemType, scriptVariant);
String declaredRegionName =
getDeclaredRegionName(moduleInfo.owner, itemType, bslModuleEventData.isInternal(), scriptVariant);
Map<String, BslModuleOffsets> regionOffsets =
getRegionOffsets(document, regionPreprocessors, declaredRegionName, scriptVariant);
getRegionOffsets(document, moduleInfo.regionPreprocessors, declaredRegionName, scriptVariant);
BslModuleOffsets bslModuleOffsets = regionOffsets.get(declaredRegionName);
int offset = getRegionOffset(regionOffsets, declaredRegionName, suffix, defaultPosition, scriptVariant);
String regionName = null;
if (!isRegionExists(regionOffsets, declaredRegionName, suffix) && project.getProject() != null
boolean createRegion = !isRegionExists(regionOffsets, declaredRegionName, suffix);
int clearOffset = 0;
int clearLength = 0;
if (bslModuleOffsets != null && bslModuleOffsets.needReplace())
{
createRegion = true;
String lineSeparator = PreferenceUtils.getLineSeparator(project.getProject());
int lineSeparatorOffset =
bslModuleOffsets.getStartOffset() >= lineSeparator.length() ? lineSeparator.length() : 0;
clearOffset = bslModuleOffsets.getStartOffset() - lineSeparatorOffset;
clearLength = bslModuleOffsets.getEndOffset() - bslModuleOffsets.getStartOffset() + lineSeparatorOffset;
}
if (createRegion && project.getProject() != null
&& moduleStructureProvider.canCreateStructure(project.getProject()))
{
regionName = suffix.isEmpty() ? declaredRegionName : (declaredRegionName + suffix);
}
return new BslModuleRegionsInfo(offset, module, regionName);
return new BslModuleRegionsInfo(resourceURI, offset, clearOffset, clearLength, regionName);
}
@Override
public String wrap(IBslModuleTextInsertInfo moduleTextInsertInfo, String content)
{
if (moduleTextInsertInfo instanceof BslModuleRegionsInfo)
if (moduleTextInsertInfo instanceof BslModuleRegionsInfo moduleRegionInformation)
{
BslModuleRegionsInfo moduleRegionInformation = (BslModuleRegionsInfo)moduleTextInsertInfo;
Module module = moduleTextInsertInfo.getModule();
String regionName = moduleRegionInformation.getRegionName();
if (module != null && regionName != null)
if (regionName != null)
{
URI moduleResourceUri = module.eResource().getURI();
IResourceServiceProvider rsp =
IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(moduleResourceUri);
IResourceServiceProvider rsp = IResourceServiceProvider.Registry.INSTANCE
.getResourceServiceProvider(moduleTextInsertInfo.getResourceURI());
IV8ProjectManager projectManager = rsp.get(IV8ProjectManager.class);
BslGeneratorMultiLangProposals proposals = rsp.get(BslGeneratorMultiLangProposals.class);
IV8Project project = projectManager.getProject(moduleResourceUri);
IV8Project project = projectManager.getProject(moduleTextInsertInfo.getResourceURI());
String lineSeparator = PreferenceUtils.getLineSeparator(project.getProject());
proposals.setRussianLang(ScriptVariant.RUSSIAN.equals(project.getScriptVariant()));
String beginRegion = proposals.getBeginRegionPropStr();
String endRegion = proposals.getEndRegionPropStr();
String space = proposals.getSpacePropStr();
StringBuilder builder = new StringBuilder();
builder.append(lineSeparator).append(beginRegion).append(space).append(regionName);
builder.append(lineSeparator).append(content).append(lineSeparator);
if (moduleTextInsertInfo.getPosition() != 0)
{
builder.append(lineSeparator);
}
builder.append(beginRegion).append(space).append(regionName);
builder.append(content);
builder.append(endRegion);
builder.append(lineSeparator);
if (moduleTextInsertInfo.getPosition() == 0)
{
builder.append(lineSeparator);
}
return builder.toString();
}
}
@ -171,6 +195,10 @@ public class BslModuleRegionsInfoService
regionOffsets.put(declaredRegionName, moduleRegionInformation);
if ((targetRegionName != null) && targetRegionName.equals(preprocessorRegionName))
{
if (node.getLength() == 0)
{
moduleRegionInformation.setNeedReplace();
}
return regionOffsets;
}
}
@ -188,6 +216,7 @@ public class BslModuleRegionsInfoService
int offset = defaultOffset;
boolean createNewRegion = !isRegionExists(regionOffsets, declaredRegionName, suffix);
BslModuleOffsets regionOffset = regionOffsets.get(declaredRegionName);
if (regionOffset != null)
{
if (!suffix.isEmpty())
@ -225,6 +254,8 @@ public class BslModuleRegionsInfoService
boolean placeBefore = false;
int offset = regionOffsets.isEmpty() ? 0 : defaultOffset;
ModuleStructureSection[] declaredRegionNames = ModuleStructureSection.values();
BslModuleOffsets lastRegionInformation = null;
BslModuleOffsets regionInformation = null;
for (int regionNameIndex = 0; regionNameIndex < declaredRegionNames.length; regionNameIndex++)
{
ModuleStructureSection moduleStructuredSection = declaredRegionNames[regionNameIndex];
@ -233,12 +264,17 @@ public class BslModuleRegionsInfoService
{
placeBefore = true;
}
BslModuleOffsets regionInformation = regionOffsets.get(declaredRegionName);
if (regionInformation != null)
{
lastRegionInformation = regionInformation;
}
regionInformation = regionOffsets.get(declaredRegionName);
if (regionInformation != null)
{
if (placeBefore && (suffix.isEmpty() || !declaredRegionName.equals(regionName)))
{
return regionInformation.getStartOffset();
return lastRegionInformation != null ? lastRegionInformation.getEndOffset()
: regionInformation.getStartOffset();
}
offset = placeBefore ? regionInformation.getStartOffset() : regionInformation.getEndOffset();
}
@ -246,20 +282,18 @@ public class BslModuleRegionsInfoService
return offset;
}
private String getDeclaredRegionName(EClass moduleOwnerClass, EventItemType itemType, ScriptVariant scriptVariant)
private String getDeclaredRegionName(EClass moduleOwnerClass, EventItemType itemType, boolean isInternal,
ScriptVariant scriptVariant)
{
String moduleOwnerName = moduleOwnerClass.getName();
switch (moduleOwnerName)
if (isInternal)
{
case "AbstractForm": //$NON-NLS-1$
return getDeclaredRegionNameForForm(itemType, scriptVariant);
case "WebService": //$NON-NLS-1$
case "HTTPService": //$NON-NLS-1$
case "IntegrationService": //$NON-NLS-1$
return getPrivateRegionName(scriptVariant);
default:
return getDefaultRegionName(scriptVariant);
}
if (moduleOwnerClass.getName().equals("AbstractForm")) //$NON-NLS-1$
{
return getDeclaredRegionNameForForm(itemType, scriptVariant);
}
return getDefaultRegionName(scriptVariant);
}
private String getDeclaredRegionNameForForm(EventItemType itemType, ScriptVariant scriptVariant)
@ -287,8 +321,12 @@ public class BslModuleRegionsInfoService
return ModuleStructureSection.EVENT_HANDLERS.getName(scriptVariant);
}
private String getSuffix(EObject eventOwner, EventItemType itemType)
private String getSuffix(EObject eventOwner, EventItemType itemType, boolean isInternal)
{
if (isInternal)
{
return StringUtils.EMPTY;
}
if (itemType.equals(EventItemType.TABLE))
{
EObject container = eventOwner;
@ -318,4 +356,35 @@ public class BslModuleRegionsInfoService
return regionName.length() >= declaredRegionNameLength
&& regionName.substring(0, declaredRegionNameLength).equals(declaredRegionName);
}
private final class ModuleInfo
{
private final EClass owner;
private final List<RegionPreprocessor> regionPreprocessors;
public ModuleInfo(EClass owner, List<RegionPreprocessor> regionPreprocessors)
{
this.owner = owner;
this.regionPreprocessors = regionPreprocessors;
}
}
private final class ModuleInfoUnitOfWork
implements IUnitOfWork<ModuleInfo, XtextResource>
{
private final BslOwnerComputerService bslOwnerComputerService;
public ModuleInfoUnitOfWork(BslOwnerComputerService bslOwnerComputerService)
{
this.bslOwnerComputerService = bslOwnerComputerService;
}
@Override
public ModuleInfo exec(XtextResource resource) throws Exception
{
Module module = (Module)resource.getParseResult().getRootASTElement();
return new ModuleInfo(bslOwnerComputerService.computeOwnerEClass(module),
BslUtil.getAllRegionPreprocessors(module));
}
}
}

View File

@ -19,9 +19,9 @@ Bundle-ActivationPolicy: lazy
Import-Package: com._1c.g5.v8.bm.core;version="[8.0.0,9.0.0)",
com._1c.g5.v8.bm.integration;version="[11.0.0,12.0.0)",
com._1c.g5.v8.dt.bm.xtext;version="[15.0.0,16.0.0)",
com._1c.g5.v8.dt.bsl;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.bsl;version="[7.0.0,8.0.0)",
com._1c.g5.v8.dt.bsl.comment;version="[3.0.0,4.0.0)",
com._1c.g5.v8.dt.bsl.common;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.bsl.common;version="[7.0.0,8.0.0)",
com._1c.g5.v8.dt.bsl.contextdef;version="[2.0.0,3.0.0)",
com._1c.g5.v8.dt.bsl.documentation.comment;version="[5.0.0,6.0.0)",
com._1c.g5.v8.dt.bsl.model;version="[5.0.0,6.0.0)",
@ -47,7 +47,7 @@ Import-Package: com._1c.g5.v8.bm.core;version="[8.0.0,9.0.0)",
com._1c.g5.wiring.binder;version="[1.0.0,2.0.0)",
com.e1c.g5.dt.core.api.naming;version="1.0.0",
com.e1c.g5.dt.core.api.platform;version="[1.1.0,2.0.0)",
com.e1c.g5.v8.dt.bsl.check;version="[2.0.0,3.0.0)",
com.e1c.g5.v8.dt.bsl.check;version="[3.0.0,4.0.0)",
com.e1c.g5.v8.dt.bsl.check.qfix;version="[3.0.0,4.0.0)",
com.e1c.g5.v8.dt.check;version="[2.0.0,3.0.0)",
com.e1c.g5.v8.dt.check.components;version="[2.0.0,3.0.0)",

View File

@ -22,7 +22,7 @@ Import-Package: com._1c.g5.v8.bm.core;version="[8.0.0,9.0.0)",
com._1c.g5.v8.dt.common;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.core.platform;version="[11.0.0,12.0.0)",
com._1c.g5.v8.dt.mcore;version="[7.0.0,8.0.0)",
com._1c.g5.v8.dt.md;version="[19.0.0,20.0.0)",
com._1c.g5.v8.dt.md;version="[20.0.0,21.0.0)",
com._1c.g5.v8.dt.metadata.mdclass;version="[9.0.0,10.0.0)",
com._1c.g5.v8.dt.platform.version;version="[2.0.0,3.0.0)",
com._1c.g5.v8.dt.rights;version="[7.0.0,8.0.0)",