mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Merge branch 'master' into upsource-master
Conflicts: plugins/gettext/src/com/jetbrains/gettext/highlighter/GetTextHighlighterData.java
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.openapi.fileEditor.impl.EditorFileSwapper;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite;
|
||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorImpl;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
@@ -66,7 +67,7 @@ public class JavaEditorFileSwapper extends EditorFileSwapper {
|
||||
|
||||
if (member != null) {
|
||||
PsiElement navigationElement = member.getNavigationElement();
|
||||
if (navigationElement.getContainingFile().getVirtualFile() == sourceFile) {
|
||||
if (Comparing.equal(navigationElement.getContainingFile().getVirtualFile(), sourceFile)) {
|
||||
position = navigationElement.getTextOffset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
myInLibrary = fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile);
|
||||
|
||||
myRefCountHolder = RefCountHolder.endUsing(myFile);
|
||||
if (myRefCountHolder == null || !myRefCountHolder.retrieveUnusedReferencesInfo(new Runnable() {
|
||||
if (myRefCountHolder == null || !myRefCountHolder.retrieveUnusedReferencesInfo((DaemonProgressIndicator)progress, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean errorFound = collectHighlights(elementSet, highlights, progress);
|
||||
|
||||
@@ -47,14 +47,9 @@ public class RefCountHolder {
|
||||
private final Map<PsiNamedElement, Boolean> myDclsUsedMap = new ConcurrentHashMap<PsiNamedElement, Boolean>();
|
||||
private final Map<PsiReference, PsiImportStatementBase> myImportStatements = new ConcurrentHashMap<PsiReference, PsiImportStatementBase>();
|
||||
private final Map<PsiElement,Boolean> myPossiblyDuplicateElements = new ConcurrentHashMap<PsiElement, Boolean>();
|
||||
private final AtomicReference<State> myState = new AtomicReference<State>(State.VIRGIN);
|
||||
|
||||
private enum State {
|
||||
VIRGIN, // just created or cleared
|
||||
BEING_WRITTEN_BY_GHP, // general highlighting pass is storing references during analysis
|
||||
READY, // may be used for highlighting unused stuff
|
||||
BEING_USED_BY_PHP, // post highlighting pass is retrieving info
|
||||
}
|
||||
private final AtomicReference<DaemonProgressIndicator> myState = new AtomicReference<DaemonProgressIndicator>(VIRGIN);
|
||||
private static final DaemonProgressIndicator VIRGIN = new DaemonProgressIndicator(); // just created or cleared
|
||||
private static final DaemonProgressIndicator READY = new DaemonProgressIndicator();
|
||||
|
||||
private static class HolderReference extends SoftReference<RefCountHolder> {
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@@ -122,20 +117,19 @@ public class RefCountHolder {
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
assertIsAnalyzing();
|
||||
myLocalRefsMap.clear();
|
||||
synchronized (myLocalRefsMap) {
|
||||
myLocalRefsMap.clear();
|
||||
}
|
||||
myImportStatements.clear();
|
||||
myDclsUsedMap.clear();
|
||||
myPossiblyDuplicateElements.clear();
|
||||
}
|
||||
|
||||
public void registerLocallyReferenced(@NotNull PsiNamedElement result) {
|
||||
assertIsAnalyzing();
|
||||
myDclsUsedMap.put(result,Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void registerReference(@NotNull PsiJavaReference ref, @NotNull JavaResolveResult resolveResult) {
|
||||
assertIsAnalyzing();
|
||||
PsiElement refElement = resolveResult.getElement();
|
||||
PsiFile psiFile = refElement == null ? null : refElement.getContainingFile();
|
||||
if (psiFile != null) psiFile = (PsiFile)psiFile.getNavigationElement(); // look at navigation elements because all references resolve into Cls elements when highlighting library source
|
||||
@@ -154,7 +148,6 @@ public class RefCountHolder {
|
||||
}
|
||||
|
||||
public boolean isRedundant(@NotNull PsiImportStatementBase importStatement) {
|
||||
assertIsRetrieving();
|
||||
return !myImportStatements.containsValue(importStatement);
|
||||
}
|
||||
|
||||
@@ -167,7 +160,6 @@ public class RefCountHolder {
|
||||
}
|
||||
|
||||
private void removeInvalidRefs() {
|
||||
assertIsAnalyzing();
|
||||
synchronized (myLocalRefsMap) {
|
||||
for(Iterator<PsiReference> iterator = myLocalRefsMap.keySet().iterator(); iterator.hasNext();){
|
||||
PsiReference ref = iterator.next();
|
||||
@@ -197,8 +189,10 @@ public class RefCountHolder {
|
||||
}
|
||||
|
||||
public boolean isReferenced(PsiNamedElement element) {
|
||||
assertIsRetrieving();
|
||||
List<PsiReference> array = myLocalRefsMap.getKeysByValue(element);
|
||||
List<PsiReference> array;
|
||||
synchronized (myLocalRefsMap) {
|
||||
array = myLocalRefsMap.getKeysByValue(element);
|
||||
}
|
||||
if (array != null && !array.isEmpty() && !isParameterUsedRecursively(element, array)) return true;
|
||||
|
||||
Boolean usedStatus = myDclsUsedMap.get(element);
|
||||
@@ -235,9 +229,11 @@ public class RefCountHolder {
|
||||
}
|
||||
|
||||
public boolean isReferencedForRead(@NotNull PsiElement element) {
|
||||
assertIsRetrieving();
|
||||
LOG.assertTrue(element instanceof PsiVariable);
|
||||
List<PsiReference> array = myLocalRefsMap.getKeysByValue(element);
|
||||
List<PsiReference> array;
|
||||
synchronized (myLocalRefsMap) {
|
||||
array = myLocalRefsMap.getKeysByValue(element);
|
||||
}
|
||||
if (array == null) return false;
|
||||
for (PsiReference ref : array) {
|
||||
PsiElement refElement = ref.getElement();
|
||||
@@ -257,9 +253,11 @@ public class RefCountHolder {
|
||||
}
|
||||
|
||||
public boolean isReferencedForWrite(@NotNull PsiElement element) {
|
||||
assertIsRetrieving();
|
||||
LOG.assertTrue(element instanceof PsiVariable);
|
||||
List<PsiReference> array = myLocalRefsMap.getKeysByValue(element);
|
||||
List<PsiReference> array;
|
||||
synchronized (myLocalRefsMap) {
|
||||
array = myLocalRefsMap.getKeysByValue(element);
|
||||
}
|
||||
if (array == null) return false;
|
||||
for (PsiReference ref : array) {
|
||||
final PsiElement refElement = ref.getElement();
|
||||
@@ -273,14 +271,14 @@ public class RefCountHolder {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean analyze(@NotNull PsiFile file, TextRange dirtyScope, @NotNull Runnable analyze) {
|
||||
State old = myState.get();
|
||||
myState.compareAndSet(State.READY, State.VIRGIN);
|
||||
if (!myState.compareAndSet(State.VIRGIN, State.BEING_WRITTEN_BY_GHP)) {
|
||||
log("a: failed to change " + old + "->" + State.BEING_WRITTEN_BY_GHP);
|
||||
public boolean analyze(@NotNull PsiFile file, TextRange dirtyScope, @NotNull Runnable analyze, @NotNull DaemonProgressIndicator indicator) {
|
||||
DaemonProgressIndicator old = myState.get();
|
||||
if (old != VIRGIN && old != READY) return false;
|
||||
if (!myState.compareAndSet(old, indicator)) {
|
||||
log("a: failed to change " + old + "->" + indicator);
|
||||
return false;
|
||||
}
|
||||
log("a: changed " + old + "->" + State.BEING_WRITTEN_BY_GHP);
|
||||
log("a: changed " + old + "->" + indicator);
|
||||
boolean finished = false;
|
||||
try {
|
||||
if (dirtyScope != null) {
|
||||
@@ -296,9 +294,9 @@ public class RefCountHolder {
|
||||
finished = true;
|
||||
}
|
||||
finally {
|
||||
boolean set = myState.compareAndSet(State.BEING_WRITTEN_BY_GHP, finished ? State.READY : State.VIRGIN);
|
||||
boolean set = myState.compareAndSet(indicator, finished ? READY : VIRGIN);
|
||||
assert set : myState.get();
|
||||
log("a: changed back " + State.BEING_WRITTEN_BY_GHP + "->" + (finished ? State.READY : State.VIRGIN));
|
||||
log("a: changed back " + indicator + "->" + (finished ? READY : VIRGIN));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -307,31 +305,21 @@ public class RefCountHolder {
|
||||
//System.err.println("RFC: "+s);
|
||||
}
|
||||
|
||||
public boolean retrieveUnusedReferencesInfo(@NotNull Runnable analyze) {
|
||||
State old = myState.get();
|
||||
if (!myState.compareAndSet(State.READY, State.BEING_USED_BY_PHP)) {
|
||||
log("r: failed to change " + old + "->" + State.BEING_USED_BY_PHP);
|
||||
public boolean retrieveUnusedReferencesInfo(@NotNull DaemonProgressIndicator indicator, @NotNull Runnable analyze) {
|
||||
DaemonProgressIndicator old = myState.get();
|
||||
if (!myState.compareAndSet(READY, indicator)) {
|
||||
log("r: failed to change " + old + "->" + indicator);
|
||||
return false;
|
||||
}
|
||||
log("r: changed " + old + "->" + State.BEING_USED_BY_PHP);
|
||||
log("r: changed " + old + "->" + indicator);
|
||||
try {
|
||||
analyze.run();
|
||||
}
|
||||
finally {
|
||||
boolean set = myState.compareAndSet(State.BEING_USED_BY_PHP, State.READY);
|
||||
boolean set = myState.compareAndSet(indicator, READY);
|
||||
assert set : myState.get();
|
||||
log("r: changed back " + State.BEING_USED_BY_PHP + "->" + State.READY);
|
||||
log("r: changed back " + indicator + "->" + READY);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void assertIsAnalyzing() {
|
||||
State state = myState.get();
|
||||
assert state == State.BEING_WRITTEN_BY_GHP : state;
|
||||
}
|
||||
private void assertIsRetrieving() {
|
||||
State state = myState.get();
|
||||
assert state == State.BEING_USED_BY_PHP : state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-1
@@ -24,6 +24,7 @@ import com.intellij.codeInsight.daemon.impl.quickfix.SetupJDKFix;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
@@ -131,7 +132,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myRefCountHolder = refCountHolder;
|
||||
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
|
||||
TextRange dirtyScope = document == null ? file.getTextRange() : fileStatusMap.getFileDirtyScope(document, Pass.UPDATE_ALL);
|
||||
success = refCountHolder.analyze(file, dirtyScope, action);
|
||||
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
success = indicator instanceof DaemonProgressIndicator && refCountHolder.analyze(file, dirtyScope, action, (DaemonProgressIndicator)indicator);
|
||||
}
|
||||
else {
|
||||
myRefCountHolder = null;
|
||||
|
||||
+2
-1
@@ -31,6 +31,7 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -77,7 +78,7 @@ public class PsiClassFavoriteNodeProvider extends FavoriteNodeProvider {
|
||||
public boolean elementContainsFile(final Object element, final VirtualFile vFile) {
|
||||
if (element instanceof PsiClass) {
|
||||
final PsiFile file = ((PsiClass)element).getContainingFile();
|
||||
if (file != null && file.getVirtualFile() == vFile) return true;
|
||||
if (file != null && Comparing.equal(file.getVirtualFile(), vFile)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension;
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.roots.ModuleRootModel;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -53,7 +54,8 @@ public class ExcludeCompilerOutputPolicy implements DirectoryIndexExcludePolicy
|
||||
@Override
|
||||
public boolean isExcludeRootForModule(final Module module, final VirtualFile excludeRoot) {
|
||||
final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
|
||||
return compilerModuleExtension.getCompilerOutputPath() == excludeRoot || compilerModuleExtension.getCompilerOutputPathForTests() == excludeRoot;
|
||||
return Comparing.equal(compilerModuleExtension.getCompilerOutputPath(), excludeRoot) ||
|
||||
Comparing.equal(compilerModuleExtension.getCompilerOutputPathForTests(), excludeRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +89,7 @@ public class ExcludeCompilerOutputPolicy implements DirectoryIndexExcludePolicy
|
||||
|
||||
private static boolean isEqualWithFileOrUrl(VirtualFile f, VirtualFile fileToCompareWith, String url) {
|
||||
if (fileToCompareWith != null) {
|
||||
if (fileToCompareWith == f) return true;
|
||||
if (Comparing.equal(fileToCompareWith, f)) return true;
|
||||
}
|
||||
else if (url != null) {
|
||||
if (FileUtil.pathsEqual(url, f.getUrl())) return true;
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.libraries.LibraryUtil;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -172,7 +173,7 @@ public class TreeModelBuilder {
|
||||
VirtualFile dir = null;
|
||||
public boolean processFile(VirtualFile fileOrDir) {
|
||||
if (!fileOrDir.isDirectory()) {
|
||||
if (lastParent != null && dir != fileOrDir.getParent()) {
|
||||
if (lastParent != null && !Comparing.equal(dir, fileOrDir.getParent())) {
|
||||
lastParent = null;
|
||||
}
|
||||
lastParent = buildFileNode(fileOrDir, lastParent);
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.ComponentWithBrowseButton;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -111,7 +112,7 @@ public abstract class JavaExtractSuperBaseDialog extends ExtractSuperBaseDialog<
|
||||
final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(sourceFile);
|
||||
if (sourceRoot != null) {
|
||||
for (PsiDirectory dir : directories) {
|
||||
if (fileIndex.getSourceRootForFile(dir.getVirtualFile()) == sourceRoot) {
|
||||
if (Comparing.equal(fileIndex.getSourceRootForFile(dir.getVirtualFile()), sourceRoot)) {
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-4
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.refactoring.move.moveClassesOrPackages;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.ui.ListCellRendererWrapper;
|
||||
import com.intellij.ide.util.DirectoryChooser;
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
@@ -122,7 +124,7 @@ public abstract class DestinationFolderComboBox extends ComboboxWithBrowseButton
|
||||
final ComboBoxModel model = getComboBox().getModel();
|
||||
for (int i = 0; i < model.getSize(); i++) {
|
||||
DirectoryChooser.ItemWrapper item = (DirectoryChooser.ItemWrapper)model.getElementAt(i);
|
||||
if (item != NULL_WRAPPER && fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()) == root) {
|
||||
if (item != NULL_WRAPPER && Comparing.equal(fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()), root)) {
|
||||
getComboBox().setSelectedItem(item);
|
||||
getComboBox().repaint();
|
||||
return;
|
||||
@@ -164,7 +166,9 @@ public abstract class DestinationFolderComboBox extends ComboboxWithBrowseButton
|
||||
}
|
||||
final PsiDirectory selectedPsiDirectory = selectedItem.getDirectory();
|
||||
VirtualFile selectedDestination = selectedPsiDirectory.getVirtualFile();
|
||||
if (showChooserWhenDefault && selectedDestination == myInitialTargetDirectory.getVirtualFile() && mySourceRoots.length > 1) {
|
||||
if (showChooserWhenDefault &&
|
||||
Comparing.equal(selectedDestination, myInitialTargetDirectory.getVirtualFile()) &&
|
||||
mySourceRoots.length > 1) {
|
||||
selectedDestination = MoveClassesOrPackagesUtil.chooseSourceRoot(targetPackage, mySourceRoots, myInitialTargetDirectory);
|
||||
}
|
||||
if (selectedDestination == null) return null;
|
||||
@@ -211,9 +215,10 @@ public abstract class DestinationFolderComboBox extends ComboboxWithBrowseButton
|
||||
DirectoryChooser.ItemWrapper itemWrapper = new DirectoryChooser.ItemWrapper(targetDirectory, pathsToCreate.get(targetDirectory));
|
||||
items.add(itemWrapper);
|
||||
final VirtualFile sourceRootForFile = fileIndex.getSourceRootForFile(targetDirectory.getVirtualFile());
|
||||
if (sourceRootForFile == initialTargetDirectorySourceRoot) {
|
||||
if (Comparing.equal(sourceRootForFile, initialTargetDirectorySourceRoot)) {
|
||||
initial = itemWrapper;
|
||||
} else if (sourceRootForFile == oldSelection) {
|
||||
}
|
||||
else if (Comparing.equal(sourceRootForFile, oldSelection)) {
|
||||
oldOne = itemWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public class MoveInnerDialog extends RefactoringDialog {
|
||||
final PsiDirectory[] directories = oldPackage.getDirectories();
|
||||
final VirtualFile root = projectRootManager.getFileIndex().getContentRootForFile(psiDirectory.getVirtualFile());
|
||||
for(PsiDirectory dir: directories) {
|
||||
if (projectRootManager.getFileIndex().getContentRootForFile(dir.getVirtualFile()) == root) {
|
||||
if (Comparing.equal(projectRootManager.getFileIndex().getContentRootForFile(dir.getVirtualFile()), root)) {
|
||||
initialDir = dir;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user