You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-06-30 22:14:07 +02:00
Merge pull request #1437 from 1C-Company/G5V8DT-24814
G5V8DT-24814 Некорректная вставка в область модуля вспомогательных методов событий
This commit is contained in:
@ -20,7 +20,7 @@ Bundle-Localization: plugin
|
|||||||
Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.0.0)",
|
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.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.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="[4.0.0,5.0.0)",
|
com._1c.g5.v8.dt.bsl.documentation.comment;version="[4.0.0,5.0.0)",
|
||||||
com._1c.g5.v8.dt.bsl.formatting;version="[3.0.0,4.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)",
|
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.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.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;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.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.event;version="[6.0.0,7.0.0)",
|
||||||
com._1c.g5.v8.dt.bsl.ui.menu;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.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.bsl.util;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.common;version="[6.0.0,7.0.0)",
|
||||||
|
@ -165,7 +165,7 @@ public class FormatDocCommentModuleEditorHandler
|
|||||||
int methodOffset = lines.get(0).getOffset();
|
int methodOffset = lines.get(0).getOffset();
|
||||||
int length = lines.get(lines.size() - 1).getEndOffset() - methodOffset;
|
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);
|
IV8Project project = v8projectManager.getProject(module);
|
||||||
boolean oldFormat = (project != null && project.getProject() != null)
|
boolean oldFormat = (project != null && project.getProject() != null)
|
||||||
? this.bslPreferences.getDocumentCommentProperties(project.getProject()).oldCommentFormat() : true;
|
? this.bslPreferences.getDocumentCommentProperties(project.getProject()).oldCommentFormat() : true;
|
||||||
|
@ -22,7 +22,7 @@ import org.eclipse.xtext.nodemodel.INode;
|
|||||||
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
|
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
|
* @author Kuznetsov Nikita
|
||||||
*/
|
*/
|
||||||
@ -32,6 +32,8 @@ public final class BslModuleOffsets
|
|||||||
private int endOffset;
|
private int endOffset;
|
||||||
private int insertOffset;
|
private int insertOffset;
|
||||||
|
|
||||||
|
private boolean needReplace;
|
||||||
|
|
||||||
private Map<String, BslModuleOffsets> suffixes;
|
private Map<String, BslModuleOffsets> suffixes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,6 +91,24 @@ public final class BslModuleOffsets
|
|||||||
return insertOffset;
|
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
|
* Add suffix of the name of this module region
|
||||||
*
|
*
|
||||||
|
@ -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
|
* This program and the accompanying materials are made
|
||||||
* available under the terms of the Eclipse Public License 2.0
|
* available under the terms of the Eclipse Public License 2.0
|
||||||
@ -12,8 +12,9 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.e1c.v8codestyle.internal.bsl.ui.services;
|
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.common.IBslModuleTextInsertInfo;
|
||||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Built-in language module region information with {@link String} region wrap data
|
* 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
|
public class BslModuleRegionsInfo
|
||||||
implements IBslModuleTextInsertInfo
|
implements IBslModuleTextInsertInfo
|
||||||
{
|
{
|
||||||
|
private final URI resourceURI;
|
||||||
private final int insertPosition;
|
private final int insertPosition;
|
||||||
private final Module module;
|
private final int clearPosition;
|
||||||
|
private final int clearLength;
|
||||||
private final String regionName;
|
private final String regionName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link BslModuleRegionsInfo} constructor
|
* {@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 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>
|
* @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.insertPosition = insertPosition;
|
||||||
this.module = module;
|
this.clearPosition = clearPosition;
|
||||||
|
this.clearLength = clearLength;
|
||||||
this.regionName = regionName;
|
this.regionName = regionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInsertPosition()
|
public URI getResourceURI()
|
||||||
{
|
{
|
||||||
return insertPosition;
|
return resourceURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Module getModule()
|
public int getPosition()
|
||||||
{
|
{
|
||||||
return module;
|
return clearLength > 0 ? clearPosition : insertPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getClearLength()
|
||||||
|
{
|
||||||
|
return clearLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
* This program and the accompanying materials are made
|
||||||
* available under the terms of the Eclipse Public License 2.0
|
* 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.INode;
|
||||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||||
import org.eclipse.xtext.resource.IResourceServiceProvider;
|
import org.eclipse.xtext.resource.IResourceServiceProvider;
|
||||||
|
import org.eclipse.xtext.resource.XtextResource;
|
||||||
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
|
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.EventItemType;
|
||||||
import com._1c.g5.v8.dt.bsl.common.IBslModuleEventData;
|
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.model.util.BslUtil;
|
||||||
import com._1c.g5.v8.dt.bsl.resource.owner.BslOwnerComputerService;
|
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.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.bsl.ui.event.BslModuleEventData;
|
||||||
import com._1c.g5.v8.dt.common.PreferenceUtils;
|
import com._1c.g5.v8.dt.common.PreferenceUtils;
|
||||||
import com._1c.g5.v8.dt.common.StringUtils;
|
import com._1c.g5.v8.dt.common.StringUtils;
|
||||||
@ -53,69 +56,90 @@ import com.google.inject.Inject;
|
|||||||
public class BslModuleRegionsInfoService
|
public class BslModuleRegionsInfoService
|
||||||
implements IBslModuleTextInsertInfoService
|
implements IBslModuleTextInsertInfoService
|
||||||
{
|
{
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private IModuleStructureProvider moduleStructureProvider;
|
private IModuleStructureProvider moduleStructureProvider;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBslModuleTextInsertInfo getEventHandlerTextInsertInfo(IXtextDocument document, Module module,
|
public IBslModuleTextInsertInfo getEventHandlerTextInsertInfo(IXtextDocument document, int defaultPosition,
|
||||||
int defaultPosition, IBslModuleEventData data)
|
IBslModuleEventData data)
|
||||||
{
|
{
|
||||||
if (!(data instanceof BslModuleEventData))
|
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 rsp =
|
||||||
IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(moduleResourceUri);
|
IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(resourceURI);
|
||||||
IV8ProjectManager projectManager = rsp.get(IV8ProjectManager.class);
|
IV8ProjectManager projectManager = rsp.get(IV8ProjectManager.class);
|
||||||
BslOwnerComputerService bslOwnerComputerService = rsp.get(BslOwnerComputerService.class);
|
IV8Project project = projectManager.getProject(resourceURI);
|
||||||
IV8Project project = projectManager.getProject(moduleResourceUri);
|
ModuleInfoUnitOfWork moduleInfoUnitOfWork = new ModuleInfoUnitOfWork(rsp.get(BslOwnerComputerService.class));
|
||||||
EClass moduleOwner = bslOwnerComputerService.computeOwnerEClass(module);
|
ModuleInfo moduleInfo = document instanceof BslXtextDocument bslXTextDocument
|
||||||
|
? bslXTextDocument.readOnlyDataModelWithoutSync(moduleInfoUnitOfWork)
|
||||||
|
: document.readOnly(moduleInfoUnitOfWork);
|
||||||
EObject eventOwner = data.getEventOwner();
|
EObject eventOwner = data.getEventOwner();
|
||||||
BslModuleEventData regionData = (BslModuleEventData)data;
|
BslModuleEventData regionData = (BslModuleEventData)data;
|
||||||
EventItemType itemType = regionData.getEventItemType();
|
EventItemType itemType = regionData.getEventItemType();
|
||||||
String suffix = getSuffix(eventOwner, itemType);
|
String suffix = getSuffix(eventOwner, itemType, bslModuleEventData.isInternal());
|
||||||
List<RegionPreprocessor> regionPreprocessors = BslUtil.getAllRegionPreprocessors(module);
|
|
||||||
ScriptVariant scriptVariant = project.getScriptVariant();
|
ScriptVariant scriptVariant = project.getScriptVariant();
|
||||||
String declaredRegionName = getDeclaredRegionName(moduleOwner, itemType, scriptVariant);
|
String declaredRegionName =
|
||||||
|
getDeclaredRegionName(moduleInfo.owner, itemType, bslModuleEventData.isInternal(), scriptVariant);
|
||||||
Map<String, BslModuleOffsets> regionOffsets =
|
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);
|
int offset = getRegionOffset(regionOffsets, declaredRegionName, suffix, defaultPosition, scriptVariant);
|
||||||
String regionName = null;
|
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()))
|
&& moduleStructureProvider.canCreateStructure(project.getProject()))
|
||||||
{
|
{
|
||||||
regionName = suffix.isEmpty() ? declaredRegionName : (declaredRegionName + suffix);
|
regionName = suffix.isEmpty() ? declaredRegionName : (declaredRegionName + suffix);
|
||||||
}
|
}
|
||||||
return new BslModuleRegionsInfo(offset, module, regionName);
|
return new BslModuleRegionsInfo(resourceURI, offset, clearOffset, clearLength, regionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String wrap(IBslModuleTextInsertInfo moduleTextInsertInfo, String content)
|
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();
|
String regionName = moduleRegionInformation.getRegionName();
|
||||||
if (module != null && regionName != null)
|
if (regionName != null)
|
||||||
{
|
{
|
||||||
URI moduleResourceUri = module.eResource().getURI();
|
IResourceServiceProvider rsp = IResourceServiceProvider.Registry.INSTANCE
|
||||||
IResourceServiceProvider rsp =
|
.getResourceServiceProvider(moduleTextInsertInfo.getResourceURI());
|
||||||
IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(moduleResourceUri);
|
|
||||||
IV8ProjectManager projectManager = rsp.get(IV8ProjectManager.class);
|
IV8ProjectManager projectManager = rsp.get(IV8ProjectManager.class);
|
||||||
BslGeneratorMultiLangProposals proposals = rsp.get(BslGeneratorMultiLangProposals.class);
|
BslGeneratorMultiLangProposals proposals = rsp.get(BslGeneratorMultiLangProposals.class);
|
||||||
IV8Project project = projectManager.getProject(moduleResourceUri);
|
IV8Project project = projectManager.getProject(moduleTextInsertInfo.getResourceURI());
|
||||||
String lineSeparator = PreferenceUtils.getLineSeparator(project.getProject());
|
String lineSeparator = PreferenceUtils.getLineSeparator(project.getProject());
|
||||||
proposals.setRussianLang(ScriptVariant.RUSSIAN.equals(project.getScriptVariant()));
|
proposals.setRussianLang(ScriptVariant.RUSSIAN.equals(project.getScriptVariant()));
|
||||||
String beginRegion = proposals.getBeginRegionPropStr();
|
String beginRegion = proposals.getBeginRegionPropStr();
|
||||||
String endRegion = proposals.getEndRegionPropStr();
|
String endRegion = proposals.getEndRegionPropStr();
|
||||||
String space = proposals.getSpacePropStr();
|
String space = proposals.getSpacePropStr();
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(lineSeparator).append(beginRegion).append(space).append(regionName);
|
if (moduleTextInsertInfo.getPosition() != 0)
|
||||||
builder.append(lineSeparator).append(content).append(lineSeparator);
|
{
|
||||||
|
builder.append(lineSeparator);
|
||||||
|
}
|
||||||
|
builder.append(beginRegion).append(space).append(regionName);
|
||||||
|
builder.append(content);
|
||||||
builder.append(endRegion);
|
builder.append(endRegion);
|
||||||
builder.append(lineSeparator);
|
if (moduleTextInsertInfo.getPosition() == 0)
|
||||||
|
{
|
||||||
|
builder.append(lineSeparator);
|
||||||
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,6 +195,10 @@ public class BslModuleRegionsInfoService
|
|||||||
regionOffsets.put(declaredRegionName, moduleRegionInformation);
|
regionOffsets.put(declaredRegionName, moduleRegionInformation);
|
||||||
if ((targetRegionName != null) && targetRegionName.equals(preprocessorRegionName))
|
if ((targetRegionName != null) && targetRegionName.equals(preprocessorRegionName))
|
||||||
{
|
{
|
||||||
|
if (node.getLength() == 0)
|
||||||
|
{
|
||||||
|
moduleRegionInformation.setNeedReplace();
|
||||||
|
}
|
||||||
return regionOffsets;
|
return regionOffsets;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,6 +216,7 @@ public class BslModuleRegionsInfoService
|
|||||||
int offset = defaultOffset;
|
int offset = defaultOffset;
|
||||||
boolean createNewRegion = !isRegionExists(regionOffsets, declaredRegionName, suffix);
|
boolean createNewRegion = !isRegionExists(regionOffsets, declaredRegionName, suffix);
|
||||||
BslModuleOffsets regionOffset = regionOffsets.get(declaredRegionName);
|
BslModuleOffsets regionOffset = regionOffsets.get(declaredRegionName);
|
||||||
|
|
||||||
if (regionOffset != null)
|
if (regionOffset != null)
|
||||||
{
|
{
|
||||||
if (!suffix.isEmpty())
|
if (!suffix.isEmpty())
|
||||||
@ -225,6 +254,8 @@ public class BslModuleRegionsInfoService
|
|||||||
boolean placeBefore = false;
|
boolean placeBefore = false;
|
||||||
int offset = regionOffsets.isEmpty() ? 0 : defaultOffset;
|
int offset = regionOffsets.isEmpty() ? 0 : defaultOffset;
|
||||||
ModuleStructureSection[] declaredRegionNames = ModuleStructureSection.values();
|
ModuleStructureSection[] declaredRegionNames = ModuleStructureSection.values();
|
||||||
|
BslModuleOffsets lastRegionInformation = null;
|
||||||
|
BslModuleOffsets regionInformation = null;
|
||||||
for (int regionNameIndex = 0; regionNameIndex < declaredRegionNames.length; regionNameIndex++)
|
for (int regionNameIndex = 0; regionNameIndex < declaredRegionNames.length; regionNameIndex++)
|
||||||
{
|
{
|
||||||
ModuleStructureSection moduleStructuredSection = declaredRegionNames[regionNameIndex];
|
ModuleStructureSection moduleStructuredSection = declaredRegionNames[regionNameIndex];
|
||||||
@ -233,12 +264,17 @@ public class BslModuleRegionsInfoService
|
|||||||
{
|
{
|
||||||
placeBefore = true;
|
placeBefore = true;
|
||||||
}
|
}
|
||||||
BslModuleOffsets regionInformation = regionOffsets.get(declaredRegionName);
|
if (regionInformation != null)
|
||||||
|
{
|
||||||
|
lastRegionInformation = regionInformation;
|
||||||
|
}
|
||||||
|
regionInformation = regionOffsets.get(declaredRegionName);
|
||||||
if (regionInformation != null)
|
if (regionInformation != null)
|
||||||
{
|
{
|
||||||
if (placeBefore && (suffix.isEmpty() || !declaredRegionName.equals(regionName)))
|
if (placeBefore && (suffix.isEmpty() || !declaredRegionName.equals(regionName)))
|
||||||
{
|
{
|
||||||
return regionInformation.getStartOffset();
|
return lastRegionInformation != null ? lastRegionInformation.getEndOffset()
|
||||||
|
: regionInformation.getStartOffset();
|
||||||
}
|
}
|
||||||
offset = placeBefore ? regionInformation.getStartOffset() : regionInformation.getEndOffset();
|
offset = placeBefore ? regionInformation.getStartOffset() : regionInformation.getEndOffset();
|
||||||
}
|
}
|
||||||
@ -246,20 +282,18 @@ public class BslModuleRegionsInfoService
|
|||||||
return offset;
|
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();
|
if (isInternal)
|
||||||
switch (moduleOwnerName)
|
|
||||||
{
|
{
|
||||||
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);
|
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)
|
private String getDeclaredRegionNameForForm(EventItemType itemType, ScriptVariant scriptVariant)
|
||||||
@ -287,8 +321,12 @@ public class BslModuleRegionsInfoService
|
|||||||
return ModuleStructureSection.EVENT_HANDLERS.getName(scriptVariant);
|
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))
|
if (itemType.equals(EventItemType.TABLE))
|
||||||
{
|
{
|
||||||
EObject container = eventOwner;
|
EObject container = eventOwner;
|
||||||
@ -318,4 +356,35 @@ public class BslModuleRegionsInfoService
|
|||||||
return regionName.length() >= declaredRegionNameLength
|
return regionName.length() >= declaredRegionNameLength
|
||||||
&& regionName.substring(0, declaredRegionNameLength).equals(declaredRegionName);
|
&& 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ Bundle-ActivationPolicy: lazy
|
|||||||
Import-Package: com._1c.g5.v8.bm.core;version="[8.0.0,9.0.0)",
|
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.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.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.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.contextdef;version="[2.0.0,3.0.0)",
|
||||||
com._1c.g5.v8.dt.bsl.documentation.comment;version="[4.0.0,5.0.0)",
|
com._1c.g5.v8.dt.bsl.documentation.comment;version="[4.0.0,5.0.0)",
|
||||||
com._1c.g5.v8.dt.bsl.model;version="[5.0.0,6.0.0)",
|
com._1c.g5.v8.dt.bsl.model;version="[5.0.0,6.0.0)",
|
||||||
|
Reference in New Issue
Block a user