mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-02-21 07:56:09 +02:00
Merge pull request #1369 from 1C-Company/G5V8DT-24189
G5V8DT-24189 При добавлении обработчика события или команды автоматически размещать его в соответствующей области
This commit is contained in:
commit
b441ad5b12
@ -23,10 +23,13 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.0
|
||||
com._1c.g5.v8.dt.bsl.common;version="[6.0.0,7.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.util;version="[4.7.0,5.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.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.editor;version="[9.0.0,10.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.quickfix;version="[4.1.0,5.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.util;version="[8.0.0,9.0.0)",
|
||||
@ -34,6 +37,7 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.0
|
||||
com._1c.g5.v8.dt.core.filesystem;version="[6.0.0,7.0.0)",
|
||||
com._1c.g5.v8.dt.core.model;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.form.model;version="[11.1.0,12.0.0)",
|
||||
com._1c.g5.v8.dt.lcore.ui.texteditor;version="[1.1.0,2.0.0)",
|
||||
com._1c.g5.v8.dt.mcore;version="[7.0.0,8.0.0)",
|
||||
com._1c.g5.v8.dt.metadata.mdclass;version="[9.0.0,10.0.0)",
|
||||
|
@ -368,5 +368,11 @@
|
||||
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.ServerExecutionSafeModeFix">
|
||||
</fix>
|
||||
</extension>
|
||||
<extension
|
||||
point="com._1c.g5.v8.dt.bsl.ui.bslModuleTextInsertInfoService">
|
||||
<bslModuleTextInsertInfoService
|
||||
class="com.e1c.v8codestyle.internal.bsl.ui.services.BslModuleRegionsInfoService">
|
||||
</bslModuleTextInsertInfoService>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
@ -0,0 +1,156 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2023, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.bsl.ui.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
|
||||
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
|
||||
|
||||
/**
|
||||
* Provides offset and suffixes information of module region
|
||||
*
|
||||
* @author Kuznetsov Nikita
|
||||
*/
|
||||
public final class BslModuleOffsets
|
||||
{
|
||||
private int startOffset;
|
||||
private int endOffset;
|
||||
private int insertOffset;
|
||||
|
||||
private Map<String, BslModuleOffsets> suffixes;
|
||||
|
||||
/**
|
||||
* Create and calculate module region offsets
|
||||
*
|
||||
* @param document actual {@link IDocument} to get offsets from, can't be {@code null}
|
||||
* @param node {@link INode} to get offsets from, can't be {@code null}
|
||||
* @param nodeAfter {@link INode} to get offsets from, can't be {@code null}
|
||||
* @return module region information with calculated region offsets or {@code null}
|
||||
*/
|
||||
public static BslModuleOffsets create(IDocument document, INode node, INode nodeAfter)
|
||||
{
|
||||
try
|
||||
{
|
||||
int startLine = node.getTotalStartLine() - 1;
|
||||
int startOffset = document.getLineOffset((startLine <= 1) ? 0 : startLine);
|
||||
int endOffset = nodeAfter.getTotalOffset();
|
||||
int insertOffset = document.getLineOffset(document.getLineOfOffset(nodeAfter.getTotalOffset()));
|
||||
return new BslModuleOffsets(startOffset, endOffset, insertOffset);
|
||||
}
|
||||
catch (BadLocationException ex)
|
||||
{
|
||||
UiPlugin.log(UiPlugin.createErrorStatus("Can't create module region information", ex)); //$NON-NLS-1$
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns start offset of module region
|
||||
*
|
||||
* @return offset before region declaration
|
||||
*/
|
||||
public int getStartOffset()
|
||||
{
|
||||
return startOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns end offset of module region
|
||||
*
|
||||
* @return offset after region declaration
|
||||
*/
|
||||
public int getEndOffset()
|
||||
{
|
||||
return endOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns before end offset inside module region
|
||||
*
|
||||
* @return offset before end of region declaration
|
||||
*/
|
||||
public int getBeforeEndOffset()
|
||||
{
|
||||
return insertOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add suffix of the name of this module region
|
||||
*
|
||||
* @param suffix to add to suffixes map of this module region
|
||||
* @param document to update offsets, can't be {@code null}
|
||||
* @param node to update offsets, can't be {@code null}
|
||||
* @param nodeAfter to update offsets, can't be {@code null}
|
||||
*/
|
||||
public void addSuffix(String suffix, IDocument document, INode node, INode nodeAfter)
|
||||
{
|
||||
if (suffixes == null)
|
||||
{
|
||||
suffixes = new HashMap<>();
|
||||
}
|
||||
BslModuleOffsets suffixRegionInformation = create(document, node, nodeAfter);
|
||||
if (suffixRegionInformation != null)
|
||||
{
|
||||
suffixes.put(suffix, suffixRegionInformation);
|
||||
int suffixStartOffset = suffixRegionInformation.getStartOffset();
|
||||
int suffixEndOffset = suffixRegionInformation.getEndOffset();
|
||||
int suffixInsertOffset = suffixRegionInformation.getBeforeEndOffset();
|
||||
if (insertOffset < suffixInsertOffset)
|
||||
{
|
||||
insertOffset = suffixInsertOffset;
|
||||
endOffset = suffixEndOffset;
|
||||
}
|
||||
if (startOffset > suffixStartOffset)
|
||||
{
|
||||
startOffset = suffixStartOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is module region has suffixes
|
||||
*
|
||||
* @return {@code true} if module region has suffixes, {@code false} otherwise
|
||||
*/
|
||||
public boolean hasSuffixes()
|
||||
{
|
||||
return suffixes != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns module region information by suffix if exists
|
||||
*
|
||||
* @param suffix {@link String} suffix of declared name module region
|
||||
* @return {@link BslModuleOffsets} if suffix exists, {@code null} otherwise
|
||||
*/
|
||||
public BslModuleOffsets getInformationBySuffix(String suffix)
|
||||
{
|
||||
if (hasSuffixes())
|
||||
{
|
||||
return suffixes.get(suffix);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private BslModuleOffsets(int startOffset, int endOffset, int insertOffset)
|
||||
{
|
||||
this.startOffset = startOffset;
|
||||
this.endOffset = endOffset;
|
||||
this.insertOffset = insertOffset;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2023, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.bsl.ui.services;
|
||||
|
||||
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
|
||||
*
|
||||
* @author Kuznetsov Nikita
|
||||
*/
|
||||
public class BslModuleRegionsInfo
|
||||
implements IBslModuleTextInsertInfo
|
||||
{
|
||||
private final int insertPosition;
|
||||
private final Module module;
|
||||
private final String regionName;
|
||||
|
||||
/**
|
||||
* {@link BslModuleRegionsInfo} constructor
|
||||
*
|
||||
* @param insertPosition <code>int</code> insertion offset, cannot be negative
|
||||
* @param module current {@link Module}, cannot be <code>null</code>
|
||||
* @param regionName {@link String} region name, can be <code>null</code>
|
||||
*/
|
||||
public BslModuleRegionsInfo(int insertPosition, Module module, String regionName)
|
||||
{
|
||||
this.insertPosition = insertPosition;
|
||||
this.module = module;
|
||||
this.regionName = regionName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInsertPosition()
|
||||
{
|
||||
return insertPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module getModule()
|
||||
{
|
||||
return module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns region name
|
||||
*
|
||||
* @return {@link String} region name, can be <code>null</code>
|
||||
*/
|
||||
public String getRegionName()
|
||||
{
|
||||
return regionName;
|
||||
}
|
||||
}
|
@ -0,0 +1,311 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2023, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.bsl.ui.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
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.ui.editor.model.IXtextDocument;
|
||||
|
||||
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.IBslModuleTextInsertInfo;
|
||||
import com._1c.g5.v8.dt.bsl.common.IBslModuleTextInsertInfoService;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
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.event.BslModuleEventData;
|
||||
import com._1c.g5.v8.dt.common.PreferenceUtils;
|
||||
import com._1c.g5.v8.dt.common.StringUtils;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8Project;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com._1c.g5.v8.dt.form.model.FormPackage;
|
||||
import com._1c.g5.v8.dt.mcore.NamedElement;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
|
||||
import com.e1c.v8codestyle.bsl.ModuleStructureSection;
|
||||
|
||||
/**
|
||||
* Module regions related implementation of {@link IBslModuleTextInsertInfoService}
|
||||
*
|
||||
* @author Kuznetsov Nikita
|
||||
*/
|
||||
public class BslModuleRegionsInfoService
|
||||
implements IBslModuleTextInsertInfoService
|
||||
{
|
||||
@Override
|
||||
public IBslModuleTextInsertInfo getEventHandlerTextInsertInfo(IXtextDocument document, Module module,
|
||||
int defaultPosition, IBslModuleEventData data)
|
||||
{
|
||||
if (!(data instanceof BslModuleEventData))
|
||||
{
|
||||
return () -> defaultPosition;
|
||||
}
|
||||
URI moduleResourceUri = module.eResource().getURI();
|
||||
IResourceServiceProvider rsp =
|
||||
IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(moduleResourceUri);
|
||||
IV8ProjectManager projectManager = rsp.get(IV8ProjectManager.class);
|
||||
BslOwnerComputerService bslOwnerComputerService = rsp.get(BslOwnerComputerService.class);
|
||||
IV8Project project = projectManager.getProject(moduleResourceUri);
|
||||
EClass moduleOwner = bslOwnerComputerService.computeOwnerEClass(module);
|
||||
EObject eventOwner = data.getEventOwner();
|
||||
BslModuleEventData regionData = (BslModuleEventData)data;
|
||||
EventItemType itemType = regionData.getEventItemType();
|
||||
String suffix = getSuffix(eventOwner, itemType);
|
||||
List<RegionPreprocessor> regionPreprocessors = BslUtil.getAllRegionPreprocessors(module);
|
||||
ScriptVariant scriptVariant = project.getScriptVariant();
|
||||
String declaredRegionName = getDeclaredRegionName(moduleOwner, itemType, scriptVariant);
|
||||
Map<String, BslModuleOffsets> regionOffsets =
|
||||
getRegionOffsets(document, regionPreprocessors, declaredRegionName, scriptVariant);
|
||||
int offset = getRegionOffset(regionOffsets, declaredRegionName, suffix, defaultPosition, scriptVariant);
|
||||
String regionName = null;
|
||||
if (!isRegionExists(regionOffsets, declaredRegionName, suffix))
|
||||
{
|
||||
regionName = suffix.isEmpty() ? declaredRegionName : (declaredRegionName + suffix);
|
||||
}
|
||||
return new BslModuleRegionsInfo(offset, module, regionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String wrap(IBslModuleTextInsertInfo moduleTextInsertInfo, String content)
|
||||
{
|
||||
if (moduleTextInsertInfo instanceof BslModuleRegionsInfo)
|
||||
{
|
||||
BslModuleRegionsInfo moduleRegionInformation = (BslModuleRegionsInfo)moduleTextInsertInfo;
|
||||
Module module = moduleTextInsertInfo.getModule();
|
||||
String regionName = moduleRegionInformation.getRegionName();
|
||||
if (module != null && regionName != null)
|
||||
{
|
||||
URI moduleResourceUri = module.eResource().getURI();
|
||||
IResourceServiceProvider rsp =
|
||||
IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(moduleResourceUri);
|
||||
IV8ProjectManager projectManager = rsp.get(IV8ProjectManager.class);
|
||||
BslGeneratorMultiLangProposals proposals = rsp.get(BslGeneratorMultiLangProposals.class);
|
||||
IV8Project project = projectManager.getProject(moduleResourceUri);
|
||||
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);
|
||||
builder.append(endRegion);
|
||||
builder.append(lineSeparator);
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
private Map<String, BslModuleOffsets> getRegionOffsets(IXtextDocument document,
|
||||
List<RegionPreprocessor> regionPreprocessors, String targetRegionName, ScriptVariant scriptVariant)
|
||||
{
|
||||
ModuleStructureSection[] declaredRegionNames = ModuleStructureSection.values();
|
||||
Map<String, BslModuleOffsets> regionOffsets = new HashMap<>(declaredRegionNames.length / 2);
|
||||
for (RegionPreprocessor regionPreprocessor : regionPreprocessors)
|
||||
{
|
||||
INode nodeAfter = NodeModelUtils.findActualNodeFor(regionPreprocessor.getItemAfter());
|
||||
if (nodeAfter != null)
|
||||
{
|
||||
String preprocessorRegionName = regionPreprocessor.getName();
|
||||
for (int regionNameIndex = 0; regionNameIndex < declaredRegionNames.length; regionNameIndex++)
|
||||
{
|
||||
ModuleStructureSection moduleStructureSection = declaredRegionNames[regionNameIndex];
|
||||
String declaredRegionName = moduleStructureSection.getName(scriptVariant);
|
||||
if ((preprocessorRegionName != null)
|
||||
&& isMatchingRegion(preprocessorRegionName, declaredRegionName))
|
||||
{
|
||||
INode node = NodeModelUtils.findActualNodeFor(regionPreprocessor.getItem());
|
||||
if (node != null)
|
||||
{
|
||||
BslModuleOffsets moduleRegionInformation = null;
|
||||
if (!preprocessorRegionName.equals(declaredRegionName))
|
||||
{
|
||||
if (!moduleStructureSection.isSuffixed())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String suffix = getSuffixOfMatchingRegion(preprocessorRegionName, declaredRegionName);
|
||||
moduleRegionInformation = regionOffsets.get(declaredRegionName);
|
||||
if (moduleRegionInformation == null)
|
||||
{
|
||||
moduleRegionInformation = BslModuleOffsets.create(document, node, nodeAfter);
|
||||
if (moduleRegionInformation == null)
|
||||
{
|
||||
return regionOffsets;
|
||||
}
|
||||
}
|
||||
moduleRegionInformation.addSuffix(suffix, document, node, nodeAfter);
|
||||
}
|
||||
if (moduleRegionInformation == null && !moduleStructureSection.isSuffixed())
|
||||
{
|
||||
moduleRegionInformation = BslModuleOffsets.create(document, node, nodeAfter);
|
||||
}
|
||||
if (moduleRegionInformation != null)
|
||||
{
|
||||
regionOffsets.put(declaredRegionName, moduleRegionInformation);
|
||||
if ((targetRegionName != null) && targetRegionName.equals(preprocessorRegionName))
|
||||
{
|
||||
return regionOffsets;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return regionOffsets;
|
||||
}
|
||||
|
||||
private int getRegionOffset(Map<String, BslModuleOffsets> regionOffsets, String declaredRegionName, String suffix,
|
||||
int defaultOffset, ScriptVariant scriptVariant)
|
||||
{
|
||||
int offset = defaultOffset;
|
||||
boolean createNewRegion = !isRegionExists(regionOffsets, declaredRegionName, suffix);
|
||||
BslModuleOffsets regionOffset = regionOffsets.get(declaredRegionName);
|
||||
if (regionOffset != null)
|
||||
{
|
||||
if (!suffix.isEmpty())
|
||||
{
|
||||
BslModuleOffsets suffixedRegionInformation = regionOffset.getInformationBySuffix(suffix);
|
||||
if (suffixedRegionInformation != null)
|
||||
{
|
||||
return suffixedRegionInformation.getBeforeEndOffset();
|
||||
}
|
||||
else if (createNewRegion)
|
||||
{
|
||||
return getNewRegionOffset(regionOffsets, declaredRegionName, suffix, defaultOffset, scriptVariant);
|
||||
}
|
||||
}
|
||||
return regionOffset.getBeforeEndOffset();
|
||||
}
|
||||
if (createNewRegion)
|
||||
{
|
||||
return getNewRegionOffset(regionOffsets, declaredRegionName, suffix, defaultOffset, scriptVariant);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
private boolean isRegionExists(Map<String, BslModuleOffsets> regionOffsets, String declaredRegionName,
|
||||
String suffix)
|
||||
{
|
||||
BslModuleOffsets moduleRegionInformation = regionOffsets.get(declaredRegionName);
|
||||
return (moduleRegionInformation != null)
|
||||
&& (suffix.isEmpty() || moduleRegionInformation.getInformationBySuffix(suffix) != null);
|
||||
}
|
||||
|
||||
private int getNewRegionOffset(Map<String, BslModuleOffsets> regionOffsets, String regionName, String suffix,
|
||||
int defaultOffset, ScriptVariant scriptVariant)
|
||||
{
|
||||
boolean placeBefore = false;
|
||||
int offset = regionOffsets.isEmpty() ? 0 : defaultOffset;
|
||||
ModuleStructureSection[] declaredRegionNames = ModuleStructureSection.values();
|
||||
for (int regionNameIndex = 0; regionNameIndex < declaredRegionNames.length; regionNameIndex++)
|
||||
{
|
||||
ModuleStructureSection moduleStructuredSection = declaredRegionNames[regionNameIndex];
|
||||
String declaredRegionName = moduleStructuredSection.getName(scriptVariant);
|
||||
if (declaredRegionName.equals(regionName))
|
||||
{
|
||||
placeBefore = true;
|
||||
}
|
||||
BslModuleOffsets regionInformation = regionOffsets.get(declaredRegionName);
|
||||
if (regionInformation != null)
|
||||
{
|
||||
if (placeBefore && (suffix.isEmpty() || !declaredRegionName.equals(regionName)))
|
||||
{
|
||||
return regionInformation.getStartOffset();
|
||||
}
|
||||
offset = placeBefore ? regionInformation.getStartOffset() : regionInformation.getEndOffset();
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
private String getDeclaredRegionName(EClass moduleOwnerClass, EventItemType itemType, ScriptVariant scriptVariant)
|
||||
{
|
||||
String moduleOwnerName = moduleOwnerClass.getName();
|
||||
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);
|
||||
default:
|
||||
return getDefaultRegionName(scriptVariant);
|
||||
}
|
||||
}
|
||||
|
||||
private String getDeclaredRegionNameForForm(EventItemType itemType, ScriptVariant scriptVariant)
|
||||
{
|
||||
switch (itemType)
|
||||
{
|
||||
case MAIN:
|
||||
return ModuleStructureSection.FORM_EVENT_HANDLERS.getName(scriptVariant);
|
||||
case COMMAND:
|
||||
return ModuleStructureSection.FORM_COMMAND_EVENT_HANDLERS.getName(scriptVariant);
|
||||
case TABLE:
|
||||
return ModuleStructureSection.FORM_TABLE_ITEMS_EVENT_HANDLERS.getName(scriptVariant);
|
||||
default:
|
||||
return ModuleStructureSection.FORM_HEADER_ITEMS_EVENT_HANDLERS.getName(scriptVariant);
|
||||
}
|
||||
}
|
||||
|
||||
private String getPrivateRegionName(ScriptVariant scriptVariant)
|
||||
{
|
||||
return ModuleStructureSection.PRIVATE.getName(scriptVariant);
|
||||
}
|
||||
|
||||
private String getDefaultRegionName(ScriptVariant scriptVariant)
|
||||
{
|
||||
return ModuleStructureSection.EVENT_HANDLERS.getName(scriptVariant);
|
||||
}
|
||||
|
||||
private String getSuffix(EObject eventOwner, EventItemType itemType)
|
||||
{
|
||||
if (itemType.equals(EventItemType.TABLE))
|
||||
{
|
||||
EObject container;
|
||||
while ((container = eventOwner.eContainer()) != null)
|
||||
{
|
||||
if (container.eClass() == FormPackage.Literals.TABLE)
|
||||
{
|
||||
return ((NamedElement)container).getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
private String getSuffixOfMatchingRegion(String regionName, String declaredRegionName)
|
||||
{
|
||||
return regionName.substring(declaredRegionName.length(), regionName.length());
|
||||
}
|
||||
|
||||
private boolean isMatchingRegion(String regionName, String declaredRegionName)
|
||||
{
|
||||
int declaredRegionNameLength = declaredRegionName.length();
|
||||
return regionName.length() >= declaredRegionNameLength
|
||||
&& regionName.substring(0, declaredRegionNameLength).equals(declaredRegionName);
|
||||
}
|
||||
}
|
@ -15,29 +15,37 @@ package com.e1c.v8codestyle.bsl;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
|
||||
|
||||
/**
|
||||
* Standard module structure dually-named section.
|
||||
* Standard module structure dually-named section;
|
||||
* <br>Sorted by priority of module regions standard.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public enum ModuleStructureSection
|
||||
{
|
||||
PUBLIC("Public", "ПрограммныйИнтерфейс"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
INTERNAL("Internal", "СлужебныйПрограммныйИнтерфейс"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
PRIVATE("Private", "СлужебныеПроцедурыИФункции"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
VARIABLES("Variables", "ОписаниеПеременных"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
INITIALIZE("Initialize", "Инициализация"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
PUBLIC("Public", "ПрограммныйИнтерфейс"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
EVENT_HANDLERS("EventHandlers", "ОбработчикиСобытий"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
INTERNAL("Internal", "СлужебныйПрограммныйИнтерфейс"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
FORM_EVENT_HANDLERS("FormEventHandlers", "ОбработчикиСобытийФормы"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
FORM_HEADER_ITEMS_EVENT_HANDLERS("FormHeaderItemsEventHandlers", "ОбработчикиСобытийЭлементовШапкиФормы"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
FORM_TABLE_ITEMS_EVENT_HANDLERS("FormTableItemsEventHandlers", "ОбработчикиСобытийЭлементовТаблицыФормы", true), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
FORM_COMMAND_EVENT_HANDLERS("FormCommandsEventHandlers", "ОбработчикиКомандФормы"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
FORM_TABLE_ITEMS_EVENT_HANDLERS("FormTableItemsEventHandlers", "ОбработчикиСобытийЭлементовТаблицыФормы"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
PRIVATE("Private", "СлужебныеПроцедурыИФункции"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
INITIALIZE("Initialize", "Инициализация"), //$NON-NLS-1$ //$NON-NLS-2$
|
||||
DEPRECATED_REGION("Deprecated", "УстаревшиеПроцедурыИФункции"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private final String[] names;
|
||||
private final boolean isSuffixed;
|
||||
|
||||
ModuleStructureSection(String name, String nameRu, boolean isSuffixed)
|
||||
{
|
||||
this.names = new String[] { name, nameRu };
|
||||
this.isSuffixed = isSuffixed;
|
||||
}
|
||||
|
||||
ModuleStructureSection(String name, String nameRu)
|
||||
{
|
||||
this.names = new String[] { name, nameRu };
|
||||
this(name, nameRu, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,4 +69,13 @@ public enum ModuleStructureSection
|
||||
return names[scriptVariant.getValue()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is module region name used only with suffix
|
||||
*
|
||||
* @return <code>true</code> if region name must be suffixed, <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isSuffixed()
|
||||
{
|
||||
return isSuffixed;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
#Region EventHandlers
|
||||
|
||||
// Enter code here.
|
||||
|
||||
//%CURRENT_CODE%
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Private
|
||||
|
@ -6,9 +6,7 @@
|
||||
#Region FormEventHandlers
|
||||
|
||||
// Enter code here.
|
||||
|
||||
//%CURRENT_CODE%
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region FormHeaderItemsEventHandlers
|
||||
@ -17,12 +15,6 @@
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region FormTableItemsEventHandlers //<FromTableName>
|
||||
|
||||
// Enter code here.
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region FormCommandsEventHandlers
|
||||
|
||||
// Enter code here.
|
||||
|
@ -2,9 +2,7 @@
|
||||
#Область ОбработчикиСобытий
|
||||
|
||||
// Код процедур и функций
|
||||
|
||||
//%CURRENT_CODE%
|
||||
|
||||
#КонецОбласти
|
||||
|
||||
#Область СлужебныеПроцедурыИФункции
|
||||
|
@ -6,9 +6,7 @@
|
||||
#Область ОбработчикиСобытийФормы
|
||||
|
||||
// Код процедур и функций
|
||||
|
||||
//%CURRENT_CODE%
|
||||
|
||||
#КонецОбласти
|
||||
|
||||
#Область ОбработчикиСобытийЭлементовШапкиФормы
|
||||
@ -17,12 +15,6 @@
|
||||
|
||||
#КонецОбласти
|
||||
|
||||
#Область ОбработчикиСобытийЭлементовТаблицыФормы //<ИмяТаблицыФормы>
|
||||
|
||||
// Код процедур и функций
|
||||
|
||||
#КонецОбласти
|
||||
|
||||
#Область ОбработчикиКомандФормы
|
||||
|
||||
// Код процедур и функций
|
||||
|
Loading…
x
Reference in New Issue
Block a user