1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2026-05-19 18:35:35 +02:00

Взаимная блокировка потоков при установке strict types

This commit is contained in:
Vadim Geraskin
2026-02-03 19:00:07 +07:00
parent 7b49d300dd
commit d2c590db3a
3 changed files with 34 additions and 23 deletions
@@ -192,12 +192,11 @@ public class AddStrictTypeAnnotationHandler
return;
}
updateFiles(files, monitor);
updateFiles(files, project, monitor);
}
private void processMdObjects(IProject project, Collection<MdObject> mdObjects, IProgressMonitor monitor)
{
if (!project.isAccessible())
{
return;
@@ -213,13 +212,11 @@ public class AddStrictTypeAnnotationHandler
return;
}
updateFiles(files, monitor);
updateFiles(files, project, monitor);
}
private void processResources(IProject project, Collection<IResource> resources, IProgressMonitor monitor)
{
if (!project.isAccessible())
{
return;
@@ -244,8 +241,7 @@ public class AddStrictTypeAnnotationHandler
return;
}
updateFiles(files, monitor);
updateFiles(files, project, monitor);
}
private void appendFilesHierarchically(IResource resource, Collection<IFile> files, IProgressMonitor monitor)
@@ -278,7 +274,7 @@ public class AddStrictTypeAnnotationHandler
}
}
private void updateFiles(Collection<IFile> files, IProgressMonitor monitor)
private void updateFiles(Collection<IFile> files, IProject project, IProgressMonitor monitor)
{
monitor.beginTask(Messages.AddStrictTypeAnnotationHandler_Update_module_files, files.size());
@@ -289,7 +285,7 @@ public class AddStrictTypeAnnotationHandler
return;
}
addAnnotationIfAbsent(file, monitor);
addAnnotationIfAbsent(file, project, monitor);
monitor.worked(1);
}
@@ -312,7 +308,7 @@ public class AddStrictTypeAnnotationHandler
return false;
}
private void addAnnotationIfAbsent(IFile file, IProgressMonitor monitor)
private void addAnnotationIfAbsent(IFile file, IProject project, IProgressMonitor monitor)
{
if (monitor.isCanceled())
{
@@ -323,7 +319,7 @@ public class AddStrictTypeAnnotationHandler
if (!StrictTypeUtil.hasStrictTypeAnnotation(file)
&& modelEditingSupport.canEdit(createModuleProxy(file), EditingMode.DIRECT) && !monitor.isCanceled())
{
StrictTypeUtil.setStrictTypeAnnotation(file, monitor);
StrictTypeUtil.setStrictTypeAnnotation(file, project, monitor);
}
}
catch (CoreException | IOException e)
@@ -69,7 +69,7 @@ public class ModuleStrictTypesNewWizardRelatedModelsFactory
IFile bslFile = getModuleFile(module);
if (bslFile != null)
{
createOrUpdateModule(bslFile);
createOrUpdateModule(bslFile, project);
}
}
}
@@ -79,7 +79,7 @@ public class ModuleStrictTypesNewWizardRelatedModelsFactory
IFile bslFile = getModuleFile(formToAddModule, project);
if (bslFile != null)
{
createOrUpdateModule(bslFile);
createOrUpdateModule(bslFile, project);
EObject module = createBslProxyModule(bslFile);
createdModels.add(module);
@@ -88,7 +88,7 @@ public class ModuleStrictTypesNewWizardRelatedModelsFactory
}
private void createOrUpdateModule(IFile bslFile)
private void createOrUpdateModule(IFile bslFile, IProject project)
{
try
{
@@ -108,7 +108,7 @@ public class ModuleStrictTypesNewWizardRelatedModelsFactory
{
createParentFolders(bslFile);
}
StrictTypeUtil.setStrictTypeAnnotation(bslFile, new NullProgressMonitor());
StrictTypeUtil.setStrictTypeAnnotation(bslFile, project, new NullProgressMonitor());
}
catch (IOException | CoreException e)
{
@@ -12,6 +12,8 @@
*******************************************************************************/
package com.e1c.v8codestyle.bsl.strict;
import static org.eclipse.core.resources.IWorkspace.AVOID_UPDATE;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -23,9 +25,12 @@ import java.util.Iterator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.DefaultScope;
@@ -214,7 +219,7 @@ public final class StrictTypeUtil
* @throws IOException Signals that an I/O exception has occurred.
* @throws CoreException the core exception
*/
public static void setStrictTypeAnnotation(IFile bslFile, IProgressMonitor monitor)
public static void setStrictTypeAnnotation(IFile bslFile, IProject project, IProgressMonitor monitor)
throws IOException, CoreException
{
String currentCode = StringUtils.EMPTY;
@@ -249,17 +254,27 @@ public final class StrictTypeUtil
return;
}
try (InputStream in = new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));)
{
if (bslFile.exists())
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.run(runnableMonitor -> {
try (InputStream in = new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));)
{
bslFile.setContents(in, true, true, monitor);
if (bslFile.exists())
{
bslFile.setContents(in, true, true, monitor);
}
else
{
bslFile.create(in, true, monitor);
}
}
else
catch (IOException e)
{
bslFile.create(in, true, monitor);
IStatus status =
BslPlugin.createErrorStatus("Can't update bsl file with name: " + bslFile.getName(), e); //$NON-NLS-1$
BslPlugin.log(status);
}
}
}, project, AVOID_UPDATE, monitor);
}
private static int getInsertOffset(String currentCode, String preferedLineSeparator)