Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vladimir.Orlov
2016-06-02 15:20:18 +03:00
11 changed files with 52 additions and 54 deletions
@@ -73,14 +73,6 @@ public class ArrayRenderer extends NodeRendererImpl{
return UNIQUE_ID;
}
public boolean isEnabled() {
return myProperties.isEnabled();
}
public void setEnabled(boolean enabled) {
myProperties.setEnabled(enabled);
}
public @NonNls String getName() {
return "Array";
}
@@ -98,16 +98,6 @@ public class ClassRenderer extends NodeRendererImpl{
return UNIQUE_ID;
}
@Override
public boolean isEnabled() {
return myProperties.isEnabled();
}
@Override
public void setEnabled(boolean enabled) {
myProperties.setEnabled(enabled);
}
@Override
public ClassRenderer clone() {
return (ClassRenderer) super.clone();
@@ -28,6 +28,7 @@ import com.intellij.psi.*;
import com.intellij.psi.impl.java.stubs.index.JavaAnonymousClassBaseRefOccurenceIndex;
import com.intellij.psi.impl.java.stubs.index.JavaSuperClassNameOccurenceIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.PsiSearchScopeUtil;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AllClassesSearch;
@@ -41,11 +42,9 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
/**
* @author max
@@ -71,7 +70,7 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
}
SearchScope scope = parameters.getScope();
PsiClass[] cache = getOrCalculateDirectSubClasses(project, baseClass);
PsiClass[] cache = getOrCalculateDirectSubClasses(project, baseClass, useScope);
if (cache.length == 0) {
return true;
@@ -132,7 +131,7 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
// The list starts with non-anonymous classes, ends with anonymous sub classes
// Classes grouped by their FQN. (Because among the same-named subclasses we should return only the same-jar ones, or all of them if there were none)
@NotNull
private static PsiClass[] getOrCalculateDirectSubClasses(@NotNull Project project, @NotNull PsiClass baseClass) {
private static PsiClass[] getOrCalculateDirectSubClasses(@NotNull Project project, @NotNull PsiClass baseClass, @NotNull SearchScope useScope) {
ConcurrentMap<PsiClass, PsiClass[]> map = HighlightingCaches.getInstance(project).DIRECT_SUB_CLASSES;
PsiClass[] cache = map.get(baseClass);
if (cache != null) {
@@ -143,7 +142,7 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
if (StringUtil.isEmpty(baseClassName)) {
return PsiClass.EMPTY_ARRAY;
}
cache = calculateDirectSubClasses(project, baseClass, baseClassName);
cache = calculateDirectSubClasses(project, baseClass, baseClassName, useScope);
// for non-physical elements ignore the cache completely because non-physical elements created so often/unpredictably so I can't figure out when to clear caches in this case
if (ApplicationManager.getApplication().runReadAction((Computable<Boolean>)baseClass::isPhysical)) {
cache = ConcurrencyUtil.cacheOrGet(map, baseClass, cache);
@@ -163,10 +162,22 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
}
@NotNull
private static PsiClass[] calculateDirectSubClasses(@NotNull Project project, @NotNull PsiClass baseClass, @NotNull String baseClassName) {
GlobalSearchScope allScope = GlobalSearchScope.allScope(project);
private static GlobalSearchScope toGlobal(@NotNull final SearchScope scope, @NotNull Project project) {
if (scope instanceof GlobalSearchScope) {
return (GlobalSearchScope)scope;
}
Set<VirtualFile> files = Arrays.stream(((LocalSearchScope)scope).getScope()).map(PsiUtil::getVirtualFile).collect(Collectors.toSet());
return GlobalSearchScope.filesScope(project, files);
}
@NotNull
private static PsiClass[] calculateDirectSubClasses(@NotNull Project project,
@NotNull PsiClass baseClass,
@NotNull String baseClassName,
@NotNull SearchScope useScope) {
GlobalSearchScope globalUseScope = ApplicationManager.getApplication().runReadAction((Computable<GlobalSearchScope>)()-> toGlobal(useScope, project));
Collection<PsiReferenceList> candidates =
MethodUsagesSearcher.resolveInReadAction(project, () -> JavaSuperClassNameOccurenceIndex.getInstance().get(baseClassName, project, allScope));
MethodUsagesSearcher.resolveInReadAction(project, () -> JavaSuperClassNameOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
// memory/speed optimisation: it really is a map(string -> PsiClass or List<PsiClass>)
final Map<String, Object> classes = new HashMap<>();
@@ -215,7 +226,7 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
}
Collection<PsiAnonymousClass> anonymousCandidates =
MethodUsagesSearcher.resolveInReadAction(project, () -> JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(baseClassName, project, allScope));
MethodUsagesSearcher.resolveInReadAction(project, () -> JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
processConcurrentlyIfTooMany(anonymousCandidates,
candidate-> {
@@ -77,11 +77,11 @@ public class InheritanceImplUtil {
String baseQName = baseClass.getQualifiedName();
if (baseQName == null) return false;
if (CommonClassNames.JAVA_LANG_ENUM.equals(baseQName)) {
return candidateClass.isEnum();
if (CommonClassNames.JAVA_LANG_ENUM.equals(baseQName) && candidateClass.isEnum()) {
return facade.findClass(baseQName, candidateClass.getResolveScope()) != null;
}
if (CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION.equals(baseQName)) {
return candidateClass.isAnnotationType();
if (CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION.equals(baseQName) && candidateClass.isAnnotationType()) {
return facade.findClass(baseQName, candidateClass.getResolveScope()) != null;
}
boolean isCandidateInterface = candidateClass.isInterface();
@@ -119,7 +119,8 @@ public class InheritanceImplUtil {
if (referenceElements.length != 0) {
GlobalSearchScope scope = extList.getResolveScope();
for (PsiJavaCodeReferenceElement ref : referenceElements) {
if (Comparing.equal(PsiNameHelper.getQualifiedClassName(ref.getQualifiedName(), false), baseQName) && facade.findClass(baseQName, scope) != null)
if (Comparing.equal(PsiNameHelper.getQualifiedClassName(ref.getQualifiedName(), false), baseQName)
&& facade.findClass(baseQName, scope) != null)
return true;
}
}
@@ -405,8 +405,8 @@ public class PsiClassImplUtil {
processDeclarationsInClassNotCached(myPsiClass, processor, ResolveState.initial(), null, null, myPsiClass, false,
PsiUtil.getLanguageLevel(myPsiClass), myResolveScope);
Map<String, PsiMember[]> result = ContainerUtil.newTroveMap();
for (Entry<String, List<PsiMember>> entry : map.entrySet()) {
result.put(entry.getKey(), entry.getValue().toArray(PsiMember.EMPTY_ARRAY));
for (String name : map.keySet()) {
result.put(name, map.get(name).toArray(PsiMember.EMPTY_ARRAY));
}
return result;
}
@@ -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.
@@ -49,7 +49,7 @@ import java.util.List;
public class LazyParseablePsiElement extends LazyParseableElement implements PsiElement, NavigationItem {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.LazyParseablePsiElement");
public LazyParseablePsiElement(@NotNull IElementType type, CharSequence buffer) {
public LazyParseablePsiElement(@NotNull IElementType type, @Nullable CharSequence buffer) {
super(type, buffer);
setPsi(this);
}
@@ -22,6 +22,7 @@ import com.intellij.concurrency.JobScheduler;
import com.intellij.diagnostic.LogEventException;
import com.intellij.diagnostic.PerformanceWatcher;
import com.intellij.diagnostic.ThreadDumper;
import com.intellij.execution.CommandLineUtil;
import com.intellij.ide.*;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.idea.IdeaApplication;
@@ -171,6 +172,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
myCommandLineMode = isCommandLine;
myDoNotSave = isUnitTestMode || isHeadless;
CommandLineUtil.VERBOSE_COMMAND_LINE_MODE = isUnitTestMode;
if (!isUnitTestMode && !isHeadless) {
Disposer.register(this, Disposer.newDisposable(), "ui");
@@ -21,7 +21,7 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.Iterator;
import java.util.Collections;
import java.util.List;
public class CommandLineUtil {
@@ -95,25 +95,27 @@ public class CommandLineUtil {
return s.length() >= 2 && s.charAt(0) == ch && s.charAt(s.length() - 1) == ch;
}
public static boolean VERBOSE_COMMAND_LINE_MODE;
@NotNull
public static String extractPresentableName(@NotNull String commandLine) {
String executable = commandLine.trim();
if (StringUtil.startsWithChar(executable, '\"') || StringUtil.startsWithChar(executable, '\'')) {
char quote = executable.charAt(0);
for (int i = 1; i < executable.length(); i++) {
if (executable.charAt(i) == quote &&
(executable.charAt(i - 1) != '\'' || StringUtil.isEscapedBackslash(executable, 0, i - 1))) {
executable = executable.substring(1, i);
break;
}
}
List<String> words = StringUtil.splitHonorQuotes(executable, ' ');
String execName;
List<String> args;
if (words.isEmpty()) {
execName = executable;
args = Collections.emptyList();
}
else {
Iterator<String> words = StringUtil.tokenize(commandLine, " \t\n\r\f").iterator();
executable = words.hasNext() ? words.next() : executable;
execName = words.get(0);
args = words.subList(1, words.size());
}
return new File(executable.trim()).getName();
if (VERBOSE_COMMAND_LINE_MODE) {
return StringUtil.firstLast(execName + " " + StringUtil.join(args, " "), 250);
}
return new File(StringUtil.unquoteString(execName)).getName();
}
}
@@ -274,7 +274,7 @@ public class BaseOSProcessHandler extends ProcessHandler implements TaskExecutor
private class SimpleOutputReader extends BaseOutputReader {
private final Key myProcessOutputType;
private SimpleOutputReader(Reader reader, Key outputType, Options options, String presentableName) {
private SimpleOutputReader(Reader reader, Key outputType, Options options, @NotNull String presentableName) {
super(reader, options);
myProcessOutputType = outputType;
start(presentableName);
@@ -41,7 +41,7 @@ public class ProcessWaitFor {
public void run() {
String oldThreadName = Thread.currentThread().getName();
if (!StringUtil.isEmptyOrSpaces(presentableName)) {
Thread.currentThread().setName(StringUtil.first("ProcessWaitFor: " + presentableName, 120, true));
Thread.currentThread().setName("ProcessWaitFor: " + presentableName);
}
int exitCode = 0;
try {
@@ -55,7 +55,7 @@ public abstract class BaseDataReader {
public void run() {
String oldThreadName = Thread.currentThread().getName();
if (!StringUtil.isEmptyOrSpaces(presentableName)) {
Thread.currentThread().setName(StringUtil.first("BaseDataReader: " + presentableName, 120, true));
Thread.currentThread().setName("BaseDataReader: " + presentableName);
}
try {
doRun();