GitOrigin-RevId: f506a673037f67634235969729ea6ad099a99c55
This commit is contained in:
Alexey Kudravtsev
2019-12-23 14:25:07 +03:00
committed by intellij-monorepo-bot
parent 5edb243cc3
commit 3e2e941004
7 changed files with 31 additions and 42 deletions

View File

@@ -75,11 +75,11 @@ public abstract class PsiShortNamesCache {
@NotNull
public abstract String[] getAllClassNames();
public boolean processAllClassNames(@NotNull Processor<String> processor) {
public boolean processAllClassNames(@NotNull Processor<? super String> processor) {
return ContainerUtil.process(getAllClassNames(), processor);
}
public boolean processAllClassNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
public boolean processAllClassNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
return ContainerUtil.process(getAllClassNames(), processor);
}
@@ -92,7 +92,7 @@ public abstract class PsiShortNamesCache {
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2020.2")
public void getAllClassNames(@NotNull HashSet<String> dest) {
public void getAllClassNames(@NotNull HashSet<? super String> dest) {
processAllClassNames(new CommonProcessors.CollectProcessor<>(dest));
}
@@ -123,11 +123,11 @@ public abstract class PsiShortNamesCache {
return processMethodsWithName(name, scope, method -> processor.process(method));
}
public boolean processAllMethodNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
public boolean processAllMethodNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
return ContainerUtil.process(getAllMethodNames(), processor);
}
public boolean processAllFieldNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
public boolean processAllFieldNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
return ContainerUtil.process(getAllFieldNames(), processor);
}

View File

@@ -83,7 +83,7 @@ public class CompositeShortNamesCache extends PsiShortNamesCache {
}
@Override
public boolean processAllClassNames(@NotNull Processor<String> processor) {
public boolean processAllClassNames(@NotNull Processor<? super String> processor) {
CommonProcessors.UniqueProcessor<String> uniqueProcessor = new CommonProcessors.UniqueProcessor<>(processor);
for (PsiShortNamesCache cache : myCaches) {
if (!cache.processAllClassNames(uniqueProcessor)) {
@@ -94,7 +94,7 @@ public class CompositeShortNamesCache extends PsiShortNamesCache {
}
@Override
public boolean processAllClassNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
public boolean processAllClassNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
for (PsiShortNamesCache cache : myCaches) {
if (!cache.processAllClassNames(processor, scope, filter)) {
return false;
@@ -104,7 +104,7 @@ public class CompositeShortNamesCache extends PsiShortNamesCache {
}
@Override
public boolean processAllMethodNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
public boolean processAllMethodNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
for (PsiShortNamesCache cache : myCaches) {
if (!cache.processAllMethodNames(processor, scope, filter)) {
return false;
@@ -114,7 +114,7 @@ public class CompositeShortNamesCache extends PsiShortNamesCache {
}
@Override
public boolean processAllFieldNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
public boolean processAllFieldNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
for (PsiShortNamesCache cache : myCaches) {
if (!cache.processAllFieldNames(processor, scope, filter)) {
return false;

View File

@@ -106,22 +106,22 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
}
@Override
public boolean processAllClassNames(@NotNull Processor<String> processor) {
public boolean processAllClassNames(@NotNull Processor<? super String> processor) {
return JavaShortClassNameIndex.getInstance().processAllKeys(myProject, processor);
}
@Override
public boolean processAllClassNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
public boolean processAllClassNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
return StubIndex.getInstance().processAllKeys(JavaStubIndexKeys.CLASS_SHORT_NAMES, processor, scope, filter);
}
@Override
public boolean processAllMethodNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
public boolean processAllMethodNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
return StubIndex.getInstance().processAllKeys(JavaStubIndexKeys.METHODS, processor, scope, filter);
}
@Override
public boolean processAllFieldNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
public boolean processAllFieldNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, IdFilter filter) {
return StubIndex.getInstance().processAllKeys(JavaStubIndexKeys.FIELDS, processor, scope, filter);
}

View File

@@ -10,7 +10,6 @@ import com.intellij.openapi.progress.ProgressIndicatorProvider;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
@@ -69,10 +68,10 @@ public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClas
return processClassesByNames(parameters.getProject(), scope, sorted, processor);
}
public static boolean processClassesByNames(Project project,
final GlobalSearchScope scope,
Collection<String> names,
Processor<? super PsiClass> processor) {
public static boolean processClassesByNames(@NotNull Project project,
@NotNull GlobalSearchScope scope,
@NotNull Collection<String> names,
@NotNull Processor<? super PsiClass> processor) {
final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
for (final String name : names) {
ProgressIndicatorProvider.checkCanceled();
@@ -86,8 +85,8 @@ public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClas
return true;
}
public static boolean processClassNames(final Project project, final GlobalSearchScope scope, final Processor<? super String> processor) {
boolean success = DumbService.getInstance(project).runReadActionInSmartMode((Computable<Boolean>)() ->
public static boolean processClassNames(@NotNull Project project, @NotNull GlobalSearchScope scope, @NotNull Processor<? super String> processor) {
boolean success = DumbService.getInstance(project).runReadActionInSmartMode(() ->
PsiShortNamesCache.getInstance(project).processAllClassNames(s -> {
ProgressManager.checkCanceled();
return processor.process(s);

View File

@@ -68,7 +68,8 @@ public class DomElementsHighlightingUtil {
TextRange range = s.first;
if (text == null) range = TextRange.from(range.getStartOffset(), 0);
range = range.shiftRight(s.second.getTextRange().getStartOffset());
final Annotation annotation = createAnnotation(severity, range, text);
String tooltip = text == null ? null : XmlStringUtil.wrapInHtml(XmlStringUtil.escapeString(text));
final Annotation annotation = new Annotation(range.getStartOffset(), range.getEndOffset(), severity, text, tooltip);
if (problemDescriptor instanceof DomElementResolveProblemDescriptor) {
annotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
@@ -81,13 +82,6 @@ public class DomElementsHighlightingUtil {
});
}
private static Annotation createAnnotation(final HighlightSeverity severity,
final TextRange range,
final String text) {
String tooltip = text == null ? null : XmlStringUtil.wrapInHtml(XmlStringUtil.escapeString(text));
return new Annotation(range.getStartOffset(), range.getEndOffset(), severity, text, tooltip);
}
@Nullable
private static <T> T createProblemDescriptors(DomElementProblemDescriptor problemDescriptor, Function<? super Pair<TextRange, PsiElement>, ? extends T> creator) {

View File

@@ -33,7 +33,9 @@ abstract class CommonAnnotationHolder<C> {
return new HolderAdapter<>(holder);
}
public abstract Annotation createAnnotation(C element, @NotNull HighlightSeverity severity, String message);
public abstract Annotation createAnnotation(@NotNull HighlightSeverity severity,
C element,
String message);
private static class DomHolderAdapter<T extends DomElement> extends CommonAnnotationHolder<T> {
private final DomElementAnnotationHolder myHolder;
@@ -43,7 +45,9 @@ abstract class CommonAnnotationHolder<C> {
}
@Override
public Annotation createAnnotation(DomElement element, @NotNull HighlightSeverity severity, String message) {
public Annotation createAnnotation(@NotNull HighlightSeverity severity,
DomElement element,
String message) {
final Annotation annotation = myHolder.createAnnotation(element, severity, message);
annotation.setTooltip(message); // no tooltip by default??
return annotation;
@@ -58,16 +62,8 @@ abstract class CommonAnnotationHolder<C> {
}
@Override
public Annotation createAnnotation(T element, @NotNull HighlightSeverity severity, String message) {
if (severity == HighlightSeverity.ERROR) {
return myHolder.createErrorAnnotation(element, message);
} else if (severity == HighlightSeverity.WARNING) {
return myHolder.createWarningAnnotation(element, message);
} else if (severity == HighlightSeverity.WEAK_WARNING) {
return myHolder.createWeakWarningAnnotation(element, message);
} else {
return myHolder.createInfoAnnotation(element, message);
}
public Annotation createAnnotation(@NotNull HighlightSeverity severity, T element, String message) {
return myHolder.createAnnotation(severity, element.getTextRange(), message);
}
}
}

View File

@@ -97,7 +97,7 @@ public final class ModelAnnotator implements Annotator, DomElementsAnnotator {
@SuppressWarnings({ "unchecked" })
private void createGutterAnnotation(CommonElement t, GutterIconRenderer renderer) {
final Annotation a = myHolder.createAnnotation((T)t, HighlightSeverity.INFORMATION, null);
final Annotation a = myHolder.createAnnotation(HighlightSeverity.INFORMATION, (T)t, null);
a.setGutterIconRenderer(renderer);
}
@@ -117,7 +117,7 @@ public final class ModelAnnotator implements Annotator, DomElementsAnnotator {
final Set<Define> set = map.get(define.getName());
if (set == null || set.size() == 0) {
//noinspection unchecked
myHolder.createAnnotation((T)define, HighlightSeverity.ERROR, "Definition doesn't override anything from " + file.getName());
myHolder.createAnnotation(HighlightSeverity.ERROR, (T)define, "Definition doesn't override anything from " + file.getName());
continue;
}