mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2024-12-01 02:32:18 +02:00
parent
aae9923819
commit
adb8599d21
@ -12,6 +12,7 @@
|
||||
- Выбор подходящего тип общего модуля из списка при создании нового
|
||||
- Панель "Bsl Документирующий комментарий"
|
||||
- Автоматическое создание структуры модуля
|
||||
- Автоматическое включение строгой типизации модулей
|
||||
|
||||
### Новые проверки
|
||||
|
||||
|
@ -127,6 +127,87 @@
|
||||
<modelClass eClass="DimensionTableForm" />
|
||||
</triggers>
|
||||
</factory>
|
||||
<factory
|
||||
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.internal.bsl.ui.wizard.ModuleStrictTypesNewWizardRelatedModelsFactory"
|
||||
order="220">
|
||||
<triggers>
|
||||
<modelClass eClass="Configuration" />
|
||||
<modelClass eClass="CatalogForm" />
|
||||
<modelClass eClass="DocumentForm" />
|
||||
<modelClass eClass="EnumForm" />
|
||||
<modelClass eClass="ChartOfCharacteristicTypesForm" />
|
||||
<modelClass eClass="InformationRegisterForm" />
|
||||
<modelClass eClass="DocumentJournalForm" />
|
||||
<modelClass eClass="ExchangePlanForm" />
|
||||
<modelClass eClass="DataProcessorForm" />
|
||||
<modelClass eClass="AccumulationRegisterForm" />
|
||||
<modelClass eClass="ReportForm" />
|
||||
<modelClass eClass="CommonModule" />
|
||||
<modelClass eClass="Bot" />
|
||||
<modelClass eClass="IntegrationService" />
|
||||
<modelClass eClass="ExchangePlan" />
|
||||
<modelClass eClass="WebService" />
|
||||
<modelClass eClass="HTTPService" />
|
||||
<modelClass eClass="Constant" />
|
||||
<modelClass eClass="Document" />
|
||||
<modelClass eClass="Catalog" />
|
||||
<modelClass eClass="Document" />
|
||||
<modelClass eClass="Sequence" />
|
||||
<modelClass eClass="DocumentJournal" />
|
||||
<modelClass eClass="Report" />
|
||||
<modelClass eClass="ExternalReport" />
|
||||
<modelClass eClass="DataProcessor" />
|
||||
<modelClass eClass="ExternalDataProcessor" />
|
||||
<modelClass eClass="InformationRegister" />
|
||||
<modelClass eClass="AccumulationRegister" />
|
||||
<modelClass eClass="SettingsStorage" />
|
||||
<modelClass eClass="Enum" />
|
||||
<modelClass eClass="Task" />
|
||||
<modelClass eClass="BusinessProcess" />
|
||||
<modelClass eClass="Table" />
|
||||
<modelClass eClass="Cube" />
|
||||
<modelClass eClass="DimensionTable" />
|
||||
<modelClass eClass="AccumulationRegisterCommand" />
|
||||
<modelClass eClass="BusinessProcessCommand" />
|
||||
<modelClass eClass="CatalogCommand" />
|
||||
<modelClass eClass="ChartOfCharacteristicTypesCommand" />
|
||||
<modelClass eClass="CommonCommand" />
|
||||
<modelClass eClass="DataProcessorCommand" />
|
||||
<modelClass eClass="DocumentCommand" />
|
||||
<modelClass eClass="DocumentJournalCommand" />
|
||||
<modelClass eClass="EnumCommand" />
|
||||
<modelClass eClass="ExchangePlanCommand" />
|
||||
<modelClass eClass="FilterCriterionCommand" />
|
||||
<modelClass eClass="InformationRegisterCommand" />
|
||||
<modelClass eClass="ReportCommand" />
|
||||
<modelClass eClass="TaskCommand" />
|
||||
<modelClass eClass="TableCommand" />
|
||||
<modelClass eClass="CubeCommand" />
|
||||
<modelClass eClass="DimensionTableCommand" />
|
||||
<modelClass eClass="CommonForm" />
|
||||
<modelClass eClass="CatalogForm" />
|
||||
<modelClass eClass="DocumentForm" />
|
||||
<modelClass eClass="EnumForm" />
|
||||
<modelClass eClass="ChartOfAccountsForm" />
|
||||
<modelClass eClass="ChartOfCalculationTypesForm" />
|
||||
<modelClass eClass="ChartOfCharacteristicTypesForm" />
|
||||
<modelClass eClass="InformationRegisterForm" />
|
||||
<modelClass eClass="DocumentJournalForm" />
|
||||
<modelClass eClass="ExchangePlanForm" />
|
||||
<modelClass eClass="FilterCriterionForm" />
|
||||
<modelClass eClass="DataProcessorForm" />
|
||||
<modelClass eClass="AccountingRegisterForm" />
|
||||
<modelClass eClass="AccumulationRegisterForm" />
|
||||
<modelClass eClass="ReportForm" />
|
||||
<modelClass eClass="BusinessProcessForm" />
|
||||
<modelClass eClass="TaskForm" />
|
||||
<modelClass eClass="SettingsStorageForm" />
|
||||
<modelClass eClass="CalculationRegisterForm" />
|
||||
<modelClass eClass="TableForm" />
|
||||
<modelClass eClass="CubeForm" />
|
||||
<modelClass eClass="DimensionTableForm" />
|
||||
</triggers>
|
||||
</factory>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.propertyPages">
|
||||
|
@ -23,6 +23,7 @@ final class Messages
|
||||
{
|
||||
private static final String BUNDLE_NAME = "com.e1c.v8codestyle.internal.bsl.ui.preferences.messages"; //$NON-NLS-1$
|
||||
public static String ModuleStructurePreferencePage_Automatically_create_module_structure;
|
||||
public static String ModuleStructurePreferencePage_Automatically_create_strict_types_module;
|
||||
static
|
||||
{
|
||||
// initialize resource bundle
|
||||
|
@ -21,6 +21,7 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||
|
||||
import com.e1c.v8codestyle.bsl.IModuleStructureProvider;
|
||||
import com.e1c.v8codestyle.bsl.strict.StrictTypeUtil;
|
||||
|
||||
/**
|
||||
* The preference page of module structure settings.
|
||||
@ -47,9 +48,11 @@ public class ModuleStructurePreferencePage
|
||||
@Override
|
||||
public void createFieldEditors()
|
||||
{
|
||||
addField(new BooleanFieldEditor(StrictTypeUtil.PREF_KEY_CREATE_STRICT_TYPES,
|
||||
Messages.ModuleStructurePreferencePage_Automatically_create_strict_types_module, getFieldEditorParent()));
|
||||
|
||||
addField(new BooleanFieldEditor(IModuleStructureProvider.PREF_KEY_CREATE_STRUCTURE,
|
||||
Messages.ModuleStructurePreferencePage_Automatically_create_module_structure, getFieldEditorParent()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,3 +1,4 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
@ -12,3 +13,5 @@
|
||||
###############################################################################
|
||||
|
||||
ModuleStructurePreferencePage_Automatically_create_module_structure = &Automatically create module structure
|
||||
|
||||
ModuleStructurePreferencePage_Automatically_create_strict_types_module = Automatically add module strict-types annotation
|
||||
|
@ -1,3 +1,4 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
@ -13,3 +14,5 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
|
||||
ModuleStructurePreferencePage_Automatically_create_module_structure = &Автоматически создавать структуру модуля
|
||||
|
||||
ModuleStructurePreferencePage_Automatically_create_strict_types_module = Автоматически добавлять аннотацию строгой типизации модуля
|
||||
|
@ -23,6 +23,7 @@ final class Messages
|
||||
{
|
||||
private static final String BUNDLE_NAME = "com.e1c.v8codestyle.internal.bsl.ui.properties.messages"; //$NON-NLS-1$
|
||||
public static String ModuleStructurePropertyPage_Automatically_create_module_structure;
|
||||
public static String ModuleStructurePropertyPage_Automatically_create_strict_types_module;
|
||||
public static String ModuleStructurePropertyPage_Open_template;
|
||||
public static String ModuleStructurePropertyPage_Open_template_tooltip;
|
||||
public static String ModuleStructurePropertyPage_Save_custom_template_to_project_settings;
|
||||
|
@ -30,7 +30,6 @@ import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.preference.PreferenceDialog;
|
||||
import org.eclipse.jface.preference.PreferencePage;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
@ -54,6 +53,7 @@ import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
|
||||
import com._1c.g5.v8.dt.ui.util.OpenHelper;
|
||||
import com.e1c.v8codestyle.bsl.IModuleStructureProvider;
|
||||
import com.e1c.v8codestyle.bsl.strict.StrictTypeUtil;
|
||||
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@ -74,12 +74,16 @@ public class ModuleStructurePropertyPage
|
||||
|
||||
private Button createStructureButton;
|
||||
|
||||
private Button createStrictTypesButton;
|
||||
|
||||
private CheckboxTableViewer checkBoxViewer;
|
||||
|
||||
private final Set<ModuleType> existTemplates = new HashSet<>();
|
||||
|
||||
private boolean currentCreateStructure;
|
||||
|
||||
private boolean currentCreateStrictTypes;
|
||||
|
||||
private final OpenHelper openHelper = new OpenHelper();
|
||||
|
||||
/**
|
||||
@ -145,8 +149,10 @@ public class ModuleStructurePropertyPage
|
||||
{
|
||||
ProjectScope scope = new ProjectScope(getProject());
|
||||
IEclipsePreferences node = scope.getNode(IModuleStructureProvider.PREF_QUALIFIER);
|
||||
boolean value = createStructureButton.getSelection();
|
||||
node.putBoolean(IModuleStructureProvider.PREF_KEY_CREATE_STRUCTURE, value);
|
||||
boolean value1 = createStructureButton.getSelection();
|
||||
boolean value2 = createStrictTypesButton.getSelection();
|
||||
node.putBoolean(IModuleStructureProvider.PREF_KEY_CREATE_STRUCTURE, value1);
|
||||
node.putBoolean(StrictTypeUtil.PREF_KEY_CREATE_STRICT_TYPES, value2);
|
||||
try
|
||||
{
|
||||
node.flush();
|
||||
@ -156,7 +162,8 @@ public class ModuleStructurePropertyPage
|
||||
UiPlugin.logError(e);
|
||||
return false;
|
||||
}
|
||||
currentCreateStructure = value;
|
||||
currentCreateStructure = value1;
|
||||
currentCreateStrictTypes = value2;
|
||||
for (ModuleType type : ModuleType.VALUES)
|
||||
{
|
||||
if (checkBoxViewer.getChecked(type) && !existTemplates.contains(type))
|
||||
@ -232,6 +239,14 @@ public class ModuleStructurePropertyPage
|
||||
{
|
||||
Composite composite = createDefaultComposite(parent);
|
||||
|
||||
Label createStrictTypesLabel = new Label(composite, SWT.NONE);
|
||||
createStrictTypesLabel.setText(Messages.ModuleStructurePropertyPage_Automatically_create_strict_types_module);
|
||||
|
||||
currentCreateStrictTypes = StrictTypeUtil.canAddModuleStrictTypesAnnotation(getProject());
|
||||
|
||||
createStrictTypesButton = new Button(composite, SWT.CHECK);
|
||||
createStrictTypesButton.setSelection(currentCreateStrictTypes);
|
||||
|
||||
Label createStructureLabel = new Label(composite, SWT.NONE);
|
||||
createStructureLabel.setText(Messages.ModuleStructurePropertyPage_Automatically_create_module_structure);
|
||||
|
||||
@ -239,7 +254,6 @@ public class ModuleStructurePropertyPage
|
||||
|
||||
createStructureButton = new Button(composite, SWT.CHECK);
|
||||
createStructureButton.setSelection(currentCreateStructure);
|
||||
|
||||
}
|
||||
|
||||
private void addSeparator(Composite parent)
|
||||
@ -330,7 +344,8 @@ public class ModuleStructurePropertyPage
|
||||
|
||||
private boolean isDirty()
|
||||
{
|
||||
if (createStructureButton.getSelection() != currentCreateStructure)
|
||||
if (createStructureButton.getSelection() != currentCreateStructure
|
||||
|| createStrictTypesButton.getSelection() != currentCreateStrictTypes)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
@ -13,6 +14,8 @@
|
||||
|
||||
ModuleStructurePropertyPage_Automatically_create_module_structure = Automatically create module structure
|
||||
|
||||
ModuleStructurePropertyPage_Automatically_create_strict_types_module = Automatically add module strict-types annotation
|
||||
|
||||
ModuleStructurePropertyPage_Open_template = Open template
|
||||
|
||||
ModuleStructurePropertyPage_Open_template_tooltip = Open existing custom project template with saving settings.
|
||||
|
@ -1,3 +1,4 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
@ -14,6 +15,8 @@
|
||||
|
||||
ModuleStructurePropertyPage_Automatically_create_module_structure = Автоматически создавать структуру модуля
|
||||
|
||||
ModuleStructurePropertyPage_Automatically_create_strict_types_module = Автоматически добавлять аннотацию строгой типизации модуля
|
||||
|
||||
ModuleStructurePropertyPage_Open_template = Открыть шаблон
|
||||
|
||||
ModuleStructurePropertyPage_Open_template_tooltip = Открыть существующий шаблон проекта с сохранением настроек.
|
||||
|
@ -0,0 +1,141 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 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.wizard;
|
||||
|
||||
import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.MODULE;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.ABSTRACT_FORM__MODULE;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.InternalEObject;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.xtext.naming.QualifiedName;
|
||||
|
||||
import com._1c.g5.v8.bm.core.IBmObject;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com._1c.g5.v8.dt.common.FileUtil;
|
||||
import com._1c.g5.v8.dt.common.StringUtils;
|
||||
import com._1c.g5.v8.dt.core.filesystem.IQualifiedNameFilePathConverter;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.AbstractForm;
|
||||
import com._1c.g5.v8.dt.ui.wizards.IDtNewWizardRelatedModelsFactory;
|
||||
|
||||
/**
|
||||
* Abstract factory for creating module in new-wizard.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public abstract class AbstractModuleNewWizardRelatedModelsFactory
|
||||
implements IDtNewWizardRelatedModelsFactory<EObject>
|
||||
{
|
||||
|
||||
private static final String LINE_SEPARATOR_WIN = "\r\n"; //$NON-NLS-1$
|
||||
|
||||
private static final String LINE_SEPARATOR_LINUX = "\n"; //$NON-NLS-1$
|
||||
|
||||
protected final IQualifiedNameFilePathConverter qualifiedNameFilePathConverter;
|
||||
|
||||
/**
|
||||
* Instantiates a new abstract module new wizard related models factory.
|
||||
*
|
||||
* @param qualifiedNameFilePathConverter the qualified name file path converter, cannot be {@code null}.
|
||||
*/
|
||||
protected AbstractModuleNewWizardRelatedModelsFactory(
|
||||
IQualifiedNameFilePathConverter qualifiedNameFilePathConverter)
|
||||
{
|
||||
this.qualifiedNameFilePathConverter = qualifiedNameFilePathConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve line separator from text content.
|
||||
*
|
||||
* @param text the text, cannot be {@code null}.
|
||||
* @return the string of line separator.
|
||||
*/
|
||||
protected String resolveLineSeparator(String text)
|
||||
{
|
||||
return text.contains(LINE_SEPARATOR_WIN) ? LINE_SEPARATOR_WIN : LINE_SEPARATOR_LINUX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new BSL proxy module object.
|
||||
*
|
||||
* @param bslFile the BSL file, cannot be {@code null}.
|
||||
* @return the object of module, never returns {@code null}.
|
||||
*/
|
||||
protected EObject createBslProxyModule(IFile bslFile)
|
||||
{
|
||||
EObject module = EcoreUtil.create(MODULE);
|
||||
URI uri = URI.createPlatformResourceURI(bslFile.getFullPath().toString(), true).appendFragment("/0"); //$NON-NLS-1$
|
||||
((InternalEObject)module).eSetProxyURI(uri);
|
||||
return module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the module file.
|
||||
*
|
||||
* @param module the model, cannot be {@code null}.
|
||||
* @return the module file or {@code null} if module URI is not platform URI.
|
||||
*/
|
||||
protected IFile getModuleFile(Module module)
|
||||
{
|
||||
URI uri = EcoreUtil.getURI(module);
|
||||
|
||||
if (uri != null && uri.isPlatform())
|
||||
{
|
||||
IPath path = new Path(uri.trimFragment().toPlatformString(true));
|
||||
return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the module file of form.
|
||||
*
|
||||
* @param form the form, cannot be {@code null}.
|
||||
* @param project the project, cannot be {@code null}.
|
||||
* @return the module file
|
||||
*/
|
||||
protected IFile getModuleFile(AbstractForm form, IProject project)
|
||||
{
|
||||
String fqn = ((IBmObject)form).bmGetFqn();
|
||||
|
||||
QualifiedName name = QualifiedName.create(fqn).append(StringUtils.capitalize(ABSTRACT_FORM__MODULE.getName()));
|
||||
|
||||
IPath path = qualifiedNameFilePathConverter.getFilePath(name, MODULE);
|
||||
|
||||
return project.getFile(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a parent directories of file without exceptions.
|
||||
*
|
||||
* @param bslFile the BSL file, cannot be {@code null}.
|
||||
*/
|
||||
protected void createParentFolders(IFile bslFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileUtil.createParentFolders(bslFile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// skip if cannot create parent folders in other threads
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,195 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 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.wizard;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
|
||||
import com._1c.g5.v8.dt.bsl.documentation.comment.IBslCommentToken;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com._1c.g5.v8.dt.common.PreferenceUtils;
|
||||
import com._1c.g5.v8.dt.common.StringUtils;
|
||||
import com._1c.g5.v8.dt.core.filesystem.IQualifiedNameFilePathConverter;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.AbstractForm;
|
||||
import com._1c.g5.v8.dt.ui.wizards.IDtNewWizardContext;
|
||||
import com.e1c.v8codestyle.bsl.strict.StrictTypeUtil;
|
||||
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* A factory for creating strict-types module when creating new object in wizard.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class ModuleStrictTypesNewWizardRelatedModelsFactory
|
||||
extends AbstractModuleNewWizardRelatedModelsFactory
|
||||
{
|
||||
|
||||
@Inject
|
||||
public ModuleStrictTypesNewWizardRelatedModelsFactory(
|
||||
IQualifiedNameFilePathConverter qualifiedNameFilePathConverter)
|
||||
{
|
||||
super(qualifiedNameFilePathConverter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createModels(IDtNewWizardContext<EObject> context, Set<EObject> createdModels)
|
||||
{
|
||||
IProject project = context.getV8project().getProject();
|
||||
if (!StrictTypeUtil.canAddModuleStrictTypesAnnotation(project))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractForm formToAddModule = null;
|
||||
for (EObject model : context.getRelatedModels())
|
||||
{
|
||||
if (model instanceof AbstractForm)
|
||||
{
|
||||
formToAddModule = (AbstractForm)model;
|
||||
}
|
||||
else if (model instanceof Module)
|
||||
{
|
||||
formToAddModule = null;
|
||||
Module module = (Module)model;
|
||||
IFile bslFile = getModuleFile(module);
|
||||
if (bslFile != null)
|
||||
{
|
||||
createOrUpdateModule(bslFile, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (formToAddModule != null)
|
||||
{
|
||||
IFile bslFile = getModuleFile(formToAddModule, project);
|
||||
if (bslFile != null)
|
||||
{
|
||||
createOrUpdateModule(bslFile, context);
|
||||
|
||||
EObject module = createBslProxyModule(bslFile);
|
||||
createdModels.add(module);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createOrUpdateModule(IFile bslFile, IDtNewWizardContext<EObject> context)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bslFile.exists() && StrictTypeUtil.hasStrictTypeAnnotation(bslFile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (CoreException | IOException e)
|
||||
{
|
||||
UiPlugin.logError(e);
|
||||
}
|
||||
|
||||
String currentCode = StringUtils.EMPTY;
|
||||
if (bslFile.exists())
|
||||
{
|
||||
try (InputStream in = bslFile.getContents();
|
||||
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);)
|
||||
{
|
||||
currentCode = CharStreams.toString(reader);
|
||||
}
|
||||
catch (IOException | CoreException e)
|
||||
{
|
||||
IStatus status = UiPlugin.createErrorStatus("Can't read bsl file with name: " + bslFile.getName(), e); //$NON-NLS-1$
|
||||
UiPlugin.log(status);
|
||||
}
|
||||
}
|
||||
|
||||
IProject project = context.getV8project().getProject();
|
||||
String preferedLineSeparator = PreferenceUtils.getLineSeparator(project);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int insertOffset = getInsertOffset(currentCode);
|
||||
if (insertOffset > 0)
|
||||
{
|
||||
sb.append(currentCode.substring(0, insertOffset));
|
||||
sb.append(preferedLineSeparator);
|
||||
}
|
||||
|
||||
sb.append(IBslCommentToken.LINE_STARTER);
|
||||
sb.append(" "); //$NON-NLS-1$
|
||||
sb.append(StrictTypeUtil.STRICT_TYPE_ANNOTATION);
|
||||
sb.append(preferedLineSeparator);
|
||||
sb.append(preferedLineSeparator);
|
||||
sb.append(currentCode.substring(insertOffset));
|
||||
|
||||
try (InputStream in = new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));)
|
||||
{
|
||||
if (bslFile.exists())
|
||||
{
|
||||
bslFile.setContents(in, true, true, new NullProgressMonitor());
|
||||
}
|
||||
else
|
||||
{
|
||||
createParentFolders(bslFile);
|
||||
bslFile.create(in, true, new NullProgressMonitor());
|
||||
}
|
||||
}
|
||||
catch (CoreException | IOException e)
|
||||
{
|
||||
IStatus status = UiPlugin.createErrorStatus("Can't create bsl file with name: " + bslFile.getName(), e); //$NON-NLS-1$
|
||||
UiPlugin.log(status);
|
||||
}
|
||||
}
|
||||
|
||||
private int getInsertOffset(String currentCode)
|
||||
{
|
||||
int separator = resolveLineSeparator(currentCode).length();
|
||||
|
||||
int offset = 0;
|
||||
for (Iterator<String> iterator = currentCode.lines().iterator(); iterator.hasNext();)
|
||||
{
|
||||
if (offset > 0)
|
||||
{
|
||||
offset = offset + separator;
|
||||
}
|
||||
|
||||
String line = iterator.next();
|
||||
if (StringUtils.isBlank(line))
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
else if (!line.stripLeading().startsWith(IBslCommentToken.LINE_STARTER))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
offset = offset + line.length();
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -12,9 +12,6 @@
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.bsl.ui.wizard;
|
||||
|
||||
import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.MODULE;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.ABSTRACT_FORM__MODULE;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -26,30 +23,20 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.InternalEObject;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.xtext.naming.QualifiedName;
|
||||
|
||||
import com._1c.g5.v8.bm.core.IBmObject;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com._1c.g5.v8.dt.bsl.model.ModuleType;
|
||||
import com._1c.g5.v8.dt.bsl.util.BslUtil;
|
||||
import com._1c.g5.v8.dt.common.FileUtil;
|
||||
import com._1c.g5.v8.dt.common.PreferenceUtils;
|
||||
import com._1c.g5.v8.dt.common.StringUtils;
|
||||
import com._1c.g5.v8.dt.core.filesystem.IQualifiedNameFilePathConverter;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.AbstractForm;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
|
||||
import com._1c.g5.v8.dt.ui.wizards.IDtNewWizardContext;
|
||||
import com._1c.g5.v8.dt.ui.wizards.IDtNewWizardRelatedModelsFactory;
|
||||
import com.e1c.v8codestyle.bsl.IModuleStructureProvider;
|
||||
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
|
||||
import com.google.common.io.CharStreams;
|
||||
@ -61,17 +48,11 @@ import com.google.inject.Inject;
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class ModuleStructureNewWizardRelatedModelsFactory
|
||||
implements IDtNewWizardRelatedModelsFactory<EObject>
|
||||
extends AbstractModuleNewWizardRelatedModelsFactory
|
||||
{
|
||||
|
||||
private static final String CURRENT_CODE = "//%CURRENT_CODE%"; //$NON-NLS-1$
|
||||
|
||||
private static final String LINE_SEPARATOR_WIN = "\r\n"; //$NON-NLS-1$
|
||||
|
||||
private static final String LINE_SEPARATOR_LINUX = "\n"; //$NON-NLS-1$
|
||||
|
||||
private final IQualifiedNameFilePathConverter qualifiedNameFilePathConverter;
|
||||
|
||||
private final IModuleStructureProvider moduleStructureProvider;
|
||||
|
||||
/**
|
||||
@ -84,7 +65,7 @@ public class ModuleStructureNewWizardRelatedModelsFactory
|
||||
public ModuleStructureNewWizardRelatedModelsFactory(IQualifiedNameFilePathConverter qualifiedNameFilePathConverter,
|
||||
IModuleStructureProvider moduleStructureProvider)
|
||||
{
|
||||
this.qualifiedNameFilePathConverter = qualifiedNameFilePathConverter;
|
||||
super(qualifiedNameFilePathConverter);
|
||||
this.moduleStructureProvider = moduleStructureProvider;
|
||||
}
|
||||
|
||||
@ -198,52 +179,4 @@ public class ModuleStructureNewWizardRelatedModelsFactory
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveLineSeparator(String text)
|
||||
{
|
||||
return text.contains(LINE_SEPARATOR_WIN) ? LINE_SEPARATOR_WIN : LINE_SEPARATOR_LINUX;
|
||||
}
|
||||
|
||||
private EObject createBslProxyModule(IFile bslFile)
|
||||
{
|
||||
EObject module = EcoreUtil.create(MODULE);
|
||||
URI uri = URI.createPlatformResourceURI(bslFile.getFullPath().toString(), true).appendFragment("/0"); //$NON-NLS-1$
|
||||
((InternalEObject)module).eSetProxyURI(uri);
|
||||
return module;
|
||||
}
|
||||
|
||||
private IFile getModuleFile(Module model)
|
||||
{
|
||||
URI uri = EcoreUtil.getURI(model);
|
||||
|
||||
if (uri != null && uri.isPlatform())
|
||||
{
|
||||
IPath path = new Path(uri.trimFragment().toPlatformString(true));
|
||||
return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private IFile getModuleFile(AbstractForm model, IProject project)
|
||||
{
|
||||
String fqn = ((IBmObject)model).bmGetFqn();
|
||||
|
||||
QualifiedName name = QualifiedName.create(fqn).append(StringUtils.capitalize(ABSTRACT_FORM__MODULE.getName()));
|
||||
|
||||
IPath path = qualifiedNameFilePathConverter.getFilePath(name, MODULE);
|
||||
|
||||
return project.getFile(path);
|
||||
}
|
||||
|
||||
private void createParentFolders(IFile bslFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileUtil.createParentFolders(bslFile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// skip if cannot create parent folders in other threads
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,14 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.preferences.ConfigurationScope;
|
||||
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.EcoreUtil2;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
@ -28,6 +35,7 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import com._1c.g5.v8.dt.bsl.documentation.comment.BslCommentUtils;
|
||||
import com._1c.g5.v8.dt.bsl.documentation.comment.IBslCommentToken;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
|
||||
|
||||
/**
|
||||
* The utility class for strict-types system.
|
||||
@ -42,8 +50,33 @@ public final class StrictTypeUtil
|
||||
|
||||
public static final String BSL_FILE_EXTENSION = "bsl"; //$NON-NLS-1$
|
||||
|
||||
/** The preference root qualifier. */
|
||||
public static final String PREF_QUALIFIER = BslPlugin.PLUGIN_ID;
|
||||
|
||||
/** The key for preferences store the state of the creating module with {@code //@strict-types} annotation */
|
||||
public static final String PREF_KEY_CREATE_STRICT_TYPES = "addModuleStrictTypesAnnotation"; //$NON-NLS-1$
|
||||
|
||||
/** The default value of creating module with strict types. */
|
||||
public static final boolean PREF_DEFAULT_CREATE_STRICT_TYPES = true;
|
||||
|
||||
private static final int COMMENT_LENGTH = IBslCommentToken.LINE_STARTER.length();
|
||||
|
||||
/**
|
||||
* Can add module strict-types annotation for project.
|
||||
*
|
||||
* @param project the project, cannot be {@code null}.
|
||||
* @return true, if can create strict-types module for the project
|
||||
*/
|
||||
public static boolean canAddModuleStrictTypesAnnotation(IProject project)
|
||||
{
|
||||
ProjectScope scope = new ProjectScope(project);
|
||||
IScopeContext[] contexts =
|
||||
new IScopeContext[] { scope, InstanceScope.INSTANCE, ConfigurationScope.INSTANCE, DefaultScope.INSTANCE };
|
||||
|
||||
return Platform.getPreferencesService()
|
||||
.getBoolean(PREF_QUALIFIER, PREF_KEY_CREATE_STRICT_TYPES, PREF_DEFAULT_CREATE_STRICT_TYPES, contexts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for {@code @strict-types} annotation in BSL module file.
|
||||
*
|
||||
|
@ -16,6 +16,7 @@ import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||
|
||||
import com.e1c.v8codestyle.bsl.IModuleStructureProvider;
|
||||
import com.e1c.v8codestyle.bsl.strict.StrictTypeUtil;
|
||||
|
||||
/**
|
||||
* Initializer of default values for module structure service.
|
||||
@ -33,6 +34,9 @@ public class ModuleStructureProviderPreferenceInitializer
|
||||
.putBoolean(IModuleStructureProvider.PREF_KEY_CREATE_STRUCTURE,
|
||||
IModuleStructureProvider.PREF_DEFAULT_CREATE_STRUCTURE);
|
||||
|
||||
DefaultScope.INSTANCE.getNode(StrictTypeUtil.PREF_QUALIFIER)
|
||||
.putBoolean(StrictTypeUtil.PREF_KEY_CREATE_STRICT_TYPES, StrictTypeUtil.PREF_DEFAULT_CREATE_STRICT_TYPES);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user