From 3f9a3776accbb42a0da9ccff7f4db963182320aa Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 15 Feb 2016 11:17:02 +0100 Subject: [PATCH] Cleanup (formatting; typos) --- .../com/intellij/ide/caches/FileContent.java | 6 +-- .../FileBasedIndexProjectHandler.java | 17 ++++--- .../util/indexing/UnindexedFilesUpdater.java | 9 ++-- .../openapi/project/CacheUpdateRunner.java | 8 ++-- .../openapi/project/FileContentQueue.java | 44 +++++++------------ 5 files changed, 36 insertions(+), 48 deletions(-) diff --git a/platform/core-api/src/com/intellij/ide/caches/FileContent.java b/platform/core-api/src/com/intellij/ide/caches/FileContent.java index c4c6d61c4513..ae97e3fd93ea 100644 --- a/platform/core-api/src/com/intellij/ide/caches/FileContent.java +++ b/platform/core-api/src/com/intellij/ide/caches/FileContent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.caches; import com.intellij.openapi.util.UserDataHolderBase; @@ -49,7 +48,6 @@ public class FileContent extends UserDataHolderBase { if (myCachedBytes == null) { myCachedBytes = myVirtualFile.isValid() ? myVirtualFile.contentsToByteArray(false) : ArrayUtil.EMPTY_BYTE_ARRAY; } - return myCachedBytes; } @@ -83,4 +81,4 @@ public class FileContent extends UserDataHolderBase { } return myCachedWritable == Boolean.TRUE; } -} +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java index 7815661e619f..7ae45e2d7b05 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,11 +46,16 @@ import java.util.Collection; public class FileBasedIndexProjectHandler extends AbstractProjectComponent implements IndexableFileSet { private static final Logger LOG = Logger.getInstance("#com.intellij.util.indexing.FileBasedIndexProjectHandler"); + private final FileBasedIndex myIndex; private final ProjectRootManagerEx myRootManager; private final FileTypeManager myFileTypeManager; - public FileBasedIndexProjectHandler(final FileBasedIndex index, final Project project, final ProjectRootManagerComponent rootManager, FileTypeManager ftManager, final ProjectManager projectManager) { + public FileBasedIndexProjectHandler(FileBasedIndex index, + Project project, + ProjectRootManagerComponent rootManager, + FileTypeManager ftManager, + ProjectManager projectManager) { super(project); myIndex = index; myRootManager = rootManager; @@ -58,10 +63,8 @@ public class FileBasedIndexProjectHandler extends AbstractProjectComponent imple if (ApplicationManager.getApplication().isInternal()) { project.getMessageBus().connect().subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() { - @Override - public void enteredDumbMode() { - } + public void enteredDumbMode() { } @Override public void exitDumbMode() { @@ -130,7 +133,7 @@ public class FileBasedIndexProjectHandler extends AbstractProjectComponent imple @Override public void disposeComponent() { - // done mostly for tests. In real life this is noop, because the set was removed on project closing + // done mostly for tests. In real life this is no-op, because the set was removed on project closing myIndex.removeIndexableSet(this); } @@ -140,8 +143,8 @@ public class FileBasedIndexProjectHandler extends AbstractProjectComponent imple if (!(i instanceof FileBasedIndexImpl)) { return null; } - final FileBasedIndexImpl index = (FileBasedIndexImpl)i; + final FileBasedIndexImpl index = (FileBasedIndexImpl)i; if (index.getChangedFileCount() < 20) { return null; } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java index e695d64ebe24..968495027cb5 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,8 +97,8 @@ public class UnindexedFilesUpdater extends DumbModeTask { indicator.setText(IdeBundle.message("progress.indexing.updating")); indexFiles(indicator, files); - snapshot.logResponsivenessSinceCreation("Unindexed files update"); + snapshot.logResponsivenessSinceCreation("Unindexed files update"); } private void indexFiles(ProgressIndicator indicator, List files) { @@ -119,8 +119,9 @@ public class UnindexedFilesUpdater extends DumbModeTask { catch (ProcessCanceledException e) { LOG.info("Unindexed files update canceled"); throw e; - } finally { + } + finally { myIndex.filesUpdateFinished(myProject); } } -} +} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java index cfc617d553fc..9d57ec1e0dc4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ public class CacheUpdateRunner { queue.queue(files, indicator); Consumer progressUpdater = new Consumer() { - // need set here to handle queue.pushbacks after checkCancelled() in order + // need set here to handle queue push-backs after checkCancelled() in order // not to count the same file several times final Set processed = new THashSet(); private boolean fileNameWasShown; @@ -256,7 +256,7 @@ public class CacheUpdateRunner { ); } catch (ProcessCanceledException e) { - myQueue.pushback(fileContent); + myQueue.pushBack(fileContent); return; } finally { @@ -269,4 +269,4 @@ public class CacheUpdateRunner { } } } -} +} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java b/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java index 508761a3f326..306f56835a63 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,22 +32,23 @@ import org.jetbrains.ide.PooledThreadExecutor; import java.io.IOException; import java.util.Collection; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; /** * @author peter */ -@SuppressWarnings({"SynchronizeOnThis"}) public class FileContentQueue { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.startup.FileContentQueue"); + private static final long MAX_SIZE_OF_BYTES_IN_QUEUE = 1024 * 1024; private static final long PROCESSED_FILE_BYTES_THRESHOLD = 1024 * 1024 * 3; private static final long LARGE_SIZE_REQUEST_THRESHOLD = PROCESSED_FILE_BYTES_THRESHOLD - 1024 * 300; // 300k for other threads + private static final int ourTasksNumber = + SystemProperties.getBooleanProperty("idea.allow.parallel.file.reading", true) ? CacheUpdateRunner.indexingThreadCount() : 1; + private static final ExecutorService ourExecutor = new BoundedTaskExecutor(PooledThreadExecutor.INSTANCE, ourTasksNumber); + // Unbounded (!) private final LinkedBlockingDeque myLoadedContents = new LinkedBlockingDeque(); private final AtomicInteger myContentsToLoad = new AtomicInteger(); @@ -58,12 +59,6 @@ public class FileContentQueue { private volatile long myBytesBeingProcessed; private volatile boolean myLargeSizeRequested; private final Object myProceedWithProcessingLock = new Object(); - private static final boolean ourAllowParallelFileReading = SystemProperties.getBooleanProperty("idea.allow.parallel.file.reading", true); - - private static final BoundedTaskExecutor ourLoadingContentsExecutor = new BoundedTaskExecutor( - PooledThreadExecutor.INSTANCE, - ourAllowParallelFileReading ? CacheUpdateRunner.indexingThreadCount() : 1 - ); public void queue(@NotNull Collection files, @NotNull final ProgressIndicator indicator) { int numberOfFiles = files.size(); @@ -72,9 +67,7 @@ public class FileContentQueue { // ABQ is more memory efficient for significant number of files (e.g. 500K) final BlockingQueue filesQueue = new ArrayBlockingQueue(numberOfFiles, false, files); - int maxFilesToBeLoadedInTheSameTime = ourAllowParallelFileReading ? CacheUpdateRunner.indexingThreadCount() : 1; - - for(int i = 0 ; i < maxFilesToBeLoadedInTheSameTime; ++i) { + for (int i = 0; i < ourTasksNumber; ++i) { Runnable task = new Runnable() { @Override public void run() { @@ -85,7 +78,7 @@ public class FileContentQueue { myLoadedContents.offer(loadContent(file, indicator)); // With loop contents of second / remaining projects will start loading only after finishing loading contents from first project. // With resubmit loading of contents of second/remaining projects will also proceed - ourLoadingContentsExecutor.submit(this); + ourExecutor.submit(this); } catch (ProcessCanceledException e) { // Do nothing, exit the thread. @@ -98,22 +91,15 @@ public class FileContentQueue { } } }; - ourLoadingContentsExecutor.submit(task); + ourExecutor.submit(task); } } - private FileContent loadContent(@NotNull VirtualFile file, @NotNull final ProgressIndicator indicator) throws InterruptedException { + private FileContent loadContent(@NotNull VirtualFile file, @NotNull ProgressIndicator indicator) throws InterruptedException { FileContent content = new FileContent(file); - - if (isValidFile(file)) { - if (!doLoadContent(content, indicator)) { - content.setEmptyContent(); - } - } - else { + if (!isValidFile(file) || !doLoadContent(content, indicator)) { content.setEmptyContent(); } - return content; } @@ -180,7 +166,7 @@ public class FileContentQueue { indicator.checkCanceled(); } catch (ProcessCanceledException e) { - pushback(content); + pushBack(content); throw e; } @@ -246,10 +232,10 @@ public class FileContentQueue { } } - public void pushback(@NotNull FileContent content) { + public void pushBack(@NotNull FileContent content) { synchronized (myProceedWithLoadingLock) { myLoadedBytesInQueue += content.getLength(); } myLoadedContents.addFirst(content); } -} +} \ No newline at end of file